Skip to content

Commit 6002649

Browse files
committed
Clean up old Place in rustc_mir
1 parent a5c428b commit 6002649

Some content is hidden

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

45 files changed

+1029
-755
lines changed

src/librustc/mir/mod.rs

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1807,7 +1807,8 @@ impl<'a, 'tcx> Place<'tcx> {
18071807
pub fn downcast(
18081808
self,
18091809
tcx: TyCtxt<'a, 'tcx, 'tcx>,
1810-
adt_def: &'tcx AdtDef, variant_index: usize,
1810+
adt_def: &'tcx AdtDef,
1811+
variant_index: usize,
18111812
) -> Self {
18121813
self.elem(tcx, ProjectionElem::Downcast(adt_def, variant_index))
18131814
}
@@ -1816,6 +1817,29 @@ impl<'a, 'tcx> Place<'tcx> {
18161817
self.elem(tcx, ProjectionElem::Index(index))
18171818
}
18181819

1820+
pub fn constant_index(
1821+
self,
1822+
tcx: TyCtxt<'a, 'tcx, 'tcx>,
1823+
offset: u32,
1824+
min_length: u32,
1825+
from_end: bool,
1826+
) -> Self {
1827+
self.elem(tcx, ProjectionElem::ConstantIndex {
1828+
offset, min_length, from_end,
1829+
})
1830+
}
1831+
1832+
pub fn subslice(
1833+
self,
1834+
tcx: TyCtxt<'a, 'tcx, 'tcx>,
1835+
from: u32,
1836+
to: u32,
1837+
) -> Self {
1838+
self.elem(tcx, ProjectionElem::Subslice {
1839+
from, to,
1840+
})
1841+
}
1842+
18191843
pub fn elem(
18201844
self,
18211845
tcx: TyCtxt<'a, 'tcx, 'tcx>,
@@ -1833,6 +1857,23 @@ impl<'a, 'tcx> Place<'tcx> {
18331857
elems: Slice::empty(),
18341858
}
18351859
}
1860+
1861+
pub fn static_(static_: Static<'tcx>) -> Self {
1862+
Place {
1863+
base: PlaceBase::Static(box static_),
1864+
elems: Slice::empty(),
1865+
}
1866+
}
1867+
1868+
pub fn promoted(
1869+
promoted: Promoted,
1870+
ty: Ty<'tcx>,
1871+
) -> Self {
1872+
Place {
1873+
base: PlaceBase::Promoted(box (promoted, ty)),
1874+
elems: Slice::empty(),
1875+
}
1876+
}
18361877
}
18371878

