Skip to content

Commit 5d9b399

Browse files
spastorinooli-obk
authored andcommitted
Remove PlaceBase enum and make Place base field be local: Local
1 parent fd5aa32 commit 5d9b399

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

+457
-657
lines changed

src/librustc/mir/mod.rs

Lines changed: 13 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1655,20 +1655,14 @@ impl Debug for Statement<'_> {
16551655
/// changing or disturbing program state.
16561656
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, HashStable)]
16571657
pub struct Place<'tcx> {
1658-
pub base: PlaceBase,
1658+
pub local: Local,
16591659

16601660
/// projection out of a place (access a field, deref a pointer, etc)
16611661
pub projection: &'tcx List<PlaceElem<'tcx>>,
16621662
}
16631663

16641664
impl<'tcx> rustc_serialize::UseSpecializedDecodable for Place<'tcx> {}
16651665

1666-
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable, HashStable)]
1667-
pub enum PlaceBase {
1668-
/// local variable
1669-
Local(Local),
1670-
}
1671-
16721666
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
16731667
#[derive(RustcEncodable, RustcDecodable, HashStable)]
16741668
pub enum ProjectionElem<V, T> {
@@ -1756,14 +1750,14 @@ rustc_index::newtype_index! {
17561750

17571751
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
17581752
pub struct PlaceRef<'a, 'tcx> {
1759-
pub base: &'a PlaceBase,
1753+
pub local: &'a Local,
17601754
pub projection: &'a [PlaceElem<'tcx>],
17611755
}
17621756

17631757
impl<'tcx> Place<'tcx> {
17641758
// FIXME change this to a const fn by also making List::empty a const fn.
17651759
pub fn return_place() -> Place<'tcx> {
1766-
Place { base: PlaceBase::Local(RETURN_PLACE), projection: List::empty() }
1760+
Place { local: RETURN_PLACE, projection: List::empty() }
17671761
}
17681762

17691763
/// Returns `true` if this `Place` contains a `Deref` projection.
@@ -1780,10 +1774,8 @@ impl<'tcx> Place<'tcx> {
17801774
// FIXME: can we safely swap the semantics of `fn base_local` below in here instead?
17811775
pub fn local_or_deref_local(&self) -> Option<Local> {
17821776
match self.as_ref() {
1783-
PlaceRef { base: &PlaceBase::Local(local), projection: &[] }
1784-
| PlaceRef { base: &PlaceBase::Local(local), projection: &[ProjectionElem::Deref] } => {
1785-
Some(local)
1786-
}
1777+
PlaceRef { local, projection: &[] }
1778+
| PlaceRef { local, projection: &[ProjectionElem::Deref] } => Some(*local),
17871779
_ => None,
17881780
}
17891781
}
@@ -1795,19 +1787,13 @@ impl<'tcx> Place<'tcx> {
17951787
}
17961788

17971789
pub fn as_ref(&self) -> PlaceRef<'_, 'tcx> {
1798-
PlaceRef { base: &self.base, projection: &self.projection }
1790+
PlaceRef { local: &self.local, projection: &self.projection }
17991791
}
18001792
}
18011793

18021794
impl From<Local> for Place<'_> {
18031795
fn from(local: Local) -> Self {
1804-
Place { base: local.into(), projection: List::empty() }
1805-
}
1806-
}
1807-
1808-
impl From<Local> for PlaceBase {
1809-
fn from(local: Local) -> Self {
1810-
PlaceBase::Local(local)
1796+
Place { local: local.into(), projection: List::empty() }
18111797
}
18121798
}
18131799

@@ -1818,10 +1804,8 @@ impl<'a, 'tcx> PlaceRef<'a, 'tcx> {
18181804
// FIXME: can we safely swap the semantics of `fn base_local` below in here instead?
18191805
pub fn local_or_deref_local(&self) -> Option<Local> {
18201806
match self {
1821-
PlaceRef { base: PlaceBase::Local(local), projection: [] }
1822-
| PlaceRef { base: PlaceBase::Local(local), projection: [ProjectionElem::Deref] } => {
1823-
Some(*local)
1824-
}
1807+
PlaceRef { local, projection: [] }
1808+
| PlaceRef { local, projection: [ProjectionElem::Deref] } => Some(**local),
18251809
_ => None,
18261810
}
18271811
}
@@ -1830,7 +1814,7 @@ impl<'a, 'tcx> PlaceRef<'a, 'tcx> {
18301814
/// projections, return `Some(_X)`.
18311815
pub fn as_local(&self) -> Option<Local> {
18321816
match self {
1833-
PlaceRef { base: PlaceBase::Local(l), projection: [] } => Some(*l),
1817+
PlaceRef { local, projection: [] } => Some(**local),
18341818
_ => None,
18351819
}
18361820
}
@@ -1852,7 +1836,7 @@ impl Debug for Place<'_> {
18521836
}
18531837
}
18541838

