Skip to content

Commit 9cc6744

Browse files
committed
Remove PlaceBase enum and make Place base field be local: Local
1 parent 9f517b7 commit 9cc6744

Some content is hidden

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

50 files changed

+442
-630
lines changed

src/librustc/mir/mod.rs

+15-51
Original file line numberDiff line numberDiff line change
@@ -1663,22 +1663,14 @@ impl Debug for Statement<'_> {
16631663
Clone, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, HashStable,
16641664
)]
16651665
pub struct Place<'tcx> {
1666-
pub base: PlaceBase,
1666+
pub local: Local,
16671667

16681668
/// projection out of a place (access a field, deref a pointer, etc)
16691669
pub projection: &'tcx List<PlaceElem<'tcx>>,
16701670
}
16711671

16721672
impl<'tcx> rustc_serialize::UseSpecializedDecodable for Place<'tcx> {}
16731673

1674-
#[derive(
1675-
Clone, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable, HashStable,
1676-
)]
1677-
pub enum PlaceBase {
1678-
/// local variable
1679-
Local(Local),
1680-
}
1681-
16821674
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
16831675
#[derive(RustcEncodable, RustcDecodable, HashStable)]
16841676
pub enum ProjectionElem<V, T> {
@@ -1767,15 +1759,15 @@ rustc_index::newtype_index! {
17671759

17681760
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
17691761
pub struct PlaceRef<'a, 'tcx> {
1770-
pub base: &'a PlaceBase,
1762+
pub local: &'a Local,
17711763
pub projection: &'a [PlaceElem<'tcx>],
17721764
}
17731765

17741766
impl<'tcx> Place<'tcx> {
17751767
// FIXME change this to a const fn by also making List::empty a const fn.
17761768
pub fn return_place() -> Place<'tcx> {
17771769
Place {
1778-
base: PlaceBase::Local(RETURN_PLACE),
1770+
local: RETURN_PLACE,
17791771
projection: List::empty(),
17801772
}
17811773
}
@@ -1795,13 +1787,13 @@ impl<'tcx> Place<'tcx> {
17951787
pub fn local_or_deref_local(&self) -> Option<Local> {
17961788
match self.as_ref() {
17971789
PlaceRef {
1798-
base: &PlaceBase::Local(local),
1790+
local,
17991791
projection: &[],
18001792
} |
18011793
PlaceRef {
1802-
base: &PlaceBase::Local(local),
1794+
local,
18031795
projection: &[ProjectionElem::Deref],
1804-
} => Some(local),
1796+
} => Some(*local),
18051797
_ => None,
18061798
}
18071799
}
@@ -1814,7 +1806,7 @@ impl<'tcx> Place<'tcx> {
18141806

18151807
pub fn as_ref(&self) -> PlaceRef<'_, 'tcx> {
18161808
PlaceRef {
1817-
base: &self.base,
1809+
local: &self.local,
18181810
projection: &self.projection,
18191811
}
18201812
}
@@ -1823,18 +1815,12 @@ impl<'tcx> Place<'tcx> {
18231815
impl From<Local> for Place<'_> {
18241816
fn from(local: Local) -> Self {
18251817
Place {
1826-
base: local.into(),
1818+
local: local.into(),
18271819
projection: List::empty(),
18281820
}
18291821
}
18301822
}
18311823

1832-
impl From<Local> for PlaceBase {
1833-
fn from(local: Local) -> Self {
1834-
PlaceBase::Local(local)
1835-
}
1836-
}
1837-
18381824
impl<'a, 'tcx> PlaceRef<'a, 'tcx> {
18391825
/// Finds the innermost `Local` from this `Place`, *if* it is either a local itself or
18401826
/// a single deref of a local.
@@ -1843,13 +1829,13 @@ impl<'a, 'tcx> PlaceRef<'a, 'tcx> {
18431829
pub fn local_or_deref_local(&self) -> Option<Local> {
18441830
match self {
18451831
PlaceRef {
1846-
base: PlaceBase::Local(local),
1832+
local,
18471833
projection: [],
18481834
} |
18491835
PlaceRef {
1850-
base: PlaceBase::Local(local),
1836+
local,
18511837
projection: [ProjectionElem::Deref],
1852-
} => Some(*local),
1838+
} => Some(**local),
18531839
_ => None,
18541840
}
18551841
}
@@ -1858,7 +1844,7 @@ impl<'a, 'tcx> PlaceRef<'a, 'tcx> {
18581844
/// projections, return `Some(_X)`.
18591845
pub fn as_local(&self) -> Option<Local> {
18601846
match self {
1861-
PlaceRef { base: PlaceBase::Local(l), projection: [] } => Some(*l),
1847+
PlaceRef { local, projection: [] } => Some(**local),
18621848
_ => None,
18631849
}
18641850
}
@@ -1880,7 +1866,7 @@ impl Debug for Place<'_> {
18801866
}
18811867
}
18821868

1883-
write!(fmt, "{:?}", self.base)?;
1869+
write!(fmt, "{:?}", self.local)?;
18841870

18851871
for elem in self.projection.iter() {
18861872
match elem {
@@ -1924,14 +1910,6 @@ impl Debug for Place<'_> {
19241910
}
19251911
}
19261912

1927-
impl Debug for PlaceBase {
1928-
fn fmt(&self, fmt: &mut Formatter<'_>) -> fmt::Result {
1929-
match *self {
1930-
PlaceBase::Local(id) => write!(fmt, "{:?}", id),
1931-
}
1932-
}
1933-
}
1934-
19351913
///////////////////////////////////////////////////////////////////////////
19361914
// Scopes
19371915

@@ -2995,27 +2973,13 @@ impl<'tcx> TypeFoldable<'tcx> for GeneratorKind {
29952973
impl<'tcx> TypeFoldable<'tcx> for Place<'tcx> {
29962974
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
29972975
Place {
2998-
base: self.base.fold_with(folder),
2976+
local: self.local.fold_with(folder),
29992977
projection: self.projection.fold_with(folder),
30002978
}
30012979
}
30022980

30032981
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
3004-
self.base.visit_with(visitor) || self.projection.visit_with(visitor)
3005-
}
3006-
}
3007-
3008-
impl<'tcx> TypeFoldable<'tcx> for PlaceBase {
3009-
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
3010-
match self {
3011-
PlaceBase::Local(local) => PlaceBase::Local(local.fold_with(folder)),
3012-
}
3013-
}
3014-
3015-
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
3016-
match self {
3017-
PlaceBase::Local(local) => local.visit_with(visitor),
3018-
}
2982+
self.local.visit_with(visitor) || self.projection.visit_with(visitor)
30192983
}
30202984
}
30212985

