Skip to content

Commit fd5aa32

Browse files
spastorinooli-obk
authored andcommitted
Remove Static from PlaceBase
1 parent 9e70c47 commit fd5aa32

37 files changed

+193
-452
lines changed

src/librustc/mir/mod.rs

Lines changed: 6 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1655,7 +1655,7 @@ 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<'tcx>,
1658+
pub base: PlaceBase,
16591659

16601660
/// projection out of a place (access a field, deref a pointer, etc)
16611661
pub projection: &'tcx List<PlaceElem<'tcx>>,
@@ -1664,34 +1664,9 @@ pub struct Place<'tcx> {
16641664
impl<'tcx> rustc_serialize::UseSpecializedDecodable for Place<'tcx> {}
16651665

16661666
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable, HashStable)]
1667-
pub enum PlaceBase<'tcx> {
1667+
pub enum PlaceBase {
16681668
/// local variable
16691669
Local(Local),
1670-
1671-
/// static or static mut variable
1672-
Static(Box<Static<'tcx>>),
1673-
}
1674-
1675-
/// We store the normalized type to avoid requiring normalization when reading MIR
1676-
#[derive(
1677-
Clone,
1678-
Debug,
1679-
PartialEq,
1680-
Eq,
1681-
PartialOrd,
1682-
Ord,
1683-
Hash,
1684-
RustcEncodable,
1685-
RustcDecodable,
1686-
HashStable
1687-
)]
1688-
pub struct Static<'tcx> {
1689-
pub ty: Ty<'tcx>,
1690-
/// The `DefId` of the item this static was declared in. For promoted values, usually, this is
1691-
/// the same as the `DefId` of the `mir::Body` containing the `Place` this promoted appears in.
1692-
/// However, after inlining, that might no longer be the case as inlined `Place`s are copied
1693-
/// into the calling frame.
1694-
pub def_id: DefId,
16951670
}
16961671

16971672
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
@@ -1781,7 +1756,7 @@ rustc_index::newtype_index! {
17811756

17821757
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
17831758
pub struct PlaceRef<'a, 'tcx> {
1784-
pub base: &'a PlaceBase<'tcx>,
1759+
pub base: &'a PlaceBase,
17851760
pub projection: &'a [PlaceElem<'tcx>],
17861761
}
17871762

@@ -1830,7 +1805,7 @@ impl From<Local> for Place<'_> {
18301805
}
18311806
}
18321807

1833-
impl From<Local> for PlaceBase<'_> {
1808+
impl From<Local> for PlaceBase {
18341809
fn from(local: Local) -> Self {
18351810
PlaceBase::Local(local)
18361811
}
@@ -1921,13 +1896,10 @@ impl Debug for Place<'_> {
19211896
}
19221897
}
19231898

1924-
impl Debug for PlaceBase<'_> {
1899+
impl Debug for PlaceBase {
19251900
fn fmt(&self, fmt: &mut Formatter<'_>) -> fmt::Result {
19261901
match *self {
19271902
PlaceBase::Local(id) => write!(fmt, "{:?}", id),
1928-
PlaceBase::Static(box self::Static { ty, def_id }) => {
1929-
write!(fmt, "({}: {:?})", ty::tls::with(|tcx| tcx.def_path_str(def_id)), ty)
1930-
}
19311903
}
19321904
}
19331905
}
@@ -3000,18 +2972,16 @@ impl<'tcx> TypeFoldable<'tcx> for Place<'tcx> {
30002972
}
30012973
}
30022974

3003-
impl<'tcx> TypeFoldable<'tcx> for PlaceBase<'tcx> {
2975+
impl<'tcx> TypeFoldable<'tcx> for PlaceBase {
30042976
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
30052977
match self {
30062978
PlaceBase::Local(local) => PlaceBase::Local(local.fold_with(folder)),
3007-
PlaceBase::Static(static_) => PlaceBase::Static(static_.fold_with(folder)),
30082979
}
30092980
}
30102981

30112982
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
30122983
match self {
30132984
PlaceBase::Local(local) => local.visit_with(visitor),
3014-
PlaceBase::Static(static_) => (**static_).visit_with(visitor),
30152985
}
30162986
}
30172987
}
@@ -3027,18 +2997,6 @@ impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<PlaceElem<'tcx>> {
30272997
}
30282998
}
30292999

