Skip to content

Commit 4d62545

Browse files
committed
Move def_id out add substsref
1 parent f13faf5 commit 4d62545

File tree

19 files changed

+134
-96
lines changed

19 files changed

+134
-96
lines changed

src/librustc/mir/mod.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1732,20 +1732,22 @@ pub enum PlaceBase<'tcx> {
17321732
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable)]
17331733
pub struct Static<'tcx> {
17341734
pub ty: Ty<'tcx>,
1735-
pub kind: StaticKind,
1735+
pub kind: StaticKind<'tcx>,
1736+
pub def_id: DefId,
17361737
}
17371738

17381739
#[derive(
17391740
Clone, PartialEq, Eq, PartialOrd, Ord, Hash, HashStable, RustcEncodable, RustcDecodable,
17401741
)]
1741-
pub enum StaticKind {
1742-
Promoted(Promoted),
1743-
Static(DefId),
1742+
pub enum StaticKind<'tcx> {
1743+
Promoted(Promoted, SubstsRef<'tcx>),
1744+
Static,
17441745
}
17451746

17461747
impl_stable_hash_for!(struct Static<'tcx> {
17471748
ty,
1748-
kind
1749+
kind,
1750+
def_id
17491751
});
17501752

17511753
/// The `Projection` data structure defines things of the form `base.x`, `*b` or `b[index]`.
@@ -2106,10 +2108,12 @@ impl Debug for PlaceBase<'_> {
21062108
fn fmt(&self, fmt: &mut Formatter<'_>) -> fmt::Result {
21072109
match *self {
21082110
PlaceBase::Local(id) => write!(fmt, "{:?}", id),
2109-
PlaceBase::Static(box self::Static { ty, kind: StaticKind::Static(def_id) }) => {
2111+
PlaceBase::Static(box self::Static { ty, kind: StaticKind::Static, def_id }) => {
21102112
write!(fmt, "({}: {:?})", ty::tls::with(|tcx| tcx.def_path_str(def_id)), ty)
21112113
}
2112-
PlaceBase::Static(box self::Static { ty, kind: StaticKind::Promoted(promoted) }) => {
2114+
PlaceBase::Static(box self::Static {
2115+
ty, kind: StaticKind::Promoted(promoted, _), def_id: _
2116+
}) => {
21132117
write!(fmt, "({:?}: {:?})", promoted, ty)
21142118
}
21152119
}

src/librustc/mir/visit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,7 @@ macro_rules! make_mir_visitor {
708708
PlaceBase::Local(local) => {
709709
self.visit_local(local, context, location);
710710
}
711-
PlaceBase::Static(box Static { kind: _, ty }) => {
711+
PlaceBase::Static(box Static { kind: _, ty, def_id: _ }) => {
712712
self.visit_ty(& $($mutability)? *ty, TyContext::Location(location));
713713
}
714714
}

src/librustc_codegen_ssa/mir/block.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -609,17 +609,19 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
609609
mir::Operand::Copy(
610610
Place {
611611
base: PlaceBase::Static(box Static {
612-
kind: StaticKind::Promoted(promoted),
612+
kind: StaticKind::Promoted(promoted, _),
613613
ty,
614+
def_id: _,
614615
}),
615616
projection: None,
616617
}
617618
) |
618619
mir::Operand::Move(
619620
Place {
620621
base: PlaceBase::Static(box Static {
621-
kind: StaticKind::Promoted(promoted),
622+
kind: StaticKind::Promoted(promoted, _),
622623
ty,
624+
def_id: _,
623625
}),
624626
projection: None,
625627
}

src/librustc_codegen_ssa/mir/place.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
use rustc::ty::{self, Ty};
1+
use rustc::ty::{self, Instance, Ty};
2+
use rustc::ty::subst::Subst;
23
use rustc::ty::layout::{self, Align, TyLayout, LayoutOf, VariantIdx, HasTyCtxt};
34
use rustc::mir;
45
use rustc::mir::tcx::PlaceTy;
@@ -454,16 +455,25 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
454455
mir::PlaceRef {
455456
base: mir::PlaceBase::Static(box mir::Static {
456457
ty,
457-
kind: mir::StaticKind::Promoted(promoted),
458+
kind: mir::StaticKind::Promoted(promoted, substs),
459+
def_id,
458460
}),
459461
projection: None,
460462
} => {
463+
debug!("promoted={:?}, def_id={:?}, substs={:?}, self_substs={:?}", promoted, def_id, substs, self.instance.substs);
461464
let param_env = ty::ParamEnv::reveal_all();
465+
let instance = Instance::new(*def_id, substs.subst(bx.tcx(), self.instance.substs));
466+
debug!("instance: {:?}", instance);
462467
let cid = mir::interpret::GlobalId {
463-
instance: self.instance,
468+
instance: instance,
464469
promoted: Some(*promoted),
465470
};
466-
let layout = cx.layout_of(self.monomorphize(&ty));
471+
let mono_ty = tcx.subst_and_normalize_erasing_regions(
472+
instance.substs,
473+
param_env,
474+
ty,
475+
);
476+
let layout = cx.layout_of(mono_ty);
467477
match bx.tcx().const_eval(param_env.and(cid)) {
468478
Ok(val) => match val.val {
469479
mir::interpret::ConstValue::ByRef { alloc, offset } => {
@@ -487,7 +497,8 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
487497
mir::PlaceRef {
488498
base: mir::PlaceBase::Static(box mir::Static {
489499
ty,
490-
kind: mir::StaticKind::Static(def_id),
500+
kind: mir::StaticKind::Static,
501+
def_id,
491502
}),
492503
projection: None,
493504
} => {

src/librustc_mir/borrow_check/error_reporting.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
159159
PlaceRef {
160160
base:
161161
PlaceBase::Static(box Static {
162-
kind: StaticKind::Promoted(_),
162+
kind: StaticKind::Promoted(..),
163163
..
164164
}),
165165
projection: None,
@@ -169,7 +169,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
169169
PlaceRef {
170170
base:
171171
PlaceBase::Static(box Static {
172-
kind: StaticKind::Static(def_id),
172+
kind: StaticKind::Static,
173+
def_id,
173174
..
174175
}),
175176
projection: None,
@@ -440,7 +441,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
440441
pub fn is_place_thread_local(&self, place_ref: PlaceRef<'cx, 'tcx>) -> bool {
441442
if let PlaceRef {
442443
base: PlaceBase::Static(box Static {
443-
kind: StaticKind::Static(def_id),
444+
kind: StaticKind::Static,
445+
def_id,
444446
..
445447
}),
446448
projection: None,

src/librustc_mir/borrow_check/mod.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1467,13 +1467,13 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
14671467
assert!(root_place.projection.is_none());
14681468
let (might_be_alive, will_be_dropped) = match root_place.base {
14691469
PlaceBase::Static(box Static {
1470-
kind: StaticKind::Promoted(_),
1470+
kind: StaticKind::Promoted(..),
14711471
..
14721472
}) => {
14731473
(true, false)
14741474
}
14751475
PlaceBase::Static(box Static {
1476-
kind: StaticKind::Static(_),
1476+
kind: StaticKind::Static,
14771477
..
14781478
}) => {
14791479
// Thread-locals might be dropped after the function exits, but
@@ -2155,7 +2155,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
21552155
// `Place::Promoted` if the promotion weren't 100% legal. So we just forward this
21562156
PlaceRef {
21572157
base: PlaceBase::Static(box Static {
2158-
kind: StaticKind::Promoted(_),
2158+
kind: StaticKind::Promoted(..),
21592159
..
21602160
}),
21612161
projection: None,
@@ -2167,7 +2167,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
21672167
}),
21682168
PlaceRef {
21692169
base: PlaceBase::Static(box Static {
2170-
kind: StaticKind::Static(def_id),
2170+
kind: StaticKind::Static,
2171+
def_id,
21712172
..
21722173
}),
21732174
projection: None,

src/librustc_mir/borrow_check/mutability_errors.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
149149
PlaceRef {
150150
base:
151151
PlaceBase::Static(box Static {
152-
kind: StaticKind::Promoted(_),
152+
kind: StaticKind::Promoted(..),
153153
..
154154
}),
155155
projection: None,
@@ -158,7 +158,8 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
158158
PlaceRef {
159159
base:
160160
PlaceBase::Static(box Static {
161-
kind: StaticKind::Static(def_id),
161+
kind: StaticKind::Static,
162+
def_id,
162163
..
163164
}),
164165
projection: None,

src/librustc_mir/borrow_check/nll/type_check/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
421421
let mut place_ty = match place_base {
422422
PlaceBase::Local(index) =>
423423
PlaceTy::from_ty(self.body.local_decls[*index].ty),
424-
PlaceBase::Static(box Static { kind, ty: sty }) => {
424+
PlaceBase::Static(box Static { kind, ty: sty, def_id }) => {
425425
let sty = self.sanitize_type(place, sty);
426426
let check_err =
427427
|verifier: &mut TypeVerifier<'a, 'b, 'tcx>,
@@ -445,7 +445,7 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
445445
};
446446
};
447447
match kind {
448-
StaticKind::Promoted(promoted) => {
448+
StaticKind::Promoted(promoted, _) => {
449449
if !self.errors_reported {
450450
let promoted_body = &self.promoted[*promoted];
451451
self.sanitize_promoted(promoted_body, location);
@@ -454,7 +454,7 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
454454
check_err(self, place, promoted_ty, sty);
455455
}
456456
}
457-
StaticKind::Static(def_id) => {
457+
StaticKind::Static => {
458458
let ty = self.tcx().type_of(*def_id);
459459
let ty = self.cx.normalize(ty, location);
460460

@@ -471,7 +471,7 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
471471
let is_promoted = match place {
472472
Place {
473473
base: PlaceBase::Static(box Static {
474-
kind: StaticKind::Promoted(_),
474+
kind: StaticKind::Promoted(..),
475475
..
476476
}),
477477
projection: None,

src/librustc_mir/borrow_check/place_ext.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ impl<'tcx> PlaceExt<'tcx> for Place<'tcx> {
4646
}
4747
}
4848
}
49-
PlaceBase::Static(box Static{ kind: StaticKind::Promoted(_), .. }) =>
49+
PlaceBase::Static(box Static{ kind: StaticKind::Promoted(_, _), .. }) =>
5050
false,
51-
PlaceBase::Static(box Static{ kind: StaticKind::Static(def_id), .. }) => {
51+
PlaceBase::Static(box Static{ kind: StaticKind::Static, def_id, .. }) => {
5252
tcx.is_mutable_static(*def_id)
5353
}
5454
};

src/librustc_mir/borrow_check/places_conflict.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -329,11 +329,11 @@ fn place_base_conflict<'tcx>(
329329
}
330330
(PlaceBase::Static(s1), PlaceBase::Static(s2)) => {
331331
match (&s1.kind, &s2.kind) {
332-
(StaticKind::Static(def_id_1), StaticKind::Static(def_id_2)) => {
333-
if def_id_1 != def_id_2 {
332+
(StaticKind::Static, StaticKind::Static) => {
333+
if s1.def_id != s2.def_id {
334334
debug!("place_element_conflict: DISJOINT-STATIC");
335335
Overlap::Disjoint
336-
} else if tcx.is_mutable_static(*def_id_1) {
336+
} else if tcx.is_mutable_static(s1.def_id) {
337337
// We ignore mutable statics - they can only be unsafe code.
338338
debug!("place_element_conflict: IGNORE-STATIC-MUT");
339339
Overlap::Disjoint
@@ -342,7 +342,7 @@ fn place_base_conflict<'tcx>(
342342
Overlap::EqualOrDisjoint
343343
}
344344
},
345-
(StaticKind::Promoted(promoted_1), StaticKind::Promoted(promoted_2)) => {
345+
(StaticKind::Promoted(promoted_1, _), StaticKind::Promoted(promoted_2, _)) => {
346346
if promoted_1 == promoted_2 {
347347
if let ty::Array(_, len) = s1.ty.sty {
348348
if let Some(0) = len.try_eval_usize(tcx, param_env) {

0 commit comments

Comments
 (0)