diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-06-06 22:39:10 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-06-06 22:39:10 +0200 |
| commit | 4c74056867e2df800b0932e5b78d8464d8dc449f (patch) | |
| tree | c7a75e1d5b3262acf2288dd6ab4212bd560ca764 | |
| parent | 654854fdb56ca204bab6b399bf59a8d753e2c13c (diff) | |
| parent | 67197e264af052c77b755031833a55dd586b974b (diff) | |
| download | rust-4c74056867e2df800b0932e5b78d8464d8dc449f.tar.gz rust-4c74056867e2df800b0932e5b78d8464d8dc449f.zip | |
Rollup merge of #61554 - spastorino:change_visit_api, r=oli-obk
Change visit api r? @oli-obk In the [first commit](https://github.com/rust-lang/rust/commit/37386d366a816bc2e63749c7b6045108a6167135) of this PR, I'm changing `visit_place` to be the function that traverses the `Place` and have only that responsibility. Then there are two other functions `visit_place_base` and `visit_projection` which are the ones in charge of visiting the base and the projection. Visitor implementors can implement any of those. In the [second commit](https://github.com/rust-lang/rust/commit/e786f631b815d171051279e0d6cfe055c75bec2e) we can already see some things that confuses me, which I think this division will make more clear. The old code, first checked if the place was a base, did something with it and then called `super_place` [here](https://github.com/rust-lang/rust/commit/e786f631b815d171051279e0d6cfe055c75bec2e#diff-d583e4efe1a72516e274158e53223633L678). `super_place` checks again if it's a base [here](https://github.com/rust-lang/rust/blob/master/src/librustc/mir/visit.rs#L679-L684) and in case is a local, visits the local and stuff like that. That's not very obvious on the code, and if I'm not wrong it's not needed. In this PR or we have [this](https://github.com/rust-lang/rust/commit/e786f631b815d171051279e0d6cfe055c75bec2e#diff-d583e4efe1a72516e274158e53223633R673) as I did or we can just do `- => self.super_place_base(...)` and that will be obvious that I'm letting the default implementation process the base.
| -rw-r--r-- | src/librustc/mir/visit.rs | 58 | ||||
| -rw-r--r-- | src/librustc_mir/monomorphize/collector.rs | 25 |
2 files changed, 44 insertions, 39 deletions
diff --git a/src/librustc/mir/visit.rs b/src/librustc/mir/visit.rs index dd33fae0d61..2f19f591830 100644 --- a/src/librustc/mir/visit.rs +++ b/src/librustc/mir/visit.rs @@ -151,17 +151,17 @@ macro_rules! make_mir_visitor { self.super_place(place, context, location); } - fn visit_projection(&mut self, - place: & $($mutability)? Projection<'tcx>, + fn visit_place_base(&mut self, + place_base: & $($mutability)? PlaceBase<'tcx>, context: PlaceContext, location: Location) { - self.super_projection(place, context, location); + self.super_place_base(place_base, context, location); } - fn visit_projection_elem(&mut self, - place: & $($mutability)? PlaceElem<'tcx>, - location: Location) { - self.super_projection_elem(place, location); + fn visit_projection(&mut self, + place: & $($mutability)? Projection<'tcx>, + location: Location) { + self.super_projection(place, location); } fn visit_constant(&mut self, @@ -676,36 +676,40 @@ macro_rules! make_mir_visitor { context: PlaceContext, location: Location) { match place { - Place::Base(PlaceBase::Local(local)) => { - self.visit_local(local, context, location); - } - Place::Base(PlaceBase::Static(box Static { kind: _, ty })) => { - self.visit_ty(& $($mutability)? *ty, TyContext::Location(location)); + Place::Base(place_base) => { + self.visit_place_base(place_base, context, location); } Place::Projection(proj) => { - self.visit_projection(proj, context, location); + let context = if context.is_mutating_use() { + PlaceContext::MutatingUse(MutatingUseContext::Projection) + } else { + PlaceContext::NonMutatingUse(NonMutatingUseContext::Projection) + }; + + self.visit_place(& $($mutability)? proj.base, context, location); + self.visit_projection(proj, location); } } } - fn super_projection(&mut self, - proj: & $($mutability)? Projection<'tcx>, + fn super_place_base(&mut self, + place_base: & $($mutability)? PlaceBase<'tcx>, context: PlaceContext, location: Location) { - let Projection { base, elem } = proj; - let context = if context.is_mutating_use() { - PlaceContext::MutatingUse(MutatingUseContext::Projection) - } else { - PlaceContext::NonMutatingUse(NonMutatingUseContext::Projection) - }; - self.visit_place(base, context, location); - self.visit_projection_elem(elem, location); + match place_base { + PlaceBase::Local(local) => { + self.visit_local(local, context, location); + } + PlaceBase::Static(box Static { kind: _, ty }) => { + self.visit_ty(& $($mutability)? *ty, TyContext::Location(location)); + } + } } - fn super_projection_elem(&mut self, - proj: & $($mutability)? PlaceElem<'tcx>, - location: Location) { - match proj { + fn super_projection(&mut self, + proj: & $($mutability)? Projection<'tcx>, + location: Location) { + match & $($mutability)? proj.elem { ProjectionElem::Deref => { } ProjectionElem::Subslice { from: _, to: _ } => { diff --git a/src/librustc_mir/monomorphize/collector.rs b/src/librustc_mir/monomorphize/collector.rs index eed051449e1..91b4af9655a 100644 --- a/src/librustc_mir/monomorphize/collector.rs +++ b/src/librustc_mir/monomorphize/collector.rs @@ -185,7 +185,7 @@ use rustc::ty::{self, TypeFoldable, Ty, TyCtxt, GenericParamDefKind, Instance}; use rustc::ty::print::obsolete::DefPathBasedNames; use rustc::ty::adjustment::{CustomCoerceUnsized, PointerCast}; use rustc::session::config::EntryFnType; -use rustc::mir::{self, Location, Place, PlaceBase, Promoted, Static, StaticKind}; +use rustc::mir::{self, Location, PlaceBase, Promoted, Static, StaticKind}; use rustc::mir::visit::Visitor as MirVisitor; use rustc::mir::mono::{MonoItem, InstantiationMode}; use rustc::mir::interpret::{Scalar, GlobalId, GlobalAlloc, ErrorHandled}; @@ -655,14 +655,12 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> { self.super_terminator_kind(kind, location); } - fn visit_place(&mut self, - place: &mir::Place<'tcx>, - context: mir::visit::PlaceContext, - location: Location) { - match place { - Place::Base( - PlaceBase::Static(box Static{ kind:StaticKind::Static(def_id), .. }) - ) => { + fn visit_place_base(&mut self, + place_base: &mir::PlaceBase<'tcx>, + _context: mir::visit::PlaceContext, + location: Location) { + match place_base { + PlaceBase::Static(box Static { kind: StaticKind::Static(def_id), .. }) => { debug!("visiting static {:?} @ {:?}", def_id, location); let tcx = self.tcx; @@ -671,10 +669,13 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> { self.output.push(MonoItem::Static(*def_id)); } } - _ => {} + PlaceBase::Static(box Static { kind: StaticKind::Promoted(_), .. }) => { + // FIXME: should we handle promoteds here instead of eagerly in collect_neighbours? + } + PlaceBase::Local(_) => { + // Locals have no relevance for collector + } } - - self.super_place(place, context, location); } } |
