Skip to content

Commit 6f2c702

Browse files
spastorinooli-obk
authored andcommitted
Remove StaticKind::Promoted
1 parent 6aa4b5a commit 6f2c702

File tree

10 files changed

+33
-197
lines changed

10 files changed

+33
-197
lines changed

src/librustc/mir/mod.rs

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1687,7 +1687,7 @@ pub enum PlaceBase<'tcx> {
16871687
)]
16881688
pub struct Static<'tcx> {
16891689
pub ty: Ty<'tcx>,
1690-
pub kind: StaticKind<'tcx>,
1690+
pub kind: StaticKind,
16911691
/// The `DefId` of the item this static was declared in. For promoted values, usually, this is
16921692
/// the same as the `DefId` of the `mir::Body` containing the `Place` this promoted appears in.
16931693
/// However, after inlining, that might no longer be the case as inlined `Place`s are copied
@@ -1707,11 +1707,7 @@ pub struct Static<'tcx> {
17071707
RustcEncodable,
17081708
RustcDecodable
17091709
)]
1710-
pub enum StaticKind<'tcx> {
1711-
/// Promoted references consist of an id (`Promoted`) and the substs necessary to monomorphize
1712-
/// it. Usually, these substs are just the identity substs for the item. However, the inliner
1713-
/// will adjust these substs when it inlines a function based on the substs at the callsite.
1714-
Promoted(Promoted, SubstsRef<'tcx>),
1710+
pub enum StaticKind {
17151711
Static,
17161712
}
17171713

@@ -1949,11 +1945,6 @@ impl Debug for PlaceBase<'_> {
19491945
PlaceBase::Static(box self::Static { ty, kind: StaticKind::Static, def_id }) => {
19501946
write!(fmt, "({}: {:?})", ty::tls::with(|tcx| tcx.def_path_str(def_id)), ty)
19511947
}
1952-
PlaceBase::Static(box self::Static {
1953-
ty,
1954-
kind: StaticKind::Promoted(promoted, _),
1955-
def_id: _,
1956-
}) => write!(fmt, "({:?}: {:?})", promoted, ty),
19571948
}
19581949
}
19591950
}
@@ -3069,21 +3060,15 @@ impl<'tcx> TypeFoldable<'tcx> for Static<'tcx> {
30693060
}
30703061
}
30713062

3072-
impl<'tcx> TypeFoldable<'tcx> for StaticKind<'tcx> {
3073-
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
3063+
impl<'tcx> TypeFoldable<'tcx> for StaticKind {
3064+
fn super_fold_with<F: TypeFolder<'tcx>>(&self, _folder: &mut F) -> Self {
30743065
match self {
3075-
StaticKind::Promoted(promoted, substs) => {
3076-
StaticKind::Promoted(promoted.fold_with(folder), substs.fold_with(folder))
3077-
}
30783066
StaticKind::Static => StaticKind::Static,
30793067
}
30803068
}
30813069

3082-
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
3070+
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, _visitor: &mut V) -> bool {
30833071
match self {
3084-
StaticKind::Promoted(promoted, substs) => {
3085-
promoted.visit_with(visitor) || substs.visit_with(visitor)
3086-
}
30873072
StaticKind::Static => false,
30883073
}
30893074
}

src/librustc_codegen_ssa/mir/block.rs

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ use crate::traits::*;
1010
use crate::MemFlags;
1111

1212
use rustc::middle::lang_items;
13+
use rustc::mir;
1314
use rustc::mir::interpret::PanicInfo;
14-
use rustc::mir::{self, PlaceBase, Static, StaticKind};
1515
use rustc::ty::layout::{self, FnAbiExt, HasTyCtxt, LayoutOf};
1616
use rustc::ty::{self, Instance, Ty, TypeFoldable};
1717
use rustc_index::vec::Idx;
@@ -613,35 +613,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
613613
// The shuffle array argument is usually not an explicit constant,
614614
// but specified directly in the code. This means it gets promoted
615615
// and we can then extract the value by evaluating the promoted.
616-
mir::Operand::Copy(place) | mir::Operand::Move(place) => {
617-
if let mir::PlaceRef {
618-
base:
619-
&PlaceBase::Static(box Static {
620-
kind: StaticKind::Promoted(promoted, substs),
621-
ty,
622-
def_id,
623-
}),
624-
projection: &[],
625-
} = place.as_ref()
626-
{
627-
let c = bx.tcx().const_eval_promoted(
628-
Instance::new(def_id, self.monomorphize(&substs)),
629-
promoted,
630-
);
631-
let (llval, ty) = self.simd_shuffle_indices(
632-
&bx,
633-
terminator.source_info.span,
634-
ty,
635-
c,
636-
);
637-
return OperandRef {
638-
val: Immediate(llval),
639-
layout: bx.layout_of(ty),
640-
};
641-
} else {
642-
span_bug!(span, "shuffle indices must be constant");
643-
}
644-
}
616+
mir::Operand::Copy(_place) | mir::Operand::Move(_place) => {}
645617

