Skip to content

Commit e2b5d7e

Browse files
committed
Auto merge of #43324 - Nashenas88:visit_locations, r=arielb1
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.
2 parents 6f815ca + 4b9acad commit e2b5d7e

File tree

4 files changed

+37
-23
lines changed

4 files changed

+37
-23
lines changed

Diff for: src/librustc/mir/visit.rs

+27-15
Original file line numberDiff line numberDiff line change
@@ -210,17 +210,20 @@ macro_rules! make_mir_visitor {
210210
}
211211

212212
fn visit_ty(&mut self,
213-
ty: & $($mutability)* Ty<'tcx>) {
213+
ty: & $($mutability)* Ty<'tcx>,
214+
_: Lookup) {
214215
self.super_ty(ty);
215216
}
216217

217218
fn visit_substs(&mut self,
218-
substs: & $($mutability)* &'tcx Substs<'tcx>) {
219+
substs: & $($mutability)* &'tcx Substs<'tcx>,
220+
_: Location) {
219221
self.super_substs(substs);
220222
}
221223

222224
fn visit_closure_substs(&mut self,
223-
substs: & $($mutability)* ClosureSubsts<'tcx>) {
225+
substs: & $($mutability)* ClosureSubsts<'tcx>,
226+
_: Location) {
224227
self.super_closure_substs(substs);
225228
}
226229

@@ -266,7 +269,11 @@ macro_rules! make_mir_visitor {
266269
self.visit_visibility_scope_data(scope);
267270
}
268271

269-
self.visit_ty(&$($mutability)* mir.return_ty);
272+
let lookup = Lookup::Src(SourceInfo {
273+
span: mir.span,
274+
scope: ARGUMENT_VISIBILITY_SCOPE,
275+
});
276+
self.visit_ty(&$($mutability)* mir.return_ty, lookup);
270277