3030-
impl<'tcx> TypeFoldable<'tcx> for Static<'tcx> {
3031-
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
3032-
Static { ty: self.ty.fold_with(folder), def_id: self.def_id }
3033-
}
3034-
3035-
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
3036-
let Static { ty, def_id: _ } = self;
3037-
3038-
ty.visit_with(visitor)
3039-
}
3040-
}
3041-
30423000
impl<'tcx> TypeFoldable<'tcx> for Rvalue<'tcx> {
30433001
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
30443002
use crate::mir::Rvalue::*;

src/librustc/mir/tcx.rs

Lines changed: 2 additions & 3 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<'tcx>,
117+
base: &PlaceBase,
118118
projection: &[PlaceElem<'tcx>],
119119
local_decls: &D,
120120
tcx: TyCtxt<'tcx>,
@@ -135,14 +135,13 @@ impl<'tcx> Place<'tcx> {
135135
}
136136
}
137137

138-
impl<'tcx> PlaceBase<'tcx> {
138+
impl<'tcx> PlaceBase {
139139
pub fn ty<D>(&self, local_decls: &D) -> PlaceTy<'tcx>
140140
where
141141
D: HasLocalDecls<'tcx>,
142142
{
143143
match self {
144144
PlaceBase::Local(index) => PlaceTy::from_ty(local_decls.local_decls()[*index].ty),
145-
PlaceBase::Static(data) => PlaceTy::from_ty(data.ty),
146145
}
147146
}
148147
}

src/librustc/mir/visit.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ macro_rules! make_mir_visitor {
164164
}
165165

