Skip to content

Commit 97bd821

Browse files
committed
x
1 parent 0ffd745 commit 97bd821

File tree

5 files changed

+9
-15
lines changed

5 files changed

+9
-15
lines changed

Lib/test/test_peepholer.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,7 @@ def f(cond, true_value, false_value):
545545
self.assertEqual(len(returns), 2)
546546
self.check_lnotab(f)
547547

548+
@unittest.expectedFailure # TODO: RUSTPYTHON; absolute jump encoding
548549
def test_elim_jump_to_uncond_jump(self):
549550
# POP_JUMP_IF_FALSE to JUMP_FORWARD --> POP_JUMP_IF_FALSE to non-jump
550551
def f():
@@ -639,12 +640,14 @@ def g()->1+1:
639640
self.assertNotInBytecode(f, 'BINARY_OP')
640641
self.check_lnotab(f)
641642

643+
@unittest.expectedFailure # TODO: RUSTPYTHON; no BUILD_LIST to BUILD_TUPLE optimization
642644
def test_in_literal_list(self):
643645
def containtest():
644646
return x in [a, b]
645647
self.assertEqual(count_instr_recursively(containtest, 'BUILD_LIST'), 0)
646648
self.check_lnotab(containtest)
647649

650+
@unittest.expectedFailure # TODO: RUSTPYTHON; no BUILD_LIST to BUILD_TUPLE optimization
648651
def test_iterate_literal_list(self):
649652
def forloop():
650653
for x in [a, b]:

crates/codegen/src/ir.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -703,10 +703,8 @@ impl CodeInfo {
703703
if matches!(ins.instr.real(), Some(Instruction::Nop)) {
704704
let line = ins.location.line;
705705
if prev_line == Some(line) {
706-
// Same line as previous instruction — safe to remove
707706
return false;
708707
}
709-
// This NOP introduces a new line — keep it
710708
}
711709
prev_line = Some(ins.location.line);
712710
true

crates/compiler-core/src/bytecode.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,8 +402,10 @@ impl CodeUnits {
402402
/// Replace the opcode at `index` in-place without changing the arg byte.
403403
///
404404
/// # Safety
405-
/// Caller must ensure `index` is in bounds and `new_op` has the same
406-
/// arg semantics as the original opcode.
405+
/// - `index` must be in bounds.
406+
/// - `new_op` must have the same arg semantics as the original opcode.
407+
/// - The caller must ensure exclusive access to the instruction buffer
408+
/// (no concurrent reads or writes to the same `CodeUnits`).
407409
pub unsafe fn replace_op(&self, index: usize, new_op: Instruction) {
408410
unsafe {
409411
let ptr = self.0.as_ptr() as *mut CodeUnit;

crates/compiler-core/src/bytecode/instruction.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ impl Instruction {
434434
/// Panics if called on an already-instrumented opcode.
435435
pub fn to_instrumented(self) -> Option<Self> {
436436
debug_assert!(
437-
self.to_base().is_none(),
437+
!self.is_instrumented(),
438438
"to_instrumented called on already-instrumented opcode {self:?}"
439439
);
440440
Some(match self {

crates/vm/src/frame.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2565,7 +2565,7 @@ impl ExecutingFrame<'_> {
25652565
}
25662566
}
25672567
}
2568-
Instruction::InstrumentedJumpForward => {
2568+
Instruction::InstrumentedJumpForward | Instruction::InstrumentedJumpBackward => {
25692569
let src_offset = (self.lasti() - 1) * 2;
25702570
let target = bytecode::Label::from(u32::from(arg));
25712571
self.jump(target);
@@ -2574,15 +2574,6 @@ impl ExecutingFrame<'_> {
25742574
}
25752575
Ok(None)
25762576
}
2577-
Instruction::InstrumentedJumpBackward => {
2578-
let src_offset = (self.lasti() - 1) * 2;
2579-
let dest = bytecode::Label::from(u32::from(arg));
2580-
self.jump(dest);
2581-
if self.monitoring_mask & monitoring::EVENT_JUMP != 0 {
2582-
monitoring::fire_jump(vm, self.code, src_offset, dest.0 * 2)?;
2583-
}
2584-
Ok(None)
2585-
}
25862577
Instruction::InstrumentedForIter => {
25872578
let src_offset = (self.lasti() - 1) * 2;
25882579
let target = bytecode::Label::from(u32::from(arg));

0 commit comments

Comments
 (0)