Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit b332e77

Browse files
authoredFeb 28, 2019
Rollup merge of #58631 - spastorino:place2_1, r=oli-obk
Put Local, Static and Promoted as one Base variant of Place Related to #52708 The `Place` 2.0 representation use a `Base` variant for `Local`, `Static` and `Promoted` so we start making this change in the current `Place` to make the following steps simpler. r? @oli-obk
2 parents acc2bca + 4cfe141 commit b332e77

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

+444
-352
lines changed
 

‎src/librustc/ich/impls_mir.rs

Lines changed: 3 additions & 3 deletions
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

Lines changed: 22 additions & 10 deletions
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)

0 commit comments

Comments
 (0)
Please sign in to comment.