1855-
write!(fmt, "{:?}", self.base)?;
1839+
write!(fmt, "{:?}", self.local)?;
18561840

18571841
for elem in self.projection.iter() {
18581842
match elem {
@@ -1896,14 +1880,6 @@ impl Debug for Place<'_> {
18961880
}
18971881
}
18981882

1899-
impl Debug for PlaceBase {
1900-
fn fmt(&self, fmt: &mut Formatter<'_>) -> fmt::Result {
1901-
match *self {
1902-
PlaceBase::Local(id) => write!(fmt, "{:?}", id),
1903-
}
1904-
}
1905-
}
1906-
19071883
///////////////////////////////////////////////////////////////////////////
19081884
// Scopes
19091885

@@ -2964,25 +2940,11 @@ impl<'tcx> TypeFoldable<'tcx> for GeneratorKind {
29642940

29652941
impl<'tcx> TypeFoldable<'tcx> for Place<'tcx> {
29662942
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
2967-
Place { base: self.base.fold_with(folder), projection: self.projection.fold_with(folder) }
2943+
Place { local: self.local.fold_with(folder), projection: self.projection.fold_with(folder) }
29682944
}
29692945

29702946
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
2971-
self.base.visit_with(visitor) || self.projection.visit_with(visitor)
2972-
}
2973-
}
2974-
2975-
impl<'tcx> TypeFoldable<'tcx> for PlaceBase {
2976-
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
2977-
match self {
2978-
PlaceBase::Local(local) => PlaceBase::Local(local.fold_with(folder)),
2979-
}
2980-
}
2981-
2982-
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
2983-
match self {
2984-
PlaceBase::Local(local) => local.visit_with(visitor),
2985-
}
2947+
self.local.visit_with(visitor) || self.projection.visit_with(visitor)
29862948
}
29872949
}
29882950