src/librustc/mir/tcx.rs

+3-13
Original file line numberDiff line numberDiff line change
@@ -116,15 +116,15 @@ impl<'tcx> PlaceTy<'tcx> {
116116

117117
impl<'tcx> Place<'tcx> {
118118
pub fn ty_from<D>(
119-
base: &PlaceBase,
119+
local: &Local,
120120
projection: &[PlaceElem<'tcx>],
121121
local_decls: &D,
122122
tcx: TyCtxt<'tcx>
123123
) -> PlaceTy<'tcx>
124124
where D: HasLocalDecls<'tcx>
125125
{
126126
projection.iter().fold(
127-
base.ty(local_decls),
127+
PlaceTy::from_ty(local_decls.local_decls()[*local].ty),
128128
|place_ty, elem| place_ty.projection_ty(tcx, elem)
129129
)
130130
}
@@ -133,17 +133,7 @@ impl<'tcx> Place<'tcx> {
133133
where
134134
D: HasLocalDecls<'tcx>,
135135
{
136-
Place::ty_from(&self.base, &self.projection, local_decls, tcx)
137-
}
138-
}
139-
140-
impl<'tcx> PlaceBase {
141-
pub fn ty<D>(&self, local_decls: &D) -> PlaceTy<'tcx>
142-
where D: HasLocalDecls<'tcx>
143-
{
144-
match self {
145-
PlaceBase::Local(index) => PlaceTy::from_ty(local_decls.local_decls()[*index].ty),
146-
}
136+
Place::ty_from(&self.local, &self.projection, local_decls, tcx)
147137
}
148138
}
149139

src/librustc/mir/visit.rs

+14-18
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,10 @@ macro_rules! make_mir_visitor {
164164
}
165165

166166
fn visit_place_base(&mut self,
167-
base: & $($mutability)? PlaceBase,
167+
local: & $($mutability)? Local,
168168
context: PlaceContext,
169169
location: Location) {
170-
self.super_place_base(base, context, location);
170+
self.super_place_base(local, context, location);
171171
}
172172

173173
visit_place_fns!($($mutability)?);
@@ -705,14 +705,10 @@ macro_rules! make_mir_visitor {
705705
}
706706

707707
fn super_place_base(&mut self,
708-
place_base: & $($mutability)? PlaceBase,
708+
local: & $($mutability)? Local,
709709
context: PlaceContext,
710710
location: Location) {
711-
match place_base {
712-
PlaceBase::Local(local) => {
713-
self.visit_local(local, context, location);
714-
}
715-
}
711+
self.visit_local(local, context, location);
716712
}
717713

718714
fn super_local_decl(&mut self,
@@ -845,7 +841,7 @@ macro_rules! visit_place_fns {
845841
context: PlaceContext,
846842
location: Location,
847843
) {
848-
self.visit_place_base(&mut place.base, context, location);
844+
self.visit_place_base(&mut place.local, context, location);
849845

850846
if let Some(new_projection) = self.process_projection(&place.projection) {
851847
place.projection = self.tcx().intern_place_elems(&new_projection);
@@ -886,23 +882,23 @@ macro_rules! visit_place_fns {
886882
() => (
887883
fn visit_projection(
888884
&mut self,
889-
base: &PlaceBase,
885+
local: &Local,
890886
projection: &[PlaceElem<'tcx>],
891887
context: PlaceContext,
892888
location: Location,
893889
) {
894-
self.super_projection(base, projection, context, location);
890+
self.super_projection(local, projection, context, location);
895891
}
896892

897893
fn visit_projection_elem(
898894
&mut self,
899-
base: &PlaceBase,
895+
local: &Local,
900896
proj_base: &[PlaceElem<'tcx>],
901897
elem: &PlaceElem<'tcx>,
902898
context: PlaceContext,
903899
location: Location,
904900
) {
905-
self.super_projection_elem(base, proj_base, elem, context, location);
901+
self.super_projection_elem(local, proj_base, elem, context, location);
906902
}
907903

908904
fn super_place(
@@ -921,31 +917,31 @@ macro_rules! visit_place_fns {
921917
};
922918
}
923919

924-
self.visit_place_base(&place.base, context, location);
920+
self.visit_place_base(&place.local, context, location);
925921

926-
self.visit_projection(&place.base,
922+
self.visit_projection(&place.local,
927923
&place.projection,
928924
context,
929925
location);
930926
}
931927

932928
fn super_projection(
933929
&mut self,
934-
base: &PlaceBase,
930+
local: &Local,
935931
projection: &[PlaceElem<'tcx>],
936932
context: PlaceContext,
937933
location: Location,
938934
) {
939935
let mut cursor = projection;
940936
while let [proj_base @ .., elem] = cursor {
941937
cursor = proj_base;
942-
self.visit_projection_elem(base, cursor, elem, context, location);
938+
self.visit_projection_elem(local, cursor, elem, context, location);
943939
}
944940
}
945941

946942
fn super_projection_elem(
947943
&mut self,
948-
_base: &PlaceBase,
944+
_local: &Local,
949945
_proj_base: &[PlaceElem<'tcx>],
950946
elem: &PlaceElem<'tcx>,
951947
_context: PlaceContext,

src/librustc/ty/codec.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -223,11 +223,11 @@ pub fn decode_place<D>(decoder: &mut D) -> Result<mir::Place<'tcx>, D::Error>
223223
where
224224
D: TyDecoder<'tcx>,
225225
{
226-
let base: mir::PlaceBase = Decodable::decode(decoder)?;
226+
let local: mir::Local = Decodable::decode(decoder)?;
227227
let len = decoder.read_usize()?;
228228
let projection: &'tcx List<mir::PlaceElem<'tcx>> =
229229
decoder.tcx().mk_place_elems((0..len).map(|_| Decodable::decode(decoder)))?;
230-
Ok(mir::Place { base, projection })
230+
Ok(mir::Place { local, projection })
231231
}
232232

233233
#[inline]

src/librustc/ty/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2637,7 +2637,7 @@ impl<'tcx> TyCtxt<'tcx> {
26372637
let mut projection = place.projection.to_vec();
26382638
projection.push(elem);
26392639

2640-
Place { base: place.base, projection: self.intern_place_elems(&projection) }
2640+
Place { local: place.local, projection: self.intern_place_elems(&projection) }
26412641
}
26422642

26432643
pub fn intern_existential_predicates(self, eps: &[ExistentialPredicate<'tcx>])

src/librustc_codegen_llvm/debuginfo/metadata.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1330,9 +1330,9 @@ fn generator_layout_and_saved_local_names(
13301330
let mut generator_saved_local_names =
13311331
IndexVec::from_elem(None, &generator_layout.field_tys);
13321332

1333-
let state_arg = mir::PlaceBase::Local(mir::Local::new(1));
1333+
let state_arg = mir::Local::new(1);
13341334
for var in &body.var_debug_info {
1335-
if var.place.base != state_arg {
1335+
if var.place.local != state_arg {
13361336
continue;
13371337
}
13381338
match var.place.projection[..] {

src/librustc_codegen_ssa/mir/analyze.rs

+6-11
Original file line numberDiff line numberDiff line change
@@ -130,18 +130,15 @@ impl<Bx: BuilderMethods<'a, 'tcx>> LocalAnalyzer<'mir, 'a, 'tcx, Bx> {
130130
};
131131
if is_consume {
132132
let base_ty =
133-
mir::Place::ty_from(place_ref.base, proj_base, *self.fx.mir, cx.tcx());
133+
mir::Place::ty_from(place_ref.local, proj_base, *self.fx.mir, cx.tcx());
134134
let base_ty = self.fx.monomorphize(&base_ty);
135135

136136
// ZSTs don't require any actual memory access.
137137
let elem_ty = base_ty
138138
.projection_ty(cx.tcx(), elem)
139139
.ty;
140140
let elem_ty = self.fx.monomorphize(&elem_ty);
141-
let span = match place_ref.base {
142-
mir::PlaceBase::Local(index) =>
143-
self.fx.mir.local_decls[*index].source_info.span,
144-
};
141+
let span = self.fx.mir.local_decls[*place_ref.local].source_info.span;
145142
if cx.spanned_layout_of(elem_ty, span).is_zst() {
146143
return;
147144
}
@@ -181,9 +178,7 @@ impl<Bx: BuilderMethods<'a, 'tcx>> LocalAnalyzer<'mir, 'a, 'tcx, Bx> {
181178
// We use `NonUseContext::VarDebugInfo` for the base,
182179
// which might not force the base local to memory,
183180
// so we have to do it manually.
184-
match place_ref.base {
185-
mir::PlaceBase::Local(local) => self.visit_local(&local, context, location),
186-
}
181+
self.visit_local(place_ref.local, context, location);
187182
}
188183
}
189184

@@ -195,7 +190,7 @@ impl<Bx: BuilderMethods<'a, 'tcx>> LocalAnalyzer<'mir, 'a, 'tcx, Bx> {
195190

196191
self.process_place(
197192
&mir::PlaceRef {
198-
base: place_ref.base,
193+
local: place_ref.local,
199194
projection: proj_base,
200195
},
201196
base_context,
@@ -224,8 +219,8 @@ impl<Bx: BuilderMethods<'a, 'tcx>> LocalAnalyzer<'mir, 'a, 'tcx, Bx> {
224219
};
225220
}
226221

227-
self.visit_place_base(place_ref.base, context, location);
228-
self.visit_projection(place_ref.base, place_ref.projection, context, location);
222+
self.visit_place_base(place_ref.local, context, location);
223+
self.visit_projection(place_ref.local, place_ref.projection, context, location);
229224
}
230225
}
231226

0 commit comments

Comments
 (0)