166166
fn visit_place_base(&mut self,
167-
base: & $($mutability)? PlaceBase<'tcx>,
167+
base: & $($mutability)? PlaceBase,
168168
context: PlaceContext,
169169
location: Location) {
170170
self.super_place_base(base, context, location);
@@ -705,16 +705,13 @@ macro_rules! make_mir_visitor {
705705
}
706706

707707
fn super_place_base(&mut self,
708-
place_base: & $($mutability)? PlaceBase<'tcx>,
708+
place_base: & $($mutability)? PlaceBase,
709709
context: PlaceContext,
710710
location: Location) {
711711
match place_base {
712712
PlaceBase::Local(local) => {
713713
self.visit_local(local, context, location);
714714
}
715-
PlaceBase::Static(box Static { ty, def_id: _ }) => {
716-
self.visit_ty(& $($mutability)? *ty, TyContext::Location(location));
717-
}
718715
}
719716
}
720717

@@ -889,7 +886,7 @@ macro_rules! visit_place_fns {
889886
() => (
890887
fn visit_projection(
891888
&mut self,
892-
base: &PlaceBase<'tcx>,
889+
base: &PlaceBase,
893890
projection: &[PlaceElem<'tcx>],
894891
context: PlaceContext,
895892
location: Location,
@@ -899,7 +896,7 @@ macro_rules! visit_place_fns {
899896

900897
fn visit_projection_elem(
901898
&mut self,
902-
base: &PlaceBase<'tcx>,
899+
base: &PlaceBase,
903900
proj_base: &[PlaceElem<'tcx>],
904901
elem: &PlaceElem<'tcx>,
905902
context: PlaceContext,
@@ -934,7 +931,7 @@ macro_rules! visit_place_fns {
934931

935932
fn super_projection(
936933
&mut self,
937-
base: &PlaceBase<'tcx>,
934+
base: &PlaceBase,
938935
projection: &[PlaceElem<'tcx>],
939936
context: PlaceContext,
940937
location: Location,
@@ -948,7 +945,7 @@ macro_rules! visit_place_fns {
948945

949946
fn super_projection_elem(
950947
&mut self,
951-
_base: &PlaceBase<'tcx>,
948+
_base: &PlaceBase,
952949
_proj_base: &[PlaceElem<'tcx>],
953950
elem: &PlaceElem<'tcx>,
954951
_context: PlaceContext,

src/librustc/ty/codec.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ 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<'tcx> = Decodable::decode(decoder)?;
229+
let base: mir::PlaceBase = 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)))?;

src/librustc_codegen_ssa/mir/analyze.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use rustc::ty::layout::{HasTyCtxt, LayoutOf};
1414
use rustc_data_structures::graph::dominators::Dominators;
1515
use rustc_index::bit_set::BitSet;
1616
use rustc_index::vec::{Idx, IndexVec};
17-
use rustc_span::DUMMY_SP;
1817

1918
pub fn non_ssa_locals<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
2019
fx: &FunctionCx<'a, 'tcx, Bx>,
@@ -135,10 +134,10 @@ impl<Bx: BuilderMethods<'a, 'tcx>> LocalAnalyzer<'mir, 'a, 'tcx, Bx> {
135134
// ZSTs don't require any actual memory access.
136135
let elem_ty = base_ty.projection_ty(cx.tcx(), elem).ty;
137136
let elem_ty = self.fx.monomorphize(&elem_ty);
138-
let span = if let mir::PlaceBase::Local(index) = place_ref.base {
139-
self.fx.mir.local_decls[*index].source_info.span
140-
} else {
141-
DUMMY_SP
137+
let span = match place_ref.base {
138+
mir::PlaceBase::Local(index) => {
139+
self.fx.mir.local_decls[*index].source_info.span
140+
}
142141
};
143142
if cx.spanned_layout_of(elem_ty, span).is_zst() {
144143
return;
@@ -179,8 +178,8 @@ impl<Bx: BuilderMethods<'a, 'tcx>> LocalAnalyzer<'mir, 'a, 'tcx, Bx> {
179178
// We use `NonUseContext::VarDebugInfo` for the base,
180179
// which might not force the base local to memory,
181180
// so we have to do it manually.
182-
if let mir::PlaceBase::Local(local) = place_ref.base {
183-
self.visit_local(&local, context, location);
181+
match place_ref.base {
182+
mir::PlaceBase::Local(local) => self.visit_local(&local, context, location),
184183
}
185184
}
186185
}

src/librustc_codegen_ssa/mir/debuginfo.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,8 @@ 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-
if let mir::PlaceBase::Local(local) = var.place.base {
262-
per_local[local].push(var);
261+
match var.place.base {
262+
mir::PlaceBase::Local(local) => per_local[local].push(var),
263263
}
264264
}
265265
Some(per_local)

src/librustc_codegen_ssa/mir/operand.rs

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -373,44 +373,44 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
373373
) -> Option<OperandRef<'tcx, Bx::Value>> {
374374
debug!("maybe_codegen_consume_direct(place_ref={:?})", place_ref);
375375

376-
if let mir::PlaceBase::Local(index) = place_ref.base {
377-
match self.locals[*index] {
378-
LocalRef::Operand(Some(mut o)) => {
379-
// Moves out of scalar and scalar pair fields are trivial.
380-
for elem in place_ref.projection.iter() {
381-
match elem {
382-
mir::ProjectionElem::Field(ref f, _) => {
383-
o = o.extract_field(bx, f.index());
384-
}
385-
mir::ProjectionElem::Index(_)
386-
| mir::ProjectionElem::ConstantIndex { .. } => {
387-
// ZSTs don't require any actual memory access.
388-
// FIXME(eddyb) deduplicate this with the identical
389-
// checks in `codegen_consume` and `extract_field`.
390-
let elem = o.layout.field(bx.cx(), 0);
391-
if elem.is_zst() {
392-
o = OperandRef::new_zst(bx, elem);
393-
} else {
394-
return None;
376+
match place_ref.base {
377+
mir::PlaceBase::Local(index) => {
378+
match self.locals[*index] {
379+
LocalRef::Operand(Some(mut o)) => {
380+
// Moves out of scalar and scalar pair fields are trivial.
381+
for elem in place_ref.projection.iter() {
382+
match elem {
383+
mir::ProjectionElem::Field(ref f, _) => {
384+
o = o.extract_field(bx, f.index());
385+
}
386+
mir::ProjectionElem::Index(_)
387+
| mir::ProjectionElem::ConstantIndex { .. } => {
388+
// ZSTs don't require any actual memory access.
389+
// FIXME(eddyb) deduplicate this with the identical
390+
// checks in `codegen_consume` and `extract_field`.
391+
let elem = o.layout.field(bx.cx(), 0);
392+
if elem.is_zst() {
393+
o = OperandRef::new_zst(bx, elem);
394+
} else {
395+
return None;
396+
}
395397
}
398+
_ => return None,
396399
}
397-
_ => return None,
398400
}
399-
}
400401

401-
Some(o)
402-
}
403-
LocalRef::Operand(None) => {
404-
bug!("use of {:?} before def", place_ref);
405-
}
406-
LocalRef::Place(..) | LocalRef::UnsizedPlace(..) => {
407-
// watch out for locals that do not have an
408-
// alloca; they are handled somewhat differently
409-
None
402+
Some(o)
403+
}
404+
LocalRef::Operand(None) => {
405+
bug!("use of {:?} before def", place_ref);
406+
}
407+
LocalRef::Place(..) | LocalRef::UnsizedPlace(..) => {
408+
// watch out for locals that do not have an
409+
// alloca; they are handled somewhat differently
410+
None
411+
}
410412
}
411413
}
412-
} else {
413-
None
414414
}
415415
}
416416

src/librustc_codegen_ssa/mir/place.rs

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,6 @@ impl<'a, 'tcx, V: CodegenObject> PlaceRef<'tcx, V> {
3737
PlaceRef { llval, llextra: None, layout, align }
3838
}
3939

40-
fn new_thin_place<Bx: BuilderMethods<'a, 'tcx, Value = V>>(
41-
bx: &mut Bx,
42-
llval: V,
43-
layout: TyLayout<'tcx>,
44-
) -> PlaceRef<'tcx, V> {
45-
assert!(!bx.cx().type_has_metadata(layout.ty));
46-
PlaceRef { llval, llextra: None, layout, align: layout.align.abi }
47-
}
48-
4940
// FIXME(eddyb) pass something else for the name so no work is done
5041
// unless LLVM IR names are turned on (e.g. for `--emit=llvm-ir`).
5142
pub fn alloca<Bx: BuilderMethods<'a, 'tcx, Value = V>>(
@@ -437,16 +428,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
437428
}
438429
}
439430
}
440-
mir::PlaceRef {
441-
base: mir::PlaceBase::Static(box mir::Static { ty, def_id }),
442-
projection: [],
443-
} => {
444-
// NB: The layout of a static may be unsized as is the case when working
445-
// with a static that is an extern_type.
446-
let layout = cx.layout_of(self.monomorphize(&ty));
447-
let static_ = bx.get_static(*def_id);
448-
PlaceRef::new_thin_place(bx, static_, layout)
449-
}
450431
mir::PlaceRef { base, projection: [proj_base @ .., mir::ProjectionElem::Deref] } => {
451432
// Load the pointer from its location.
452433
self.codegen_consume(bx, &mir::PlaceRef { base, projection: proj_base })

src/librustc_mir/borrow_check/borrow_set.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,10 @@ impl<'a, 'tcx> Visitor<'tcx> for GatherBorrows<'a, 'tcx> {
208208

209209
self.insert_as_pending_if_two_phase(location, &assigned_place, kind, idx);
210210

211-
if let mir::PlaceBase::Local(local) = borrowed_place.base {
212-
self.local_map.entry(local).or_default().insert(idx);
211+
match borrowed_place.base {
212+
mir::PlaceBase::Local(local) => {
213+
self.local_map.entry(local).or_default().insert(idx);
214+
}
213215
}
214216
}
215217

src/librustc_mir/borrow_check/constraint_generation.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,6 @@ impl<'cx, 'cg, 'tcx> ConstraintGeneration<'cx, 'cg, 'tcx> {
207207
);
208208
}
209209

210-
PlaceRef { base: &PlaceBase::Static(_), .. } => {
211-
// Ignore kills of static or static mut variables.
212-
}
213-
214210
PlaceRef { base: &PlaceBase::Local(local), projection: &[.., _] } => {
215211
// Kill conflicting borrows of the innermost local.
216212
debug!(

0 commit comments

Comments
 (0)