Skip to content

Commit 222abfc

Browse files
committed
Make StatementKind::Assign carry a NeoPlace instead of a Place
1 parent cf4da24 commit 222abfc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+339
-170
lines changed

src/librustc/mir/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1753,7 +1753,7 @@ impl<'tcx> Statement<'tcx> {
17531753
#[derive(Clone, Debug, RustcEncodable, RustcDecodable)]
17541754
pub enum StatementKind<'tcx> {
17551755
/// Write the RHS Rvalue to the LHS Place.
1756-
Assign(Place<'tcx>, Box<Rvalue<'tcx>>),
1756+
Assign(NeoPlace<'tcx>, Box<Rvalue<'tcx>>),
17571757

17581758
/// This represents all the reading that a pattern match may do
17591759
/// (e.g., inspecting constants and discriminant values), and the

src/librustc/mir/visit.rs

+18-10
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ macro_rules! make_mir_visitor {
9696

9797
fn visit_assign(&mut self,
9898
block: BasicBlock,
99-
place: & $($mutability)* Place<'tcx>,
99+
place: & $($mutability)* NeoPlace<'tcx>,
100100
rvalue: & $($mutability)* Rvalue<'tcx>,
101101
location: Location) {
102102
self.super_assign(block, place, rvalue, location);
@@ -441,10 +441,10 @@ macro_rules! make_mir_visitor {
441441

442442
fn super_assign(&mut self,
443443
_block: BasicBlock,
444-
place: &$($mutability)* Place<'tcx>,
444+
place: &$($mutability)* NeoPlace<'tcx>,
445445
rvalue: &$($mutability)* Rvalue<'tcx>,
446446
location: Location) {
447-
self.visit_place(
447+
self.visit_neoplace(
448448
place,
449449
PlaceContext::MutatingUse(MutatingUseContext::Store),
450450
location
@@ -771,6 +771,16 @@ macro_rules! make_mir_visitor {
771771
base,
772772
elems,
773773
} = place;
774+
775+
let mut context = context;
776+
777+
if !elems.is_empty() {
778+
context = if context.is_mutating_use() {
779+
PlaceContext::MutatingUse(MutatingUseContext::Projection)
780+
} else {
781+
PlaceContext::NonMutatingUse(NonMutatingUseContext::Projection)
782+
};
783+
}
774784

775785
match base {
776786
PlaceBase::Local(local) => {
@@ -784,13 +794,11 @@ macro_rules! make_mir_visitor {
784794
}
785795
}
786796

787-
if !elems.is_empty() {
788-
for elem in elems.iter().cloned().rev() {
789-
self.visit_projection_elem(
790-
&$($mutability)* elem.clone(),
791-
location
792-
);
793-
}
797+
for elem in elems.iter().cloned().rev() {
798+
self.visit_projection_elem(
799+
&$($mutability)* elem.clone(),
800+
location
801+
);
794802
}
795803
}
796804

src/librustc_codegen_ssa/mir/analyze.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -98,18 +98,18 @@ impl<'mir, 'a: 'mir, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> Visitor<'tcx>
9898
for LocalAnalyzer<'mir, 'a, 'tcx, Bx> {
9999
fn visit_assign(&mut self,
100100
block: mir::BasicBlock,
101-
place: &mir::Place<'tcx>,
101+
place: &mir::NeoPlace<'tcx>,
102102
rvalue: &mir::Rvalue<'tcx>,
103103
location: Location) {
104104
debug!("visit_assign(block={:?}, place={:?}, rvalue={:?})", block, place, rvalue);
105105

106-
if let mir::Place::Local(index) = *place {
106+
if let Some(index) = place.as_local() {
107107
self.assign(index, location);
108108
if !self.fx.rvalue_creates_operand(rvalue) {
109109
self.not_ssa(index);
110110
}
111111
} else {
112-
self.visit_place(
112+
self.visit_neoplace(
113113
place,
114114
PlaceContext::MutatingUse(MutatingUseContext::Store),
115115
location

src/librustc_codegen_ssa/mir/statement.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
1717
self.set_debug_loc(&mut bx, statement.source_info);
1818
match statement.kind {
1919
mir::StatementKind::Assign(ref place, ref rvalue) => {
20-
if let mir::Place::Local(index) = *place {
20+
if let Some(index) = place.as_local() {
2121
match self.locals[index] {
2222
LocalRef::Place(cg_dest) => {
2323
self.codegen_rvalue(bx, cg_dest, rvalue)
@@ -43,7 +43,7 @@ impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
4343
}
4444
}
4545
} else {
46-
let cg_dest = self.codegen_place(&mut bx, place);
46+
let cg_dest = self.codegen_place(&mut bx, &place.clone().into_tree());
4747
self.codegen_rvalue(bx, cg_dest, rvalue)
4848
}
4949
}

src/librustc_mir/borrow_check/borrow_set.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ impl<'a, 'gcx, 'tcx> Visitor<'tcx> for GatherBorrows<'a, 'gcx, 'tcx> {
187187
fn visit_assign(
188188
&mut self,
189189
block: mir::BasicBlock,
190-
assigned_place: &mir::Place<'tcx>,
190+
assigned_place: &mir::NeoPlace<'tcx>,
191191
rvalue: &mir::Rvalue<'tcx>,
192192
location: mir::Location,
193193
) {
@@ -206,15 +206,14 @@ impl<'a, 'gcx, 'tcx> Visitor<'tcx> for GatherBorrows<'a, 'gcx, 'tcx> {
206206
reserve_location: location,
207207
activation_location: TwoPhaseActivation::NotTwoPhase,
208208
borrowed_place: borrowed_place.clone(),
209-
assigned_place: assigned_place.clone(),
209+
assigned_place: assigned_place.clone().into_tree(),
210210
};
211211
let idx = self.idx_vec.push(borrow);
212212
self.location_map.insert(location, idx);
213213

214-
self.insert_as_pending_if_two_phase(location, &assigned_place, kind, idx);
214+
self.insert_as_pending_if_two_phase(location, &assigned_place.clone().into_tree(), kind, idx);
215215

216-
let neo_place = self.tcx.as_new_place(borrowed_place);
217-
if let mir::PlaceBase::Local(local) = neo_place.base {
216+
if let mir::PlaceBase::Local(local) = borrowed_neo_place.base {
218217
self.local_map.entry(local).or_default().insert(idx);
219218
}
220219
}

src/librustc_mir/borrow_check/error_reporting.rs

+10-5
Original file line numberDiff line numberDiff line change
@@ -1495,8 +1495,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
14951495
target == neo_place.base_local()
14961496
} =>
14971497
{
1498-
let neo_into = self.infcx.tcx.as_new_place(into);
1499-
target = neo_into.base_local();
1498+
target = into.base_local();
15001499
}
15011500
_ => {},
15021501
}
@@ -1931,7 +1930,6 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
19311930
"annotate_argument_and_return_for_borrow: reservation={:?}",
19321931
reservation
19331932
);
1934-
let reservation = self.infcx.tcx.as_new_place(reservation);
19351933
// Check that the initial assignment of the reserve location is into a temporary.
19361934
let mut target = match reservation.as_local() {
19371935
Some(local) if self.mir.local_kind(local) == LocalKind::Temp => local,
@@ -1946,7 +1944,11 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
19461944
"annotate_argument_and_return_for_borrow: target={:?} stmt={:?}",
19471945
target, stmt
19481946
);
1949-
if let StatementKind::Assign(Place::Local(assigned_to), box rvalue) = &stmt.kind
1947+
if let StatementKind::Assign(
1948+
NeoPlace {
1949+
base: PlaceBase::Local(assigned_to),
1950+
elems: &[],
1951+
}, box rvalue) = &stmt.kind
19501952
{
19511953
debug!(
19521954
"annotate_argument_and_return_for_borrow: assigned_to={:?} \
@@ -2513,7 +2515,10 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
25132515
.get(location.statement_index)
25142516
{
25152517
Some(&Statement {
2516-
kind: StatementKind::Assign(Place::Local(local), _),
2518+
kind: StatementKind::Assign(NeoPlace {
2519+
base: PlaceBase::Local(local),
2520+
elems: &[],
2521+
}, _),
25172522
..
25182523
}) => local,
25192524
_ => return OtherUse(use_span),

src/librustc_mir/borrow_check/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -503,9 +503,10 @@ impl<'cx, 'gcx, 'tcx> DataflowResultsConsumer<'cx, 'tcx> for MirBorrowckCtxt<'cx
503503
flow_state,
504504
);
505505

506+
let lhs = lhs.clone().into_tree();
506507
self.mutate_place(
507508
ContextKind::AssignLhs.new(location),
508-
(lhs, span),
509+
(&lhs, span),
509510
Shallow(None),
510511
JustWrite,
511512
flow_state,

src/librustc_mir/borrow_check/move_errors.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,7 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> {
118118
.get(location.statement_index)
119119
.map(|stmt| &stmt.kind)
120120
{
121-
let neo_place = self.infcx.tcx.as_new_place(&place);
122-
if let Some(PlaceBase::Local(local)) = neo_place.as_place_base() {
121+
if let Some(PlaceBase::Local(local)) = place.as_place_base() {
123122
let local_decl = &self.mir.local_decls[*local];
124123
// opt_match_place is the
125124
// match_span is the span of the expression being matched on

src/librustc_mir/borrow_check/nll/constraint_generation.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use borrow_check::nll::region_infer::values::LivenessValues;
66
use rustc::infer::InferCtxt;
77
use rustc::mir::visit::TyContext;
88
use rustc::mir::visit::Visitor;
9-
use rustc::mir::{BasicBlock, BasicBlockData, Location, Mir, Place, Rvalue};
9+
use rustc::mir::{BasicBlock, BasicBlockData, Location, Mir, Place, NeoPlace, Rvalue};
1010
use rustc::mir::{SourceInfo, Statement, Terminator};
1111
use rustc::mir::UserTypeProjection;
1212
use rustc::ty::fold::TypeFoldable;
@@ -123,15 +123,15 @@ impl<'cg, 'cx, 'gcx, 'tcx> Visitor<'tcx> for ConstraintGeneration<'cg, 'cx, 'gcx
123123
fn visit_assign(
124124
&mut self,
125125
block: BasicBlock,
126-
place: &Place<'tcx>,
126+
place: &NeoPlace<'tcx>,
127127
rvalue: &Rvalue<'tcx>,
128128
location: Location,
129129
) {
130130
// When we see `X = ...`, then kill borrows of
131131
// `(*X).foo` and so forth.
132132
if let Some(all_facts) = self.all_facts {
133-
if let Place::Local(temp) = place {
134-
if let Some(borrow_indices) = self.borrow_set.local_map.get(temp) {
133+
if let Some(temp) = place.as_local() {
134+
if let Some(borrow_indices) = self.borrow_set.local_map.get(&temp) {
135135
all_facts.killed.reserve(borrow_indices.len());
136136
for &borrow_index in borrow_indices {
137137
let location_index = self.location_table.mid_index(location);

src/librustc_mir/borrow_check/nll/explain_borrow/mod.rs

+15-7
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use borrow_check::{Context, MirBorrowckCtxt, WriteKind};
66
use rustc::ty::{self, TyCtxt};
77
use rustc::mir::{
88
CastKind, ConstraintCategory, FakeReadCause, Local, Location, Mir, Operand,
9-
Place, Projection, ProjectionElem, Rvalue, Statement, StatementKind,
9+
Place, NeoPlace, PlaceBase, ProjectionElem, Rvalue, Statement, StatementKind,
1010
TerminatorKind
1111
};
1212
use rustc_errors::DiagnosticBuilder;
@@ -422,7 +422,10 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
422422
// it which simplifies the termination logic.
423423
let mut queue = vec![location];
424424
let mut target = if let Some(&Statement {
425-
kind: StatementKind::Assign(Place::Local(local), _),
425+
kind: StatementKind::Assign(NeoPlace {
426+
base: PlaceBase::Local(local),
427+
elems: &[],
428+
}, _),
426429
..
427430
}) = stmt {
428431
local
@@ -446,11 +449,16 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
446449
box rvalue,
447450
) = &stmt.kind {
448451
let into = match place {
449-
Place::Local(into) => into,
450-
Place::Projection(box Projection {
451-
base: Place::Local(into),
452-
elem: ProjectionElem::Deref,
453-
}) => into,
452+
NeoPlace {
453+
base: PlaceBase::Local(into),
454+
elems: &[],
455+
} => into,
456+
457+
NeoPlace {
458+
base: PlaceBase::Local(into),
459+
elems,
460+
} if elems.last().unwrap() == &ProjectionElem::Deref => into,
461+
454462
_ => {
455463
// Continue at the next location.
456464
queue.push(current_location.successor_within_block());

src/librustc_mir/borrow_check/nll/invalidation.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ impl<'cx, 'tcx, 'gcx> Visitor<'tcx> for InvalidationGenerator<'cx, 'tcx, 'gcx> {
7373

7474
self.mutate_place(
7575
ContextKind::AssignLhs.new(location),
76-
lhs,
76+
&lhs.clone().into_tree(),
7777
Shallow(None),
7878
JustWrite
7979
);

src/librustc_mir/borrow_check/nll/type_check/mod.rs

+20-19
Original file line numberDiff line numberDiff line change
@@ -1234,32 +1234,33 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
12341234
// they are not caused by the user, but rather artifacts
12351235
// of lowering. Assignments to other sorts of places *are* interesting
12361236
// though.
1237-
let category = match *place {
1238-
Place::Local(RETURN_PLACE) => if let Some(BorrowCheckContext {
1239-
universal_regions:
1240-
UniversalRegions {
1241-
defining_ty: DefiningTy::Const(def_id, _),
1237+
let category = match place.as_local() {
1238+
Some(RETURN_PLACE) =>
1239+
if let Some(BorrowCheckContext {
1240+
universal_regions:
1241+
UniversalRegions {
1242+
defining_ty: DefiningTy::Const(def_id, _),
1243+
..
1244+
},
12421245
..
1243-
},
1244-
..
1245-
}) = self.borrowck_context
1246-
{
1247-
if tcx.is_static(*def_id).is_some() {
1248-
ConstraintCategory::UseAsStatic
1246+
}) = self.borrowck_context {
1247+
if tcx.is_static(*def_id).is_some() {
1248+
ConstraintCategory::UseAsStatic
1249+
} else {
1250+
ConstraintCategory::UseAsConst
1251+
}
12491252
} else {
1250-
ConstraintCategory::UseAsConst
1251-
}
1252-
} else {
1253-
ConstraintCategory::Return
1254-
},
1255-
Place::Local(l) if !mir.local_decls[l].is_user_variable.is_some() => {
1253+
ConstraintCategory::Return
1254+
},
1255+
1256+
Some(l) if !mir.local_decls[l].is_user_variable.is_some() => {
12561257
ConstraintCategory::Boring
12571258
}
1259+
12581260
_ => ConstraintCategory::Assignment,
12591261
};
12601262

1261-
let neo_place = tcx.as_new_place(place);
1262-
let place_ty = neo_place.ty(mir, tcx).to_ty(tcx);
1263+
let place_ty = place.ty(mir, tcx).to_ty(tcx);
12631264
let rv_ty = rv.ty(mir, tcx);
12641265
if let Err(terr) =
12651266
self.sub_types_or_anon(rv_ty, place_ty, location.to_locations(), category)

src/librustc_mir/borrow_check/used_muts.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,7 @@ impl<'visit, 'cx, 'gcx, 'tcx> Visitor<'tcx> for GatherUsedMutsVisitor<'visit, 'c
8888
// be those that were never initialized - we will consider those as being used as
8989
// they will either have been removed by unreachable code optimizations; or linted
9090
// as unused variables.
91-
let neo_into = self.mbcx.infcx.tcx.as_new_place(into);
92-
if let Some(local) = neo_into.base_local() {
91+
if let Some(local) = into.base_local() {
9392
debug!(
9493
"visit_statement: statement={:?} local={:?} \
9594
never_initialized_mut_locals={:?}",

src/librustc_mir/build/block.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,8 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
184184
if destination_ty.is_unit() {
185185
// We only want to assign an implicit `()` as the return value of the block if the
186186
// block does not diverge. (Otherwise, we may try to assign a unit to a `!`-type.)
187-
this.cfg.push_assign_unit(block, source_info, destination);
187+
let destination = tcx.as_new_place(destination);
188+
this.cfg.push_assign_unit(block, source_info, &destination);
188189
}
189190
}
190191
// Finally, we pop all the let scopes before exiting out from the scope of block

src/librustc_mir/build/cfg.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ impl<'tcx> CFG<'tcx> {
3333
pub fn push_assign(&mut self,
3434
block: BasicBlock,
3535
source_info: SourceInfo,
36-
place: &Place<'tcx>,
36+
place: &NeoPlace<'tcx>,
3737
rvalue: Rvalue<'tcx>) {
3838
self.push(block, Statement {
3939
source_info,
@@ -44,7 +44,7 @@ impl<'tcx> CFG<'tcx> {
4444
pub fn push_assign_constant(&mut self,
4545
block: BasicBlock,
4646
source_info: SourceInfo,
47-
temp: &Place<'tcx>,
47+
temp: &NeoPlace<'tcx>,
4848
constant: Constant<'tcx>) {
4949
self.push_assign(block, source_info, temp,
5050
Rvalue::Use(Operand::Constant(box constant)));
@@ -53,7 +53,7 @@ impl<'tcx> CFG<'tcx> {
5353
pub fn push_assign_unit(&mut self,
5454
block: BasicBlock,
5555
source_info: SourceInfo,
56-
place: &Place<'tcx>) {
56+
place: &NeoPlace<'tcx>) {
5757
self.push_assign(block, source_info, place, Rvalue::Aggregate(
5858
box AggregateKind::Tuple, vec![]
5959
));

0 commit comments

Comments
 (0)