From 5900b32ceee5cbb7f7db11d9aed52a35ba3ec9be Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Mon, 25 Nov 2019 16:23:44 +0100 Subject: [PATCH] unify call_intrinsic handling of intruction pointer with other machine hooks --- src/librustc_mir/interpret/machine.rs | 8 ++++---- src/librustc_mir/interpret/terminator.rs | 20 +------------------- 2 files changed, 5 insertions(+), 23 deletions(-) diff --git a/src/librustc_mir/interpret/machine.rs b/src/librustc_mir/interpret/machine.rs index 0ddd0962ba54..82899d432573 100644 --- a/src/librustc_mir/interpret/machine.rs +++ b/src/librustc_mir/interpret/machine.rs @@ -141,7 +141,7 @@ pub trait Machine<'mir, 'tcx>: Sized { /// Returns either the mir to use for the call, or `None` if execution should /// just proceed (which usually means this hook did all the work that the /// called function should usually have done). In the latter case, it is - /// this hook's responsibility to call `goto_block(ret)` to advance the instruction pointer! + /// this hook's responsibility to advance the instruction pointer! /// (This is to support functions like `__rust_maybe_catch_panic` that neither find a MIR /// nor just jump to `ret`, but instead push their own stack frame.) /// Passing `dest`and `ret` in the same `Option` proved very annoying when only one of them @@ -155,7 +155,7 @@ pub trait Machine<'mir, 'tcx>: Sized { unwind: Option ) -> InterpResult<'tcx, Option<&'mir mir::Body<'tcx>>>; - /// Execute `fn_val`. it is the hook's responsibility to advance the instruction + /// Execute `fn_val`. It is the hook's responsibility to advance the instruction /// pointer as appropriate. fn call_extra_fn( ecx: &mut InterpCx<'mir, 'tcx, Self>, @@ -165,8 +165,8 @@ pub trait Machine<'mir, 'tcx>: Sized { ret: Option, ) -> 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. + /// Directly process an intrinsic without pushing a stack frame. It is the hook's + /// responsibility to advance the instruction pointer as appropriate. fn call_intrinsic( ecx: &mut InterpCx<'mir, 'tcx, Self>, span: Span, diff --git a/src/librustc_mir/interpret/terminator.rs b/src/librustc_mir/interpret/terminator.rs index f61fe7b5e38a..ad4613bf5b36 100644 --- a/src/librustc_mir/interpret/terminator.rs +++ b/src/librustc_mir/interpret/terminator.rs @@ -254,25 +254,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { match instance.def { ty::InstanceDef::Intrinsic(..) => { assert!(caller_abi == Abi::RustIntrinsic || caller_abi == Abi::PlatformIntrinsic); - - let old_stack = self.cur_frame(); - let old_bb = self.frame().block; - M::call_intrinsic(self, span, instance, args, dest, ret, unwind)?; - // No stack frame gets pushed, the main loop will just act as if the - // call completed. - if ret.is_some() { - self.return_to_block(ret)?; - } else { - // If this intrinsic call doesn't have a ret block, - // then the intrinsic implementation should have - // changed the stack frame (otherwise, we'll end - // up trying to execute this intrinsic call again) - debug_assert!(self.cur_frame() != old_stack || self.frame().block != old_bb); - } - if let Some(dest) = dest { - self.dump_place(*dest) - } - Ok(()) + return M::call_intrinsic(self, span, instance, args, dest, ret, unwind); } ty::InstanceDef::VtableShim(..) | ty::InstanceDef::ReifyShim(..) |