diff options
| author | Ralf Jung <post@ralfj.de> | 2022-06-04 15:28:14 -0400 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2022-06-04 15:59:24 -0400 |
| commit | 7892e1cedb0b1fe8d924516425481654b89ba834 (patch) | |
| tree | 5c9419adb3acea9a67d8efc9112397696ad7c6bf /compiler/rustc_const_eval/src/interpret | |
| parent | 9e00fb0d8911dfdf9cb9583adcc05d55bef4d34f (diff) | |
| download | rust-7892e1cedb0b1fe8d924516425481654b89ba834.tar.gz rust-7892e1cedb0b1fe8d924516425481654b89ba834.zip | |
Move statement_index increment out of statement() function
That function is called by const_prop, where updating the index like that is totally meaningless.
Diffstat (limited to 'compiler/rustc_const_eval/src/interpret')
| -rw-r--r-- | compiler/rustc_const_eval/src/interpret/step.rs | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/compiler/rustc_const_eval/src/interpret/step.rs b/compiler/rustc_const_eval/src/interpret/step.rs index 9ac86911c7d..c511581371b 100644 --- a/compiler/rustc_const_eval/src/interpret/step.rs +++ b/compiler/rustc_const_eval/src/interpret/step.rs @@ -55,33 +55,33 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { }; let basic_block = &self.body().basic_blocks()[loc.block]; - let old_frames = self.frame_idx(); if let Some(stmt) = basic_block.statements.get(loc.statement_index) { - assert_eq!(old_frames, self.frame_idx()); + let old_frames = self.frame_idx(); self.statement(stmt)?; + // Make sure we are not updating `statement_index` of the wrong frame. + assert_eq!(old_frames, self.frame_idx()); + // Advance the program counter. + self.frame_mut().loc.as_mut().unwrap().statement_index += 1; return Ok(true); } M::before_terminator(self)?; let terminator = basic_block.terminator(); - assert_eq!(old_frames, self.frame_idx()); self.terminator(terminator)?; Ok(true) } /// Runs the interpretation logic for the given `mir::Statement` at the current frame and - /// statement counter. This also moves the statement counter forward. + /// statement counter. + /// + /// This does NOT move the statement counter forward, the caller has to do that! pub fn statement(&mut self, stmt: &mir::Statement<'tcx>) -> InterpResult<'tcx> { info!("{:?}", stmt); use rustc_middle::mir::StatementKind::*; - // Some statements (e.g., box) push new stack frames. - // We have to record the stack frame number *before* executing the statement. - let frame_idx = self.frame_idx(); - match &stmt.kind { Assign(box (place, rvalue)) => self.eval_rvalue_into_place(rvalue, *place)?, @@ -144,7 +144,6 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { Nop => {} } - self.stack_mut()[frame_idx].loc.as_mut().unwrap().statement_index += 1; Ok(()) } @@ -300,6 +299,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { Ok(()) } + /// Evaluate the given terminator. Will also adjust the stack frame and statement position accordingly. fn terminator(&mut self, terminator: &mir::Terminator<'tcx>) -> InterpResult<'tcx> { info!("{:?}", terminator.kind); |
