Visitar URL original
Bytecode parity by youknowone · Pull Request #7481 · RustPython/RustPython · GitHub
Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Revert peephole_optimize to use remove() for chaining support
NOP replacement broke chaining of peephole optimizations (e.g.
LOAD_CONST+TO_BOOL then LOAD_CONST+UNARY_NOT for 'not True').
The remove() approach is used by upstream and works correctly here;
fold_unary_negative keeps NOP replacement since it doesn't need chaining.
  • Loading branch information
youknowone committed Mar 25, 2026
commit ce07e05795ed4bee1d87a53a0e3161ff177e373c
8 changes: 3 additions & 5 deletions crates/codegen/src/ir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1054,11 +1054,9 @@ impl CodeInfo {
// Combine: keep first instruction's location, replace with combined instruction
block.instructions[i].instr = new_instr.into();
block.instructions[i].arg = new_arg;
// Replace the second instruction with NOP
let loc = block.instructions[i].location;
block.instructions[i + 1].instr = Instruction::Nop.into();
block.instructions[i + 1].location = loc;
i += 2;
// Remove the second instruction
block.instructions.remove(i + 1);
// Don't increment i - check if we can combine again with the next instruction
} else {
i += 1;
}
Expand Down
Loading