Skip to content

Commit 9f517b7

Browse files
committed
Remove Static from PlaceBase
1 parent 428e6cb commit 9f517b7

37 files changed

+183
-447
lines changed

src/librustc/mir/mod.rs

Lines changed: 6 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1663,7 +1663,7 @@ impl Debug for Statement<'_> {
16631663
Clone, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, HashStable,
16641664
)]
16651665
pub struct Place<'tcx> {
1666-
pub base: PlaceBase<'tcx>,
1666+
pub base: PlaceBase,
16671667

16681668
/// projection out of a place (access a field, deref a pointer, etc)
16691669
pub projection: &'tcx List<PlaceElem<'tcx>>,
@@ -1674,24 +1674,9 @@ impl<'tcx> rustc_serialize::UseSpecializedDecodable for Place<'tcx> {}
16741674
#[derive(
16751675
Clone, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable, HashStable,
16761676
)]
1677-
pub enum PlaceBase<'tcx> {
1677+
pub enum PlaceBase {
16781678
/// local variable
16791679
Local(Local),
1680-
1681-
/// static or static mut variable
1682-
Static(Box<Static<'tcx>>),
1683-
}
1684-
1685-
/// We store the normalized type to avoid requiring normalization when reading MIR
1686-
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash,
1687-
RustcEncodable, RustcDecodable, HashStable)]
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,
16951680
}
16961681

16971682
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
@@ -1782,7 +1767,7 @@ rustc_index::newtype_index! {
17821767

17831768
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
17841769
pub struct PlaceRef<'a, 'tcx> {
1785-
pub base: &'a PlaceBase<'tcx>,
1770+
pub base: &'a PlaceBase,
17861771
pub projection: &'a [PlaceElem<'tcx>],
17871772
}
17881773

@@ -1844,7 +1829,7 @@ impl From<Local> for Place<'_> {
18441829
}
18451830
}
18461831

1847-
impl From<Local> for PlaceBase<'_> {
1832+
impl From<Local> for PlaceBase {
18481833
fn from(local: Local) -> Self {
18491834
PlaceBase::Local(local)
18501835
}
@@ -1939,13 +1924,10 @@ impl Debug for Place<'_> {
19391924
}
19401925
}
19411926

1942-
impl Debug for PlaceBase<'_> {
1927+
impl Debug for PlaceBase {
19431928
fn fmt(&self, fmt: &mut Formatter<'_>) -> fmt::Result {
19441929
match *self {
19451930
PlaceBase::Local(id) => write!(fmt, "{:?}", id),
1946-
PlaceBase::Static(box self::Static { ty, def_id }) => {
1947-
write!(fmt, "({}: {:?})", ty::tls::with(|tcx| tcx.def_path_str(def_id)), ty)
1948-
}
19491931
}
19501932
}
19511933
}
@@ -3023,18 +3005,16 @@ impl<'tcx> TypeFoldable<'tcx> for Place<'tcx> {
30233005
}
30243006
}
30253007

3026-
impl<'tcx> TypeFoldable<'tcx> for PlaceBase<'tcx> {
3008+
impl<'tcx> TypeFoldable<'tcx> for PlaceBase {
30273009
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
30283010
match self {
30293011
PlaceBase::Local(local) => PlaceBase::Local(local.fold_with(folder)),
3030-
PlaceBase::Static(static_) => PlaceBase::Static(static_.fold_with(folder)),
30313012
}
30323013
}
30333014

30343015
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
30353016
match self {
30363017
PlaceBase::Local(local) => local.visit_with(visitor),
3037-
PlaceBase::Static(static_) => (**static_).visit_with(visitor),
30383018
}
30393019
}
30403020
}
@@ -3050,21 +3030,6 @@ impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<PlaceElem<'tcx>> {
30503030
}
30513031
}
30523032

3053-
impl<'tcx> TypeFoldable<'tcx> for Static<'tcx> {
3054-
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
3055-
Static {
3056-
ty: self.ty.fold_with(folder),
3057-
def_id: self.def_id,
3058-
}
3059-
}
3060-
3061-
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
3062-
let Static { ty, def_id: _ } = self;
3063-
3064-
ty.visit_with(visitor)
3065-
}
3066-
}
3067-
30683033
impl<'tcx> TypeFoldable<'tcx> for Rvalue<'tcx> {
30693034
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
30703035
use crate::mir::Rvalue::*;