271278
for local_decl in &$($mutability)* mir.local_decls {
272279
self.visit_local_decl(local_decl);
@@ -385,7 +392,7 @@ macro_rules! make_mir_visitor {
385392
ref values,
386393
ref targets } => {
387394
self.visit_operand(discr, source_location);
388-
self.visit_ty(switch_ty);
395+
self.visit_ty(switch_ty, Lookup::Loc(source_location));
389396
for value in &values[..] {
390397
self.visit_const_int(value, source_location);
391398
}
@@ -489,7 +496,7 @@ macro_rules! make_mir_visitor {
489496
ref $($mutability)* operand,
490497
ref $($mutability)* ty) => {
491498
self.visit_operand(operand, location);
492-
self.visit_ty(ty);
499+
self.visit_ty(ty, Lookup::Loc(location));
493500
}
494501

495502
Rvalue::BinaryOp(_bin_op,
@@ -511,28 +518,28 @@ macro_rules! make_mir_visitor {
511518
}
512519

513520
Rvalue::NullaryOp(_op, ref $($mutability)* ty) => {
514-
self.visit_ty(ty);
521+
self.visit_ty(ty, Lookup::Loc(location));
515522
}
516523

517524
Rvalue::Aggregate(ref $($mutability)* kind,
518525
ref $($mutability)* operands) => {
519526
let kind = &$($mutability)* **kind;
520527
match *kind {
521528
AggregateKind::Array(ref $($mutability)* ty) => {
522-
self.visit_ty(ty);
529+
self.visit_ty(ty, Lookup::Loc(location));
523530
}
524531
AggregateKind::Tuple => {
525532
}
526533
AggregateKind::Adt(_adt_def,
527534
_variant_index,
528535
ref $($mutability)* substs,
529536
_active_field_index) => {
530-
self.visit_substs(substs);
537+
self.visit_substs(substs, location);
531538
}
532539
AggregateKind::Closure(ref $($mutability)* def_id,
533540
ref $($mutability)* closure_substs) => {
534541
self.visit_def_id(def_id, location);
535-
self.visit_closure_substs(closure_substs);
542+
self.visit_closure_substs(closure_substs, location);
536543
}
537544
}
538545

@@ -581,7 +588,7 @@ macro_rules! make_mir_visitor {
581588
ref $($mutability)* ty,
582589
} = *static_;
583590
self.visit_def_id(def_id, location);
584-
self.visit_ty(ty);
591+
self.visit_ty(ty, Lookup::Loc(location));
585592
}
586593

587594
fn super_projection(&mut self,
@@ -611,7 +618,7 @@ macro_rules! make_mir_visitor {
611618
ProjectionElem::Subslice { from: _, to: _ } => {
612619
}
613620
ProjectionElem::Field(_field, ref $($mutability)* ty) => {
614-
self.visit_ty(ty);
621+
self.visit_ty(ty, Lookup::Loc(location));
615622
}
616623
ProjectionElem::Index(ref $($mutability)* operand) => {
617624
self.visit_operand(operand, location);
@@ -635,7 +642,7 @@ macro_rules! make_mir_visitor {
635642
is_user_variable: _,
636643
} = *local_decl;
637644

638-
self.visit_ty(ty);
645+
self.visit_ty(ty, Lookup::Src(*source_info));
639646
self.visit_source_info(source_info);
640647
}
641648

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

660667
self.visit_span(span);
661-
self.visit_ty(ty);
668+
self.visit_ty(ty, Lookup::Loc(location));
662669
self.visit_literal(literal, location);
663670
}
664671

@@ -669,7 +676,7 @@ macro_rules! make_mir_visitor {
669676
Literal::Item { ref $($mutability)* def_id,
670677
ref $($mutability)* substs } => {
671678
self.visit_def_id(def_id, location);
672-
self.visit_substs(substs);
679+
self.visit_substs(substs, location);
673680
}
674681
Literal::Value { ref $($mutability)* value } => {
675682
self.visit_const_val(value, location);
@@ -734,6 +741,11 @@ macro_rules! make_mir_visitor {
734741
make_mir_visitor!(Visitor,);
735742
make_mir_visitor!(MutVisitor,mut);
736743

744+
pub enum Lookup {
745+
Loc(Location),
746+
Src(SourceInfo),
747+
}
748+
737749
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
738750
pub enum LvalueContext<'tcx> {
739751
// Appears as LHS of an assignment

Diff for: src/librustc_mir/build/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use rustc::hir::def_id::DefId;
1717
use rustc::middle::region::CodeExtent;
1818
use rustc::mir::*;
1919
use rustc::mir::transform::MirSource;
20-
use rustc::mir::visit::MutVisitor;
20+
use rustc::mir::visit::{MutVisitor, Lookup};
2121
use rustc::ty::{self, Ty, TyCtxt};
2222
use rustc::ty::subst::Substs;
2323
use rustc::util::nodemap::NodeMap;
@@ -143,7 +143,7 @@ struct GlobalizeMir<'a, 'gcx: 'a> {
143143
}
144144

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

156-
fn visit_substs(&mut self, substs: &mut &'tcx Substs<'tcx>) {
156+
fn visit_substs(&mut self, substs: &mut &'tcx Substs<'tcx>, _: Location) {
157157
if let Some(lifted) = self.tcx.lift(substs) {
158158
*substs = lifted;
159159
} else {

Diff for: src/librustc_mir/transform/erase_regions.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use rustc::ty::subst::Substs;
1616
use rustc::ty::{Ty, TyCtxt, ClosureSubsts};
1717
use rustc::mir::*;
18-
use rustc::mir::visit::MutVisitor;
18+
use rustc::mir::visit::{MutVisitor, Lookup};
1919
use rustc::mir::transform::{MirPass, MirSource};
2020

2121
struct EraseRegionsVisitor<'a, 'tcx: 'a> {
@@ -31,12 +31,12 @@ impl<'a, 'tcx> EraseRegionsVisitor<'a, 'tcx> {
3131
}
3232

3333
impl<'a, 'tcx> MutVisitor<'tcx> for EraseRegionsVisitor<'a, 'tcx> {
34-
fn visit_ty(&mut self, ty: &mut Ty<'tcx>) {
34+
fn visit_ty(&mut self, ty: &mut Ty<'tcx>, _: Lookup) {
3535
let old_ty = *ty;
3636
*ty = self.tcx.erase_regions(&old_ty);
3737
}
3838

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

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

6464
fn visit_closure_substs(&mut self,
65-
substs: &mut ClosureSubsts<'tcx>) {
65+
substs: &mut ClosureSubsts<'tcx>,
66+
_: Location) {
6667
*substs = self.tcx.erase_regions(substs);
6768
}
6869

Diff for: src/librustc_passes/mir_stats.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,8 @@ impl<'a, 'tcx> mir_visit::Visitor<'tcx> for StatCollector<'a, 'tcx> {
279279
}
280280

281281
fn visit_closure_substs(&mut self,
282-
substs: &ClosureSubsts<'tcx>) {
282+
substs: &ClosureSubsts<'tcx>,
283+
_: Location) {
283284
self.record("ClosureSubsts", substs);
284285
self.super_closure_substs(substs);
285286
}

0 commit comments

Comments
 (0)