Remove StaticKind

This commit is contained in:
Santiago Pastorino 2019-12-11 01:53:46 -03:00 committed by Oliver Scherer
parent 6f2c7025b8
commit b63597dedb
12 changed files with 53 additions and 115 deletions

View File

@ -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<V, T> {
@ -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 @@ impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<PlaceElem<'tcx>> {
impl<'tcx> TypeFoldable<'tcx> for Static<'tcx> {
fn super_fold_with<F: TypeFolder<'tcx>>(&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<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
let Static { ty, kind, def_id: _ } = self;
let Static { ty, def_id: _ } = self;
ty.visit_with(visitor) || kind.visit_with(visitor)
}
}
impl<'tcx> TypeFoldable<'tcx> for StaticKind {
fn super_fold_with<F: TypeFolder<'tcx>>(&self, _folder: &mut F) -> Self {
match self {
StaticKind::Static => StaticKind::Static,
}
}
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, _visitor: &mut V) -> bool {
match self {
StaticKind::Static => false,
}
ty.visit_with(visitor)
}
}

View File

@ -712,7 +712,7 @@ macro_rules! make_mir_visitor {
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));
}
}

View File

@ -438,12 +438,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
}
}
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

View File

@ -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 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
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] }

View File

@ -5,7 +5,7 @@ use rustc::lint::builtin::MUTABLE_BORROW_RESERVATION_CONFLICT;
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 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
}),
}
}
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 {

View File

@ -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(_))

View File

@ -467,7 +467,7 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
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 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
);
};
};
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)
}
};

View File

@ -212,7 +212,7 @@ pub trait Machine<'mir, 'tcx>: Sized {
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,

View File

@ -625,33 +625,27 @@ where
&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

View File

@ -182,7 +182,7 @@ use rustc::mir::interpret::{AllocId, ConstValue};
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 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
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;

View File

@ -194,8 +194,8 @@ impl<'a, 'tcx> Visitor<'tcx> for UnsafetyChecker<'a, 'tcx> {
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");
}
}

View File

@ -39,7 +39,7 @@ use crate::transform::{MirPass, MirSource};
/// 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<IndexVec<Promoted, BodyAndCache<'tcx>>>,