Add process_* place hooks to improve code reutilization
This commit is contained in:
parent
7fa3425ef6
commit
d53fc9cae5
@ -786,10 +786,32 @@ macro_rules! visit_place_fns {
|
||||
(mut) => (
|
||||
fn super_place(
|
||||
&mut self,
|
||||
_place: &mut Place<'tcx>,
|
||||
_context: PlaceContext,
|
||||
_location: Location,
|
||||
place: &mut Place<'tcx>,
|
||||
context: PlaceContext,
|
||||
location: Location,
|
||||
) {
|
||||
self.visit_place_base(&mut place.base, context, location);
|
||||
|
||||
place.projection = self.process_projection(&place.projection);
|
||||
}
|
||||
|
||||
fn process_projection(
|
||||
&mut self,
|
||||
projection: &Box<[PlaceElem<'tcx>]>,
|
||||
) -> Box<[PlaceElem<'tcx>]> {
|
||||
let new_projection: Vec<_> = projection.iter().map(|elem|
|
||||
self.process_projection_elem(elem)
|
||||
).collect();
|
||||
|
||||
new_projection.into_boxed_slice()
|
||||
}
|
||||
|
||||
fn process_projection_elem(
|
||||
&mut self,
|
||||
elem: &PlaceElem<'tcx>,
|
||||
) -> PlaceElem<'tcx> {
|
||||
// FIXME: avoid cloning here
|
||||
elem.clone()
|
||||
}
|
||||
);
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
use rustc::ty::subst::SubstsRef;
|
||||
use rustc::ty::{self, Ty, TypeFoldable};
|
||||
use rustc::mir::{Body, Location, Place, PlaceElem, Promoted};
|
||||
use rustc::mir::visit::{MutVisitor, PlaceContext, TyContext};
|
||||
use rustc::mir::{Body, Location, PlaceElem, Promoted};
|
||||
use rustc::mir::visit::{MutVisitor, TyContext};
|
||||
use rustc::infer::{InferCtxt, NLLRegionVariableOrigin};
|
||||
use rustc_index::vec::IndexVec;
|
||||
|
||||
@ -62,23 +62,15 @@ fn visit_ty(&mut self, ty: &mut Ty<'tcx>, ty_context: TyContext) {
|
||||
debug!("visit_ty: ty={:?}", ty);
|
||||
}
|
||||
|
||||
fn visit_place(
|
||||
fn process_projection_elem(
|
||||
&mut self,
|
||||
place: &mut Place<'tcx>,
|
||||
context: PlaceContext,
|
||||
location: Location,
|
||||
) {
|
||||
self.visit_place_base(&mut place.base, context, location);
|
||||
|
||||
let new_projection: Vec<_> = place.projection.iter().map(|elem|
|
||||
if let PlaceElem::Field(field, ty) = elem {
|
||||
PlaceElem::Field(*field, self.renumber_regions(ty))
|
||||
} else {
|
||||
elem.clone()
|
||||
}
|
||||
).collect();
|
||||
|
||||
place.projection = new_projection.into_boxed_slice();
|
||||
elem: &PlaceElem<'tcx>,
|
||||
) -> PlaceElem<'tcx> {
|
||||
if let PlaceElem::Field(field, ty) = elem {
|
||||
PlaceElem::Field(*field, self.renumber_regions(ty))
|
||||
} else {
|
||||
elem.clone()
|
||||
}
|
||||
}
|
||||
|
||||
fn visit_substs(&mut self, substs: &mut SubstsRef<'tcx>, location: Location) {
|
||||
|
@ -7,7 +7,7 @@
|
||||
use rustc::ty::subst::SubstsRef;
|
||||
use rustc::ty::{self, Ty, TyCtxt};
|
||||
use rustc::mir::*;
|
||||
use rustc::mir::visit::{MutVisitor, PlaceContext, TyContext};
|
||||
use rustc::mir::visit::{MutVisitor, TyContext};
|
||||
use crate::transform::{MirPass, MirSource};
|
||||
|
||||
struct EraseRegionsVisitor<'tcx> {
|
||||
@ -39,23 +39,15 @@ fn visit_substs(&mut self, substs: &mut SubstsRef<'tcx>, _: Location) {
|
||||
*substs = self.tcx.erase_regions(substs);
|
||||
}
|
||||
|
||||
fn visit_place(
|
||||
fn process_projection_elem(
|
||||
&mut self,
|
||||
place: &mut Place<'tcx>,
|
||||
context: PlaceContext,
|
||||
location: Location,
|
||||
) {
|
||||
self.visit_place_base(&mut place.base, context, location);
|
||||
|
||||
let new_projection: Vec<_> = place.projection.iter().map(|elem|
|
||||
if let PlaceElem::Field(field, ty) = elem {
|
||||
PlaceElem::Field(*field, self.tcx.erase_regions(ty))
|
||||
} else {
|
||||
elem.clone()
|
||||
}
|
||||
).collect();
|
||||
|
||||
place.projection = new_projection.into_boxed_slice();
|
||||
elem: &PlaceElem<'tcx>,
|
||||
) -> PlaceElem<'tcx> {
|
||||
if let PlaceElem::Field(field, ty) = elem {
|
||||
PlaceElem::Field(*field, self.tcx.erase_regions(ty))
|
||||
} else {
|
||||
elem.clone()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -695,21 +695,22 @@ fn visit_place(
|
||||
*place = self.destination.clone();
|
||||
},
|
||||
_ => {
|
||||
self.visit_place_base(&mut place.base, context, location);
|
||||
|
||||
let new_projection: Vec<_> = place.projection.iter().map(|elem|
|
||||
if let PlaceElem::Index(local) = elem {
|
||||
PlaceElem::Index(self.make_integrate_local(local))
|
||||
} else {
|
||||
elem.clone()
|
||||
}
|
||||
).collect();
|
||||
|
||||
place.projection = new_projection.into_boxed_slice();
|
||||
self.super_place(place, context, location);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn process_projection_elem(
|
||||
&mut self,
|
||||
elem: &PlaceElem<'tcx>,
|
||||
) -> PlaceElem<'tcx> {
|
||||
if let PlaceElem::Index(local) = elem {
|
||||
PlaceElem::Index(self.make_integrate_local(local))
|
||||
} else {
|
||||
elem.clone()
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
|
@ -405,24 +405,16 @@ fn visit_local(&mut self,
|
||||
}
|
||||
}
|
||||
|
||||
fn visit_place(
|
||||
fn process_projection_elem(
|
||||
&mut self,
|
||||
place: &mut Place<'tcx>,
|
||||
context: PlaceContext,
|
||||
location: Location,
|
||||
) {
|
||||
self.visit_place_base(&mut place.base, context, location);
|
||||
|
||||
let new_projection: Vec<_> = place.projection.iter().map(|elem|
|
||||
match elem {
|
||||
PlaceElem::Index(local) if self.is_temp_kind(*local) => {
|
||||
PlaceElem::Index(self.promote_temp(*local))
|
||||
}
|
||||
_ => elem.clone(),
|
||||
elem: &PlaceElem<'tcx>,
|
||||
) -> PlaceElem<'tcx> {
|
||||
match elem {
|
||||
PlaceElem::Index(local) if self.is_temp_kind(*local) => {
|
||||
PlaceElem::Index(self.promote_temp(*local))
|
||||
}
|
||||
).collect();
|
||||
|
||||
place.projection = new_projection.into_boxed_slice();
|
||||
_ => elem.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -371,22 +371,14 @@ fn visit_local(&mut self, l: &mut Local, _: PlaceContext, _: Location) {
|
||||
*l = self.map[*l].unwrap();
|
||||
}
|
||||
|
||||
fn visit_place(
|
||||
fn process_projection_elem(
|
||||
&mut self,
|
||||
place: &mut Place<'tcx>,
|
||||
context: PlaceContext,
|
||||
location: Location,
|
||||
) {
|
||||
self.visit_place_base(&mut place.base, context, location);
|
||||
|
||||
let new_projection: Vec<_> = place.projection.iter().map(|elem|
|
||||
if let PlaceElem::Index(local) = elem {
|
||||
PlaceElem::Index(self.map[*local].unwrap())
|
||||
} else {
|
||||
elem.clone()
|
||||
}
|
||||
).collect();
|
||||
|
||||
place.projection = new_projection.into_boxed_slice();
|
||||
elem: &PlaceElem<'tcx>,
|
||||
) -> PlaceElem<'tcx> {
|
||||
if let PlaceElem::Index(local) = elem {
|
||||
PlaceElem::Index(self.map[*local].unwrap())
|
||||
} else {
|
||||
elem.clone()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
//! Def-use analysis.
|
||||
|
||||
use rustc::mir::{Body, Local, Location, Place, PlaceElem};
|
||||
use rustc::mir::{Body, Local, Location, PlaceElem};
|
||||
use rustc::mir::visit::{PlaceContext, MutVisitor, Visitor};
|
||||
use rustc_index::vec::IndexVec;
|
||||
use std::mem;
|
||||
@ -138,21 +138,15 @@ fn visit_local(&mut self,
|
||||
}
|
||||
}
|
||||
|
||||
fn visit_place(&mut self,
|
||||
place: &mut Place<'tcx>,
|
||||
context: PlaceContext,
|
||||
location: Location) {
|
||||
self.visit_place_base(&mut place.base, context, location);
|
||||
|
||||
let new_projection: Vec<_> = place.projection.iter().map(|elem|
|
||||
match elem {
|
||||
PlaceElem::Index(local) if *local == self.query => {
|
||||
PlaceElem::Index(self.new_local)
|
||||
}
|
||||
_ => elem.clone(),
|
||||
fn process_projection_elem(
|
||||
&mut self,
|
||||
elem: &PlaceElem<'tcx>,
|
||||
) -> PlaceElem<'tcx> {
|
||||
match elem {
|
||||
PlaceElem::Index(local) if *local == self.query => {
|
||||
PlaceElem::Index(self.new_local)
|
||||
}
|
||||
).collect();
|
||||
|
||||
place.projection = new_projection.into_boxed_slice();
|
||||
_ => elem.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user