store the normalized types of statics in MIR Lvalues
The types of statics, like all other items, are stored in the tcx
unnormalized. This is necessarily so, because
a) Item types other than statics have generics, which can't be
normalized.
b) Eager normalization causes undesirable on-demand dependencies.
Keeping with the principle that MIR lvalues require no normalization in
order to interpret, this patch stores the normalized type of the statics
in the Lvalue and reads it to get the lvalue type.
Fixes #39367.
This commit is contained in:
parent
ca8708273b
commit
34ff9aa83f
8 changed files with 100 additions and 16 deletions
|
|
@ -816,12 +816,20 @@ pub enum Lvalue<'tcx> {
|
|||
Local(Local),
|
||||
|
||||
/// static or static mut variable
|
||||
Static(DefId),
|
||||
Static(Box<Static<'tcx>>),
|
||||
|
||||
/// projection out of an lvalue (access a field, deref a pointer, etc)
|
||||
Projection(Box<LvalueProjection<'tcx>>),
|
||||
}
|
||||
|
||||
/// The def-id of a static, along with its normalized type (which is
|
||||
/// stored to avoid requiring normalization when reading MIR).
|
||||
#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable)]
|
||||
pub struct Static<'tcx> {
|
||||
pub def_id: DefId,
|
||||
pub ty: Ty<'tcx>,
|
||||
}
|
||||
|
||||
/// The `Projection` data structure defines things of the form `B.x`
|
||||
/// or `*B` or `B[index]`. Note that it is parameterized because it is
|
||||
/// shared between `Constant` and `Lvalue`. See the aliases
|
||||
|
|
@ -911,8 +919,8 @@ impl<'tcx> Debug for Lvalue<'tcx> {
|
|||
|
||||
match *self {
|
||||
Local(id) => write!(fmt, "{:?}", id),
|
||||
Static(def_id) =>
|
||||
write!(fmt, "{}", ty::tls::with(|tcx| tcx.item_path_str(def_id))),
|
||||
Static(box self::Static { def_id, ty }) =>
|
||||
write!(fmt, "({}: {:?})", ty::tls::with(|tcx| tcx.item_path_str(def_id)), ty),
|
||||
Projection(ref data) =>
|
||||
match data.elem {
|
||||
ProjectionElem::Downcast(ref adt_def, index) =>
|
||||
|
|
|
|||
|
|
@ -125,8 +125,8 @@ impl<'tcx> Lvalue<'tcx> {
|
|||
match *self {
|
||||
Lvalue::Local(index) =>
|
||||
LvalueTy::Ty { ty: mir.local_decls[index].ty },
|
||||
Lvalue::Static(def_id) =>
|
||||
LvalueTy::Ty { ty: tcx.item_type(def_id) },
|
||||
Lvalue::Static(ref data) =>
|
||||
LvalueTy::Ty { ty: data.ty },
|
||||
Lvalue::Projection(ref proj) =>
|
||||
proj.base.ty(mir, tcx).projection_ty(tcx, &proj.elem),
|
||||
}
|
||||
|
|
|
|||
|
|
@ -154,6 +154,13 @@ macro_rules! make_mir_visitor {
|
|||
self.super_lvalue(lvalue, context, location);
|
||||
}
|
||||
|
||||
fn visit_static(&mut self,
|
||||
static_: & $($mutability)* Static<'tcx>,
|
||||
context: LvalueContext<'tcx>,
|
||||
location: Location) {
|
||||
self.super_static(static_, context, location);
|
||||
}
|
||||
|
||||
fn visit_projection(&mut self,
|
||||
lvalue: & $($mutability)* LvalueProjection<'tcx>,
|
||||
context: LvalueContext<'tcx>,
|
||||
|
|
@ -559,8 +566,8 @@ macro_rules! make_mir_visitor {
|
|||
match *lvalue {
|
||||
Lvalue::Local(_) => {
|
||||
}
|
||||
Lvalue::Static(ref $($mutability)* def_id) => {
|
||||
self.visit_def_id(def_id, location);
|
||||
Lvalue::Static(ref $($mutability)* static_) => {
|
||||
self.visit_static(static_, context, location);
|
||||
}
|
||||
Lvalue::Projection(ref $($mutability)* proj) => {
|
||||
self.visit_projection(proj, context, location);
|
||||
|
|
@ -568,6 +575,18 @@ macro_rules! make_mir_visitor {
|
|||
}
|
||||
}
|
||||
|
||||
fn super_static(&mut self,
|
||||
static_: & $($mutability)* Static<'tcx>,
|
||||
_context: LvalueContext<'tcx>,
|
||||
location: Location) {
|
||||
let Static {
|
||||
ref $($mutability)* def_id,
|
||||
ref $($mutability)* ty,
|
||||
} = *static_;
|
||||
self.visit_def_id(def_id, location);
|
||||
self.visit_ty(ty);
|
||||
}
|
||||
|
||||
fn super_projection(&mut self,
|
||||
proj: & $($mutability)* LvalueProjection<'tcx>,
|
||||
context: LvalueContext<'tcx>,
|
||||
|
|
@ -837,4 +856,3 @@ impl<'tcx> LvalueContext<'tcx> {
|
|||
self.is_mutating_use() || self.is_nonmutating_use()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue