Skip to content

Commit

Permalink
Put Local, Static and Promoted as one Base variant of Place
Browse files Browse the repository at this point in the history
  • Loading branch information
spastorino committed Feb 26, 2019
1 parent ea43c3c commit 4cfe141
Show file tree
Hide file tree
Showing 63 changed files with 444 additions and 352 deletions.
6 changes: 3 additions & 3 deletions src/librustc/ich/impls_mir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,13 @@ impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for mir::Place<'gcx> {
hasher: &mut StableHasher<W>) {
mem::discriminant(self).hash_stable(hcx, hasher);
match *self {
mir::Place::Local(ref local) => {
mir::Place::Base(mir::PlaceBase::Local(ref local)) => {
local.hash_stable(hcx, hasher);
}
mir::Place::Static(ref statik) => {
mir::Place::Base(mir::PlaceBase::Static(ref statik)) => {
statik.hash_stable(hcx, hasher);
}
mir::Place::Promoted(ref promoted) => {
mir::Place::Base(mir::PlaceBase::Promoted(ref promoted)) => {
promoted.hash_stable(hcx, hasher);
}
mir::Place::Projection(ref place_projection) => {
Expand Down
32 changes: 22 additions & 10 deletions src/librustc/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1896,6 +1896,14 @@ impl<'tcx> Debug for Statement<'tcx> {
/// changing or disturbing program state.
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable)]
pub enum Place<'tcx> {
Base(PlaceBase<'tcx>),

/// projection out of a place (access a field, deref a pointer, etc)
Projection(Box<PlaceProjection<'tcx>>),
}

#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable)]
pub enum PlaceBase<'tcx> {
/// local variable
Local(Local),

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

/// Constant code promoted to an injected static
Promoted(Box<(Promoted, Ty<'tcx>)>),

/// projection out of a place (access a field, deref a pointer, etc)
Projection(Box<PlaceProjection<'tcx>>),
}

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

impl<'tcx> Place<'tcx> {
pub const RETURN_PLACE: Place<'tcx> = Place::Base(PlaceBase::Local(RETURN_PLACE));

pub fn field(self, f: Field, ty: Ty<'tcx>) -> Place<'tcx> {
self.elem(ProjectionElem::Field(f, ty))
}
Expand All @@ -2020,9 +2027,9 @@ impl<'tcx> Place<'tcx> {
// FIXME: can we safely swap the semantics of `fn base_local` below in here instead?
pub fn local(&self) -> Option<Local> {
match self {
Place::Local(local) |
Place::Base(PlaceBase::Local(local)) |
Place::Projection(box Projection {
base: Place::Local(local),
base: Place::Base(PlaceBase::Local(local)),
elem: ProjectionElem::Deref,
}) => Some(*local),
_ => None,
Expand All @@ -2032,9 +2039,9 @@ impl<'tcx> Place<'tcx> {
/// Finds the innermost `Local` from this `Place`.
pub fn base_local(&self) -> Option<Local> {
match self {
Place::Local(local) => Some(*local),
Place::Base(PlaceBase::Local(local)) => Some(*local),
Place::Projection(box Projection { base, elem: _ }) => base.base_local(),
Place::Promoted(..) | Place::Static(..) => None,
Place::Base(PlaceBase::Promoted(..)) | Place::Base(PlaceBase::Static(..)) => None,
}
}
}
Expand All @@ -2044,14 +2051,19 @@ impl<'tcx> Debug for Place<'tcx> {
use self::Place::*;

match *self {
Local(id) => write!(fmt, "{:?}", id),
Static(box self::Static { def_id, ty }) => write!(
Base(PlaceBase::Local(id)) => write!(fmt, "{:?}", id),
Base(PlaceBase::Static(box self::Static { def_id, ty })) => write!(
fmt,
"({}: {:?})",
ty::tls::with(|tcx| tcx.item_path_str(def_id)),
ty
),
Promoted(ref promoted) => write!(fmt, "({:?}: {:?})", promoted.0, promoted.1),
Base(PlaceBase::Promoted(ref promoted)) => write!(
fmt,
"({:?}: {:?})",
promoted.0,
promoted.1
),
Projection(ref data) => match data.elem {
ProjectionElem::Downcast(ref adt_def, index) => {
write!(fmt, "({:?} as {})", data.base, adt_def.variants[index].ident)
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/mir/tcx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,10 @@ impl<'tcx> Place<'tcx> {
where D: HasLocalDecls<'tcx>
{
match *self {
Place::Local(index) =>
Place::Base(PlaceBase::Local(index)) =>
PlaceTy::Ty { ty: local_decls.local_decls()[index].ty },
Place::Promoted(ref data) => PlaceTy::Ty { ty: data.1 },
Place::Static(ref data) =>
Place::Base(PlaceBase::Promoted(ref data)) => PlaceTy::Ty { ty: data.1 },
Place::Base(PlaceBase::Static(ref data)) =>
PlaceTy::Ty { ty: data.ty },
Place::Projection(ref proj) =>
proj.base.ty(local_decls, tcx).projection_ty(tcx, &proj.elem),
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/mir/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -733,13 +733,13 @@ macro_rules! make_mir_visitor {
context: PlaceContext<'tcx>,
location: Location) {
match place {
Place::Local(local) => {
Place::Base(PlaceBase::Local(local)) => {
self.visit_local(local, context, location);
}
Place::Static(static_) => {
Place::Base(PlaceBase::Static(static_)) => {
self.visit_static(static_, context, location);
}
Place::Promoted(promoted) => {
Place::Base(PlaceBase::Promoted(promoted)) => {
self.visit_ty(& $($mutability)? promoted.1, TyContext::Location(location));
},
Place::Projection(proj) => {
Expand Down
5 changes: 3 additions & 2 deletions src/librustc_codegen_ssa/mir/analyze.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ impl<'mir, 'a: 'mir, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> Visitor<'tcx>
location: Location) {
debug!("visit_assign(block={:?}, place={:?}, rvalue={:?})", block, place, rvalue);

if let mir::Place::Local(index) = *place {
if let mir::Place::Base(mir::PlaceBase::Local(index)) = *place {
self.assign(index, location);
if !self.fx.rvalue_creates_operand(rvalue) {
self.not_ssa(index);
Expand Down Expand Up @@ -245,7 +245,8 @@ impl<'mir, 'a: 'mir, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> Visitor<'tcx>
}

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

// Only need the place if we're actually dropping it.
Expand Down
17 changes: 12 additions & 5 deletions src/librustc_codegen_ssa/mir/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,10 @@ impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {

PassMode::Direct(_) | PassMode::Pair(..) => {
let op =
self.codegen_consume(&mut bx, &mir::Place::Local(mir::RETURN_PLACE));
self.codegen_consume(
&mut bx,
&mir::Place::RETURN_PLACE,
);
if let Ref(llval, _, align) = op.val {
bx.load(llval, align)
} else {
Expand Down Expand Up @@ -589,8 +592,12 @@ impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
// The shuffle array argument is usually not an explicit constant,
// but specified directly in the code. This means it gets promoted
// and we can then extract the value by evaluating the promoted.
mir::Operand::Copy(mir::Place::Promoted(box(index, ty))) |
mir::Operand::Move(mir::Place::Promoted(box(index, ty))) => {
mir::Operand::Copy(
mir::Place::Base(mir::PlaceBase::Promoted(box(index, ty)))
) |
mir::Operand::Move(
mir::Place::Base(mir::PlaceBase::Promoted(box(index, ty)))
) => {
let param_env = ty::ParamEnv::reveal_all();
let cid = mir::interpret::GlobalId {
instance: self.instance,
Expand Down Expand Up @@ -964,7 +971,7 @@ impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
if fn_ret.is_ignore() {
return ReturnDest::Nothing;
}
let dest = if let mir::Place::Local(index) = *dest {
let dest = if let mir::Place::Base(mir::PlaceBase::Local(index)) = *dest {
match self.locals[index] {
LocalRef::Place(dest) => dest,
LocalRef::UnsizedPlace(_) => bug!("return type must be sized"),
Expand Down Expand Up @@ -1019,7 +1026,7 @@ impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
src: &mir::Operand<'tcx>,
dst: &mir::Place<'tcx>
) {
if let mir::Place::Local(index) = *dst {
if let mir::Place::Base(mir::PlaceBase::Local(index)) = *dst {
match self.locals[index] {
LocalRef::Place(place) => self.codegen_transmute_into(bx, src, place),
LocalRef::UnsizedPlace(_) => bug!("transmute must not involve unsized locals"),
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_ssa/mir/operand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {

// watch out for locals that do not have an
// alloca; they are handled somewhat differently
if let mir::Place::Local(index) = *place {
if let mir::Place::Base(mir::PlaceBase::Local(index)) = *place {
match self.locals[index] {
LocalRef::Operand(Some(o)) => {
return Some(o);
Expand Down
12 changes: 7 additions & 5 deletions src/librustc_codegen_ssa/mir/place.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
let cx = self.cx;
let tcx = self.cx.tcx();

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

let result = match *place {
mir::Place::Local(_) => bug!(), // handled above
mir::Place::Promoted(box (index, ty)) => {
mir::Place::Base(mir::PlaceBase::Local(_)) => bug!(), // handled above
mir::Place::Base(mir::PlaceBase::Promoted(box (index, ty))) => {
let param_env = ty::ParamEnv::reveal_all();
let cid = mir::interpret::GlobalId {
instance: self.instance,
Expand All @@ -435,7 +435,7 @@ impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
}
}
}
mir::Place::Static(box mir::Static { def_id, ty }) => {
mir::Place::Base(mir::PlaceBase::Static(box mir::Static { def_id, ty })) => {
// NB: The layout of a static may be unsized as is the case when working
// with a static that is an extern_type.
let layout = cx.layout_of(self.monomorphize(&ty));
Expand All @@ -457,7 +457,9 @@ impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
cg_base.project_field(bx, field.index())
}
mir::ProjectionElem::Index(index) => {
let index = &mir::Operand::Copy(mir::Place::Local(index));
let index = &mir::Operand::Copy(
mir::Place::Base(mir::PlaceBase::Local(index))
);
let index = self.codegen_operand(bx, index);
let llindex = index.immediate();
cg_base.project_index(bx, llindex)
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_ssa/mir/rvalue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
) -> Bx::Value {
// ZST are passed as operands and require special handling
// because codegen_place() panics if Local is operand.
if let mir::Place::Local(index) = *place {
if let mir::Place::Base(mir::PlaceBase::Local(index)) = *place {
if let LocalRef::Operand(Some(op)) = self.locals[index] {
if let ty::Array(_, n) = op.layout.ty.sty {
let n = n.unwrap_usize(bx.cx().tcx());
Expand Down
2 changes: 1 addition & 1 deletion 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 mir::Place::Base(mir::PlaceBase::Local(index)) = *place {
match self.locals[index] {
LocalRef::Place(cg_dest) => {
self.codegen_rvalue(bx, cg_dest, rvalue)
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/borrow_check/borrow_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ impl<'a, 'gcx, 'tcx> GatherBorrows<'a, 'gcx, 'tcx> {
// TEMP = &foo
//
// so extract `temp`.
let temp = if let &mir::Place::Local(temp) = assigned_place {
let temp = if let &mir::Place::Base(mir::PlaceBase::Local(temp)) = assigned_place {
temp
} else {
span_bug!(
Expand Down
Loading

0 comments on commit 4cfe141

Please sign in to comment.