src/librustc/mir/tcx.rs

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ impl<'tcx> PlaceTy<'tcx> {
114114

115115
impl<'tcx> Place<'tcx> {
116116
pub fn ty_from<D>(
117-
base: &PlaceBase,
117+
local: &Local,
118118
projection: &[PlaceElem<'tcx>],
119119
local_decls: &D,
120120
tcx: TyCtxt<'tcx>,
@@ -124,25 +124,16 @@ impl<'tcx> Place<'tcx> {
124124
{
125125
projection
126126
.iter()
127-
.fold(base.ty(local_decls), |place_ty, elem| place_ty.projection_ty(tcx, elem))
127+
.fold(PlaceTy::from_ty(local_decls.local_decls()[*local].ty), |place_ty, elem| {
128+
place_ty.projection_ty(tcx, elem)
129+
})
128130
}
129131

130132
pub fn ty<D>(&self, local_decls: &D, tcx: TyCtxt<'tcx>) -> PlaceTy<'tcx>
131133
where
132134
D: HasLocalDecls<'tcx>,
133135
{
134-
Place::ty_from(&self.base, &self.projection, local_decls, tcx)
135-
}
136-
}
137-
138-
impl<'tcx> PlaceBase {
139-
pub fn ty<D>(&self, local_decls: &D) -> PlaceTy<'tcx>
140-
where
141-
D: HasLocalDecls<'tcx>,
142-
{
143-
match self {
144-
PlaceBase::Local(index) => PlaceTy::from_ty(local_decls.local_decls()[*index].ty),
145-
}
136+
Place::ty_from(&self.local, &self.projection, local_decls, tcx)
146137
}
147138
}
148139

src/librustc/mir/visit.rs

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,11 +226,11 @@ pub fn decode_place<D>(decoder: &mut D) -> Result<mir::Place<'tcx>, D::Error>
226226
where
227227
D: TyDecoder<'tcx>,
228228
{
229-
let base: mir::PlaceBase = Decodable::decode(decoder)?;
229+
let local: mir::Local = Decodable::decode(decoder)?;
230230
let len = decoder.read_usize()?;
231231
let projection: &'tcx List<mir::PlaceElem<'tcx>> =
232232
decoder.tcx().mk_place_elems((0..len).map(|_| Decodable::decode(decoder)))?;
233-
Ok(mir::Place { base, projection })
233+
Ok(mir::Place { local, projection })
234234
}
235235

236236
#[inline]

src/librustc/ty/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2434,7 +2434,7 @@ impl<'tcx> TyCtxt<'tcx> {
24342434
let mut projection = place.projection.to_vec();
24352435
projection.push(elem);
24362436

2437-
Place { base: place.base, projection: self.intern_place_elems(&projection) }
2437+
Place { local: place.local, projection: self.intern_place_elems(&projection) }
24382438
}
24392439

24402440
pub fn intern_existential_predicates(

src/librustc_codegen_llvm/debuginfo/metadata.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1286,9 +1286,9 @@ fn generator_layout_and_saved_local_names(
12861286
let generator_layout = body.generator_layout.as_ref().unwrap();
12871287
let mut generator_saved_local_names = IndexVec::from_elem(None, &generator_layout.field_tys);
12881288

1289-
let state_arg = mir::PlaceBase::Local(mir::Local::new(1));
1289+
let state_arg = mir::Local::new(1);
12901290
for var in &body.var_debug_info {
1291-
if var.place.base != state_arg {
1291+
if var.place.local != state_arg {
12921292
continue;
12931293
}
12941294
match var.place.projection[..] {

src/librustc_codegen_ssa/mir/analyze.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -128,17 +128,13 @@ impl<Bx: BuilderMethods<'a, 'tcx>> LocalAnalyzer<'mir, 'a, 'tcx, Bx> {
128128
};
129129
if is_consume {
130130
let base_ty =
131-
mir::Place::ty_from(place_ref.base, proj_base, *self.fx.mir, cx.tcx());
131+
mir::Place::ty_from(place_ref.local, proj_base, *self.fx.mir, cx.tcx());
132132
let base_ty = self.fx.monomorphize(&base_ty);
133133

134134
// ZSTs don't require any actual memory access.
135135
let elem_ty = base_ty.projection_ty(cx.tcx(), elem).ty;
136136
let elem_ty = self.fx.monomorphize(&elem_ty);
137-
let span = match place_ref.base {
138-
mir::PlaceBase::Local(index) => {
139-
self.fx.mir.local_decls[*index].source_info.span
140-
}
141-
};
137+
let span = self.fx.mir.local_decls[*place_ref.local].source_info.span;
142138
if cx.spanned_layout_of(elem_ty, span).is_zst() {
143139
return;
144140
}
@@ -178,9 +174,7 @@ impl<Bx: BuilderMethods<'a, 'tcx>> LocalAnalyzer<'mir, 'a, 'tcx, Bx> {
178174
// We use `NonUseContext::VarDebugInfo` for the base,
179175
// which might not force the base local to memory,
180176
// so we have to do it manually.
181-
match place_ref.base {
182-
mir::PlaceBase::Local(local) => self.visit_local(&local, context, location),
183-
}
177+
self.visit_local(place_ref.local, context, location);
184178
}
185179
}
186180

@@ -191,7 +185,7 @@ impl<Bx: BuilderMethods<'a, 'tcx>> LocalAnalyzer<'mir, 'a, 'tcx, Bx> {
191185
}
192186

193187
self.process_place(
194-
&mir::PlaceRef { base: place_ref.base, projection: proj_base },
188+
&mir::PlaceRef { local: place_ref.local, projection: proj_base },
195189
base_context,
196190
location,
197191
);
@@ -218,8 +212,8 @@ impl<Bx: BuilderMethods<'a, 'tcx>> LocalAnalyzer<'mir, 'a, 'tcx, Bx> {
218212
};
219213
}
220214

221-
self.visit_place_base(place_ref.base, context, location);
222-
self.visit_projection(place_ref.base, place_ref.projection, context, location);
215+
self.visit_place_base(place_ref.local, context, location);
216+
self.visit_projection(place_ref.local, place_ref.projection, context, location);
223217
}
224218
}
225219
}

src/librustc_codegen_ssa/mir/block.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1109,7 +1109,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
11091109
} else {
11101110
self.codegen_place(
11111111
bx,
1112-
&mir::PlaceRef { base: &dest.base, projection: &dest.projection },
1112+
&mir::PlaceRef { local: &dest.local, projection: &dest.projection },
11131113
)
11141114
};
11151115
if fn_ret.is_indirect() {

src/librustc_codegen_ssa/mir/debuginfo.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,9 +258,7 @@ pub fn per_local_var_debug_info(
258258
if tcx.sess.opts.debuginfo == DebugInfo::Full || !tcx.sess.fewer_names() {
259259
let mut per_local = IndexVec::from_elem(vec![], &body.local_decls);
260260
for var in &body.var_debug_info {
261-
match var.place.base {
262-
mir::PlaceBase::Local(local) => per_local[local].push(var),
263-
}
261+
per_local[var.place.local].push(var);
264262
}
265263
Some(per_local)
266264
} else {

0 commit comments

Comments
 (0)