Pass the PlaceElem::Index local to visit_local

This commit is contained in:
Jonas Schievink 2020-04-11 01:39:50 +02:00
parent 9682f0e14d
commit 72ae73ae61
7 changed files with 40 additions and 75 deletions

View File

@ -838,7 +838,7 @@ macro_rules! make_mir_visitor {
}
macro_rules! visit_place_fns {
(mut) => (
(mut) => {
fn tcx<'a>(&'a self) -> TyCtxt<'tcx>;
fn super_place(
@ -849,7 +849,7 @@ macro_rules! visit_place_fns {
) {
self.visit_place_base(&mut place.local, context, location);
if let Some(new_projection) = self.process_projection(&place.projection) {
if let Some(new_projection) = self.process_projection(&place.projection, location) {
place.projection = self.tcx().intern_place_elems(&new_projection);
}
}
@ -857,12 +857,13 @@ macro_rules! visit_place_fns {
fn process_projection(
&mut self,
projection: &'a [PlaceElem<'tcx>],
location: Location,
) -> Option<Vec<PlaceElem<'tcx>>> {
let mut projection = Cow::Borrowed(projection);
for i in 0..projection.len() {
if let Some(elem) = projection.get(i) {
if let Some(elem) = self.process_projection_elem(elem) {
if let Some(elem) = self.process_projection_elem(elem, location) {
// This converts the borrowed projection into `Cow::Owned(_)` and returns a
// clone of the projection so we can mutate and reintern later.
let vec = projection.to_mut();
@ -879,13 +880,30 @@ macro_rules! visit_place_fns {
fn process_projection_elem(
&mut self,
_elem: &PlaceElem<'tcx>,
elem: &PlaceElem<'tcx>,
location: Location,
) -> Option<PlaceElem<'tcx>> {
None
}
);
match elem {
PlaceElem::Index(local) => {
let mut new_local = *local;
self.visit_local(
&mut new_local,
PlaceContext::NonMutatingUse(NonMutatingUseContext::Copy),
location,
);
() => (
if new_local == *local { None } else { Some(PlaceElem::Index(new_local)) }
}
PlaceElem::Deref
| PlaceElem::Field(..)
| PlaceElem::ConstantIndex { .. }
| PlaceElem::Subslice { .. }
| PlaceElem::Downcast(..) => None,
}
}
};
() => {
fn visit_projection(
&mut self,
local: Local,
@ -907,12 +925,7 @@ macro_rules! visit_place_fns {
self.super_projection_elem(local, proj_base, elem, context, location);
}
fn super_place(
&mut self,
place: &Place<'tcx>,
context: PlaceContext,
location: Location,
) {
fn super_place(&mut self, place: &Place<'tcx>, context: PlaceContext, location: Location) {
let mut context = context;
if !place.projection.is_empty() {
@ -925,10 +938,7 @@ macro_rules! visit_place_fns {
self.visit_place_base(&place.local, context, location);
self.visit_projection(place.local,
&place.projection,
context,
location);
self.visit_projection(place.local, &place.projection, context, location);
}
fn super_projection(
@ -961,19 +971,16 @@ macro_rules! visit_place_fns {
self.visit_local(
local,
PlaceContext::NonMutatingUse(NonMutatingUseContext::Copy),
location
location,
);
}
ProjectionElem::Deref |
ProjectionElem::Subslice { from: _, to: _, from_end: _ } |
ProjectionElem::ConstantIndex { offset: _,
min_length: _,
from_end: _ } |
ProjectionElem::Downcast(_, _) => {
}
ProjectionElem::Deref
| ProjectionElem::Subslice { from: _, to: _, from_end: _ }
| ProjectionElem::ConstantIndex { offset: _, min_length: _, from_end: _ }
| ProjectionElem::Downcast(_, _) => {}
}
}
);
};
}
make_mir_visitor!(Visitor,);

View File

@ -64,7 +64,11 @@ impl<'a, 'tcx> MutVisitor<'tcx> for NLLVisitor<'a, 'tcx> {
debug!("visit_ty: ty={:?}", ty);
}
fn process_projection_elem(&mut self, elem: &PlaceElem<'tcx>) -> Option<PlaceElem<'tcx>> {
fn process_projection_elem(
&mut self,
elem: &PlaceElem<'tcx>,
_: Location,
) -> Option<PlaceElem<'tcx>> {
if let PlaceElem::Field(field, ty) = elem {
let new_ty = self.renumber_regions(ty);

View File

@ -89,13 +89,6 @@ impl<'tcx> MutVisitor<'tcx> for RenameLocalVisitor<'tcx> {
*local = self.to;
}
}
fn process_projection_elem(&mut self, elem: &PlaceElem<'tcx>) -> Option<PlaceElem<'tcx>> {
match elem {
PlaceElem::Index(local) if *local == self.from => Some(PlaceElem::Index(self.to)),
_ => None,
}
}
}
struct DerefArgVisitor<'tcx> {

View File

@ -706,18 +706,6 @@ impl<'a, 'tcx> MutVisitor<'tcx> for Integrator<'a, 'tcx> {
self.super_place(place, context, location)
}
fn process_projection_elem(&mut self, elem: &PlaceElem<'tcx>) -> Option<PlaceElem<'tcx>> {
if let PlaceElem::Index(local) = elem {
let new_local = self.make_integrate_local(*local);
if new_local != *local {
return Some(PlaceElem::Index(new_local));
}
}
None
}
fn visit_basic_block_data(&mut self, block: BasicBlock, data: &mut BasicBlockData<'tcx>) {
self.in_cleanup_block = data.is_cleanup;
self.super_basic_block_data(block, data);

View File

@ -1036,15 +1036,6 @@ impl<'a, 'tcx> MutVisitor<'tcx> for Promoter<'a, 'tcx> {
*local = self.promote_temp(*local);
}
}
fn process_projection_elem(&mut self, elem: &PlaceElem<'tcx>) -> Option<PlaceElem<'tcx>> {
match elem {
PlaceElem::Index(local) if self.is_temp_kind(*local) => {
Some(PlaceElem::Index(self.promote_temp(*local)))
}
_ => None,
}
}
}
pub fn promote_candidates<'tcx>(

View File

@ -417,11 +417,4 @@ impl<'tcx> MutVisitor<'tcx> for LocalUpdater<'tcx> {
fn visit_local(&mut self, l: &mut Local, _: PlaceContext, _: Location) {
*l = self.map[*l].unwrap();
}
fn process_projection_elem(&mut self, elem: &PlaceElem<'tcx>) -> Option<PlaceElem<'tcx>> {
match elem {
PlaceElem::Index(local) => Some(PlaceElem::Index(self.map[*local].unwrap())),
_ => None,
}
}
}

View File

@ -2,9 +2,7 @@
use rustc_index::vec::IndexVec;
use rustc_middle::mir::visit::{MutVisitor, PlaceContext, Visitor};
use rustc_middle::mir::{
Body, BodyAndCache, Local, Location, PlaceElem, ReadOnlyBodyAndCache, VarDebugInfo,
};
use rustc_middle::mir::{Body, BodyAndCache, Local, Location, ReadOnlyBodyAndCache, VarDebugInfo};
use rustc_middle::ty::TyCtxt;
use std::mem;
@ -157,13 +155,4 @@ impl MutVisitor<'tcx> for MutateUseVisitor<'tcx> {
*local = self.new_local;
}
}
fn process_projection_elem(&mut self, elem: &PlaceElem<'tcx>) -> Option<PlaceElem<'tcx>> {
match elem {
PlaceElem::Index(local) if *local == self.query => {
Some(PlaceElem::Index(self.new_local))
}
_ => None,
}
}
}