From e47553909650b4e4339e902eaa19c0fbdf3610ab Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Wed, 26 Jun 2019 13:13:19 -0500 Subject: [PATCH 1/2] Add MemoryExtra in InterpretCx constructor params --- src/librustc_mir/const_eval.rs | 8 ++++++-- src/librustc_mir/interpret/eval_context.rs | 9 +++++++-- src/librustc_mir/interpret/memory.rs | 4 ++-- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/librustc_mir/const_eval.rs b/src/librustc_mir/const_eval.rs index 887ef4b520ea3..96e45c2c8fe5b 100644 --- a/src/librustc_mir/const_eval.rs +++ b/src/librustc_mir/const_eval.rs @@ -47,7 +47,7 @@ pub(crate) fn mk_eval_cx<'mir, 'tcx>( param_env: ty::ParamEnv<'tcx>, ) -> CompileTimeEvalContext<'mir, 'tcx> { debug!("mk_eval_cx: {:?}", param_env); - InterpretCx::new(tcx.at(span), param_env, CompileTimeInterpreter::new()) + InterpretCx::new(tcx.at(span), param_env, CompileTimeInterpreter::new(), Default::default()) } pub(crate) fn eval_promoted<'mir, 'tcx>( @@ -632,7 +632,11 @@ pub fn const_eval_raw_provider<'tcx>( } let span = tcx.def_span(cid.instance.def_id()); - let mut ecx = InterpretCx::new(tcx.at(span), key.param_env, CompileTimeInterpreter::new()); + let mut ecx = InterpretCx::new( + tcx.at(span), + key.param_env, + CompileTimeInterpreter::new(), + Default::default()); let res = ecx.load_mir(cid.instance.def); res.map(|body| { diff --git a/src/librustc_mir/interpret/eval_context.rs b/src/librustc_mir/interpret/eval_context.rs index c6e762bddd4d9..4c4330ffb261d 100644 --- a/src/librustc_mir/interpret/eval_context.rs +++ b/src/librustc_mir/interpret/eval_context.rs @@ -196,12 +196,17 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> LayoutOf for InterpretCx<'mir, 'tcx, M> } impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpretCx<'mir, 'tcx, M> { - pub fn new(tcx: TyCtxtAt<'tcx>, param_env: ty::ParamEnv<'tcx>, machine: M) -> Self { + pub fn new( + tcx: TyCtxtAt<'tcx>, + param_env: ty::ParamEnv<'tcx>, + machine: M, + memory_extra: M::MemoryExtra, + ) -> Self { InterpretCx { machine, tcx, param_env, - memory: Memory::new(tcx), + memory: Memory::new(tcx, memory_extra), stack: Vec::new(), vtables: FxHashMap::default(), } diff --git a/src/librustc_mir/interpret/memory.rs b/src/librustc_mir/interpret/memory.rs index c3eec677a4850..c06fdccf6cac6 100644 --- a/src/librustc_mir/interpret/memory.rs +++ b/src/librustc_mir/interpret/memory.rs @@ -106,11 +106,11 @@ where } impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> { - pub fn new(tcx: TyCtxtAt<'tcx>) -> Self { + pub fn new(tcx: TyCtxtAt<'tcx>, extra: M::MemoryExtra) -> Self { Memory { alloc_map: M::MemoryMap::default(), dead_alloc_map: FxHashMap::default(), - extra: M::MemoryExtra::default(), + extra, tcx, } } From e32b8eb00a94274e680d1ae63c429d5b7db65e99 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Wed, 26 Jun 2019 13:56:33 -0500 Subject: [PATCH 2/2] Remove default bound for Machine::MemoryExtra --- src/librustc_mir/const_eval.rs | 3 ++- src/librustc_mir/interpret/machine.rs | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/librustc_mir/const_eval.rs b/src/librustc_mir/const_eval.rs index 96e45c2c8fe5b..4d5a2ccf659bb 100644 --- a/src/librustc_mir/const_eval.rs +++ b/src/librustc_mir/const_eval.rs @@ -636,7 +636,8 @@ pub fn const_eval_raw_provider<'tcx>( tcx.at(span), key.param_env, CompileTimeInterpreter::new(), - Default::default()); + Default::default() + ); let res = ecx.load_mir(cid.instance.def); res.map(|body| { diff --git a/src/librustc_mir/interpret/machine.rs b/src/librustc_mir/interpret/machine.rs index 4eb95f20d9354..a3956e12300f1 100644 --- a/src/librustc_mir/interpret/machine.rs +++ b/src/librustc_mir/interpret/machine.rs @@ -73,7 +73,7 @@ pub trait Machine<'mir, 'tcx>: Sized { /// Extra data stored in memory. A reference to this is available when `AllocExtra` /// gets initialized, so you can e.g., have an `Rc` here if there is global state you /// need access to in the `AllocExtra` hooks. - type MemoryExtra: Default; + type MemoryExtra; /// Extra data stored in every allocation. type AllocExtra: AllocationExtra + 'static;