646618
mir::Operand::Constant(constant) => {
647619
let c = self.eval_mir_constant(constant);

src/librustc_codegen_ssa/mir/place.rs

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::MemFlags;
99
use rustc::mir;
1010
use rustc::mir::tcx::PlaceTy;
1111
use rustc::ty::layout::{self, Align, HasTyCtxt, LayoutOf, TyLayout, VariantIdx};
12-
use rustc::ty::{self, Instance, Ty};
12+
use rustc::ty::{self, Ty};
1313

1414
#[derive(Copy, Clone, Debug)]
1515
pub struct PlaceRef<'tcx, V> {
@@ -437,39 +437,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
437437
}
438438
}
439439
}
440-
mir::PlaceRef {
441-
base:
442-
mir::PlaceBase::Static(box mir::Static {
443-
ty,
444-
kind: mir::StaticKind::Promoted(promoted, substs),
445-
def_id,
446-
}),
447-
projection: [],
448-
} => {
449-
let instance = Instance::new(*def_id, self.monomorphize(substs));
450-
let layout = cx.layout_of(self.monomorphize(&ty));
451-
match bx.tcx().const_eval_promoted(instance, *promoted) {
452-
Ok(val) => match val.val {
453-
ty::ConstKind::Value(mir::interpret::ConstValue::ByRef {
454-
alloc,
455-
offset,
456-
}) => bx.cx().from_const_alloc(layout, alloc, offset),
457-
_ => bug!("promoteds should have an allocation: {:?}", val),
458-
},
459-
Err(_) => {
460-
// This is unreachable as long as runtime
461-
// and compile-time agree perfectly.
462-
// With floats that won't always be true,
463-
// so we generate a (safe) abort.
464-
bx.abort();
465-
// We still have to return a place but it doesn't matter,
466-
// this code is unreachable.
467-
let llval =
468-
bx.cx().const_undef(bx.cx().type_ptr_to(bx.cx().backend_type(layout)));
469-
PlaceRef::new_sized(llval, layout)
470-
}
471-
}
472-
}
473440
mir::PlaceRef {
474441
base:
475442
mir::PlaceBase::Static(box mir::Static {

src/librustc_mir/borrow_check/diagnostics/mod.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -172,12 +172,6 @@ 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::Promoted(..), .. }),
177-
projection: [],
178-
} => {
179-
buf.push_str("promoted");
180-
}
181175
PlaceRef {
182176
base: PlaceBase::Static(box Static { kind: StaticKind::Static, def_id, .. }),
183177
projection: [],

src/librustc_mir/borrow_check/mod.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2196,16 +2196,6 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
21962196
}),
21972197
}
21982198
}
2199-
// The rules for promotion are made by `qualify_consts`, there wouldn't even be a
2200-
// `Place::Promoted` if the promotion weren't 100% legal. So we just forward this
2201-
PlaceRef {
2202-
base: PlaceBase::Static(box Static { kind: StaticKind::Promoted(..), .. }),
2203-
projection: [],
2204-
} => Ok(RootPlace {
2205-
place_base: place.base,
2206-
place_projection: place.projection,
2207-
is_local_mutation_allowed,
2208-
}),
22092199
PlaceRef {
22102200
base: PlaceBase::Static(box Static { kind: StaticKind::Static, def_id, .. }),
22112201
projection: [],

src/librustc_mir/borrow_check/places_conflict.rs

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ fn place_components_conflict<'tcx>(
310310
// between `elem1` and `elem2`.
311311
fn place_base_conflict<'tcx>(
312312
tcx: TyCtxt<'tcx>,
313-
param_env: ty::ParamEnv<'tcx>,
313+
_param_env: ty::ParamEnv<'tcx>,
314314
elem1: &PlaceBase<'tcx>,
315315
elem2: &PlaceBase<'tcx>,
316316
) -> Overlap {
@@ -341,28 +341,6 @@ fn place_base_conflict<'tcx>(
341341
Overlap::EqualOrDisjoint
342342
}
343343
}
344-
(StaticKind::Promoted(promoted_1, _), StaticKind::Promoted(promoted_2, _)) => {
345-
if promoted_1 == promoted_2 {
346-
if let ty::Array(_, len) = s1.ty.kind {
347-
if let Some(0) = len.try_eval_usize(tcx, param_env) {
348-
// Ignore conflicts with promoted [T; 0].
349-
debug!("place_element_conflict: IGNORE-LEN-0-PROMOTED");
350-
return Overlap::Disjoint;
351-
}
352-
}
353-
// the same promoted - base case, equal
354-
debug!("place_element_conflict: DISJOINT-OR-EQ-PROMOTED");
355-
Overlap::EqualOrDisjoint
356-
} else {
357-
// different promoteds - base case, disjoint
358-
debug!("place_element_conflict: DISJOINT-PROMOTED");
359-
Overlap::Disjoint
360-
}
361-
}
362-
(_, _) => {
363-
debug!("place_element_conflict: DISJOINT-STATIC-PROMOTED");
364-
Overlap::Disjoint
365-
}
366344
}
367345
}
368346
(PlaceBase::Local(_), PlaceBase::Static(_))

