Skip to content

Commit

Permalink
Auto merge of #43324 - Nashenas88:visit_locations, r=arielb1
Browse files Browse the repository at this point in the history
Provide positional information when visiting ty, substs and closure_substs in MIR

This will enable the region renumbering portion of #43234 (non-lexical lifetimes). @nikomatsakis's current plan [here](https://gist.github.com/nikomatsakis/dfc27b28cd024eb25054b52bb11082f2) shows that we need spans of the original code to create new region variables, e.g. `self.infcx.next_region_var(infer::MiscVariable(span))`. The current visitor impls did not pass positional information (`Location` in some, `Span` and `SourceInfo` for others) for all types. I did not expand this to all visits, just the ones necessary for the above-mentioned plan.
  • Loading branch information
bors committed Jul 28, 2017
2 parents 6f815ca + 4b9acad commit e2b5d7e
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 23 deletions.
42 changes: 27 additions & 15 deletions src/librustc/mir/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,17 +210,20 @@ macro_rules! make_mir_visitor {
}

fn visit_ty(&mut self,
ty: & $($mutability)* Ty<'tcx>) {
ty: & $($mutability)* Ty<'tcx>,
_: Lookup) {
self.super_ty(ty);
}

fn visit_substs(&mut self,
substs: & $($mutability)* &'tcx Substs<'tcx>) {
substs: & $($mutability)* &'tcx Substs<'tcx>,
_: Location) {
self.super_substs(substs);
}

fn visit_closure_substs(&mut self,
substs: & $($mutability)* ClosureSubsts<'tcx>) {
substs: & $($mutability)* ClosureSubsts<'tcx>,
_: Location) {
self.super_closure_substs(substs);
}

Expand Down Expand Up @@ -266,7 +269,11 @@ macro_rules! make_mir_visitor {
self.visit_visibility_scope_data(scope);
}

self.visit_ty(&$($mutability)* mir.return_ty);
let lookup = Lookup::Src(SourceInfo {
span: mir.span,
scope: ARGUMENT_VISIBILITY_SCOPE,
});
self.visit_ty(&$($mutability)* mir.return_ty, lookup);

