Remove region from borrow place contexts
This commit is contained in:
parent
7ab92cde55
commit
22226fa7fb
@ -1,6 +1,6 @@
|
||||
use crate::hir::def_id::DefId;
|
||||
use crate::ty::subst::SubstsRef;
|
||||
use crate::ty::{CanonicalUserTypeAnnotation, ClosureSubsts, GeneratorSubsts, Region, Ty};
|
||||
use crate::ty::{CanonicalUserTypeAnnotation, ClosureSubsts, GeneratorSubsts, Ty};
|
||||
use crate::mir::*;
|
||||
use syntax_pos::Span;
|
||||
|
||||
@ -147,14 +147,14 @@ macro_rules! make_mir_visitor {
|
||||
|
||||
fn visit_place(&mut self,
|
||||
place: & $($mutability)? Place<'tcx>,
|
||||
context: PlaceContext<'tcx>,
|
||||
context: PlaceContext,
|
||||
location: Location) {
|
||||
self.super_place(place, context, location);
|
||||
}
|
||||
|
||||
fn visit_projection(&mut self,
|
||||
place: & $($mutability)? PlaceProjection<'tcx>,
|
||||
context: PlaceContext<'tcx>,
|
||||
context: PlaceContext,
|
||||
location: Location) {
|
||||
self.super_projection(place, context, location);
|
||||
}
|
||||
@ -252,7 +252,7 @@ macro_rules! make_mir_visitor {
|
||||
|
||||
fn visit_local(&mut self,
|
||||
_local: & $($mutability)? Local,
|
||||
_context: PlaceContext<'tcx>,
|
||||
_context: PlaceContext,
|
||||
_location: Location) {
|
||||
}
|
||||
|
||||
@ -576,16 +576,16 @@ macro_rules! make_mir_visitor {
|
||||
self.visit_region(r, location);
|
||||
let ctx = match bk {
|
||||
BorrowKind::Shared => PlaceContext::NonMutatingUse(
|
||||
NonMutatingUseContext::SharedBorrow(*r)
|
||||
NonMutatingUseContext::SharedBorrow
|
||||
),
|
||||
BorrowKind::Shallow => PlaceContext::NonMutatingUse(
|
||||
NonMutatingUseContext::ShallowBorrow(*r)
|
||||
NonMutatingUseContext::ShallowBorrow
|
||||
),
|
||||
BorrowKind::Unique => PlaceContext::NonMutatingUse(
|
||||
NonMutatingUseContext::UniqueBorrow(*r)
|
||||
NonMutatingUseContext::UniqueBorrow
|
||||
),
|
||||
BorrowKind::Mut { .. } =>
|
||||
PlaceContext::MutatingUse(MutatingUseContext::Borrow(*r)),
|
||||
PlaceContext::MutatingUse(MutatingUseContext::Borrow),
|
||||
};
|
||||
self.visit_place(path, ctx, location);
|
||||
}
|
||||
@ -716,7 +716,7 @@ macro_rules! make_mir_visitor {
|
||||
|
||||
fn super_place(&mut self,
|
||||
place: & $($mutability)? Place<'tcx>,
|
||||
context: PlaceContext<'tcx>,
|
||||
context: PlaceContext,
|
||||
location: Location) {
|
||||
match place {
|
||||
Place::Base(PlaceBase::Local(local)) => {
|
||||
@ -736,7 +736,7 @@ macro_rules! make_mir_visitor {
|
||||
|
||||
fn super_projection(&mut self,
|
||||
proj: & $($mutability)? PlaceProjection<'tcx>,
|
||||
context: PlaceContext<'tcx>,
|
||||
context: PlaceContext,
|
||||
location: Location) {
|
||||
let Projection { base, elem } = proj;
|
||||
let context = if context.is_mutating_use() {
|
||||
@ -948,7 +948,7 @@ pub enum TyContext {
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
||||
pub enum NonMutatingUseContext<'tcx> {
|
||||
pub enum NonMutatingUseContext {
|
||||
/// Being inspected in some way, like loading a len.
|
||||
Inspect,
|
||||
/// Consumed as part of an operand.
|
||||
@ -956,11 +956,11 @@ pub enum NonMutatingUseContext<'tcx> {
|
||||
/// Consumed as part of an operand.
|
||||
Move,
|
||||
/// Shared borrow.
|
||||
SharedBorrow(Region<'tcx>),
|
||||
SharedBorrow,
|
||||
/// Shallow borrow.
|
||||
ShallowBorrow(Region<'tcx>),
|
||||
ShallowBorrow,
|
||||
/// Unique borrow.
|
||||
UniqueBorrow(Region<'tcx>),
|
||||
UniqueBorrow,
|
||||
/// Used as base for another place, e.g., `x` in `x.y`. Will not mutate the place.
|
||||
/// For example, the projection `x.y` is not marked as a mutation in these cases:
|
||||
///
|
||||
@ -971,7 +971,7 @@ pub enum NonMutatingUseContext<'tcx> {
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
||||
pub enum MutatingUseContext<'tcx> {
|
||||
pub enum MutatingUseContext {
|
||||
/// Appears as LHS of an assignment.
|
||||
Store,
|
||||
/// Can often be treated as a `Store`, but needs to be separate because
|
||||
@ -983,7 +983,7 @@ pub enum MutatingUseContext<'tcx> {
|
||||
/// Being dropped.
|
||||
Drop,
|
||||
/// Mutable borrow.
|
||||
Borrow(Region<'tcx>),
|
||||
Borrow,
|
||||
/// Used as base for another place, e.g., `x` in `x.y`. Could potentially mutate the place.
|
||||
/// For example, the projection `x.y` is marked as a mutation in these cases:
|
||||
///
|
||||
@ -1006,13 +1006,13 @@ pub enum NonUseContext {
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
||||
pub enum PlaceContext<'tcx> {
|
||||
NonMutatingUse(NonMutatingUseContext<'tcx>),
|
||||
MutatingUse(MutatingUseContext<'tcx>),
|
||||
pub enum PlaceContext {
|
||||
NonMutatingUse(NonMutatingUseContext),
|
||||
MutatingUse(MutatingUseContext),
|
||||
NonUse(NonUseContext),
|
||||
}
|
||||
|
||||
impl<'tcx> PlaceContext<'tcx> {
|
||||
impl<'tcx> PlaceContext {
|
||||
/// Returns `true` if this place context represents a drop.
|
||||
pub fn is_drop(&self) -> bool {
|
||||
match *self {
|
||||
@ -1024,10 +1024,10 @@ impl<'tcx> PlaceContext<'tcx> {
|
||||
/// Returns `true` if this place context represents a borrow.
|
||||
pub fn is_borrow(&self) -> bool {
|
||||
match *self {
|
||||
PlaceContext::NonMutatingUse(NonMutatingUseContext::SharedBorrow(..)) |
|
||||
PlaceContext::NonMutatingUse(NonMutatingUseContext::ShallowBorrow(..)) |
|
||||
PlaceContext::NonMutatingUse(NonMutatingUseContext::UniqueBorrow(..)) |
|
||||
PlaceContext::MutatingUse(MutatingUseContext::Borrow(..)) => true,
|
||||
PlaceContext::NonMutatingUse(NonMutatingUseContext::SharedBorrow) |
|
||||
PlaceContext::NonMutatingUse(NonMutatingUseContext::ShallowBorrow) |
|
||||
PlaceContext::NonMutatingUse(NonMutatingUseContext::UniqueBorrow) |
|
||||
PlaceContext::MutatingUse(MutatingUseContext::Borrow) => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
@ -151,7 +151,7 @@ impl<'mir, 'a: 'mir, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> Visitor<'tcx>
|
||||
|
||||
fn visit_place(&mut self,
|
||||
place: &mir::Place<'tcx>,
|
||||
context: PlaceContext<'tcx>,
|
||||
context: PlaceContext,
|
||||
location: Location) {
|
||||
debug!("visit_place(place={:?}, context={:?})", place, context);
|
||||
let cx = self.fx.cx;
|
||||
@ -203,7 +203,7 @@ impl<'mir, 'a: 'mir, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> Visitor<'tcx>
|
||||
|
||||
fn visit_local(&mut self,
|
||||
&local: &mir::Local,
|
||||
context: PlaceContext<'tcx>,
|
||||
context: PlaceContext,
|
||||
location: Location) {
|
||||
match context {
|
||||
PlaceContext::MutatingUse(MutatingUseContext::Call) => {
|
||||
@ -233,11 +233,11 @@ impl<'mir, 'a: 'mir, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> Visitor<'tcx>
|
||||
PlaceContext::NonMutatingUse(NonMutatingUseContext::Inspect) |
|
||||
PlaceContext::MutatingUse(MutatingUseContext::Store) |
|
||||
PlaceContext::MutatingUse(MutatingUseContext::AsmOutput) |
|
||||
PlaceContext::MutatingUse(MutatingUseContext::Borrow(..)) |
|
||||
PlaceContext::MutatingUse(MutatingUseContext::Borrow) |
|
||||
PlaceContext::MutatingUse(MutatingUseContext::Projection) |
|
||||
PlaceContext::NonMutatingUse(NonMutatingUseContext::SharedBorrow(..)) |
|
||||
PlaceContext::NonMutatingUse(NonMutatingUseContext::UniqueBorrow(..)) |
|
||||
PlaceContext::NonMutatingUse(NonMutatingUseContext::ShallowBorrow(..)) |
|
||||
PlaceContext::NonMutatingUse(NonMutatingUseContext::SharedBorrow) |
|
||||
PlaceContext::NonMutatingUse(NonMutatingUseContext::UniqueBorrow) |
|
||||
PlaceContext::NonMutatingUse(NonMutatingUseContext::ShallowBorrow) |
|
||||
PlaceContext::NonMutatingUse(NonMutatingUseContext::Projection) => {
|
||||
self.not_ssa(local);
|
||||
}
|
||||
|
@ -95,7 +95,7 @@ impl LocalsStateAtExit {
|
||||
struct HasStorageDead(BitSet<Local>);
|
||||
|
||||
impl<'tcx> Visitor<'tcx> for HasStorageDead {
|
||||
fn visit_local(&mut self, local: &Local, ctx: PlaceContext<'tcx>, _: Location) {
|
||||
fn visit_local(&mut self, local: &Local, ctx: PlaceContext, _: Location) {
|
||||
if ctx == PlaceContext::NonUse(NonUseContext::StorageDead) {
|
||||
self.0.insert(*local);
|
||||
}
|
||||
@ -220,7 +220,7 @@ impl<'a, 'gcx, 'tcx> Visitor<'tcx> for GatherBorrows<'a, 'gcx, 'tcx> {
|
||||
fn visit_local(
|
||||
&mut self,
|
||||
temp: &Local,
|
||||
context: PlaceContext<'tcx>,
|
||||
context: PlaceContext,
|
||||
location: Location,
|
||||
) {
|
||||
if !context.is_use() {
|
||||
|
@ -113,7 +113,7 @@ enum DefUseResult {
|
||||
}
|
||||
|
||||
impl<'cx, 'gcx, 'tcx> Visitor<'tcx> for DefUseVisitor<'cx, 'gcx, 'tcx> {
|
||||
fn visit_local(&mut self, &local: &Local, context: PlaceContext<'tcx>, _: Location) {
|
||||
fn visit_local(&mut self, &local: &Local, context: PlaceContext, _: Location) {
|
||||
let local_ty = self.mir.local_decls[local].ty;
|
||||
|
||||
let mut found_it = false;
|
||||
|
@ -160,7 +160,7 @@ impl LocalUseMapBuild<'_> {
|
||||
}
|
||||
|
||||
impl Visitor<'tcx> for LocalUseMapBuild<'_> {
|
||||
fn visit_local(&mut self, &local: &Local, context: PlaceContext<'tcx>, location: Location) {
|
||||
fn visit_local(&mut self, &local: &Local, context: PlaceContext, location: Location) {
|
||||
if self.locals_with_use_data[local] {
|
||||
match categorize(context) {
|
||||
Some(DefUse::Def) => self.insert_def(local, location),
|
||||
|
@ -269,7 +269,7 @@ impl<'a, 'b, 'gcx, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'gcx, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
fn visit_place(&mut self, place: &Place<'tcx>, context: PlaceContext<'_>, location: Location) {
|
||||
fn visit_place(&mut self, place: &Place<'tcx>, context: PlaceContext, location: Location) {
|
||||
self.sanitize_place(place, location, context);
|
||||
}
|
||||
|
||||
@ -447,7 +447,7 @@ impl<'a, 'b, 'gcx, 'tcx> TypeVerifier<'a, 'b, 'gcx, 'tcx> {
|
||||
&mut self,
|
||||
place: &Place<'tcx>,
|
||||
location: Location,
|
||||
context: PlaceContext<'_>,
|
||||
context: PlaceContext,
|
||||
) -> PlaceTy<'tcx> {
|
||||
debug!("sanitize_place: {:?}", place);
|
||||
let place_ty = match place {
|
||||
|
@ -102,7 +102,7 @@ impl<'visit, 'cx, 'gcx, 'tcx> Visitor<'tcx> for GatherUsedMutsVisitor<'visit, 'c
|
||||
fn visit_local(
|
||||
&mut self,
|
||||
local: &Local,
|
||||
place_context: PlaceContext<'tcx>,
|
||||
place_context: PlaceContext,
|
||||
location: Location,
|
||||
) {
|
||||
if place_context.is_place_assignment() && self.temporary_used_locals.contains(local) {
|
||||
|
@ -658,7 +658,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
|
||||
|
||||
fn visit_place(&mut self,
|
||||
place: &mir::Place<'tcx>,
|
||||
context: mir::visit::PlaceContext<'tcx>,
|
||||
context: mir::visit::PlaceContext,
|
||||
location: Location) {
|
||||
match place {
|
||||
Place::Base(
|
||||
|
@ -199,7 +199,7 @@ impl<'a, 'tcx> Visitor<'tcx> for UnsafetyChecker<'a, 'tcx> {
|
||||
|
||||
fn visit_place(&mut self,
|
||||
place: &Place<'tcx>,
|
||||
context: PlaceContext<'tcx>,
|
||||
context: PlaceContext,
|
||||
location: Location) {
|
||||
match place {
|
||||
&Place::Projection(box Projection {
|
||||
|
@ -510,7 +510,7 @@ impl<'tcx> Visitor<'tcx> for CanConstProp {
|
||||
fn visit_local(
|
||||
&mut self,
|
||||
&local: &Local,
|
||||
context: PlaceContext<'tcx>,
|
||||
context: PlaceContext,
|
||||
_: Location,
|
||||
) {
|
||||
use rustc::mir::visit::PlaceContext::*;
|
||||
|
@ -134,9 +134,9 @@ impl MirPass for CopyPropagation {
|
||||
}
|
||||
}
|
||||
|
||||
fn eliminate_self_assignments<'tcx>(
|
||||
mir: &mut Mir<'tcx>,
|
||||
def_use_analysis: &DefUseAnalysis<'tcx>,
|
||||
fn eliminate_self_assignments(
|
||||
mir: &mut Mir<'_>,
|
||||
def_use_analysis: &DefUseAnalysis,
|
||||
) -> bool {
|
||||
let mut changed = false;
|
||||
|
||||
@ -177,7 +177,7 @@ enum Action<'tcx> {
|
||||
}
|
||||
|
||||
impl<'tcx> Action<'tcx> {
|
||||
fn local_copy(mir: &Mir<'tcx>, def_use_analysis: &DefUseAnalysis<'_>, src_place: &Place<'tcx>)
|
||||
fn local_copy(mir: &Mir<'tcx>, def_use_analysis: &DefUseAnalysis, src_place: &Place<'tcx>)
|
||||
-> Option<Action<'tcx>> {
|
||||
// The source must be a local.
|
||||
let src_local = if let Place::Base(PlaceBase::Local(local)) = *src_place {
|
||||
@ -233,7 +233,7 @@ impl<'tcx> Action<'tcx> {
|
||||
|
||||
fn perform(self,
|
||||
mir: &mut Mir<'tcx>,
|
||||
def_use_analysis: &DefUseAnalysis<'tcx>,
|
||||
def_use_analysis: &DefUseAnalysis,
|
||||
dest_local: Local,
|
||||
location: Location)
|
||||
-> bool {
|
||||
|
@ -80,7 +80,7 @@ struct RenameLocalVisitor {
|
||||
impl<'tcx> MutVisitor<'tcx> for RenameLocalVisitor {
|
||||
fn visit_local(&mut self,
|
||||
local: &mut Local,
|
||||
_: PlaceContext<'tcx>,
|
||||
_: PlaceContext,
|
||||
_: Location) {
|
||||
if *local == self.from {
|
||||
*local = self.to;
|
||||
@ -93,14 +93,14 @@ struct DerefArgVisitor;
|
||||
impl<'tcx> MutVisitor<'tcx> for DerefArgVisitor {
|
||||
fn visit_local(&mut self,
|
||||
local: &mut Local,
|
||||
_: PlaceContext<'tcx>,
|
||||
_: PlaceContext,
|
||||
_: Location) {
|
||||
assert_ne!(*local, self_arg());
|
||||
}
|
||||
|
||||
fn visit_place(&mut self,
|
||||
place: &mut Place<'tcx>,
|
||||
context: PlaceContext<'tcx>,
|
||||
context: PlaceContext,
|
||||
location: Location) {
|
||||
if *place == Place::Base(PlaceBase::Local(self_arg())) {
|
||||
*place = Place::Projection(Box::new(Projection {
|
||||
@ -120,14 +120,14 @@ struct PinArgVisitor<'tcx> {
|
||||
impl<'tcx> MutVisitor<'tcx> for PinArgVisitor<'tcx> {
|
||||
fn visit_local(&mut self,
|
||||
local: &mut Local,
|
||||
_: PlaceContext<'tcx>,
|
||||
_: PlaceContext,
|
||||
_: Location) {
|
||||
assert_ne!(*local, self_arg());
|
||||
}
|
||||
|
||||
fn visit_place(&mut self,
|
||||
place: &mut Place<'tcx>,
|
||||
context: PlaceContext<'tcx>,
|
||||
context: PlaceContext,
|
||||
location: Location) {
|
||||
if *place == Place::Base(PlaceBase::Local(self_arg())) {
|
||||
*place = Place::Projection(Box::new(Projection {
|
||||
@ -221,14 +221,14 @@ impl<'a, 'tcx> TransformVisitor<'a, 'tcx> {
|
||||
impl<'a, 'tcx> MutVisitor<'tcx> for TransformVisitor<'a, 'tcx> {
|
||||
fn visit_local(&mut self,
|
||||
local: &mut Local,
|
||||
_: PlaceContext<'tcx>,
|
||||
_: PlaceContext,
|
||||
_: Location) {
|
||||
assert_eq!(self.remap.get(local), None);
|
||||
}
|
||||
|
||||
fn visit_place(&mut self,
|
||||
place: &mut Place<'tcx>,
|
||||
context: PlaceContext<'tcx>,
|
||||
context: PlaceContext,
|
||||
location: Location) {
|
||||
if let Place::Base(PlaceBase::Local(l)) = *place {
|
||||
// Replace an Local in the remap with a generator struct access
|
||||
|
@ -662,7 +662,7 @@ impl<'a, 'tcx> Integrator<'a, 'tcx> {
|
||||
impl<'a, 'tcx> MutVisitor<'tcx> for Integrator<'a, 'tcx> {
|
||||
fn visit_local(&mut self,
|
||||
local: &mut Local,
|
||||
_ctxt: PlaceContext<'tcx>,
|
||||
_ctxt: PlaceContext,
|
||||
_location: Location) {
|
||||
if *local == RETURN_PLACE {
|
||||
match self.destination {
|
||||
@ -683,7 +683,7 @@ impl<'a, 'tcx> MutVisitor<'tcx> for Integrator<'a, 'tcx> {
|
||||
|
||||
fn visit_place(&mut self,
|
||||
place: &mut Place<'tcx>,
|
||||
_ctxt: PlaceContext<'tcx>,
|
||||
_ctxt: PlaceContext,
|
||||
_location: Location) {
|
||||
|
||||
match place {
|
||||
|
@ -77,7 +77,7 @@ struct TempCollector<'tcx> {
|
||||
impl<'tcx> Visitor<'tcx> for TempCollector<'tcx> {
|
||||
fn visit_local(&mut self,
|
||||
&index: &Local,
|
||||
context: PlaceContext<'tcx>,
|
||||
context: PlaceContext,
|
||||
location: Location) {
|
||||
debug!("visit_local: index={:?} context={:?} location={:?}", index, context, location);
|
||||
// We're only interested in temporaries and the return place
|
||||
@ -361,7 +361,7 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
|
||||
impl<'a, 'tcx> MutVisitor<'tcx> for Promoter<'a, 'tcx> {
|
||||
fn visit_local(&mut self,
|
||||
local: &mut Local,
|
||||
_: PlaceContext<'tcx>,
|
||||
_: PlaceContext,
|
||||
_: Location) {
|
||||
if self.source.local_kind(*local) == LocalKind::Temp {
|
||||
*local = self.promote_temp(*local);
|
||||
|
@ -929,7 +929,7 @@ impl<'a, 'tcx> Checker<'a, 'tcx> {
|
||||
impl<'a, 'tcx> Visitor<'tcx> for Checker<'a, 'tcx> {
|
||||
fn visit_place(&mut self,
|
||||
place: &Place<'tcx>,
|
||||
context: PlaceContext<'tcx>,
|
||||
context: PlaceContext,
|
||||
location: Location) {
|
||||
debug!("visit_place: place={:?} context={:?} location={:?}", place, context, location);
|
||||
self.super_place(place, context, location);
|
||||
@ -1066,7 +1066,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Checker<'a, 'tcx> {
|
||||
debug!("visit_rvalue: rvalue={:?} location={:?}", rvalue, location);
|
||||
|
||||
// Check nested operands and places.
|
||||
if let Rvalue::Ref(region, kind, ref place) = *rvalue {
|
||||
if let Rvalue::Ref(_, kind, ref place) = *rvalue {
|
||||
// Special-case reborrows.
|
||||
let mut is_reborrow = false;
|
||||
if let Place::Projection(ref proj) = *place {
|
||||
@ -1081,16 +1081,16 @@ impl<'a, 'tcx> Visitor<'tcx> for Checker<'a, 'tcx> {
|
||||
if is_reborrow {
|
||||
let ctx = match kind {
|
||||
BorrowKind::Shared => PlaceContext::NonMutatingUse(
|
||||
NonMutatingUseContext::SharedBorrow(region),
|
||||
NonMutatingUseContext::SharedBorrow,
|
||||
),
|
||||
BorrowKind::Shallow => PlaceContext::NonMutatingUse(
|
||||
NonMutatingUseContext::ShallowBorrow(region),
|
||||
NonMutatingUseContext::ShallowBorrow,
|
||||
),
|
||||
BorrowKind::Unique => PlaceContext::NonMutatingUse(
|
||||
NonMutatingUseContext::UniqueBorrow(region),
|
||||
NonMutatingUseContext::UniqueBorrow,
|
||||
),
|
||||
BorrowKind::Mut { .. } => PlaceContext::MutatingUse(
|
||||
MutatingUseContext::Borrow(region),
|
||||
MutatingUseContext::Borrow,
|
||||
),
|
||||
};
|
||||
self.super_place(place, ctx, location);
|
||||
|
@ -345,7 +345,7 @@ struct DeclMarker {
|
||||
}
|
||||
|
||||
impl<'tcx> Visitor<'tcx> for DeclMarker {
|
||||
fn visit_local(&mut self, local: &Local, ctx: PlaceContext<'tcx>, _: Location) {
|
||||
fn visit_local(&mut self, local: &Local, ctx: PlaceContext, _: Location) {
|
||||
// Ignore storage markers altogether, they get removed along with their otherwise unused
|
||||
// decls.
|
||||
// FIXME: Extend this to all non-uses.
|
||||
@ -372,7 +372,7 @@ impl<'tcx> MutVisitor<'tcx> for LocalUpdater {
|
||||
});
|
||||
self.super_basic_block_data(block, data);
|
||||
}
|
||||
fn visit_local(&mut self, l: &mut Local, _: PlaceContext<'tcx>, _: Location) {
|
||||
fn visit_local(&mut self, l: &mut Local, _: PlaceContext, _: Location) {
|
||||
*l = self.map[*l].unwrap();
|
||||
}
|
||||
}
|
||||
|
@ -304,7 +304,7 @@ impl<'tcx> Visitor<'tcx> for RestoreDataCollector {
|
||||
|
||||
fn visit_local(&mut self,
|
||||
local: &Local,
|
||||
context: PlaceContext<'tcx>,
|
||||
context: PlaceContext,
|
||||
location: Location) {
|
||||
let local_use = &mut self.locals_use[*local];
|
||||
match context {
|
||||
|
@ -27,7 +27,7 @@ struct FindLocalAssignmentVisitor {
|
||||
impl<'tcx> Visitor<'tcx> for FindLocalAssignmentVisitor {
|
||||
fn visit_local(&mut self,
|
||||
local: &Local,
|
||||
place_context: PlaceContext<'tcx>,
|
||||
place_context: PlaceContext,
|
||||
location: Location) {
|
||||
if self.needle != *local {
|
||||
return;
|
||||
|
@ -3,34 +3,31 @@
|
||||
use rustc::mir::{Local, Location, Mir};
|
||||
use rustc::mir::visit::{PlaceContext, MutVisitor, Visitor};
|
||||
use rustc_data_structures::indexed_vec::IndexVec;
|
||||
use std::marker::PhantomData;
|
||||
use std::mem;
|
||||
use std::slice;
|
||||
use std::iter;
|
||||
|
||||
pub struct DefUseAnalysis<'tcx> {
|
||||
info: IndexVec<Local, Info<'tcx>>,
|
||||
pub struct DefUseAnalysis {
|
||||
info: IndexVec<Local, Info>,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Info<'tcx> {
|
||||
pub defs_and_uses: Vec<Use<'tcx>>,
|
||||
pub struct Info {
|
||||
pub defs_and_uses: Vec<Use>,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Use<'tcx> {
|
||||
pub context: PlaceContext<'tcx>,
|
||||
pub struct Use {
|
||||
pub context: PlaceContext,
|
||||
pub location: Location,
|
||||
}
|
||||
|
||||
impl<'tcx> DefUseAnalysis<'tcx> {
|
||||
pub fn new(mir: &Mir<'tcx>) -> DefUseAnalysis<'tcx> {
|
||||
impl DefUseAnalysis {
|
||||
pub fn new(mir: &Mir<'_>) -> DefUseAnalysis {
|
||||
DefUseAnalysis {
|
||||
info: IndexVec::from_elem_n(Info::new(), mir.local_decls.len()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn analyze(&mut self, mir: &Mir<'tcx>) {
|
||||
pub fn analyze(&mut self, mir: &Mir<'_>) {
|
||||
self.clear();
|
||||
|
||||
let mut finder = DefUseFinder {
|
||||
@ -46,13 +43,13 @@ impl<'tcx> DefUseAnalysis<'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn local_info(&self, local: Local) -> &Info<'tcx> {
|
||||
pub fn local_info(&self, local: Local) -> &Info {
|
||||
&self.info[local]
|
||||
}
|
||||
|
||||
fn mutate_defs_and_uses<F>(&self, local: Local, mir: &mut Mir<'tcx>, mut callback: F)
|
||||
fn mutate_defs_and_uses<F>(&self, local: Local, mir: &mut Mir<'_>, mut callback: F)
|
||||
where F: for<'a> FnMut(&'a mut Local,
|
||||
PlaceContext<'tcx>,
|
||||
PlaceContext,
|
||||
Location) {
|
||||
for place_use in &self.info[local].defs_and_uses {
|
||||
MutateUseVisitor::new(local,
|
||||
@ -64,20 +61,20 @@ impl<'tcx> DefUseAnalysis<'tcx> {
|
||||
// FIXME(pcwalton): this should update the def-use chains.
|
||||
pub fn replace_all_defs_and_uses_with(&self,
|
||||
local: Local,
|
||||
mir: &mut Mir<'tcx>,
|
||||
mir: &mut Mir<'_>,
|
||||
new_local: Local) {
|
||||
self.mutate_defs_and_uses(local, mir, |local, _, _| *local = new_local)
|
||||
}
|
||||
}
|
||||
|
||||
struct DefUseFinder<'tcx> {
|
||||
info: IndexVec<Local, Info<'tcx>>,
|
||||
struct DefUseFinder {
|
||||
info: IndexVec<Local, Info>,
|
||||
}
|
||||
|
||||
impl<'tcx> Visitor<'tcx> for DefUseFinder<'tcx> {
|
||||
impl Visitor<'_> for DefUseFinder {
|
||||
fn visit_local(&mut self,
|
||||
&local: &Local,
|
||||
context: PlaceContext<'tcx>,
|
||||
context: PlaceContext,
|
||||
location: Location) {
|
||||
self.info[local].defs_and_uses.push(Use {
|
||||
context,
|
||||
@ -86,8 +83,8 @@ impl<'tcx> Visitor<'tcx> for DefUseFinder<'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> Info<'tcx> {
|
||||
fn new() -> Info<'tcx> {
|
||||
impl Info {
|
||||
fn new() -> Info {
|
||||
Info {
|
||||
defs_and_uses: vec![],
|
||||
}
|
||||
@ -107,7 +104,7 @@ impl<'tcx> Info<'tcx> {
|
||||
|
||||
pub fn defs_not_including_drop(
|
||||
&self,
|
||||
) -> iter::Filter<slice::Iter<'_, Use<'tcx>>, fn(&&Use<'tcx>) -> bool> {
|
||||
) -> impl Iterator<Item=&Use> {
|
||||
self.defs_and_uses.iter().filter(|place_use| {
|
||||
place_use.context.is_mutating_use() && !place_use.context.is_drop()
|
||||
})
|
||||
@ -120,29 +117,27 @@ impl<'tcx> Info<'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
struct MutateUseVisitor<'tcx, F> {
|
||||
struct MutateUseVisitor<F> {
|
||||
query: Local,
|
||||
callback: F,
|
||||
phantom: PhantomData<&'tcx ()>,
|
||||
}
|
||||
|
||||
impl<'tcx, F> MutateUseVisitor<'tcx, F> {
|
||||
fn new(query: Local, callback: F, _: &Mir<'tcx>)
|
||||
-> MutateUseVisitor<'tcx, F>
|
||||
where F: for<'a> FnMut(&'a mut Local, PlaceContext<'tcx>, Location) {
|
||||
impl<F> MutateUseVisitor<F> {
|
||||
fn new(query: Local, callback: F, _: &Mir<'_>)
|
||||
-> MutateUseVisitor<F>
|
||||
where F: for<'a> FnMut(&'a mut Local, PlaceContext, Location) {
|
||||
MutateUseVisitor {
|
||||
query,
|
||||
callback,
|
||||
phantom: PhantomData,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx, F> MutVisitor<'tcx> for MutateUseVisitor<'tcx, F>
|
||||
where F: for<'a> FnMut(&'a mut Local, PlaceContext<'tcx>, Location) {
|
||||
impl<F> MutVisitor<'_> for MutateUseVisitor<F>
|
||||
where F: for<'a> FnMut(&'a mut Local, PlaceContext, Location) {
|
||||
fn visit_local(&mut self,
|
||||
local: &mut Local,
|
||||
context: PlaceContext<'tcx>,
|
||||
context: PlaceContext,
|
||||
location: Location) {
|
||||
if *local == self.query {
|
||||
(self.callback)(local, context, location)
|
||||
|
@ -110,7 +110,7 @@ pub enum DefUse {
|
||||
Drop,
|
||||
}
|
||||
|
||||
pub fn categorize<'tcx>(context: PlaceContext<'tcx>) -> Option<DefUse> {
|
||||
pub fn categorize<'tcx>(context: PlaceContext) -> Option<DefUse> {
|
||||
match context {
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// DEFS
|
||||
@ -147,10 +147,10 @@ pub fn categorize<'tcx>(context: PlaceContext<'tcx>) -> Option<DefUse> {
|
||||
// This won't affect the results since we use this analysis for generators
|
||||
// and we only care about the result at suspension points. Borrows cannot
|
||||
// cross suspension points so this behavior is unproblematic.
|
||||
PlaceContext::MutatingUse(MutatingUseContext::Borrow(..)) |
|
||||
PlaceContext::NonMutatingUse(NonMutatingUseContext::SharedBorrow(..)) |
|
||||
PlaceContext::NonMutatingUse(NonMutatingUseContext::ShallowBorrow(..)) |
|
||||
PlaceContext::NonMutatingUse(NonMutatingUseContext::UniqueBorrow(..)) |
|
||||
PlaceContext::MutatingUse(MutatingUseContext::Borrow) |
|
||||
PlaceContext::NonMutatingUse(NonMutatingUseContext::SharedBorrow) |
|
||||
PlaceContext::NonMutatingUse(NonMutatingUseContext::ShallowBorrow) |
|
||||
PlaceContext::NonMutatingUse(NonMutatingUseContext::UniqueBorrow) |
|
||||
|
||||
PlaceContext::NonMutatingUse(NonMutatingUseContext::Inspect) |
|
||||
PlaceContext::NonMutatingUse(NonMutatingUseContext::Copy) |
|
||||
@ -220,7 +220,7 @@ impl DefsUses {
|
||||
|
||||
impl<'tcx> Visitor<'tcx> for DefsUsesVisitor
|
||||
{
|
||||
fn visit_local(&mut self, &local: &Local, context: PlaceContext<'tcx>, _: Location) {
|
||||
fn visit_local(&mut self, &local: &Local, context: PlaceContext, _: Location) {
|
||||
match categorize(context) {
|
||||
Some(DefUse::Def) => self.defs_uses.add_def(local),
|
||||
Some(DefUse::Use) | Some(DefUse::Drop) => self.defs_uses.add_use(local),
|
||||
|
Loading…
Reference in New Issue
Block a user