Skip to content

Commit 0f993d5

Browse files
committed
Put Local, Static and Promoted as one Base variant of Place
1 parent 1999a22 commit 0f993d5

Some content is hidden

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

63 files changed

+441
-352
lines changed

src/librustc/ich/impls_mir.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -209,13 +209,13 @@ impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for mir::Place<'gcx> {
209209
hasher: &mut StableHasher<W>) {
210210
mem::discriminant(self).hash_stable(hcx, hasher);
211211
match *self {
212-
mir::Place::Local(ref local) => {
212+
mir::Place::Base(mir::PlaceBase::Local(ref local)) => {
213213
local.hash_stable(hcx, hasher);
214214
}
215-
mir::Place::Static(ref statik) => {
215+
mir::Place::Base(mir::PlaceBase::Static(ref statik)) => {
216216
statik.hash_stable(hcx, hasher);
217217
}
218-
mir::Place::Promoted(ref promoted) => {
218+
mir::Place::Base(mir::PlaceBase::Promoted(ref promoted)) => {
219219
promoted.hash_stable(hcx, hasher);
220220
}
221221
mir::Place::Projection(ref place_projection) => {

src/librustc/mir/mod.rs

+22-10
Original file line numberDiff line numberDiff line change
@@ -1896,6 +1896,14 @@ impl<'tcx> Debug for Statement<'tcx> {
18961896
/// changing or disturbing program state.
18971897
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable)]
18981898
pub enum Place<'tcx> {
1899+
Base(PlaceBase<'tcx>),
1900+
1901+
/// projection out of a place (access a field, deref a pointer, etc)
1902+
Projection(Box<PlaceProjection<'tcx>>),
1903+
}
1904+
1905+
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable)]
1906+
pub enum PlaceBase<'tcx> {
18991907
/// local variable
19001908
Local(Local),
19011909

@@ -1904,9 +1912,6 @@ pub enum Place<'tcx> {
19041912

19051913
/// Constant code promoted to an injected static
19061914
Promoted(Box<(Promoted, Ty<'tcx>)>),
1907-
1908-
/// projection out of a place (access a field, deref a pointer, etc)
1909-
Projection(Box<PlaceProjection<'tcx>>),
19101915
}
19111916

19121917
/// The `DefId` of a static, along with its normalized type (which is
@@ -1994,6 +1999,8 @@ newtype_index! {
19941999
}
19952000

19962001
impl<'tcx> Place<'tcx> {
2002+
pub const RETURN_PLACE: Place<'tcx> = Place::Base(PlaceBase::Local(RETURN_PLACE));
2003+
19972004
pub fn field(self, f: Field, ty: Ty<'tcx>) -> Place<'tcx> {
19982005
self.elem(ProjectionElem::Field(f, ty))
19992006
}
@@ -2020,9 +2027,9 @@ impl<'tcx> Place<'tcx> {
20202027
// FIXME: can we safely swap the semantics of `fn base_local` below in here instead?
20212028
pub fn local(&self) -> Option<Local> {
20222029
match self {
2023-
Place::Local(local) |
2030+
Place::Base(PlaceBase::Local(local)) |
20242031
Place::Projection(box Projection {
2025-
base: Place::Local(local),
2032+
base: Place::Base(PlaceBase::Local(local)),
20262033
elem: ProjectionElem::Deref,
20272034
}) => Some(*local),
20282035
_ => None,
@@ -2032,9 +2039,9 @@ impl<'tcx> Place<'tcx> {
20322039
/// Finds the innermost `Local` from this `Place`.
20332040
pub fn base_local(&self) -> Option<Local> {
20342041
match self {
2035-
Place::Local(local) => Some(*local),
2042+
Place::Base(PlaceBase::Local(local)) => Some(*local),
20362043
Place::Projection(box Projection { base, elem: _ }) => base.base_local(),
2037-
Place::Promoted(..) | Place::Static(..) => None,
2044+
Place::Base(PlaceBase::Promoted(..)) | Place::Base(PlaceBase::Static(..)) => None,
20382045
}
20392046
}
20402047
}
@@ -2044,14 +2051,19 @@ impl<'tcx> Debug for Place<'tcx> {
20442051
use self::Place::*;
20452052

20462053
match *self {
2047-
Local(id) => write!(fmt, "{:?}", id),
2048-
Static(box self::Static { def_id, ty }) => write!(
2054+
Base(PlaceBase::Local(id)) => write!(fmt, "{:?}", id),
2055+
Base(PlaceBase::Static(box self::Static { def_id, ty })) => write!(
20492056
fmt,
20502057
"({}: {:?})",
20512058
ty::tls::with(|tcx| tcx.item_path_str(def_id)),
20522059
ty
20532060
),
2054-
Promoted(ref promoted) => write!(fmt, "({:?}: {:?})", promoted.0, promoted.1),
2061+
Base(PlaceBase::Promoted(ref promoted)) => write!(
2062+
fmt,
2063+
"({:?}: {:?})",
2064+
promoted.0,
2065+
promoted.1
2066+
),
20552067
Projection(ref data) => match data.elem {
20562068
ProjectionElem::Downcast(ref adt_def, index) => {
20572069
write!(fmt, "({:?} as {})", data.base, adt_def.variants[index].ident)

src/librustc/mir/tcx.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,10 @@ impl<'tcx> Place<'tcx> {
158158
where D: HasLocalDecls<'tcx>
159159
{
160160
match *self {
161-
Place::Local(index) =>
161+
Place::Base(PlaceBase::Local(index)) =>
162162
PlaceTy::Ty { ty: local_decls.local_decls()[index].ty },
163-
Place::Promoted(ref data) => PlaceTy::Ty { ty: data.1 },
164-
Place::Static(ref data) =>
163+
Place::Base(PlaceBase::Promoted(ref data)) => PlaceTy::Ty { ty: data.1 },
164+
Place::Base(PlaceBase::Static(ref data)) =>
165165
PlaceTy::Ty { ty: data.ty },
166166
Place::Projection(ref proj) =>
167167
proj.base.ty(local_decls, tcx).projection_ty(tcx, &proj.elem),

src/librustc/mir/visit.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -733,13 +733,13 @@ macro_rules! make_mir_visitor {
733733
context: PlaceContext<'tcx>,
734734
location: Location) {
735735
match place {
736-
Place::Local(local) => {
736+
Place::Base(PlaceBase::Local(local)) => {
737737
self.visit_local(local, context, location);
738738
}
739-
Place::Static(static_) => {
739+
Place::Base(PlaceBase::Static(static_)) => {
740740
self.visit_static(static_, context, location);
741741
}
742-
Place::Promoted(promoted) => {
742+
Place::Base(PlaceBase::Promoted(promoted)) => {
743743
self.visit_ty(& $($mutability)? promoted.1, TyContext::Location(location));
744744
},
745745
Place::Projection(proj) => {

src/librustc_codegen_ssa/mir/analyze.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ impl<'mir, 'a: 'mir, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> Visitor<'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 mir::Place::Base(mir::PlaceBase::Local(index)) = *place {
107107
self.assign(index, location);
108108
if !self.fx.rvalue_creates_operand(rvalue) {
109109
self.not_ssa(index);
@@ -245,7 +245,8 @@ impl<'mir, 'a: 'mir, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> Visitor<'tcx>
245245
}
246246

247247
PlaceContext::MutatingUse(MutatingUseContext::Drop) => {
248-
let ty = mir::Place::Local(local).ty(self.fx.mir, self.fx.cx.tcx());
248+
let ty = mir::Place::Base(mir::PlaceBase::Local(local)).ty(self.fx.mir,
249+
self.fx.cx.tcx());
249250
let ty = self.fx.monomorphize(&ty.to_ty(self.fx.cx.tcx()));
250251

251252
// Only need the place if we're actually dropping it.

src/librustc_codegen_ssa/mir/block.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
249249

250250
PassMode::Direct(_) | PassMode::Pair(..) => {
251251
let op =
252-
self.codegen_consume(&mut bx, &mir::Place::Local(mir::RETURN_PLACE));
252+
self.codegen_consume(&mut bx, &mir::Place::RETURN_PLACE);
253253
if let Ref(llval, _, align) = op.val {
254254
bx.load(llval, align)
255255
} else {
@@ -615,8 +615,12 @@ impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
615615
// The shuffle array argument is usually not an explicit constant,
616616
// but specified directly in the code. This means it gets promoted
617617
// and we can then extract the value by evaluating the promoted.
618-
mir::Operand::Copy(mir::Place::Promoted(box(index, ty))) |
619-
mir::Operand::Move(mir::Place::Promoted(box(index, ty))) => {
618+
mir::Operand::Copy(
619+
mir::Place::Base(mir::PlaceBase::Promoted(box(index, ty)))
620+
) |
621+
mir::Operand::Move(
622+
mir::Place::Base(mir::PlaceBase::Promoted(box(index, ty)))
623+
) => {
620624
let param_env = ty::ParamEnv::reveal_all();
621625
let cid = mir::interpret::GlobalId {
622626
instance: self.instance,
@@ -1106,7 +1110,7 @@ impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
11061110
if fn_ret.is_ignore() {
11071111
return ReturnDest::Nothing;
11081112
}
1109-
let dest = if let mir::Place::Local(index) = *dest {
1113+
let dest = if let mir::Place::Base(mir::PlaceBase::Local(index)) = *dest {
11101114
match self.locals[index] {
11111115
LocalRef::Place(dest) => dest,
11121116
LocalRef::UnsizedPlace(_) => bug!("return type must be sized"),
@@ -1161,7 +1165,7 @@ impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
11611165
src: &mir::Operand<'tcx>,
11621166
dst: &mir::Place<'tcx>
11631167
) {
1164-
if let mir::Place::Local(index) = *dst {
1168+
if let mir::Place::Base(mir::PlaceBase::Local(index)) = *dst {
11651169
match self.locals[index] {
11661170
LocalRef::Place(place) => self.codegen_transmute_into(bx, src, place),
11671171
LocalRef::UnsizedPlace(_) => bug!("transmute must not involve unsized locals"),

src/librustc_codegen_ssa/mir/operand.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
378378

379379
// watch out for locals that do not have an
380380
// alloca; they are handled somewhat differently
381-
if let mir::Place::Local(index) = *place {
381+
if let mir::Place::Base(mir::PlaceBase::Local(index)) = *place {
382382
match self.locals[index] {
383383
LocalRef::Operand(Some(o)) => {
384384
return Some(o);

src/librustc_codegen_ssa/mir/place.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
392392
let cx = self.cx;
393393
let tcx = self.cx.tcx();
394394

395-
if let mir::Place::Local(index) = *place {
395+
if let mir::Place::Base(mir::PlaceBase::Local(index)) = *place {
396396
match self.locals[index] {
397397
LocalRef::Place(place) => {
398398
return place;
@@ -407,8 +407,8 @@ impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
407407
}
408408

409409
let result = match *place {
410-
mir::Place::Local(_) => bug!(), // handled above
411-
mir::Place::Promoted(box (index, ty)) => {
410+
mir::Place::Base(mir::PlaceBase::Local(_)) => bug!(), // handled above
411+
mir::Place::Base(mir::PlaceBase::Promoted(box (index, ty))) => {
412412
let param_env = ty::ParamEnv::reveal_all();
413413
let cid = mir::interpret::GlobalId {
414414
instance: self.instance,
@@ -435,7 +435,7 @@ impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
435435
}
436436
}
437437
}
438-
mir::Place::Static(box mir::Static { def_id, ty }) => {
438+
mir::Place::Base(mir::PlaceBase::Static(box mir::Static { def_id, ty })) => {
439439
// NB: The layout of a static may be unsized as is the case when working
440440
// with a static that is an extern_type.
441441
let layout = cx.layout_of(self.monomorphize(&ty));
@@ -457,7 +457,9 @@ impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
457457
cg_base.project_field(bx, field.index())
458458
}
459459
mir::ProjectionElem::Index(index) => {
460-
let index = &mir::Operand::Copy(mir::Place::Local(index));
460+
let index = &mir::Operand::Copy(
461+
mir::Place::Base(mir::PlaceBase::Local(index))
462+
);
461463
let index = self.codegen_operand(bx, index);
462464
let llindex = index.immediate();
463465
cg_base.project_index(bx, llindex)

src/librustc_codegen_ssa/mir/rvalue.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
534534
) -> Bx::Value {
535535
// ZST are passed as operands and require special handling
536536
// because codegen_place() panics if Local is operand.
537-
if let mir::Place::Local(index) = *place {
537+
if let mir::Place::Base(mir::PlaceBase::Local(index)) = *place {
538538
if let LocalRef::Operand(Some(op)) = self.locals[index] {
539539
if let ty::Array(_, n) = op.layout.ty.sty {
540540
let n = n.unwrap_usize(bx.cx().tcx());

src/librustc_codegen_ssa/mir/statement.rs

+1-1
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 mir::Place::Base(mir::PlaceBase::Local(index)) = *place {
2121
match self.locals[index] {
2222
LocalRef::Place(cg_dest) => {
2323
self.codegen_rvalue(bx, cg_dest, rvalue)

src/librustc_mir/borrow_check/borrow_set.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ impl<'a, 'gcx, 'tcx> GatherBorrows<'a, 'gcx, 'tcx> {
333333
// TEMP = &foo
334334
//
335335
// so extract `temp`.
336-
let temp = if let &mir::Place::Local(temp) = assigned_place {
336+
let temp = if let &mir::Place::Base(mir::PlaceBase::Local(temp)) = assigned_place {
337337
temp
338338
} else {
339339
span_bug!(

0 commit comments

Comments
 (0)