diff options
| author | Ralf Jung <post@ralfj.de> | 2019-06-30 15:06:13 +0200 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2019-07-04 10:38:54 +0200 |
| commit | 5612feb5133d24caaf68f18e9ae8812ecbaa0ba3 (patch) | |
| tree | 5b1bc76b043a0772b92ac153fc57a85e9d522bdf | |
| parent | 1297a274a37f6e7c48ad8cc8a402c28d83cb98b5 (diff) | |
add machine hook to handle calls to 'extra' function values
| -rw-r--r-- | src/librustc_mir/const_eval.rs | 10 | ||||
| -rw-r--r-- | src/librustc_mir/interpret/machine.rs | 10 | ||||
| -rw-r--r-- | src/librustc_mir/interpret/terminator.rs | 7 |
3 files changed, 26 insertions, 1 deletions
diff --git a/src/librustc_mir/const_eval.rs b/src/librustc_mir/const_eval.rs index a5c52324c89..74df2898db4 100644 --- a/src/librustc_mir/const_eval.rs +++ b/src/librustc_mir/const_eval.rs @@ -371,6 +371,16 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir, })) } + fn call_extra_fn( + _ecx: &mut InterpretCx<'mir, 'tcx, Self>, + fn_val: !, + _args: &[OpTy<'tcx>], + _dest: Option<PlaceTy<'tcx>>, + _ret: Option<mir::BasicBlock>, + ) -> InterpResult<'tcx> { + match fn_val {} + } + fn call_intrinsic( ecx: &mut InterpCx<'mir, 'tcx, Self>, instance: ty::Instance<'tcx>, diff --git a/src/librustc_mir/interpret/machine.rs b/src/librustc_mir/interpret/machine.rs index 02ba0050844..b35d468c49a 100644 --- a/src/librustc_mir/interpret/machine.rs +++ b/src/librustc_mir/interpret/machine.rs @@ -124,6 +124,16 @@ pub trait Machine<'mir, 'tcx>: Sized { ret: Option<mir::BasicBlock>, ) -> InterpResult<'tcx, Option<&'mir mir::Body<'tcx>>>; + /// Execute `fn_val`. it is the hook's responsibility to advance the instruction + /// pointer as appropriate. + fn call_extra_fn( + ecx: &mut InterpretCx<'mir, 'tcx, Self>, + fn_val: Self::ExtraFnVal, + args: &[OpTy<'tcx, Self::PointerTag>], + dest: Option<PlaceTy<'tcx, Self::PointerTag>>, + ret: Option<mir::BasicBlock>, + ) -> InterpResult<'tcx>; + /// Directly process an intrinsic without pushing a stack frame. /// If this returns successfully, the engine will take care of jumping to the next block. fn call_intrinsic( diff --git a/src/librustc_mir/interpret/terminator.rs b/src/librustc_mir/interpret/terminator.rs index 4440d677a41..7978e8c36c7 100644 --- a/src/librustc_mir/interpret/terminator.rs +++ b/src/librustc_mir/interpret/terminator.rs @@ -237,7 +237,12 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { ) -> InterpResult<'tcx> { trace!("eval_fn_call: {:#?}", fn_val); - let instance = fn_val.as_instance()?; + let instance = match fn_val { + FnVal::Instance(instance) => instance, + FnVal::Other(extra) => { + return M::call_extra_fn(self, extra, args, dest, ret); + } + }; match instance.def { ty::InstanceDef::Intrinsic(..) => { |