18381879
impl<'tcx> Debug for PlaceBase<'tcx> {

src/librustc_mir/borrow_check/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1792,7 +1792,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
17921792
// to a direct owner of `place` (which means there is nothing
17931793
// that borrowck tracks for its analysis).
17941794

1795-
match self.move_data.rev_lookup.find(place) {
1795+
match self.move_data.rev_lookup.find(self.tcx, place) {
17961796
LookupResult::Parent(_) => None,
17971797
LookupResult::Exact(mpi) => Some(mpi),
17981798
}

src/librustc_mir/borrow_check/move_errors.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> {
154154
let from_simple_let = match_place.is_none();
155155
let match_place = match_place.as_ref().unwrap_or(move_from);
156156

157-
match self.move_data.rev_lookup.find(match_place) {
157+
match self.move_data.rev_lookup.find(self.tcx, match_place) {
158158
// Error with the match place
159159
LookupResult::Parent(_) => {
160160
for ge in &mut *grouped_errors {
@@ -185,7 +185,7 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> {
185185
}
186186
// Error with the pattern
187187
LookupResult::Exact(_) => {
188-
let mpi = match self.move_data.rev_lookup.find(move_from) {
188+
let mpi = match self.move_data.rev_lookup.find(self.tcx, move_from) {
189189
LookupResult::Parent(Some(mpi)) => mpi,
190190
// move_from should be a projection from match_place.
191191
_ => unreachable!("Probably not unreachable..."),

src/librustc_mir/build/expr/as_operand.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
7474
Category::Rvalue(..) => {
7575
let operand =
7676
unpack!(block = this.as_temp(block, scope, expr));
77-
block.and(Operand::Move(Place::Local(operand)))
77+
block.and(Operand::Move(Place::local(operand)))
7878
}
7979
}
8080
}

src/librustc_mir/build/expr/as_place.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,12 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
4848
}
4949
ExprKind::Field { lhs, name } => {
5050
let place = unpack!(block = this.as_place(block, lhs));
51-
let place = place.field(name, expr.ty);
51+
let place = place.field(this.hir.tcx(), name, expr.ty);
5252
block.and(place)
5353
}
5454
ExprKind::Deref { arg } => {
5555
let place = unpack!(block = this.as_place(block, arg));
56-
let place = place.deref();
56+
let place = place.deref(this.hir.tcx());
5757
block.and(place)
5858
}
5959
ExprKind::Index { lhs, index } => {
@@ -72,34 +72,34 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
7272
&len, Rvalue::Len(slice.clone()));
7373
this.cfg.push_assign(block, source_info, // lt = idx < len
7474
&lt, Rvalue::BinaryOp(BinOp::Lt,
75-
Operand::Copy(Place::Local(idx)),
75+
Operand::Copy(Place::local(idx)),
7676
Operand::Copy(len.clone())));
7777

7878
let msg = BoundsCheck {
7979
len: Operand::Move(len),
80-
index: Operand::Copy(Place::Local(idx))
80+
index: Operand::Copy(Place::local(idx))
8181
};
8282
let success = this.assert(block, Operand::Move(lt), true,
8383
msg, expr_span);
84-
success.and(slice.index(idx))
84+
success.and(slice.index(this.hir.tcx(), idx))
8585
}
8686
ExprKind::SelfRef => {
87-
block.and(Place::Local(Local::new(1)))
87+
block.and(Place::local(Local::new(1)))
8888
}
8989
ExprKind::VarRef { id } => {
9090
let place = if this.is_bound_var_in_guard(id) &&
9191
this.hir.tcx().all_pat_vars_are_implicit_refs_within_guards()
9292
{
9393
let index = this.var_local_id(id, RefWithinGuard);
94-
Place::Local(index).deref()
94+
Place::local(index).deref(this.hir.tcx())
9595
} else {
9696
let index = this.var_local_id(id, OutsideGuard);
97-
Place::Local(index)
97+
Place::local(index)
9898
};
9999
block.and(place)
100100
}
101101
ExprKind::StaticRef { id } => {
102-
block.and(Place::Static(Box::new(Static { def_id: id, ty: expr.ty })))
102+
block.and(Place::static_(Static { def_id: id, ty: expr.ty }))
103103
}
104104

105105
ExprKind::Array { .. } |
@@ -138,7 +138,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
138138
_ => true,
139139
});
140140
let temp = unpack!(block = this.as_temp(block, expr.temp_lifetime, expr));
141-
block.and(Place::Local(temp))
141+
block.and(Place::local(temp))
142142
}
143143
}
144144
}

src/librustc_mir/build/expr/as_rvalue.rs

Lines changed: 78 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -103,17 +103,17 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
103103
if let Some(scope) = scope {
104104
// schedule a shallow free of that memory, lest we unwind:
105105
this.schedule_drop_storage_and_value(
106-
expr_span, scope, &Place::Local(result), value.ty,
106+
expr_span, scope, &Place::local(result), value.ty,
107107
);
108108
}
109109

110110
// malloc some memory of suitable type (thus far, uninitialized):
111111
let box_ = Rvalue::NullaryOp(NullOp::Box, value.ty);
112-
this.cfg.push_assign(block, source_info, &Place::Local(result), box_);
112+
this.cfg.push_assign(block, source_info, &Place::local(result), box_);
113113

114114
// initialize the box contents:
115-
unpack!(block = this.into(&Place::Local(result).deref(), block, value));
116-
block.and(Rvalue::Use(Operand::Move(Place::Local(result))))
115+
unpack!(block = this.into(&Place::local(result).deref(this.hir.tcx()), block, value));
116+
block.and(Rvalue::Use(Operand::Move(Place::local(result))))
117117
}
118118
ExprKind::Cast { source } => {
119119
let source = this.hir.mirror(source);
@@ -277,7 +277,11 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
277277
.zip(field_types.into_iter())
278278
.map(|(n, ty)| match fields_map.get(&n) {
279279
Some(v) => v.clone(),
280-
None => this.consume_by_copy_or_move(base.clone().field(n, ty))
280+
None => this.consume_by_copy_or_move(base.clone().field(
281+
this.hir.tcx(),
282+
n,
283+
ty,
284+
))
281285
})
282286
.collect()
283287
} else {
@@ -350,8 +354,8 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
350354
let val_fld = Field::new(0);
351355
let of_fld = Field::new(1);
352356

353-
let val = result_value.clone().field(val_fld, ty);
354-
let of = result_value.field(of_fld, bool_ty);
357+
let val = result_value.clone().field(self.hir.tcx(), val_fld, ty);
358+
let of = result_value.field(self.hir.tcx(), of_fld, bool_ty);
355359

356360
let err = EvalErrorKind::Overflow(op);
357361

@@ -423,6 +427,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
423427
) -> BlockAnd<Operand<'tcx>> {
424428
let this = self;
425429

