From 172662dede507cc678747cc3d090f2ae744733cf Mon Sep 17 00:00:00 2001 From: Bryan Garza <1396101+bryangarza@users.noreply.github.com> Date: Fri, 30 Dec 2022 00:34:17 +0000 Subject: [PATCH] Add back Machine::before_terminator(...) method Added it back because it's used by Miri, but in the compiler itself, it will not do anything (just return `Ok(())`. --- compiler/rustc_const_eval/src/const_eval/machine.rs | 5 +++++ compiler/rustc_const_eval/src/interpret/machine.rs | 6 ++++++ compiler/rustc_const_eval/src/interpret/step.rs | 2 ++ 3 files changed, 13 insertions(+) diff --git a/compiler/rustc_const_eval/src/const_eval/machine.rs b/compiler/rustc_const_eval/src/const_eval/machine.rs index a5bc121485d..e51f52783d4 100644 --- a/compiler/rustc_const_eval/src/const_eval/machine.rs +++ b/compiler/rustc_const_eval/src/const_eval/machine.rs @@ -561,6 +561,11 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir, throw_unsup_format!("pointer arithmetic or comparison is not supported at compile-time"); } + // Not used here, but used by Miri (see `src/tools/miri/src/machine.rs`). + fn before_terminator(_ecx: &mut InterpCx<'mir, 'tcx, Self>) -> InterpResult<'tcx> { + Ok(()) + } + fn increment_const_eval_counter(ecx: &mut InterpCx<'mir, 'tcx, Self>) -> InterpResult<'tcx> { // The step limit has already been hit in a previous call to `increment_const_eval_counter`. if ecx.machine.steps_remaining == 0 { diff --git a/compiler/rustc_const_eval/src/interpret/machine.rs b/compiler/rustc_const_eval/src/interpret/machine.rs index 1f63a4ac537..76ed7b80f8d 100644 --- a/compiler/rustc_const_eval/src/interpret/machine.rs +++ b/compiler/rustc_const_eval/src/interpret/machine.rs @@ -243,6 +243,12 @@ pub trait Machine<'mir, 'tcx>: Sized { ecx.stack_mut()[frame].locals[local].access_mut() } + /// Called before a basic block terminator is executed. + #[inline] + fn before_terminator(_ecx: &mut InterpCx<'mir, 'tcx, Self>) -> InterpResult<'tcx> { + Ok(()) + } + /// Called when the interpreter encounters a `StatementKind::ConstEvalCounter` instruction. /// You can use this to detect long or endlessly running programs. #[inline] diff --git a/compiler/rustc_const_eval/src/interpret/step.rs b/compiler/rustc_const_eval/src/interpret/step.rs index 7668e890c7b..d101937fd74 100644 --- a/compiler/rustc_const_eval/src/interpret/step.rs +++ b/compiler/rustc_const_eval/src/interpret/step.rs @@ -62,6 +62,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { return Ok(true); } + M::before_terminator(self)?; + let terminator = basic_block.terminator(); self.terminator(terminator)?; Ok(true)