Skip to content

Commit dbdcb54

Browse files
committed
Remove StaticKind::Promoted
1 parent a42e3b6 commit dbdcb54

File tree

10 files changed

+30
-217
lines changed

10 files changed

+30
-217
lines changed

src/librustc/mir/mod.rs

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1687,7 +1687,7 @@ pub enum PlaceBase<'tcx> {
16871687
RustcEncodable, RustcDecodable, HashStable)]
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
@@ -1698,11 +1698,7 @@ pub struct Static<'tcx> {
16981698
#[derive(
16991699
Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, HashStable, RustcEncodable, RustcDecodable,
17001700
)]
1701-
pub enum StaticKind<'tcx> {
1702-
/// Promoted references consist of an id (`Promoted`) and the substs necessary to monomorphize
1703-
/// it. Usually, these substs are just the identity substs for the item. However, the inliner
1704-
/// will adjust these substs when it inlines a function based on the substs at the callsite.
1705-
Promoted(Promoted, SubstsRef<'tcx>),
1701+
pub enum StaticKind {
17061702
Static,
17071703
}
17081704

@@ -1958,11 +1954,6 @@ impl Debug for PlaceBase<'_> {
19581954
PlaceBase::Static(box self::Static { ty, kind: StaticKind::Static, def_id }) => {
19591955
write!(fmt, "({}: {:?})", ty::tls::with(|tcx| tcx.def_path_str(def_id)), ty)
19601956
}
1961-
PlaceBase::Static(box self::Static {
1962-
ty, kind: StaticKind::Promoted(promoted, _), def_id: _
1963-
}) => {
1964-
write!(fmt, "({:?}: {:?})", promoted, ty)
1965-
}
19661957
}
19671958
}
19681959
}
@@ -3083,19 +3074,15 @@ impl<'tcx> TypeFoldable<'tcx> for Static<'tcx> {
30833074
}
30843075
}
30853076

3086-
impl<'tcx> TypeFoldable<'tcx> for StaticKind<'tcx> {
3087-
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
3077+
impl<'tcx> TypeFoldable<'tcx> for StaticKind {
3078+
fn super_fold_with<F: TypeFolder<'tcx>>(&self, _folder: &mut F) -> Self {
30883079
match self {
3089-
StaticKind::Promoted(promoted, substs) =>
3090-
StaticKind::Promoted(promoted.fold_with(folder), substs.fold_with(folder)),
30913080
StaticKind::Static => StaticKind::Static
30923081
}
30933082
}
30943083

3095-
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
3084+
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, _visitor: &mut V) -> bool {
30963085
match self {
3097-
StaticKind::Promoted(promoted, substs) =>
3098-
promoted.visit_with(visitor) || substs.visit_with(visitor),
30993086
StaticKind::Static => { false }
31003087
}
31013088
}