430+
let tcx = this.hir.tcx();
426431
let source_info = this.source_info(upvar_span);
427432
let temp = this.local_decls.push(LocalDecl::new_temp(upvar_ty, upvar_span));
428433

@@ -433,56 +438,73 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
433438

434439
let arg_place = unpack!(block = this.as_place(block, arg));
435440

436-
let mutability = match arg_place {
437-
Place::Local(local) => this.local_decls[local].mutability,
438-
Place::Projection(box Projection {
439-
base: Place::Local(local),
440-
elem: ProjectionElem::Deref,
441-
}) => {
442-
debug_assert!(
443-
if let Some(ClearCrossCrate::Set(BindingForm::RefForGuard))
444-
= this.local_decls[local].is_user_variable {
445-
true
441+
let mutability = if let Some((base_place, projection)) = arg_place.split_projection(tcx) {
442+
match projection {
443+
ProjectionElem::Deref => {
444+
if let PlaceBase::Local(local) = base_place.base {
445+
debug_assert!(
446+
if let Some(ClearCrossCrate::Set(BindingForm::RefForGuard))
447+
= this.local_decls[local].is_user_variable {
448+
true
449+
} else {
450+
false
451+
},
452+
"Unexpected capture place",
453+
);
454+
this.local_decls[local].mutability
455+
} else if let Some((base_place, projection)) = base_place.split_projection(tcx) {
456+
if let ProjectionElem::Field(upvar_index, _) = projection {
457+
// Not projected from the implicit `self` in a closure.
458+
debug_assert!(
459+
if let Some((base_place, projection)) = base_place.split_projection(tcx) {
460+
PlaceBase::Local(Local::new(1)) == base_place.base
461+
} else {
462+
match base_place.base {
463+
PlaceBase::Local(local) => local == Local::new(1),
464+
_ => false,
465+
}
466+
},
467+
"Unexpected capture place"
468+
);
469+
// Not in a closure
470+
debug_assert!(
471+
this.upvar_decls.len() > upvar_index.index(),
472+
"Unexpected capture place"
473+
);
474+
this.upvar_decls[upvar_index.index()].mutability
475+
}
446476
} else {
447-
false
448-
},
449-
"Unexpected capture place",
450-
);
451-
this.local_decls[local].mutability
477+
bug!("Unexpected capture place");
478+
}
479+
},
480+
ProjectionElem::Field(upvar_index, _) => {
481+
// Not projected from the implicit `self` in a closure.
482+
debug_assert!(
483+
if let Some((base_place, projection)) = base_place.split_projection(tcx) {
484+
PlaceBase::Local(Local::new(1)) == base_place.base
485+
} else {
486+
match base_place.base {
487+
PlaceBase::Local(local) => local == Local::new(1),
488+
_ => false,
489+
}
490+
},
491+
"Unexpected capture place"
492+
);
493+
// Not in a closure
494+
debug_assert!(
495+
this.upvar_decls.len() > upvar_index.index(),
496+
"Unexpected capture place"
497+
);
498+
this.upvar_decls[upvar_index.index()].mutability
499+
}
452500
}
453-
Place::Projection(box Projection {
454-
ref base,
455-
elem: ProjectionElem::Field(upvar_index, _),
456-
})
457-
| Place::Projection(box Projection {
458-
base: Place::Projection(box Projection {
459-
ref base,
460-
elem: ProjectionElem::Field(upvar_index, _),
461-
}),
462-
elem: ProjectionElem::Deref,
463-
}) => {
464-
// Not projected from the implicit `self` in a closure.
465-
debug_assert!(
466-
match *base {
467-
Place::Local(local) => local == Local::new(1),
468-
Place::Projection(box Projection {
469-
ref base,
470-
elem: ProjectionElem::Deref,
471-
}) => *base == Place::Local(Local::new(1)),
472-
_ => false,
473-
},
474-
"Unexpected capture place"
475-
);
476-
// Not in a closure
477-
debug_assert!(
478-
this.upvar_decls.len() > upvar_index.index(),
479-
"Unexpected capture place"
480-
);
481-
this.upvar_decls[upvar_index.index()].mutability
501+
} else {
502+
if let PlaceBase::Local(local) = arg_place.base {
503+
this.local_decls[local].mutability
504+
} else {
505+
bug!("Unexpected capture place");
482506
}
483-
_ => bug!("Unexpected capture place"),
484507
};
485-
486508
let borrow_kind = match mutability {
487509
Mutability::Not => BorrowKind::Unique,
488510
Mutability::Mut => BorrowKind::Mut { allow_two_phase_borrow: false },
@@ -491,7 +513,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
491513
this.cfg.push_assign(
492514
block,
493515
source_info,
494-
&Place::Local(temp),
516+
&Place::local(temp),
495517
Rvalue::Ref(region, borrow_kind, arg_place),
496518
);
497519

@@ -500,11 +522,11 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
500522
// a constant at this time, even if the type may need dropping.
501523
if let Some(temp_lifetime) = temp_lifetime {
502524
this.schedule_drop_storage_and_value(
503-
upvar_span, temp_lifetime, &Place::Local(temp), upvar_ty,
525+
upvar_span, temp_lifetime, &Place::local(temp), upvar_ty,
504526
);
505527
}
506528

507-
block.and(Operand::Move(Place::Local(temp)))
529+
block.and(Operand::Move(Place::local(temp)))
508530
}
509531

510532
// Helper to get a `-1` value of the appropriate type

src/librustc_mir/build/expr/as_temp.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,14 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
5656
});
5757
}
5858

59-
unpack!(block = this.into(&Place::Local(temp), block, expr));
59+
unpack!(block = this.into(&Place::local(temp), block, expr));
6060

6161
// In constants, temp_lifetime is None. We should not need to drop
6262
// anything because no values with a destructor can be created in
6363
// a constant at this time, even if the type may need dropping.
6464
if let Some(temp_lifetime) = temp_lifetime {
6565
this.schedule_drop_storage_and_value(
66-
expr_span, temp_lifetime, &Place::Local(temp), expr_ty,
66+
expr_span, temp_lifetime, &Place::local(temp), expr_ty,
6767
);
6868
}
6969

0 commit comments

Comments
 (0)