Skip to content

Commit a1e8b45

Browse files
committed
Remove StaticKind
1 parent dbdcb54 commit a1e8b45

File tree

12 files changed

+53
-95
lines changed

12 files changed

+53
-95
lines changed

src/librustc/mir/mod.rs

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1687,21 +1687,13 @@ pub enum PlaceBase<'tcx> {
16871687
RustcEncodable, RustcDecodable, HashStable)]
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, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, HashStable, RustcEncodable, RustcDecodable,
1700-
)]
1701-
pub enum StaticKind {
1702-
Static,
1703-
}
1704-
17051697
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
17061698
#[derive(RustcEncodable, RustcDecodable, HashStable)]
17071699
pub enum ProjectionElem<V, T> {
@@ -1951,7 +1943,7 @@ impl Debug for PlaceBase<'_> {
19511943
fn fmt(&self, fmt: &mut Formatter<'_>) -> fmt::Result {
19521944
match *self {
19531945
PlaceBase::Local(id) => write!(fmt, "{:?}", id),
1954-
PlaceBase::Static(box self::Static { ty, kind: StaticKind::Static, def_id }) => {
1946+
PlaceBase::Static(box self::Static { ty, def_id }) => {
19551947
write!(fmt, "({}: {:?})", ty::tls::with(|tcx| tcx.def_path_str(def_id)), ty)
19561948
}
19571949
}
@@ -3062,29 +3054,14 @@ impl<'tcx> TypeFoldable<'tcx> for Static<'tcx> {
30623054
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
30633055
Static {
30643056
ty: self.ty.fold_with(folder),
3065-
kind: self.kind.fold_with(folder),
30663057
def_id: self.def_id,
30673058
}
30683059
}
30693060

30703061
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
3071-
let Static { ty, kind, def_id: _ } = self;
3072-
3073-
ty.visit_with(visitor) || kind.visit_with(visitor)
3074-
}
3075-
}
3062+
let Static { ty, def_id: _ } = self;
30763063