for local_decl in &$($mutability)* mir.local_decls {
self.visit_local_decl(local_decl);
Expand Down Expand Up @@ -385,7 +392,7 @@ macro_rules! make_mir_visitor {
ref values,
ref targets } => {
self.visit_operand(discr, source_location);
self.visit_ty(switch_ty);
self.visit_ty(switch_ty, Lookup::Loc(source_location));
for value in &values[..] {
self.visit_const_int(value, source_location);
}
Expand Down Expand Up @@ -489,7 +496,7 @@ macro_rules! make_mir_visitor {
ref $($mutability)* operand,
ref $($mutability)* ty) => {
self.visit_operand(operand, location);
self.visit_ty(ty);
self.visit_ty(ty, Lookup::Loc(location));
}

Rvalue::BinaryOp(_bin_op,
Expand All @@ -511,28 +518,28 @@ macro_rules! make_mir_visitor {
}

Rvalue::NullaryOp(_op, ref $($mutability)* ty) => {
self.visit_ty(ty);
self.visit_ty(ty, Lookup::Loc(location));
}

Rvalue::Aggregate(ref $($mutability)* kind,
ref $($mutability)* operands) => {
let kind = &$($mutability)* **kind;
match *kind {
AggregateKind::Array(ref $($mutability)* ty) => {
self.visit_ty(ty);
self.visit_ty(ty, Lookup::Loc(location));
}
AggregateKind::Tuple => {
}
AggregateKind::Adt(_adt_def,
_variant_index,
ref $($mutability)* substs,
_active_field_index) => {
self.visit_substs(substs);
self.visit_substs(substs, location);
}
AggregateKind::Closure(ref $($mutability)* def_id,
ref $($mutability)* closure_substs) => {
self.visit_def_id(def_id, location);
self.visit_closure_substs(closure_substs);
self.visit_closure_substs(closure_substs, location);
}
}

Expand Down Expand Up @@ -581,7 +588,7 @@ macro_rules! make_mir_visitor {
ref $($mutability)* ty,
} = *static_;
self.visit_def_id(def_id, location);
self.visit_ty(ty);
self.visit_ty(ty, Lookup::Loc(location));
}

fn super_projection(&mut self,
Expand Down Expand Up @@ -611,7 +618,7 @@ macro_rules! make_mir_visitor {
ProjectionElem::Subslice { from: _, to: _ } => {
}
ProjectionElem::Field(_field, ref $($mutability)* ty) => {
self.visit_ty(ty);
self.visit_ty(ty, Lookup::Loc(location));
}
ProjectionElem::Index(ref $($mutability)* operand) => {
self.visit_operand(operand, location);
Expand All @@ -635,7 +642,7 @@ macro_rules! make_mir_visitor {
is_user_variable: _,
} = *local_decl;

self.visit_ty(ty);
self.visit_ty(ty, Lookup::Src(*source_info));
self.visit_source_info(source_info);
}

Expand All @@ -658,7 +665,7 @@ macro_rules! make_mir_visitor {
} = *constant;

self.visit_span(span);
self.visit_ty(ty);
self.visit_ty(ty, Lookup::Loc(location));
self.visit_literal(literal, location);
}

Expand All @@ -669,7 +676,7 @@ macro_rules! make_mir_visitor {
Literal::Item { ref $($mutability)* def_id,
ref $($mutability)* substs } => {
self.visit_def_id(def_id, location);
self.visit_substs(substs);
self.visit_substs(substs, location);
}
Literal::Value { ref $($mutability)* value } => {
self.visit_const_val(value, location);
Expand Down Expand Up @@ -734,6 +741,11 @@ macro_rules! make_mir_visitor {
make_mir_visitor!(Visitor,);
make_mir_visitor!(MutVisitor,mut);

pub enum Lookup {
Loc(Location),
Src(SourceInfo),
}

#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum LvalueContext<'tcx> {
// Appears as LHS of an assignment
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_mir/build/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use rustc::hir::def_id::DefId;
use rustc::middle::region::CodeExtent;
use rustc::mir::*;
use rustc::mir::transform::MirSource;
use rustc::mir::visit::MutVisitor;
use rustc::mir::visit::{MutVisitor, Lookup};
use rustc::ty::{self, Ty, TyCtxt};
use rustc::ty::subst::Substs;
use rustc::util::nodemap::NodeMap;
Expand Down Expand Up @@ -143,7 +143,7 @@ struct GlobalizeMir<'a, 'gcx: 'a> {
}

impl<'a, 'gcx: 'tcx, 'tcx> MutVisitor<'tcx> for GlobalizeMir<'a, 'gcx> {
fn visit_ty(&mut self, ty: &mut Ty<'tcx>) {
fn visit_ty(&mut self, ty: &mut Ty<'tcx>, _: Lookup) {
if let Some(lifted) = self.tcx.lift(ty) {
*ty = lifted;
} else {
Expand All @@ -153,7 +153,7 @@ impl<'a, 'gcx: 'tcx, 'tcx> MutVisitor<'tcx> for GlobalizeMir<'a, 'gcx> {
}
}

fn visit_substs(&mut self, substs: &mut &'tcx Substs<'tcx>) {
fn visit_substs(&mut self, substs: &mut &'tcx Substs<'tcx>, _: Location) {
if let Some(lifted) = self.tcx.lift(substs) {
*substs = lifted;
} else {
Expand Down
9 changes: 5 additions & 4 deletions src/librustc_mir/transform/erase_regions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use rustc::ty::subst::Substs;
use rustc::ty::{Ty, TyCtxt, ClosureSubsts};
use rustc::mir::*;
use rustc::mir::visit::MutVisitor;
use rustc::mir::visit::{MutVisitor, Lookup};
use rustc::mir::transform::{MirPass, MirSource};

struct EraseRegionsVisitor<'a, 'tcx: 'a> {
Expand All @@ -31,12 +31,12 @@ impl<'a, 'tcx> EraseRegionsVisitor<'a, 'tcx> {
}

impl<'a, 'tcx> MutVisitor<'tcx> for EraseRegionsVisitor<'a, 'tcx> {
fn visit_ty(&mut self, ty: &mut Ty<'tcx>) {
fn visit_ty(&mut self, ty: &mut Ty<'tcx>, _: Lookup) {
let old_ty = *ty;
*ty = self.tcx.erase_regions(&old_ty);
}

fn visit_substs(&mut self, substs: &mut &'tcx Substs<'tcx>) {
fn visit_substs(&mut self, substs: &mut &'tcx Substs<'tcx>, _: Location) {
*substs = self.tcx.erase_regions(&{*substs});
}

Expand All @@ -62,7 +62,8 @@ impl<'a, 'tcx> MutVisitor<'tcx> for EraseRegionsVisitor<'a, 'tcx> {
}

fn visit_closure_substs(&mut self,
substs: &mut ClosureSubsts<'tcx>) {
substs: &mut ClosureSubsts<'tcx>,
_: Location) {
*substs = self.tcx.erase_regions(substs);
}

Expand Down
3 changes: 2 additions & 1 deletion src/librustc_passes/mir_stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,8 @@ impl<'a, 'tcx> mir_visit::Visitor<'tcx> for StatCollector<'a, 'tcx> {
}

fn visit_closure_substs(&mut self,
substs: &ClosureSubsts<'tcx>) {
substs: &ClosureSubsts<'tcx>,
_: Location) {
self.record("ClosureSubsts", substs);
self.super_closure_substs(substs);
}
Expand Down

0 comments on commit e2b5d7e

Please sign in to comment.