Skip to content

Commit 4509e89

Browse files
authored
Rollup merge of rust-lang#62158 - christianpoveda:ecx-memory-extra, r=RalfJung
Add MemoryExtra in InterpretCx constructor params This is to avoid modifying `MemoryExtra` inside `InterpretCx` after initialization. Related miri PR: rust-lang/miri#792 r? @RalfJung
2 parents 892c653 + e45bbaf commit 4509e89

File tree

4 files changed

+17
-7
lines changed

4 files changed

+17
-7
lines changed

src/librustc_mir/const_eval.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ pub(crate) fn mk_eval_cx<'mir, 'tcx>(
4747
param_env: ty::ParamEnv<'tcx>,
4848
) -> CompileTimeEvalContext<'mir, 'tcx> {
4949
debug!("mk_eval_cx: {:?}", param_env);
50-
InterpCx::new(tcx.at(span), param_env, CompileTimeInterpreter::new())
50+
InterpCx::new(tcx.at(span), param_env, CompileTimeInterpreter::new(), Default::default())
5151
}
5252

5353
pub(crate) fn eval_promoted<'mir, 'tcx>(
@@ -632,7 +632,12 @@ pub fn const_eval_raw_provider<'tcx>(
632632
}
633633

634634
let span = tcx.def_span(cid.instance.def_id());
635-
let mut ecx = InterpCx::new(tcx.at(span), key.param_env, CompileTimeInterpreter::new());
635+
let mut ecx = InterpCx::new(
636+
tcx.at(span),
637+
key.param_env,
638+
CompileTimeInterpreter::new(),
639+
Default::default()
640+
);
636641

637642
let res = ecx.load_mir(cid.instance.def);
638643
res.map(|body| {

src/librustc_mir/interpret/eval_context.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -196,12 +196,17 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> LayoutOf for InterpCx<'mir, 'tcx, M> {
196196
}
197197

198198
impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
199-
pub fn new(tcx: TyCtxtAt<'tcx>, param_env: ty::ParamEnv<'tcx>, machine: M) -> Self {
199+
pub fn new(
200+
tcx: TyCtxtAt<'tcx>,
201+
param_env: ty::ParamEnv<'tcx>,
202+
machine: M,
203+
memory_extra: M::MemoryExtra,
204+
) -> Self {
200205
InterpCx {
201206
machine,
202207
tcx,
203208
param_env,
204-
memory: Memory::new(tcx),
209+
memory: Memory::new(tcx, memory_extra),
205210
stack: Vec::new(),
206211
vtables: FxHashMap::default(),
207212
}

src/librustc_mir/interpret/machine.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ pub trait Machine<'mir, 'tcx>: Sized {
7373
/// Extra data stored in memory. A reference to this is available when `AllocExtra`
7474
/// gets initialized, so you can e.g., have an `Rc` here if there is global state you
7575
/// need access to in the `AllocExtra` hooks.
76-
type MemoryExtra: Default;
76+
type MemoryExtra;
7777

7878
/// Extra data stored in every allocation.
7979
type AllocExtra: AllocationExtra<Self::PointerTag> + 'static;

src/librustc_mir/interpret/memory.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,11 @@ where
106106
}
107107

108108
impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
109-
pub fn new(tcx: TyCtxtAt<'tcx>) -> Self {
109+
pub fn new(tcx: TyCtxtAt<'tcx>, extra: M::MemoryExtra) -> Self {
110110
Memory {
111111
alloc_map: M::MemoryMap::default(),
112112
dead_alloc_map: FxHashMap::default(),
113-
extra: M::MemoryExtra::default(),
113+
extra,
114114
tcx,
115115
}
116116
}

0 commit comments

Comments
 (0)