Skip to content

Commit b63597d

Browse files
spastorinooli-obk
authored andcommitted
Remove StaticKind
1 parent 6f2c702 commit b63597d

File tree

12 files changed

+53
-115
lines changed

12 files changed

+53
-115
lines changed

src/librustc/mir/mod.rs

Lines changed: 4 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1687,30 +1687,13 @@ pub enum PlaceBase<'tcx> {
16871687
)]
16881688
pub struct Static<'tcx> {
16891689
pub ty: Ty<'tcx>,
1690-
pub kind: StaticKind,
16911690
/// The `DefId` of the item this static was declared in. For promoted values, usually, this is
16921691
/// the same as the `DefId` of the `mir::Body` containing the `Place` this promoted appears in.
16931692
/// However, after inlining, that might no longer be the case as inlined `Place`s are copied
16941693
/// into the calling frame.
16951694
pub def_id: DefId,
16961695
}
16971696

1698-
#[derive(
1699-
Clone,
1700-
Debug,
1701-
PartialEq,
1702-
Eq,
1703-
PartialOrd,
1704-
Ord,
1705-
Hash,
1706-
HashStable,
1707-
RustcEncodable,
1708-
RustcDecodable
1709-
)]
1710-
pub enum StaticKind {
1711-
Static,
1712-
}
1713-
17141697
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
17151698
#[derive(RustcEncodable, RustcDecodable, HashStable)]
17161699
pub enum ProjectionElem<V, T> {
@@ -1942,7 +1925,7 @@ impl Debug for PlaceBase<'_> {
19421925
fn fmt(&self, fmt: &mut Formatter<'_>) -> fmt::Result {
19431926
match *self {
19441927
PlaceBase::Local(id) => write!(fmt, "{:?}", id),
1945-
PlaceBase::Static(box self::Static { ty, kind: StaticKind::Static, def_id }) => {
1928+
PlaceBase::Static(box self::Static { ty, def_id }) => {
19461929
write!(fmt, "({}: {:?})", ty::tls::with(|tcx| tcx.def_path_str(def_id)), ty)
19471930
}
19481931
}
@@ -3046,31 +3029,13 @@ impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<PlaceElem<'tcx>> {
30463029

30473030
impl<'tcx> TypeFoldable<'tcx> for Static<'tcx> {
30483031
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
3049-
Static {
3050-
ty: self.ty.fold_with(folder),
3051-
kind: self.kind.fold_with(folder),
3052-
def_id: self.def_id,
3053-
}
3032+
Static { ty: self.ty.fold_with(folder), def_id: self.def_id }
30543033
}
30553034

30563035
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
3057-
let Static { ty, kind, def_id: _ } = self;
3058-
3059-
ty.visit_with(visitor) || kind.visit_with(visitor)
3060-
}
3061-
}
3036+
let Static { ty, def_id: _ } = self;
30623037

3063-
impl<'tcx> TypeFoldable<'tcx> for StaticKind {
3064-
fn super_fold_with<F: TypeFolder<'tcx>>(&self, _folder: &mut F) -> Self {
3065-
match self {
3066-
StaticKind::Static => StaticKind::Static,
3067-
}
3068-
}
3069-
3070-
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, _visitor: &mut V) -> bool {
3071-
match self {
3072-
StaticKind::Static => false,
3073-
}
3038+
ty.visit_with(visitor)
30743039
}
30753040
}
30763041