src/librustc/mir/tcx.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ impl<'tcx> PlaceTy<'tcx> {
116116

117117
impl<'tcx> Place<'tcx> {
118118
pub fn ty_from<D>(
119-
base: &PlaceBase<'tcx>,
119+
base: &PlaceBase,
120120
projection: &[PlaceElem<'tcx>],
121121
local_decls: &D,
122122
tcx: TyCtxt<'tcx>
@@ -137,13 +137,12 @@ impl<'tcx> Place<'tcx> {
137137
}
138138
}
139139

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

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
@@ -223,7 +223,7 @@ 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<'tcx> = Decodable::decode(decoder)?;
226+
let base: mir::PlaceBase = 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)))?;

src/librustc_codegen_ssa/mir/analyze.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use rustc::mir::traversal;
1212
use rustc::session::config::DebugInfo;
1313
use rustc::ty;
1414
use rustc::ty::layout::{LayoutOf, HasTyCtxt};
15-
use syntax_pos::DUMMY_SP;
1615
use super::FunctionCx;
1716
use crate::traits::*;
1817

@@ -139,10 +138,9 @@ impl<Bx: BuilderMethods<'a, 'tcx>> LocalAnalyzer<'mir, 'a, 'tcx, Bx> {
139138
.projection_ty(cx.tcx(), elem)
140139
.ty;
141140
let elem_ty = self.fx.monomorphize(&elem_ty);
142-
let span = if let mir::PlaceBase::Local(index) = place_ref.base {
143-
self.fx.mir.local_decls[*index].source_info.span
144-
} else {
145-
DUMMY_SP
141+
let span = match place_ref.base {
142+
mir::PlaceBase::Local(index) =>
143+
self.fx.mir.local_decls[*index].source_info.span,
146144
};
147145
if cx.spanned_layout_of(elem_ty, span).is_zst() {
148146
return;
@@ -183,8 +181,8 @@ impl<Bx: BuilderMethods<'a, 'tcx>> LocalAnalyzer<'mir, 'a, 'tcx, Bx> {
183181
// We use `NonUseContext::VarDebugInfo` for the base,
184182
// which might not force the base local to memory,
185183
// so we have to do it manually.
186-
if let mir::PlaceBase::Local(local) = place_ref.base {
187-
self.visit_local(&local, context, location);
184+
match place_ref.base {
185+
mir::PlaceBase::Local(local) => self.visit_local(&local, context, location),
188186
}
189187
}
190188
}

src/librustc_codegen_ssa/mir/debuginfo.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,8 @@ pub fn per_local_var_debug_info(
261261
if tcx.sess.opts.debuginfo == DebugInfo::Full || !tcx.sess.fewer_names() {
262262
let mut per_local = IndexVec::from_elem(vec![], &body.local_decls);
263263
for var in &body.var_debug_info {
264-
if let mir::PlaceBase::Local(local) = var.place.base {
265-
per_local[local].push(var);
264+
match var.place.base {
265+
mir::PlaceBase::Local(local) => per_local[local].push(var),
266266
}
267267
}
268268
Some(per_local)

src/librustc_codegen_ssa/mir/operand.rs

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

388-
if let mir::PlaceBase::Local(index) = place_ref.base {
389-
match self.locals[*index] {
390-
LocalRef::Operand(Some(mut o)) => {
391-
// Moves out of scalar and scalar pair fields are trivial.
392-
for elem in place_ref.projection.iter() {
393-
match elem {
394-
mir::ProjectionElem::Field(ref f, _) => {
395-
o = o.extract_field(bx, f.index());
396-
}
397-
mir::ProjectionElem::Index(_) |
398-
mir::ProjectionElem::ConstantIndex { .. } => {
399-
// ZSTs don't require any actual memory access.
400-
// FIXME(eddyb) deduplicate this with the identical
401-
// checks in `codegen_consume` and `extract_field`.
402-
let elem = o.layout.field(bx.cx(), 0);
403-
if elem.is_zst() {
404-
o = OperandRef::new_zst(bx, elem);
405-
} else {
406-
return None;
388+
match place_ref.base {
389+
mir::PlaceBase::Local(index) => {
390+
match self.locals[*index] {
391+
LocalRef::Operand(Some(mut o)) => {
392+
// Moves out of scalar and scalar pair fields are trivial.
393+
for elem in place_ref.projection.iter() {
394+
match elem {
395+
mir::ProjectionElem::Field(ref f, _) => {
396+
o = o.extract_field(bx, f.index());
397+
}
398+
mir::ProjectionElem::Index(_) |
399+
mir::ProjectionElem::ConstantIndex { .. } => {
400+
// ZSTs don't require any actual memory access.
401+
// FIXME(eddyb) deduplicate this with the identical
402+
// checks in `codegen_consume` and `extract_field`.
403+
let elem = o.layout.field(bx.cx(), 0);
404+
if elem.is_zst() {
405+
o = OperandRef::new_zst(bx, elem);
406+
} else {
407+
return None;
408+
}
407409
}
410+
_ => return None,
408411
}
409-
_ => return None,
410412
}
411-
}
412413

413-
Some(o)
414-
}
415-
LocalRef::Operand(None) => {
416-
bug!("use of {:?} before def", place_ref);
417-
}
418-
LocalRef::Place(..) | LocalRef::UnsizedPlace(..) => {
419-
// watch out for locals that do not have an
420-
// alloca; they are handled somewhat differently
421-
None
414+
Some(o)
415+
}
416+
LocalRef::Operand(None) => {
417+
bug!("use of {:?} before def", place_ref);
418+
}
419+
LocalRef::Place(..) | LocalRef::UnsizedPlace(..) => {
420+
// watch out for locals that do not have an
421+
// alloca; they are handled somewhat differently
422+
None
423+
}
422424
}
423425
}
424-
} else {
425-
None
426426
}
427427
}
428428

src/librustc_codegen_ssa/mir/place.rs

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -54,20 +54,6 @@ impl<'a, 'tcx, V: CodegenObject> PlaceRef<'tcx, V> {
5454
}
5555
}
5656

57-
fn new_thin_place<Bx: BuilderMethods<'a, 'tcx, Value = V>>(
58-
bx: &mut Bx,
59-
llval: V,
60-
layout: TyLayout<'tcx>,
61-
) -> PlaceRef<'tcx, V> {
62-
assert!(!bx.cx().type_has_metadata(layout.ty));
63-
PlaceRef {
64-
llval,
65-
llextra: None,
66-
layout,
67-
align: layout.align.abi
68-
}
69-
}
70-
7157
// FIXME(eddyb) pass something else for the name so no work is done
7258
// unless LLVM IR names are turned on (e.g. for `--emit=llvm-ir`).
7359
pub fn alloca<Bx: BuilderMethods<'a, 'tcx, Value = V>>(
@@ -465,19 +451,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
465451
}
466452
}
467453
}
468-
mir::PlaceRef {
469-
base: mir::PlaceBase::Static(box mir::Static {
470-
ty,
471-
def_id,
472-
}),
473-
projection: [],
474-
} => {
475-
// NB: The layout of a static may be unsized as is the case when working
476-
// with a static that is an extern_type.
477-
let layout = cx.layout_of(self.monomorphize(&ty));
478-
let static_ = bx.get_static(*def_id);
479-
PlaceRef::new_thin_place(bx, static_, layout)
480-
},
481454
mir::PlaceRef {
482455
base,
483456
projection: [proj_base @ .., mir::ProjectionElem::Deref],

src/librustc_mir/borrow_check/borrow_set.rs

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

211211
self.insert_as_pending_if_two_phase(location, &assigned_place, kind, idx);
212212

213-
if let mir::PlaceBase::Local(local) = borrowed_place.base {
214-
self.local_map.entry(local).or_default().insert(idx);
213+
match borrowed_place.base {
214+
mir::PlaceBase::Local(local) => {
215+
self.local_map.entry(local).or_default().insert(idx);
216+
}
215217
}
216218
}
217219

src/librustc_mir/borrow_check/constraint_generation.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -238,13 +238,6 @@ impl<'cx, 'cg, 'tcx> ConstraintGeneration<'cx, 'cg, 'tcx> {
238238
);
239239
}
240240

241-
PlaceRef {
242-
base: &PlaceBase::Static(_),
243-
..
244-
} => {
245-
// Ignore kills of static or static mut variables.
246-
}
247-
248241
PlaceRef {
249242
base: &PlaceBase::Local(local),
250243
projection: &[.., _],

0 commit comments

Comments
 (0)