From: Santiago Pastorino Date: Wed, 11 Dec 2019 04:53:46 +0000 (-0300) Subject: Remove StaticKind X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=b63597dedba1c94a1fa9f2521ce50723cc019e78;p=rust.git Remove StaticKind --- diff --git a/src/librustc/mir/mod.rs b/src/librustc/mir/mod.rs index 2a33e91a69f..42d24d9f332 100644 --- a/src/librustc/mir/mod.rs +++ b/src/librustc/mir/mod.rs @@ -1687,7 +1687,6 @@ pub enum PlaceBase<'tcx> { )] pub struct Static<'tcx> { pub ty: Ty<'tcx>, - pub kind: StaticKind, /// The `DefId` of the item this static was declared in. For promoted values, usually, this is /// the same as the `DefId` of the `mir::Body` containing the `Place` this promoted appears in. /// However, after inlining, that might no longer be the case as inlined `Place`s are copied @@ -1695,22 +1694,6 @@ pub struct Static<'tcx> { pub def_id: DefId, } -#[derive( - Clone, - Debug, - PartialEq, - Eq, - PartialOrd, - Ord, - Hash, - HashStable, - RustcEncodable, - RustcDecodable -)] -pub enum StaticKind { - Static, -} - #[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] #[derive(RustcEncodable, RustcDecodable, HashStable)] pub enum ProjectionElem { @@ -1942,7 +1925,7 @@ impl Debug for PlaceBase<'_> { fn fmt(&self, fmt: &mut Formatter<'_>) -> fmt::Result { match *self { PlaceBase::Local(id) => write!(fmt, "{:?}", id), - PlaceBase::Static(box self::Static { ty, kind: StaticKind::Static, def_id }) => { + PlaceBase::Static(box self::Static { ty, def_id }) => { write!(fmt, "({}: {:?})", ty::tls::with(|tcx| tcx.def_path_str(def_id)), ty) } } @@ -3046,31 +3029,13 @@ fn super_visit_with>(&self, visitor: &mut V) -> bool { impl<'tcx> TypeFoldable<'tcx> for Static<'tcx> { fn super_fold_with>(&self, folder: &mut F) -> Self { - Static { - ty: self.ty.fold_with(folder), - kind: self.kind.fold_with(folder), - def_id: self.def_id, - } + Static { ty: self.ty.fold_with(folder), def_id: self.def_id } } fn super_visit_with>(&self, visitor: &mut V) -> bool { - let Static { ty, kind, def_id: _ } = self; - - ty.visit_with(visitor) || kind.visit_with(visitor) - } -} + let Static { ty, def_id: _ } = self; -impl<'tcx> TypeFoldable<'tcx> for StaticKind { - fn super_fold_with>(&self, _folder: &mut F) -> Self { - match self { - StaticKind::Static => StaticKind::Static, - } - } - - fn super_visit_with>(&self, _visitor: &mut V) -> bool { - match self { - StaticKind::Static => false, - } + ty.visit_with(visitor) } } diff --git a/src/librustc/mir/visit.rs b/src/librustc/mir/visit.rs index 9173c328006..3924a1aa47e 100644 --- a/src/librustc/mir/visit.rs +++ b/src/librustc/mir/visit.rs @@ -712,7 +712,7 @@ fn super_place_base(&mut self, PlaceBase::Local(local) => { self.visit_local(local, context, location); } - PlaceBase::Static(box Static { kind: _, ty, def_id: _ }) => { + PlaceBase::Static(box Static { ty, def_id: _ }) => { self.visit_ty(& $($mutability)? *ty, TyContext::Location(location)); } } diff --git a/src/librustc_codegen_ssa/mir/place.rs b/src/librustc_codegen_ssa/mir/place.rs index 639a98107cd..49c3edbb2b3 100644 --- a/src/librustc_codegen_ssa/mir/place.rs +++ b/src/librustc_codegen_ssa/mir/place.rs @@ -438,12 +438,7 @@ pub fn codegen_place( } } mir::PlaceRef { - base: - mir::PlaceBase::Static(box mir::Static { - ty, - kind: mir::StaticKind::Static, - def_id, - }), + base: mir::PlaceBase::Static(box mir::Static { ty, def_id }), projection: [], } => { // NB: The layout of a static may be unsized as is the case when working diff --git a/src/librustc_mir/borrow_check/diagnostics/mod.rs b/src/librustc_mir/borrow_check/diagnostics/mod.rs index d1c6ee8af58..8ef4273a2f6 100644 --- a/src/librustc_mir/borrow_check/diagnostics/mod.rs +++ b/src/librustc_mir/borrow_check/diagnostics/mod.rs @@ -2,8 +2,8 @@ use rustc::mir::{ AggregateKind, Constant, Field, Local, LocalInfo, LocalKind, Location, Operand, Place, - PlaceBase, PlaceRef, ProjectionElem, Rvalue, Statement, StatementKind, Static, StaticKind, - Terminator, TerminatorKind, + PlaceBase, PlaceRef, ProjectionElem, Rvalue, Statement, StatementKind, Static, Terminator, + TerminatorKind, }; use rustc::ty::layout::VariantIdx; use rustc::ty::print::Print; @@ -172,10 +172,7 @@ fn append_place_to_string( PlaceRef { base: PlaceBase::Local(local), projection: [] } => { self.append_local_to_string(*local, buf)?; } - PlaceRef { - base: PlaceBase::Static(box Static { kind: StaticKind::Static, def_id, .. }), - projection: [], - } => { + PlaceRef { base: PlaceBase::Static(box Static { def_id, .. }), projection: [] } => { buf.push_str(&self.infcx.tcx.item_name(*def_id).to_string()); } PlaceRef { base: &PlaceBase::Local(local), projection: [ProjectionElem::Deref] } diff --git a/src/librustc_mir/borrow_check/mod.rs b/src/librustc_mir/borrow_check/mod.rs index 238a5949090..6c9b811ebd0 100644 --- a/src/librustc_mir/borrow_check/mod.rs +++ b/src/librustc_mir/borrow_check/mod.rs @@ -5,7 +5,7 @@ use rustc::lint::builtin::UNUSED_MUT; use rustc::mir::{ read_only, Body, BodyAndCache, ClearCrossCrate, Local, Location, Mutability, Operand, Place, - PlaceBase, PlaceElem, PlaceRef, ReadOnlyBodyAndCache, Static, StaticKind, + PlaceBase, PlaceElem, PlaceRef, ReadOnlyBodyAndCache, Static, }; use rustc::mir::{AggregateKind, BasicBlock, BorrowCheckResult, BorrowKind}; use rustc::mir::{Field, ProjectionElem, Promoted, Rvalue, Statement, StatementKind}; @@ -2196,10 +2196,7 @@ fn is_mutable<'d>( }), } } - PlaceRef { - base: PlaceBase::Static(box Static { kind: StaticKind::Static, def_id, .. }), - projection: [], - } => { + PlaceRef { base: PlaceBase::Static(box Static { def_id, .. }), projection: [] } => { if !self.infcx.tcx.is_mutable_static(*def_id) { Err(place) } else { diff --git a/src/librustc_mir/borrow_check/places_conflict.rs b/src/librustc_mir/borrow_check/places_conflict.rs index 422bcd2b75c..815ace55a37 100644 --- a/src/librustc_mir/borrow_check/places_conflict.rs +++ b/src/librustc_mir/borrow_check/places_conflict.rs @@ -1,9 +1,7 @@ use crate::borrow_check::ArtificialField; use crate::borrow_check::Overlap; use crate::borrow_check::{AccessDepth, Deep, Shallow}; -use rustc::mir::{ - Body, BorrowKind, Place, PlaceBase, PlaceElem, PlaceRef, ProjectionElem, StaticKind, -}; +use rustc::mir::{Body, BorrowKind, Place, PlaceBase, PlaceElem, PlaceRef, ProjectionElem}; use rustc::ty::{self, TyCtxt}; use rustc_hir as hir; use std::cmp::max; @@ -327,20 +325,16 @@ fn place_base_conflict<'tcx>( } } (PlaceBase::Static(s1), PlaceBase::Static(s2)) => { - match (&s1.kind, &s2.kind) { - (StaticKind::Static, StaticKind::Static) => { - if s1.def_id != s2.def_id { - debug!("place_element_conflict: DISJOINT-STATIC"); - Overlap::Disjoint - } else if tcx.is_mutable_static(s1.def_id) { - // We ignore mutable statics - they can only be unsafe code. - debug!("place_element_conflict: IGNORE-STATIC-MUT"); - Overlap::Disjoint - } else { - debug!("place_element_conflict: DISJOINT-OR-EQ-STATIC"); - Overlap::EqualOrDisjoint - } - } + if s1.def_id != s2.def_id { + debug!("place_element_conflict: DISJOINT-STATIC"); + Overlap::Disjoint + } else if tcx.is_mutable_static(s1.def_id) { + // We ignore mutable statics - they can only be unsafe code. + debug!("place_element_conflict: IGNORE-STATIC-MUT"); + Overlap::Disjoint + } else { + debug!("place_element_conflict: DISJOINT-OR-EQ-STATIC"); + Overlap::EqualOrDisjoint } } (PlaceBase::Local(_), PlaceBase::Static(_)) diff --git a/src/librustc_mir/borrow_check/type_check/mod.rs b/src/librustc_mir/borrow_check/type_check/mod.rs index f66af1f04a3..f771330e2d7 100644 --- a/src/librustc_mir/borrow_check/type_check/mod.rs +++ b/src/librustc_mir/borrow_check/type_check/mod.rs @@ -467,7 +467,7 @@ fn sanitize_place( let mut place_ty = match &place.base { PlaceBase::Local(index) => PlaceTy::from_ty(self.body.local_decls[*index].ty), - PlaceBase::Static(box Static { kind, ty, def_id }) => { + PlaceBase::Static(box Static { ty, def_id }) => { let san_ty = self.sanitize_type(place, ty); let check_err = |verifier: &mut TypeVerifier<'a, 'b, 'tcx>, place: &Place<'tcx>, ty, san_ty| { @@ -487,14 +487,10 @@ fn sanitize_place( ); }; }; - match kind { - StaticKind::Static => { - let ty = self.tcx().type_of(*def_id); - let ty = self.cx.normalize(ty, location); + let ty = self.tcx().type_of(*def_id); + let ty = self.cx.normalize(ty, location); - check_err(self, place, ty, san_ty); - } - } + check_err(self, place, ty, san_ty); PlaceTy::from_ty(san_ty) } }; diff --git a/src/librustc_mir/interpret/machine.rs b/src/librustc_mir/interpret/machine.rs index 6d15827536c..3309e9b9b62 100644 --- a/src/librustc_mir/interpret/machine.rs +++ b/src/librustc_mir/interpret/machine.rs @@ -212,7 +212,7 @@ fn access_local( frame.locals[local].access() } - /// Called before a `StaticKind::Static` value is accessed. + /// Called before a `Static` value is accessed. fn before_access_static( _memory_extra: &Self::MemoryExtra, _allocation: &Allocation, diff --git a/src/librustc_mir/interpret/place.rs b/src/librustc_mir/interpret/place.rs index 79411d872a9..aa15f3d1f17 100644 --- a/src/librustc_mir/interpret/place.rs +++ b/src/librustc_mir/interpret/place.rs @@ -625,33 +625,27 @@ pub(super) fn eval_static_to_mplace( &self, place_static: &mir::Static<'tcx>, ) -> InterpResult<'tcx, MPlaceTy<'tcx, M::PointerTag>> { - use rustc::mir::StaticKind; - - Ok(match place_static.kind { - StaticKind::Static => { - let ty = place_static.ty; - assert!(!ty.needs_subst()); - let layout = self.layout_of(ty)?; - // Just create a lazy reference, so we can support recursive statics. - // tcx takes care of assigning every static one and only one unique AllocId. - // When the data here is ever actually used, memory will notice, - // and it knows how to deal with alloc_id that are present in the - // global table but not in its local memory: It calls back into tcx through - // a query, triggering the CTFE machinery to actually turn this lazy reference - // into a bunch of bytes. IOW, statics are evaluated with CTFE even when - // this InterpCx uses another Machine (e.g., in miri). This is what we - // want! This way, computing statics works consistently between codegen - // and miri: They use the same query to eventually obtain a `ty::Const` - // and use that for further computation. - // - // Notice that statics have *two* AllocIds: the lazy one, and the resolved - // one. Here we make sure that the interpreted program never sees the - // resolved ID. Also see the doc comment of `Memory::get_static_alloc`. - let alloc_id = self.tcx.alloc_map.lock().create_static_alloc(place_static.def_id); - let ptr = self.tag_static_base_pointer(Pointer::from(alloc_id)); - MPlaceTy::from_aligned_ptr(ptr, layout) - } - }) + let ty = place_static.ty; + assert!(!ty.needs_subst()); + let layout = self.layout_of(ty)?; + // Just create a lazy reference, so we can support recursive statics. + // tcx takes care of assigning every static one and only one unique AllocId. + // When the data here is ever actually used, memory will notice, + // and it knows how to deal with alloc_id that are present in the + // global table but not in its local memory: It calls back into tcx through + // a query, triggering the CTFE machinery to actually turn this lazy reference + // into a bunch of bytes. IOW, statics are evaluated with CTFE even when + // this InterpCx uses another Machine (e.g., in miri). This is what we + // want! This way, computing statics works consistently between codegen + // and miri: They use the same query to eventually obtain a `ty::Const` + // and use that for further computation. + // + // Notice that statics have *two* AllocIds: the lazy one, and the resolved + // one. Here we make sure that the interpreted program never sees the + // resolved ID. Also see the doc comment of `Memory::get_static_alloc`. + let alloc_id = self.tcx.alloc_map.lock().create_static_alloc(place_static.def_id); + let ptr = self.tag_static_base_pointer(Pointer::from(alloc_id)); + Ok(MPlaceTy::from_aligned_ptr(ptr, layout)) } /// Computes a place. You should only use this if you intend to write into this diff --git a/src/librustc_mir/monomorphize/collector.rs b/src/librustc_mir/monomorphize/collector.rs index 84b641a763a..2ecae7c6b0c 100644 --- a/src/librustc_mir/monomorphize/collector.rs +++ b/src/librustc_mir/monomorphize/collector.rs @@ -182,7 +182,7 @@ use rustc::mir::interpret::{ErrorHandled, GlobalAlloc, Scalar}; use rustc::mir::mono::{InstantiationMode, MonoItem}; use rustc::mir::visit::Visitor as MirVisitor; -use rustc::mir::{self, Location, PlaceBase, Static, StaticKind}; +use rustc::mir::{self, Location, PlaceBase, Static}; use rustc::session::config::EntryFnType; use rustc::ty::adjustment::{CustomCoerceUnsized, PointerCast}; use rustc::ty::print::obsolete::DefPathBasedNames; @@ -647,7 +647,7 @@ fn visit_place_base( location: Location, ) { match place_base { - PlaceBase::Static(box Static { kind: StaticKind::Static, def_id, .. }) => { + PlaceBase::Static(box Static { def_id, .. }) => { debug!("visiting static {:?} @ {:?}", def_id, location); let tcx = self.tcx; diff --git a/src/librustc_mir/transform/check_unsafety.rs b/src/librustc_mir/transform/check_unsafety.rs index 88fce075d7c..be9c2b741a2 100644 --- a/src/librustc_mir/transform/check_unsafety.rs +++ b/src/librustc_mir/transform/check_unsafety.rs @@ -194,8 +194,8 @@ fn visit_place(&mut self, place: &Place<'tcx>, context: PlaceContext, _location: PlaceBase::Local(..) => { // Locals are safe. } - PlaceBase::Static(box Static { kind: StaticKind::Static, .. }) => { - bug!("StaticKind::Static should not exist"); + PlaceBase::Static(box Static { .. }) => { + bug!("Static should not exist"); } } diff --git a/src/librustc_mir/transform/promote_consts.rs b/src/librustc_mir/transform/promote_consts.rs index 1052d037326..76f1e2d186e 100644 --- a/src/librustc_mir/transform/promote_consts.rs +++ b/src/librustc_mir/transform/promote_consts.rs @@ -39,7 +39,7 @@ /// errors when promotion of `#[rustc_args_required_const]` arguments fails. /// /// After this pass is run, `promoted_fragments` will hold the MIR body corresponding to each -/// newly created `StaticKind::Promoted`. +/// newly created `Constant`. #[derive(Default)] pub struct PromoteTemps<'tcx> { pub promoted_fragments: Cell>>,