src/librustc/mir/visit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,7 @@ macro_rules! make_mir_visitor {
712712
PlaceBase::Local(local) => {
713713
self.visit_local(local, context, location);
714714
}
715-
PlaceBase::Static(box Static { kind: _, ty, def_id: _ }) => {
715+
PlaceBase::Static(box Static { ty, def_id: _ }) => {
716716
self.visit_ty(& $($mutability)? *ty, TyContext::Location(location));
717717
}
718718
}

src/librustc_codegen_ssa/mir/place.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -438,12 +438,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
438438
}
439439
}
440440
mir::PlaceRef {
441-
base:
442-
mir::PlaceBase::Static(box mir::Static {
443-
ty,
444-
kind: mir::StaticKind::Static,
445-
def_id,
446-
}),
441+
base: mir::PlaceBase::Static(box mir::Static { ty, def_id }),
447442
projection: [],
448443
} => {
449444
// NB: The layout of a static may be unsized as is the case when working

src/librustc_mir/borrow_check/diagnostics/mod.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
33
use rustc::mir::{
44
AggregateKind, Constant, Field, Local, LocalInfo, LocalKind, Location, Operand, Place,
5-
PlaceBase, PlaceRef, ProjectionElem, Rvalue, Statement, StatementKind, Static, StaticKind,
6-
Terminator, TerminatorKind,
5+
PlaceBase, PlaceRef, ProjectionElem, Rvalue, Statement, StatementKind, Static, Terminator,
6+
TerminatorKind,
77
};
88
use rustc::ty::layout::VariantIdx;
99
use rustc::ty::print::Print;
@@ -172,10 +172,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
172172
PlaceRef { base: PlaceBase::Local(local), projection: [] } => {
173173
self.append_local_to_string(*local, buf)?;
174174
}
175-
PlaceRef {
176-
base: PlaceBase::Static(box Static { kind: StaticKind::Static, def_id, .. }),
177-
projection: [],
178-
} => {
175+
PlaceRef { base: PlaceBase::Static(box Static { def_id, .. }), projection: [] } => {
179176
buf.push_str(&self.infcx.tcx.item_name(*def_id).to_string());
180177
}
181178
PlaceRef { base: &PlaceBase::Local(local), projection: [ProjectionElem::Deref] }

src/librustc_mir/borrow_check/mod.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rustc::lint::builtin::MUTABLE_BORROW_RESERVATION_CONFLICT;
55
use rustc::lint::builtin::UNUSED_MUT;
66
use rustc::mir::{
77
read_only, Body, BodyAndCache, ClearCrossCrate, Local, Location, Mutability, Operand, Place,
8-
PlaceBase, PlaceElem, PlaceRef, ReadOnlyBodyAndCache, Static, StaticKind,
8+
PlaceBase, PlaceElem, PlaceRef, ReadOnlyBodyAndCache, Static,
99
};
1010
use rustc::mir::{AggregateKind, BasicBlock, BorrowCheckResult, BorrowKind};
1111
use rustc::mir::{Field, ProjectionElem, Promoted, Rvalue, Statement, StatementKind};
@@ -2196,10 +2196,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
21962196
}),
21972197
}
21982198
}
2199-
PlaceRef {
2200-
base: PlaceBase::Static(box Static { kind: StaticKind::Static, def_id, .. }),
2201-
projection: [],
2202-
} => {
2199+
PlaceRef { base: PlaceBase::Static(box Static { def_id, .. }), projection: [] } => {
22032200
if !self.infcx.tcx.is_mutable_static(*def_id) {
22042201
Err(place)
22052202
} else {

src/librustc_mir/borrow_check/places_conflict.rs

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
use crate::borrow_check::ArtificialField;
22
use crate::borrow_check::Overlap;
33
use crate::borrow_check::{AccessDepth, Deep, Shallow};
4-
use rustc::mir::{
5-
Body, BorrowKind, Place, PlaceBase, PlaceElem, PlaceRef, ProjectionElem, StaticKind,
6-
};
4+
use rustc::mir::{Body, BorrowKind, Place, PlaceBase, PlaceElem, PlaceRef, ProjectionElem};
75
use rustc::ty::{self, TyCtxt};
86
use rustc_hir as hir;
97
use std::cmp::max;
@@ -327,20 +325,16 @@ fn place_base_conflict<'tcx>(
327325
}
328326
}
329327
(PlaceBase::Static(s1), PlaceBase::Static(s2)) => {
330-
match (&s1.kind, &s2.kind) {
331-
(StaticKind::Static, StaticKind::Static) => {
332-
if s1.def_id != s2.def_id {
333-
debug!("place_element_conflict: DISJOINT-STATIC");
334-
Overlap::Disjoint
335-
} else if tcx.is_mutable_static(s1.def_id) {
336-
// We ignore mutable statics - they can only be unsafe code.
337-
debug!("place_element_conflict: IGNORE-STATIC-MUT");
338-
Overlap::Disjoint
339-
} else {
340-
debug!("place_element_conflict: DISJOINT-OR-EQ-STATIC");
341-
Overlap::EqualOrDisjoint
342-
}
343-
}
328+
if s1.def_id != s2.def_id {
329+
debug!("place_element_conflict: DISJOINT-STATIC");
330+
Overlap::Disjoint
331+
} else if tcx.is_mutable_static(s1.def_id) {
332+
// We ignore mutable statics - they can only be unsafe code.
333+
debug!("place_element_conflict: IGNORE-STATIC-MUT");
334+
Overlap::Disjoint
335+
} else {
336+
debug!("place_element_conflict: DISJOINT-OR-EQ-STATIC");
337+
Overlap::EqualOrDisjoint
344338
}
345339
}
346340
(PlaceBase::Local(_), PlaceBase::Static(_))

src/librustc_mir/borrow_check/type_check/mod.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
467467

468468
let mut place_ty = match &place.base {
469469
PlaceBase::Local(index) => PlaceTy::from_ty(self.body.local_decls[*index].ty),
470-
PlaceBase::Static(box Static { kind, ty, def_id }) => {
470+
PlaceBase::Static(box Static { ty, def_id }) => {
471471
let san_ty = self.sanitize_type(place, ty);
472472
let check_err =
473473
|verifier: &mut TypeVerifier<'a, 'b, 'tcx>, place: &Place<'tcx>, ty, san_ty| {
@@ -487,14 +487,10 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
487487
);
488488
};
489489
};
490-
match kind {
491-
StaticKind::Static => {
492-
let ty = self.tcx().type_of(*def_id);
493-
let ty = self.cx.normalize(ty, location);
490+
let ty = self.tcx().type_of(*def_id);
491+
let ty = self.cx.normalize(ty, location);
494492

495-
check_err(self, place, ty, san_ty);
496-
}
497-
}
493+
check_err(self, place, ty, san_ty);
498494
PlaceTy::from_ty(san_ty)
499495
}
500496
};

src/librustc_mir/interpret/machine.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ pub trait Machine<'mir, 'tcx>: Sized {
212212
frame.locals[local].access()
213213
}
214214

215-
/// Called before a `StaticKind::Static` value is accessed.
215+
/// Called before a `Static` value is accessed.
216216
fn before_access_static(
217217
_memory_extra: &Self::MemoryExtra,
218218
_allocation: &Allocation,

src/librustc_mir/interpret/place.rs

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -625,33 +625,27 @@ where
625625
&self,
626626
place_static: &mir::Static<'tcx>,
627627
) -> InterpResult<'tcx, MPlaceTy<'tcx, M::PointerTag>> {
628-
use rustc::mir::StaticKind;
629-
630-
Ok(match place_static.kind {
631-
StaticKind::Static => {
632-
let ty = place_static.ty;
633-
assert!(!ty.needs_subst());
634-
let layout = self.layout_of(ty)?;
635-
// Just create a lazy reference, so we can support recursive statics.
636-
// tcx takes care of assigning every static one and only one unique AllocId.
637-
// When the data here is ever actually used, memory will notice,
638-
// and it knows how to deal with alloc_id that are present in the
639-
// global table but not in its local memory: It calls back into tcx through
640-
// a query, triggering the CTFE machinery to actually turn this lazy reference
641-
// into a bunch of bytes. IOW, statics are evaluated with CTFE even when
642-
// this InterpCx uses another Machine (e.g., in miri). This is what we
643-
// want! This way, computing statics works consistently between codegen
644-
// and miri: They use the same query to eventually obtain a `ty::Const`
645-
// and use that for further computation.
646-
//
647-
// Notice that statics have *two* AllocIds: the lazy one, and the resolved
648-
// one. Here we make sure that the interpreted program never sees the
649-
// resolved ID. Also see the doc comment of `Memory::get_static_alloc`.
650-
let alloc_id = self.tcx.alloc_map.lock().create_static_alloc(place_static.def_id);
651-
let ptr = self.tag_static_base_pointer(Pointer::from(alloc_id));
652-
MPlaceTy::from_aligned_ptr(ptr, layout)
653-
}
654-
})
628+
let ty = place_static.ty;
629+
assert!(!ty.needs_subst());
630+
let layout = self.layout_of(ty)?;
631+
// Just create a lazy reference, so we can support recursive statics.
632+
// tcx takes care of assigning every static one and only one unique AllocId.
633+
// When the data here is ever actually used, memory will notice,
634+
// and it knows how to deal with alloc_id that are present in the
635+
// global table but not in its local memory: It calls back into tcx through
636+
// a query, triggering the CTFE machinery to actually turn this lazy reference
637+
// into a bunch of bytes. IOW, statics are evaluated with CTFE even when
638+
// this InterpCx uses another Machine (e.g., in miri). This is what we
639+
// want! This way, computing statics works consistently between codegen
640+
// and miri: They use the same query to eventually obtain a `ty::Const`
641+
// and use that for further computation.
642+
//
643+
// Notice that statics have *two* AllocIds: the lazy one, and the resolved
644+
// one. Here we make sure that the interpreted program never sees the
645+
// resolved ID. Also see the doc comment of `Memory::get_static_alloc`.
646+
let alloc_id = self.tcx.alloc_map.lock().create_static_alloc(place_static.def_id);
647+
let ptr = self.tag_static_base_pointer(Pointer::from(alloc_id));
648+
Ok(MPlaceTy::from_aligned_ptr(ptr, layout))
655649
}
656650

657651
/// Computes a place. You should only use this if you intend to write into this

src/librustc_mir/monomorphize/collector.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ use rustc::mir::interpret::{AllocId, ConstValue};
182182
use rustc::mir::interpret::{ErrorHandled, GlobalAlloc, Scalar};
183183
use rustc::mir::mono::{InstantiationMode, MonoItem};
184184
use rustc::mir::visit::Visitor as MirVisitor;
185-
use rustc::mir::{self, Location, PlaceBase, Static, StaticKind};
185+
use rustc::mir::{self, Location, PlaceBase, Static};
186186
use rustc::session::config::EntryFnType;
187187
use rustc::ty::adjustment::{CustomCoerceUnsized, PointerCast};
188188
use rustc::ty::print::obsolete::DefPathBasedNames;
@@ -647,7 +647,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
647647
location: Location,
648648
) {
649649
match place_base {
650-
PlaceBase::Static(box Static { kind: StaticKind::Static, def_id, .. }) => {
650+
PlaceBase::Static(box Static { def_id, .. }) => {
651651
debug!("visiting static {:?} @ {:?}", def_id, location);
652652

653653
let tcx = self.tcx;

src/librustc_mir/transform/check_unsafety.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,8 @@ impl<'a, 'tcx> Visitor<'tcx> for UnsafetyChecker<'a, 'tcx> {
194194
PlaceBase::Local(..) => {
195195
// Locals are safe.
196196
}
197-
PlaceBase::Static(box Static { kind: StaticKind::Static, .. }) => {
198-
bug!("StaticKind::Static should not exist");
197+
PlaceBase::Static(box Static { .. }) => {
198+
bug!("Static should not exist");
199199
}
200200
}
201201

src/librustc_mir/transform/promote_consts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ use crate::transform::{MirPass, MirSource};
3939
/// errors when promotion of `#[rustc_args_required_const]` arguments fails.
4040
///
4141
/// After this pass is run, `promoted_fragments` will hold the MIR body corresponding to each
42-
/// newly created `StaticKind::Promoted`.
42+
/// newly created `Constant`.
4343
#[derive(Default)]
4444
pub struct PromoteTemps<'tcx> {
4545
pub promoted_fragments: Cell<IndexVec<Promoted, BodyAndCache<'tcx>>>,

0 commit comments

Comments
 (0)