3077-
impl<'tcx> TypeFoldable<'tcx> for StaticKind {
3078-
fn super_fold_with<F: TypeFolder<'tcx>>(&self, _folder: &mut F) -> Self {
3079-
match self {
3080-
StaticKind::Static => StaticKind::Static
3081-
}
3082-
}
3083-
3084-
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, _visitor: &mut V) -> bool {
3085-
match self {
3086-
StaticKind::Static => { false }
3087-
}
3064+
ty.visit_with(visitor)
30883065
}
30893066
}
30903067

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: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
468468
mir::PlaceRef {
469469
base: mir::PlaceBase::Static(box mir::Static {
470470
ty,
471-
kind: mir::StaticKind::Static,
472471
def_id,
473472
}),
474473
projection: [],

src/librustc_mir/borrow_check/diagnostics/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc::hir::GeneratorKind;
77
use rustc::mir::{
88
AggregateKind, Constant, Field, Local, LocalInfo, LocalKind, Location, Operand,
99
Place, PlaceBase, PlaceRef, ProjectionElem, Rvalue, Statement, StatementKind,
10-
Static, StaticKind, Terminator, TerminatorKind,
10+
Static, Terminator, TerminatorKind,
1111
};
1212
use rustc::ty::{self, DefIdTree, Ty, TyCtxt};
1313
use rustc::ty::layout::VariantIdx;
@@ -177,7 +177,6 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
177177
PlaceRef {
178178
base:
179179
PlaceBase::Static(box Static {
180-
kind: StaticKind::Static,
181180
def_id,
182181
..
183182
}),

src/librustc_mir/borrow_check/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc::lint::builtin::{MUTABLE_BORROW_RESERVATION_CONFLICT};
99
use rustc::mir::{AggregateKind, BasicBlock, BorrowCheckResult, BorrowKind};
1010
use rustc::mir::{
1111
ClearCrossCrate, Local, Location, Body, BodyAndCache, Mutability, Operand, Place, PlaceBase,
12-
PlaceElem, PlaceRef, ReadOnlyBodyAndCache, Static, StaticKind, read_only
12+
PlaceElem, PlaceRef, ReadOnlyBodyAndCache, Static, read_only
1313
};
1414
use rustc::mir::{Field, ProjectionElem, Promoted, Rvalue, Statement, StatementKind};
1515
use rustc::mir::{Terminator, TerminatorKind};
@@ -2181,7 +2181,6 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
21812181
}
21822182
PlaceRef {
21832183
base: PlaceBase::Static(box Static {
2184-
kind: StaticKind::Static,
21852184
def_id,
21862185
..
21872186
}),

src/librustc_mir/borrow_check/places_conflict.rs

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ use crate::borrow_check::ArtificialField;
22
use crate::borrow_check::Overlap;
33
use crate::borrow_check::{Deep, Shallow, AccessDepth};
44
use rustc::hir;
5-
use rustc::mir::{
6-
Body, BorrowKind, Place, PlaceBase, PlaceElem, PlaceRef, ProjectionElem, StaticKind,
7-
};
5+
use rustc::mir::{Body, BorrowKind, Place, PlaceBase, PlaceElem, PlaceRef, ProjectionElem};
86
use rustc::ty::{self, TyCtxt};
97
use std::cmp::max;
108

@@ -329,20 +327,16 @@ fn place_base_conflict<'tcx>(
329327
}
330328
}
331329
(PlaceBase::Static(s1), PlaceBase::Static(s2)) => {
332-
match (&s1.kind, &s2.kind) {
333-
(StaticKind::Static, StaticKind::Static) => {
334-
if s1.def_id != s2.def_id {
335-
debug!("place_element_conflict: DISJOINT-STATIC");
336-
Overlap::Disjoint
337-
} else if tcx.is_mutable_static(s1.def_id) {
338-
// We ignore mutable statics - they can only be unsafe code.
339-
debug!("place_element_conflict: IGNORE-STATIC-MUT");
340-
Overlap::Disjoint
341-
} else {
342-
debug!("place_element_conflict: DISJOINT-OR-EQ-STATIC");
343-
Overlap::EqualOrDisjoint
344-
}
345-
},
330+
if s1.def_id != s2.def_id {
331+
debug!("place_element_conflict: DISJOINT-STATIC");
332+
Overlap::Disjoint
333+
} else if tcx.is_mutable_static(s1.def_id) {
334+
// We ignore mutable statics - they can only be unsafe code.
335+
debug!("place_element_conflict: IGNORE-STATIC-MUT");
336+
Overlap::Disjoint
337+
} else {
338+
debug!("place_element_conflict: DISJOINT-OR-EQ-STATIC");
339+
Overlap::EqualOrDisjoint
346340
}
347341
}
348342
(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
@@ -485,7 +485,7 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
485485
let mut place_ty = match &place.base {
486486
PlaceBase::Local(index) =>
487487
PlaceTy::from_ty(self.body.local_decls[*index].ty),
488-
PlaceBase::Static(box Static { kind, ty, def_id }) => {
488+
PlaceBase::Static(box Static { ty, def_id }) => {
489489
let san_ty = self.sanitize_type(place, ty);
490490
let check_err =
491491
|verifier: &mut TypeVerifier<'a, 'b, 'tcx>,
@@ -508,14 +508,10 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
508508
);
509509
};
510510
};
511-
match kind {
512-
StaticKind::Static => {
513-
let ty = self.tcx().type_of(*def_id);
514-
let ty = self.cx.normalize(ty, location);
511+
let ty = self.tcx().type_of(*def_id);
512+
let ty = self.cx.normalize(ty, location);
515513

516-
check_err(self, place, ty, san_ty);
517-
}
518-
}
514+
check_err(self, place, ty, san_ty);
519515
PlaceTy::from_ty(san_ty)
520516
}
521517
};

src/librustc_mir/interpret/machine.rs

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

223-
/// Called before a `StaticKind::Static` value is accessed.
223+
/// Called before a `Static` value is accessed.
224224
fn before_access_static(
225225
_allocation: &Allocation,
226226
) -> InterpResult<'tcx> {

src/librustc_mir/interpret/place.rs

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -596,38 +596,32 @@ where
596596
&self,
597597
place_static: &mir::Static<'tcx>
598598
) -> InterpResult<'tcx, MPlaceTy<'tcx, M::PointerTag>> {
599-
use rustc::mir::StaticKind;
600-
601-
Ok(match place_static.kind {
602-
StaticKind::Static => {
603-
let ty = place_static.ty;
604-
assert!(!ty.needs_subst());
605-
let layout = self.layout_of(ty)?;
606-
let instance = ty::Instance::mono(*self.tcx, place_static.def_id);
607-
let cid = GlobalId {
608-
instance,
609-
promoted: None
610-
};
611-
// Just create a lazy reference, so we can support recursive statics.
612-
// tcx takes care of assigning every static one and only one unique AllocId.
613-
// When the data here is ever actually used, memory will notice,
614-
// and it knows how to deal with alloc_id that are present in the
615-
// global table but not in its local memory: It calls back into tcx through
616-
// a query, triggering the CTFE machinery to actually turn this lazy reference
617-
// into a bunch of bytes. IOW, statics are evaluated with CTFE even when
618-
// this InterpCx uses another Machine (e.g., in miri). This is what we
619-
// want! This way, computing statics works consistently between codegen
620-
// and miri: They use the same query to eventually obtain a `ty::Const`
621-
// and use that for further computation.
622-
//
623-
// Notice that statics have *two* AllocIds: the lazy one, and the resolved
624-
// one. Here we make sure that the interpreted program never sees the
625-
// resolved ID. Also see the doc comment of `Memory::get_static_alloc`.
626-
let alloc_id = self.tcx.alloc_map.lock().create_static_alloc(cid.instance.def_id());
627-
let ptr = self.tag_static_base_pointer(Pointer::from(alloc_id));
628-
MPlaceTy::from_aligned_ptr(ptr, layout)
629-
}
630-
})
599+
let ty = place_static.ty;
600+
assert!(!ty.needs_subst());
601+
let layout = self.layout_of(ty)?;
602+
let instance = ty::Instance::mono(*self.tcx, place_static.def_id);
603+
let cid = GlobalId {
604+
instance,
605+
promoted: None
606+
};
607+
// Just create a lazy reference, so we can support recursive statics.
608+
// tcx takes care of assigning every static one and only one unique AllocId.
609+
// When the data here is ever actually used, memory will notice,
610+
// and it knows how to deal with alloc_id that are present in the
611+
// global table but not in its local memory: It calls back into tcx through
612+
// a query, triggering the CTFE machinery to actually turn this lazy reference
613+
// into a bunch of bytes. IOW, statics are evaluated with CTFE even when
614+
// this InterpCx uses another Machine (e.g., in miri). This is what we
615+
// want! This way, computing statics works consistently between codegen
616+
// and miri: They use the same query to eventually obtain a `ty::Const`
617+
// and use that for further computation.
618+
//
619+
// Notice that statics have *two* AllocIds: the lazy one, and the resolved
620+
// one. Here we make sure that the interpreted program never sees the
621+
// resolved ID. Also see the doc comment of `Memory::get_static_alloc`.
622+
let alloc_id = self.tcx.alloc_map.lock().create_static_alloc(cid.instance.def_id());
623+
let ptr = self.tag_static_base_pointer(Pointer::from(alloc_id));
624+
Ok(MPlaceTy::from_aligned_ptr(ptr, layout))
631625
}
632626

633627
/// 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
@@ -186,7 +186,7 @@ use rustc::ty::{self, TypeFoldable, Ty, TyCtxt, GenericParamDefKind, Instance};
186186
use rustc::ty::print::obsolete::DefPathBasedNames;
187187
use rustc::ty::adjustment::{CustomCoerceUnsized, PointerCast};
188188
use rustc::session::config::EntryFnType;
189-
use rustc::mir::{self, Location, PlaceBase, Static, StaticKind};
189+
use rustc::mir::{self, Location, PlaceBase, Static};
190190
use rustc::mir::visit::Visitor as MirVisitor;
191191
use rustc::mir::mono::{MonoItem, InstantiationMode};
192192
use rustc::mir::interpret::{Scalar, GlobalId, GlobalAlloc, ErrorHandled};
@@ -667,7 +667,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
667667
_context: mir::visit::PlaceContext,
668668
location: Location) {
669669
match place_base {
670-
PlaceBase::Static(box Static { kind: StaticKind::Static, def_id, .. }) => {
670+
PlaceBase::Static(box Static { def_id, .. }) => {
671671
debug!("visiting static {:?} @ {:?}", def_id, location);
672672

673673
let tcx = self.tcx;

0 commit comments

Comments
 (0)