Rollup merge of #49216 - bjorn3:patch-1, r=estebank
Don't check interpret_interner when accessing a static to fix miri mutable statics Mutable statics don't work in my PR to fix the standalone [miri](https://github.com/solson/miri), as init_static didn't get called when the interpret_interner already contained a entry for the static, which is always immutable. cc solson/miri#364
This commit is contained in:
commit
346a46e9d6
@ -339,6 +339,14 @@ impl<'mir, 'tcx> super::Machine<'mir, 'tcx> for CompileTimeEvaluator {
|
||||
ecx: &mut EvalContext<'a, 'mir, 'tcx, Self>,
|
||||
cid: GlobalId<'tcx>,
|
||||
) -> EvalResult<'tcx, AllocId> {
|
||||
let alloc = ecx
|
||||
.tcx
|
||||
.interpret_interner
|
||||
.get_cached(cid.instance.def_id());
|
||||
// Don't evaluate when already cached to prevent cycles
|
||||
if let Some(alloc) = alloc {
|
||||
return Ok(alloc)
|
||||
}
|
||||
// ensure the static is computed
|
||||
ecx.const_eval(cid)?;
|
||||
Ok(ecx
|
||||
|
@ -197,29 +197,17 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
|
||||
},
|
||||
|
||||
Static(ref static_) => {
|
||||
let alloc = self
|
||||
.tcx
|
||||
.interpret_interner
|
||||
.get_cached(static_.def_id);
|
||||
let layout = self.layout_of(self.place_ty(mir_place))?;
|
||||
if let Some(alloc) = alloc {
|
||||
Place::Ptr {
|
||||
ptr: MemoryPointer::new(alloc, 0).into(),
|
||||
align: layout.align,
|
||||
extra: PlaceExtra::None,
|
||||
}
|
||||
} else {
|
||||
let instance = ty::Instance::mono(*self.tcx, static_.def_id);
|
||||
let cid = GlobalId {
|
||||
instance,
|
||||
promoted: None
|
||||
};
|
||||
let alloc = Machine::init_static(self, cid)?;
|
||||
Place::Ptr {
|
||||
ptr: MemoryPointer::new(alloc, 0).into(),
|
||||
align: layout.align,
|
||||
extra: PlaceExtra::None,
|
||||
}
|
||||
let instance = ty::Instance::mono(*self.tcx, static_.def_id);
|
||||
let cid = GlobalId {
|
||||
instance,
|
||||
promoted: None
|
||||
};
|
||||
let alloc = Machine::init_static(self, cid)?;
|
||||
Place::Ptr {
|
||||
ptr: MemoryPointer::new(alloc, 0).into(),
|
||||
align: layout.align,
|
||||
extra: PlaceExtra::None,
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user