Skip to content

Commit 7892e1c

Browse files
committed
Move statement_index increment out of statement() function
That function is called by const_prop, where updating the index like that is totally meaningless.
1 parent 9e00fb0 commit 7892e1c

File tree

1 file changed

+9
-9
lines changed
  • compiler/rustc_const_eval/src/interpret

1 file changed

+9
-9
lines changed

compiler/rustc_const_eval/src/interpret/step.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,33 +55,33 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
5555
};
5656
let basic_block = &self.body().basic_blocks()[loc.block];
5757

58-
let old_frames = self.frame_idx();
5958

6059
if let Some(stmt) = basic_block.statements.get(loc.statement_index) {
61-
assert_eq!(old_frames, self.frame_idx());
60+
let old_frames = self.frame_idx();
6261
self.statement(stmt)?;
62+
// Make sure we are not updating `statement_index` of the wrong frame.
63+
assert_eq!(old_frames, self.frame_idx());
64+
// Advance the program counter.
65+
self.frame_mut().loc.as_mut().unwrap().statement_index += 1;
6366
return Ok(true);
6467
}
6568

6669
M::before_terminator(self)?;
6770

6871
let terminator = basic_block.terminator();
69-
assert_eq!(old_frames, self.frame_idx());
7072
self.terminator(terminator)?;
7173
Ok(true)
7274
}
7375

7476
/// Runs the interpretation logic for the given `mir::Statement` at the current frame and
75-
/// statement counter. This also moves the statement counter forward.
77+
/// statement counter.
78+
///
79+
/// This does NOT move the statement counter forward, the caller has to do that!
7680
pub fn statement(&mut self, stmt: &mir::Statement<'tcx>) -> InterpResult<'tcx> {
7781
info!("{:?}", stmt);
7882

7983
use rustc_middle::mir::StatementKind::*;
8084

81-
// Some statements (e.g., box) push new stack frames.
82-
// We have to record the stack frame number *before* executing the statement.
83-
let frame_idx = self.frame_idx();
84-
8585
match &stmt.kind {
8686
Assign(box (place, rvalue)) => self.eval_rvalue_into_place(rvalue, *place)?,
8787

@@ -144,7 +144,6 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
144144
Nop => {}
145145
}
146146

147-
self.stack_mut()[frame_idx].loc.as_mut().unwrap().statement_index += 1;
148147
Ok(())
149148
}
150149

@@ -300,6 +299,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
300299
Ok(())
301300
}
302301

302+
/// Evaluate the given terminator. Will also adjust the stack frame and statement position accordingly.
303303
fn terminator(&mut self, terminator: &mir::Terminator<'tcx>) -> InterpResult<'tcx> {
304304
info!("{:?}", terminator.kind);
305305

0 commit comments

Comments
 (0)