src/librustc_codegen_ssa/mir/block.rs

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use rustc_index::vec::Idx;
22
use rustc::middle::lang_items;
33
use rustc::ty::{self, Ty, TypeFoldable, Instance};
44
use rustc::ty::layout::{self, LayoutOf, HasTyCtxt, FnAbiExt};
5-
use rustc::mir::{self, PlaceBase, Static, StaticKind};
5+
use rustc::mir;
66
use rustc::mir::interpret::PanicInfo;
77
use rustc_target::abi::call::{ArgAbi, FnAbi, PassMode};
88
use rustc_target::spec::abi::Abi;
@@ -627,36 +627,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
627627
// The shuffle array argument is usually not an explicit constant,
628628
// but specified directly in the code. This means it gets promoted
629629
// and we can then extract the value by evaluating the promoted.
630-
mir::Operand::Copy(place) | mir::Operand::Move(place) => {
631-
if let mir::PlaceRef {
632-
base:
633-
&PlaceBase::Static(box Static {
634-
kind: StaticKind::Promoted(promoted, _),
635-
ty,
636-
def_id: _,
637-
}),
638-
projection: &[],
639-
} = place.as_ref()
640-
{
641-
let param_env = ty::ParamEnv::reveal_all();
642-
let cid = mir::interpret::GlobalId {
643-
instance: self.instance,
644-
promoted: Some(promoted),
645-
};
646-
let c = bx.tcx().const_eval(param_env.and(cid));
647-
let (llval, ty) = self.simd_shuffle_indices(
648-
&bx,
649-
terminator.source_info.span,
650-
ty,
651-
c,
652-
);
653-
return OperandRef {
654-
val: Immediate(llval),
655-
layout: bx.layout_of(ty),
656-
};
657-
} else {
658-
span_bug!(span, "shuffle indices must be constant");
659-
}
630+
mir::Operand::Copy(_place) | mir::Operand::Move(_place) => {
660631
}
661632

662633
mir::Operand::Constant(constant) => {

src/librustc_codegen_ssa/mir/place.rs

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::common::IntPredicate;
66
use crate::glue;
77
use crate::traits::*;
88

9-
use rustc::ty::{self, Instance, Ty};
9+
use rustc::ty::{self, Ty};
1010
use rustc::ty::layout::{self, Align, TyLayout, LayoutOf, VariantIdx, HasTyCtxt};
1111
use rustc::mir;
1212
use rustc::mir::tcx::PlaceTy;
@@ -465,45 +465,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
465465
}
466466
}
467467
}
468-
mir::PlaceRef {
469-
base: mir::PlaceBase::Static(box mir::Static {
470-
ty,
471-
kind: mir::StaticKind::Promoted(promoted, substs),
472-
def_id,
473-
}),
474-
projection: [],
475-
} => {
476-
let param_env = ty::ParamEnv::reveal_all();
477-
let instance = Instance::new(*def_id, self.monomorphize(substs));
478-
let cid = mir::interpret::GlobalId {
479-
instance: instance,
480-
promoted: Some(*promoted),
481-
};
482-
let layout = cx.layout_of(self.monomorphize(&ty));
483-
match bx.tcx().const_eval(param_env.and(cid)) {
484-
Ok(val) => match val.val {
485-
ty::ConstKind::Value(mir::interpret::ConstValue::ByRef {
486-
alloc, offset
487-
}) => {
488-
bx.cx().from_const_alloc(layout, alloc, offset)
489-
}
490-
_ => bug!("promoteds should have an allocation: {:?}", val),
491-
},
492-
Err(_) => {
493-
// This is unreachable as long as runtime
494-
// and compile-time agree perfectly.
495-
// With floats that won't always be true,
496-
// so we generate a (safe) abort.
497-
bx.abort();
498-
// We still have to return a place but it doesn't matter,
499-
// this code is unreachable.
500-
let llval = bx.cx().const_undef(
501-
bx.cx().type_ptr_to(bx.cx().backend_type(layout))
502-
);
503-
PlaceRef::new_sized(llval, layout)
504-
}
505-
}
506-
}
507468
mir::PlaceRef {
508469
base: mir::PlaceBase::Static(box mir::Static {
509470
ty,

src/librustc_mir/borrow_check/diagnostics/mod.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -174,16 +174,6 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
174174
} => {
175175
self.append_local_to_string(*local, buf)?;
176176
}
177-
PlaceRef {
178-
base:
179-
PlaceBase::Static(box Static {
180-
kind: StaticKind::Promoted(..),
181-
..
182-
}),
183-
projection: [],
184-
} => {
185-
buf.push_str("promoted");
186-
}
187177
PlaceRef {
188178
base:
189179
PlaceBase::Static(box Static {

src/librustc_mir/borrow_check/mod.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2179,20 +2179,6 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
21792179
}),
21802180
}
21812181
}
2182-
// The rules for promotion are made by `qualify_consts`, there wouldn't even be a
2183-
// `Place::Promoted` if the promotion weren't 100% legal. So we just forward this
2184-
PlaceRef {
2185-
base: PlaceBase::Static(box Static {
2186-
kind: StaticKind::Promoted(..),
2187-
..
2188-
}),
2189-
projection: [],
2190-
} =>
2191-
Ok(RootPlace {
2192-
place_base: place.base,
2193-
place_projection: place.projection,
2194-
is_local_mutation_allowed,
2195-
}),
21962182
PlaceRef {
21972183
base: PlaceBase::Static(box Static {
21982184
kind: StaticKind::Static,

src/librustc_mir/borrow_check/places_conflict.rs

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

src/librustc_mir/borrow_check/type_check/mod.rs

Lines changed: 20 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -509,15 +509,6 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
509509
};
510510
};
511511
match kind {
512-
StaticKind::Promoted(promoted, _) => {
513-
if !self.errors_reported {
514-
let promoted_body_cache = self.promoted[*promoted];
515-
self.sanitize_promoted(promoted_body_cache, location);
516-
517-
let promoted_ty = promoted_body_cache.return_ty();
518-
check_err(self, place, promoted_ty, san_ty);
519-
}
520-
}
521512
StaticKind::Static => {
522513
let ty = self.tcx().type_of(*def_id);
523514
let ty = self.cx.normalize(ty, location);
@@ -531,41 +522,28 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
531522

532523
if place.projection.is_empty() {
533524
if let PlaceContext::NonMutatingUse(NonMutatingUseContext::Copy) = context {
534-
let is_promoted = match place.as_ref() {
535-
PlaceRef {
536-
base: &PlaceBase::Static(box Static {
537-
kind: StaticKind::Promoted(..),
538-
..
539-
}),
540-
projection: &[],
541-
} => true,
542-
_ => false,
525+
let tcx = self.tcx();
526+
let trait_ref = ty::TraitRef {
527+
def_id: tcx.lang_items().copy_trait().unwrap(),
528+
substs: tcx.mk_substs_trait(place_ty.ty, &[]),
543529
};
544530

545-
if !is_promoted {
546-
let tcx = self.tcx();
547-
let trait_ref = ty::TraitRef {
548-
def_id: tcx.lang_items().copy_trait().unwrap(),
549-
substs: tcx.mk_substs_trait(place_ty.ty, &[]),
550-
};
551-
552-
// To have a `Copy` operand, the type `T` of the
553-
// value must be `Copy`. Note that we prove that `T: Copy`,
554-
// rather than using the `is_copy_modulo_regions`
555-
// test. This is important because
556-
// `is_copy_modulo_regions` ignores the resulting region
557-
// obligations and assumes they pass. This can result in
558-
// bounds from `Copy` impls being unsoundly ignored (e.g.,
559-
// #29149). Note that we decide to use `Copy` before knowing
560-
// whether the bounds fully apply: in effect, the rule is
561-
// that if a value of some type could implement `Copy`, then
562-
// it must.
563-
self.cx.prove_trait_ref(
564-
trait_ref,
565-
location.to_locations(),
566-
ConstraintCategory::CopyBound,
567-
);
568-
}
531+
// To have a `Copy` operand, the type `T` of the
532+
// value must be `Copy`. Note that we prove that `T: Copy`,
533+
// rather than using the `is_copy_modulo_regions`
534+
// test. This is important because
535+
// `is_copy_modulo_regions` ignores the resulting region
536+
// obligations and assumes they pass. This can result in
537+
// bounds from `Copy` impls being unsoundly ignored (e.g.,
538+
// #29149). Note that we decide to use `Copy` before knowing
539+
// whether the bounds fully apply: in effect, the rule is
540+
// that if a value of some type could implement `Copy`, then
541+
// it must.
542+
self.cx.prove_trait_ref(
543+
trait_ref,
544+
location.to_locations(),
545+
ConstraintCategory::CopyBound,
546+
);
569547
}
570548
}
571549

src/librustc_mir/interpret/place.rs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -599,22 +599,6 @@ where
599599
use rustc::mir::StaticKind;
600600

601601
Ok(match place_static.kind {
602-
StaticKind::Promoted(promoted, promoted_substs) => {
603-
let substs = self.subst_from_frame_and_normalize_erasing_regions(promoted_substs);
604-
let instance = ty::Instance::new(place_static.def_id, substs);
605-
606-
// Even after getting `substs` from the frame, this instance may still be
607-
// polymorphic because `ConstProp` will try to promote polymorphic MIR.
608-
if instance.needs_subst() {
609-
throw_inval!(TooGeneric);
610-
}
611-
612-
self.const_eval_raw(GlobalId {
613-
instance,
614-
promoted: Some(promoted),
615-
})?
616-
}
617-
618602
StaticKind::Static => {
619603
let ty = place_static.ty;
620604
assert!(!ty.needs_subst());

src/librustc_mir/monomorphize/collector.rs

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ use rustc::hir::itemlikevisit::ItemLikeVisitor;
181181
use rustc::hir::def_id::{DefId, LOCAL_CRATE};
182182
use rustc::mir::interpret::{AllocId, ConstValue};
183183
use rustc::middle::lang_items::{ExchangeMallocFnLangItem, StartFnLangItem};
184-
use rustc::ty::subst::{InternalSubsts, Subst, SubstsRef};
184+
use rustc::ty::subst::{InternalSubsts, SubstsRef};
185185
use rustc::ty::{self, TypeFoldable, Ty, TyCtxt, GenericParamDefKind, Instance};
186186
use rustc::ty::print::obsolete::DefPathBasedNames;
187187
use rustc::ty::adjustment::{CustomCoerceUnsized, PointerCast};
@@ -676,25 +676,6 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
676676
self.output.push(MonoItem::Static(*def_id));
677677
}
678678
}
679-
PlaceBase::Static(box Static {
680-
kind: StaticKind::Promoted(promoted, substs),
681-
def_id,
682-
..
683-
}) => {
684-
let param_env = ty::ParamEnv::reveal_all();
685-
let cid = GlobalId {
686-
instance: Instance::new(*def_id, substs.subst(self.tcx, self.param_substs)),
687-
promoted: Some(*promoted),
688-
};
689-
match self.tcx.const_eval(param_env.and(cid)) {
690-
Ok(val) => collect_const(self.tcx, val, substs, self.output),
691-
Err(ErrorHandled::Reported) => {},
692-
Err(ErrorHandled::TooGeneric) => {
693-
let span = self.tcx.promoted_mir(*def_id)[*promoted].span;
694-
span_bug!(span, "collection encountered polymorphic constant")
695-
},
696-
}
697-
}
698679
PlaceBase::Local(_) => {
699680
// Locals have no relevance for collector.
700681
}

src/librustc_mir/transform/check_unsafety.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,6 @@ impl<'a, 'tcx> Visitor<'tcx> for UnsafetyChecker<'a, 'tcx> {
200200
PlaceBase::Local(..) => {
201201
// Locals are safe.
202202
}
203-
PlaceBase::Static(box Static { kind: StaticKind::Promoted(_, _), .. }) => {
204-
bug!("unsafety checking should happen before promotion");
205-
}
206203
PlaceBase::Static(box Static { kind: StaticKind::Static, .. }) => {
207204
bug!("StaticKind::Static should not exist");
208205
}

0 commit comments

Comments
 (0)