Skip to content

Commit

Permalink
Make StatementKind::Assign carry a NeoPlace instead of a Place
Browse files Browse the repository at this point in the history
  • Loading branch information
spastorino committed Feb 3, 2019
1 parent cf4da24 commit 222abfc
Show file tree
Hide file tree
Showing 44 changed files with 339 additions and 170 deletions.
2 changes: 1 addition & 1 deletion src/librustc/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1753,7 +1753,7 @@ impl<'tcx> Statement<'tcx> {
#[derive(Clone, Debug, RustcEncodable, RustcDecodable)]
pub enum StatementKind<'tcx> {
/// Write the RHS Rvalue to the LHS Place.
Assign(Place<'tcx>, Box<Rvalue<'tcx>>),
Assign(NeoPlace<'tcx>, Box<Rvalue<'tcx>>),

/// This represents all the reading that a pattern match may do
/// (e.g., inspecting constants and discriminant values), and the
Expand Down
28 changes: 18 additions & 10 deletions src/librustc/mir/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ macro_rules! make_mir_visitor {

fn visit_assign(&mut self,
block: BasicBlock,
place: & $($mutability)* Place<'tcx>,
place: & $($mutability)* NeoPlace<'tcx>,
rvalue: & $($mutability)* Rvalue<'tcx>,
location: Location) {
self.super_assign(block, place, rvalue, location);
Expand Down Expand Up @@ -441,10 +441,10 @@ macro_rules! make_mir_visitor {

fn super_assign(&mut self,
_block: BasicBlock,
place: &$($mutability)* Place<'tcx>,
place: &$($mutability)* NeoPlace<'tcx>,
rvalue: &$($mutability)* Rvalue<'tcx>,
location: Location) {
self.visit_place(
self.visit_neoplace(
place,
PlaceContext::MutatingUse(MutatingUseContext::Store),
location
Expand Down Expand Up @@ -771,6 +771,16 @@ macro_rules! make_mir_visitor {
base,
elems,
} = place;

let mut context = context;

if !elems.is_empty() {
context = if context.is_mutating_use() {
PlaceContext::MutatingUse(MutatingUseContext::Projection)
} else {
PlaceContext::NonMutatingUse(NonMutatingUseContext::Projection)
};
}

match base {
PlaceBase::Local(local) => {
Expand All @@ -784,13 +794,11 @@ macro_rules! make_mir_visitor {
}
}

if !elems.is_empty() {
for elem in elems.iter().cloned().rev() {
self.visit_projection_elem(
&$($mutability)* elem.clone(),
location
);
}
for elem in elems.iter().cloned().rev() {
self.visit_projection_elem(
&$($mutability)* elem.clone(),
location
);
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/librustc_codegen_ssa/mir/analyze.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,18 +98,18 @@ impl<'mir, 'a: 'mir, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> Visitor<'tcx>
for LocalAnalyzer<'mir, 'a, 'tcx, Bx> {
fn visit_assign(&mut self,
block: mir::BasicBlock,
place: &mir::Place<'tcx>,
place: &mir::NeoPlace<'tcx>,
rvalue: &mir::Rvalue<'tcx>,
location: Location) {
debug!("visit_assign(block={:?}, place={:?}, rvalue={:?})", block, place, rvalue);

if let mir::Place::Local(index) = *place {
if let Some(index) = place.as_local() {
self.assign(index, location);
if !self.fx.rvalue_creates_operand(rvalue) {
self.not_ssa(index);
}
} else {
self.visit_place(
self.visit_neoplace(
place,
PlaceContext::MutatingUse(MutatingUseContext::Store),
location
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_codegen_ssa/mir/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
self.set_debug_loc(&mut bx, statement.source_info);
match statement.kind {
mir::StatementKind::Assign(ref place, ref rvalue) => {
if let mir::Place::Local(index) = *place {
if let Some(index) = place.as_local() {
match self.locals[index] {
LocalRef::Place(cg_dest) => {
self.codegen_rvalue(bx, cg_dest, rvalue)
Expand All @@ -43,7 +43,7 @@ impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
}
}
} else {
let cg_dest = self.codegen_place(&mut bx, place);
let cg_dest = self.codegen_place(&mut bx, &place.clone().into_tree());
self.codegen_rvalue(bx, cg_dest, rvalue)
}
}
Expand Down
9 changes: 4 additions & 5 deletions src/librustc_mir/borrow_check/borrow_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ impl<'a, 'gcx, 'tcx> Visitor<'tcx> for GatherBorrows<'a, 'gcx, 'tcx> {
fn visit_assign(
&mut self,
block: mir::BasicBlock,
assigned_place: &mir::Place<'tcx>,
assigned_place: &mir::NeoPlace<'tcx>,
rvalue: &mir::Rvalue<'tcx>,
location: mir::Location,
) {
Expand All @@ -206,15 +206,14 @@ impl<'a, 'gcx, 'tcx> Visitor<'tcx> for GatherBorrows<'a, 'gcx, 'tcx> {
reserve_location: location,
activation_location: TwoPhaseActivation::NotTwoPhase,
borrowed_place: borrowed_place.clone(),
assigned_place: assigned_place.clone(),
assigned_place: assigned_place.clone().into_tree(),
};
let idx = self.idx_vec.push(borrow);
self.location_map.insert(location, idx);

self.insert_as_pending_if_two_phase(location, &assigned_place, kind, idx);
self.insert_as_pending_if_two_phase(location, &assigned_place.clone().into_tree(), kind, idx);

let neo_place = self.tcx.as_new_place(borrowed_place);
if let mir::PlaceBase::Local(local) = neo_place.base {
if let mir::PlaceBase::Local(local) = borrowed_neo_place.base {
self.local_map.entry(local).or_default().insert(idx);
}
}
Expand Down
15 changes: 10 additions & 5 deletions src/librustc_mir/borrow_check/error_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1495,8 +1495,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
target == neo_place.base_local()
} =>
{
let neo_into = self.infcx.tcx.as_new_place(into);
target = neo_into.base_local();
target = into.base_local();
}
_ => {},
}
Expand Down Expand Up @@ -1931,7 +1930,6 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
"annotate_argument_and_return_for_borrow: reservation={:?}",
reservation
);
let reservation = self.infcx.tcx.as_new_place(reservation);
// Check that the initial assignment of the reserve location is into a temporary.
let mut target = match reservation.as_local() {
Some(local) if self.mir.local_kind(local) == LocalKind::Temp => local,
Expand All @@ -1946,7 +1944,11 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
"annotate_argument_and_return_for_borrow: target={:?} stmt={:?}",
target, stmt
);
if let StatementKind::Assign(Place::Local(assigned_to), box rvalue) = &stmt.kind
if let StatementKind::Assign(
NeoPlace {
base: PlaceBase::Local(assigned_to),
elems: &[],
}, box rvalue) = &stmt.kind
{
debug!(
"annotate_argument_and_return_for_borrow: assigned_to={:?} \
Expand Down Expand Up @@ -2513,7 +2515,10 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
.get(location.statement_index)
{
Some(&Statement {
kind: StatementKind::Assign(Place::Local(local), _),
kind: StatementKind::Assign(NeoPlace {
base: PlaceBase::Local(local),
elems: &[],
}, _),
..
}) => local,
_ => return OtherUse(use_span),
Expand Down
3 changes: 2 additions & 1 deletion src/librustc_mir/borrow_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -503,9 +503,10 @@ impl<'cx, 'gcx, 'tcx> DataflowResultsConsumer<'cx, 'tcx> for MirBorrowckCtxt<'cx
flow_state,
);

let lhs = lhs.clone().into_tree();
self.mutate_place(
ContextKind::AssignLhs.new(location),
(lhs, span),
(&lhs, span),
Shallow(None),
JustWrite,
flow_state,
Expand Down
3 changes: 1 addition & 2 deletions src/librustc_mir/borrow_check/move_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,7 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> {
.get(location.statement_index)
.map(|stmt| &stmt.kind)
{
let neo_place = self.infcx.tcx.as_new_place(&place);
if let Some(PlaceBase::Local(local)) = neo_place.as_place_base() {
if let Some(PlaceBase::Local(local)) = place.as_place_base() {
let local_decl = &self.mir.local_decls[*local];
// opt_match_place is the
// match_span is the span of the expression being matched on
Expand Down
8 changes: 4 additions & 4 deletions src/librustc_mir/borrow_check/nll/constraint_generation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use borrow_check::nll::region_infer::values::LivenessValues;
use rustc::infer::InferCtxt;
use rustc::mir::visit::TyContext;
use rustc::mir::visit::Visitor;
use rustc::mir::{BasicBlock, BasicBlockData, Location, Mir, Place, Rvalue};
use rustc::mir::{BasicBlock, BasicBlockData, Location, Mir, Place, NeoPlace, Rvalue};
use rustc::mir::{SourceInfo, Statement, Terminator};
use rustc::mir::UserTypeProjection;
use rustc::ty::fold::TypeFoldable;
Expand Down Expand Up @@ -123,15 +123,15 @@ impl<'cg, 'cx, 'gcx, 'tcx> Visitor<'tcx> for ConstraintGeneration<'cg, 'cx, 'gcx
fn visit_assign(
&mut self,
block: BasicBlock,
place: &Place<'tcx>,
place: &NeoPlace<'tcx>,
rvalue: &Rvalue<'tcx>,
location: Location,
) {
// When we see `X = ...`, then kill borrows of
// `(*X).foo` and so forth.
if let Some(all_facts) = self.all_facts {
if let Place::Local(temp) = place {
if let Some(borrow_indices) = self.borrow_set.local_map.get(temp) {
if let Some(temp) = place.as_local() {
if let Some(borrow_indices) = self.borrow_set.local_map.get(&temp) {
all_facts.killed.reserve(borrow_indices.len());
for &borrow_index in borrow_indices {
let location_index = self.location_table.mid_index(location);
Expand Down
22 changes: 15 additions & 7 deletions src/librustc_mir/borrow_check/nll/explain_borrow/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use borrow_check::{Context, MirBorrowckCtxt, WriteKind};
use rustc::ty::{self, TyCtxt};
use rustc::mir::{
CastKind, ConstraintCategory, FakeReadCause, Local, Location, Mir, Operand,
Place, Projection, ProjectionElem, Rvalue, Statement, StatementKind,
Place, NeoPlace, PlaceBase, ProjectionElem, Rvalue, Statement, StatementKind,
TerminatorKind
};
use rustc_errors::DiagnosticBuilder;
Expand Down Expand Up @@ -422,7 +422,10 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
// it which simplifies the termination logic.
let mut queue = vec![location];
let mut target = if let Some(&Statement {
kind: StatementKind::Assign(Place::Local(local), _),
kind: StatementKind::Assign(NeoPlace {
base: PlaceBase::Local(local),
elems: &[],
}, _),
..
}) = stmt {
local
Expand All @@ -446,11 +449,16 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
box rvalue,
) = &stmt.kind {
let into = match place {
Place::Local(into) => into,
Place::Projection(box Projection {
base: Place::Local(into),
elem: ProjectionElem::Deref,
}) => into,
NeoPlace {
base: PlaceBase::Local(into),
elems: &[],
} => into,

NeoPlace {
base: PlaceBase::Local(into),
elems,
} if elems.last().unwrap() == &ProjectionElem::Deref => into,

_ => {
// Continue at the next location.
queue.push(current_location.successor_within_block());
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/borrow_check/nll/invalidation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl<'cx, 'tcx, 'gcx> Visitor<'tcx> for InvalidationGenerator<'cx, 'tcx, 'gcx> {

self.mutate_place(
ContextKind::AssignLhs.new(location),
lhs,
&lhs.clone().into_tree(),
Shallow(None),
JustWrite
);
Expand Down
39 changes: 20 additions & 19 deletions src/librustc_mir/borrow_check/nll/type_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1234,32 +1234,33 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
// they are not caused by the user, but rather artifacts
// of lowering. Assignments to other sorts of places *are* interesting
// though.
let category = match *place {
Place::Local(RETURN_PLACE) => if let Some(BorrowCheckContext {
universal_regions:
UniversalRegions {
defining_ty: DefiningTy::Const(def_id, _),
let category = match place.as_local() {
Some(RETURN_PLACE) =>
if let Some(BorrowCheckContext {
universal_regions:
UniversalRegions {
defining_ty: DefiningTy::Const(def_id, _),
..
},
..
},
..
}) = self.borrowck_context
{
if tcx.is_static(*def_id).is_some() {
ConstraintCategory::UseAsStatic
}) = self.borrowck_context {
if tcx.is_static(*def_id).is_some() {
ConstraintCategory::UseAsStatic
} else {
ConstraintCategory::UseAsConst
}
} else {
ConstraintCategory::UseAsConst
}
} else {
ConstraintCategory::Return
},
Place::Local(l) if !mir.local_decls[l].is_user_variable.is_some() => {
ConstraintCategory::Return
},

Some(l) if !mir.local_decls[l].is_user_variable.is_some() => {
ConstraintCategory::Boring
}

_ => ConstraintCategory::Assignment,
};

let neo_place = tcx.as_new_place(place);
let place_ty = neo_place.ty(mir, tcx).to_ty(tcx);
let place_ty = place.ty(mir, tcx).to_ty(tcx);
let rv_ty = rv.ty(mir, tcx);
if let Err(terr) =
self.sub_types_or_anon(rv_ty, place_ty, location.to_locations(), category)
Expand Down
3 changes: 1 addition & 2 deletions src/librustc_mir/borrow_check/used_muts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ impl<'visit, 'cx, 'gcx, 'tcx> Visitor<'tcx> for GatherUsedMutsVisitor<'visit, 'c
// be those that were never initialized - we will consider those as being used as
// they will either have been removed by unreachable code optimizations; or linted
// as unused variables.
let neo_into = self.mbcx.infcx.tcx.as_new_place(into);
if let Some(local) = neo_into.base_local() {
if let Some(local) = into.base_local() {
debug!(
"visit_statement: statement={:?} local={:?} \
never_initialized_mut_locals={:?}",
Expand Down
3 changes: 2 additions & 1 deletion src/librustc_mir/build/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
if destination_ty.is_unit() {
// We only want to assign an implicit `()` as the return value of the block if the
// block does not diverge. (Otherwise, we may try to assign a unit to a `!`-type.)
this.cfg.push_assign_unit(block, source_info, destination);
let destination = tcx.as_new_place(destination);
this.cfg.push_assign_unit(block, source_info, &destination);
}
}
// Finally, we pop all the let scopes before exiting out from the scope of block
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_mir/build/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl<'tcx> CFG<'tcx> {
pub fn push_assign(&mut self,
block: BasicBlock,
source_info: SourceInfo,
place: &Place<'tcx>,
place: &NeoPlace<'tcx>,
rvalue: Rvalue<'tcx>) {
self.push(block, Statement {
source_info,
Expand All @@ -44,7 +44,7 @@ impl<'tcx> CFG<'tcx> {
pub fn push_assign_constant(&mut self,
block: BasicBlock,
source_info: SourceInfo,
temp: &Place<'tcx>,
temp: &NeoPlace<'tcx>,
constant: Constant<'tcx>) {
self.push_assign(block, source_info, temp,
Rvalue::Use(Operand::Constant(box constant)));
Expand All @@ -53,7 +53,7 @@ impl<'tcx> CFG<'tcx> {
pub fn push_assign_unit(&mut self,
block: BasicBlock,
source_info: SourceInfo,
place: &Place<'tcx>) {
place: &NeoPlace<'tcx>) {
self.push_assign(block, source_info, place, Rvalue::Aggregate(
box AggregateKind::Tuple, vec![]
));
Expand Down
Loading

0 comments on commit 222abfc

Please sign in to comment.