Skip to content

Commit 346a46e

Browse files
committed
Rollup merge of rust-lang#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 rust-lang/miri#364
2 parents 70ae917 + 5aa29c4 commit 346a46e

File tree

2 files changed

+18
-22
lines changed

2 files changed

+18
-22
lines changed

src/librustc_mir/interpret/const_eval.rs

+8
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,14 @@ impl<'mir, 'tcx> super::Machine<'mir, 'tcx> for CompileTimeEvaluator {
339339
ecx: &mut EvalContext<'a, 'mir, 'tcx, Self>,
340340
cid: GlobalId<'tcx>,
341341
) -> EvalResult<'tcx, AllocId> {
342+
let alloc = ecx
343+
.tcx
344+
.interpret_interner
345+
.get_cached(cid.instance.def_id());
346+
// Don't evaluate when already cached to prevent cycles
347+
if let Some(alloc) = alloc {
348+
return Ok(alloc)
349+
}
342350
// ensure the static is computed
343351
ecx.const_eval(cid)?;
344352
Ok(ecx

src/librustc_mir/interpret/place.rs

+10-22
Original file line numberDiff line numberDiff line change
@@ -197,29 +197,17 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
197197
},
198198

199199
Static(ref static_) => {
200-
let alloc = self
201-
.tcx
202-
.interpret_interner
203-
.get_cached(static_.def_id);
204200
let layout = self.layout_of(self.place_ty(mir_place))?;
205-
if let Some(alloc) = alloc {
206-
Place::Ptr {
207-
ptr: MemoryPointer::new(alloc, 0).into(),
208-
align: layout.align,
209-
extra: PlaceExtra::None,
210-
}
211-
} else {
212-
let instance = ty::Instance::mono(*self.tcx, static_.def_id);
213-
let cid = GlobalId {
214-
instance,
215-
promoted: None
216-
};
217-
let alloc = Machine::init_static(self, cid)?;
218-
Place::Ptr {
219-
ptr: MemoryPointer::new(alloc, 0).into(),
220-
align: layout.align,
221-
extra: PlaceExtra::None,
222-
}
201+
let instance = ty::Instance::mono(*self.tcx, static_.def_id);
202+
let cid = GlobalId {
203+
instance,
204+
promoted: None
205+
};
206+
let alloc = Machine::init_static(self, cid)?;
207+
Place::Ptr {
208+
ptr: MemoryPointer::new(alloc, 0).into(),
209+
align: layout.align,
210+
extra: PlaceExtra::None,
223211
}
224212
}
225213

0 commit comments

Comments
 (0)