src/librustc_mir/borrow_check/type_check/mod.rs

Lines changed: 20 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -488,15 +488,6 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
488488
};
489489
};
490490
match kind {
491-
StaticKind::Promoted(promoted, _) => {
492-
if !self.errors_reported {
493-
let promoted_body_cache = self.promoted[*promoted];
494-
self.sanitize_promoted(promoted_body_cache, location);
495-
496-
let promoted_ty = promoted_body_cache.return_ty();
497-
check_err(self, place, promoted_ty, san_ty);
498-
}
499-
}
500491
StaticKind::Static => {
501492
let ty = self.tcx().type_of(*def_id);
502493
let ty = self.cx.normalize(ty, location);
@@ -510,38 +501,28 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
510501

511502
if place.projection.is_empty() {
512503
if let PlaceContext::NonMutatingUse(NonMutatingUseContext::Copy) = context {
513-
let is_promoted = match place.as_ref() {
514-
PlaceRef {
515-
base: &PlaceBase::Static(box Static { kind: StaticKind::Promoted(..), .. }),
516-
projection: &[],
517-
} => true,
518-
_ => false,
504+
let tcx = self.tcx();
505+
let trait_ref = ty::TraitRef {
506+
def_id: tcx.lang_items().copy_trait().unwrap(),
507+
substs: tcx.mk_substs_trait(place_ty.ty, &[]),
519508
};
520509

521-
if !is_promoted {
522-
let tcx = self.tcx();
523-
let trait_ref = ty::TraitRef {
524-
def_id: tcx.lang_items().copy_trait().unwrap(),
525-
substs: tcx.mk_substs_trait(place_ty.ty, &[]),
526-
};
527-
528-
// To have a `Copy` operand, the type `T` of the
529-
// value must be `Copy`. Note that we prove that `T: Copy`,
530-
// rather than using the `is_copy_modulo_regions`
531-
// test. This is important because
532-
// `is_copy_modulo_regions` ignores the resulting region
533-
// obligations and assumes they pass. This can result in
534-
// bounds from `Copy` impls being unsoundly ignored (e.g.,
535-
// #29149). Note that we decide to use `Copy` before knowing
536-
// whether the bounds fully apply: in effect, the rule is
537-
// that if a value of some type could implement `Copy`, then
538-
// it must.
539-
self.cx.prove_trait_ref(
540-
trait_ref,
541-
location.to_locations(),
542-
ConstraintCategory::CopyBound,
543-
);
544-
}
510+
// To have a `Copy` operand, the type `T` of the
511+
// value must be `Copy`. Note that we prove that `T: Copy`,
512+
// rather than using the `is_copy_modulo_regions`
513+
// test. This is important because
514+
// `is_copy_modulo_regions` ignores the resulting region
515+
// obligations and assumes they pass. This can result in
516+
// bounds from `Copy` impls being unsoundly ignored (e.g.,
517+
// #29149). Note that we decide to use `Copy` before knowing
518+
// whether the bounds fully apply: in effect, the rule is
519+
// that if a value of some type could implement `Copy`, then
520+
// it must.
521+
self.cx.prove_trait_ref(
522+
trait_ref,
523+
location.to_locations(),
524+
ConstraintCategory::CopyBound,
525+
);
545526
}
546527
}
547528

src/librustc_mir/interpret/place.rs

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ use rustc::ty::{self, Ty};
1515
use rustc_macros::HashStable;
1616

1717
use super::{
18-
AllocId, AllocMap, Allocation, AllocationExtra, GlobalId, ImmTy, Immediate, InterpCx,
19-
InterpResult, LocalValue, Machine, MemoryKind, OpTy, Operand, Pointer, PointerArithmetic,
20-
RawConst, Scalar, ScalarMaybeUndef,
18+
AllocId, AllocMap, Allocation, AllocationExtra, ImmTy, Immediate, InterpCx, InterpResult,
19+
LocalValue, Machine, MemoryKind, OpTy, Operand, Pointer, PointerArithmetic, RawConst, Scalar,
20+
ScalarMaybeUndef,
2121
};
2222

2323
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, HashStable)]
@@ -628,19 +628,6 @@ where
628628
use rustc::mir::StaticKind;
629629

630630
Ok(match place_static.kind {
631-
StaticKind::Promoted(promoted, promoted_substs) => {
632-
let substs = self.subst_from_frame_and_normalize_erasing_regions(promoted_substs);
633-
let instance = ty::Instance::new(place_static.def_id, substs);
634-
635-
// Even after getting `substs` from the frame, this instance may still be
636-
// polymorphic because `ConstProp` will try to promote polymorphic MIR.
637-
if instance.needs_subst() {
638-
throw_inval!(TooGeneric);
639-
}
640-
641-
self.const_eval_raw(GlobalId { instance, promoted: Some(promoted) })?
642-
}
643-
644631
StaticKind::Static => {
645632
let ty = place_static.ty;
646633
assert!(!ty.needs_subst());

src/librustc_mir/monomorphize/collector.rs

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ use rustc::mir::{self, Location, PlaceBase, Static, StaticKind};
186186
use rustc::session::config::EntryFnType;
187187
use rustc::ty::adjustment::{CustomCoerceUnsized, PointerCast};
188188
use rustc::ty::print::obsolete::DefPathBasedNames;
189-
use rustc::ty::subst::{InternalSubsts, Subst, SubstsRef};
189+
use rustc::ty::subst::{InternalSubsts, SubstsRef};
190190
use rustc::ty::{self, GenericParamDefKind, Instance, Ty, TyCtxt, TypeFoldable};
191191
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
192192
use rustc_data_structures::sync::{par_iter, MTLock, MTRef, ParallelIterator};
@@ -656,21 +656,6 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
656656
self.output.push(MonoItem::Static(*def_id));
657657
}
658658
}
659-
PlaceBase::Static(box Static {
660-
kind: StaticKind::Promoted(promoted, substs),
661-
def_id,
662-
..
663-
}) => {
664-
let instance = Instance::new(*def_id, substs.subst(self.tcx, self.param_substs));
665-
match self.tcx.const_eval_promoted(instance, *promoted) {
666-
Ok(val) => collect_const(self.tcx, val, substs, self.output),
667-
Err(ErrorHandled::Reported) => {}
668-
Err(ErrorHandled::TooGeneric) => {
669-
let span = self.tcx.promoted_mir(*def_id)[*promoted].span;
670-
span_bug!(span, "collection encountered polymorphic constant")
671-
}
672-
}
673-
}
674659
PlaceBase::Local(_) => {
675660
// Locals have no relevance for collector.
676661
}

src/librustc_mir/transform/check_unsafety.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,6 @@ impl<'a, 'tcx> Visitor<'tcx> for UnsafetyChecker<'a, 'tcx> {
194194
PlaceBase::Local(..) => {
195195
// Locals are safe.
196196
}
197-
PlaceBase::Static(box Static { kind: StaticKind::Promoted(_, _), .. }) => {
198-
bug!("unsafety checking should happen before promotion");
199-
}
200197
PlaceBase::Static(box Static { kind: StaticKind::Static, .. }) => {
201198
bug!("StaticKind::Static should not exist");
202199
}

0 commit comments

Comments
 (0)