Skip to content
Prev Previous commit
Revert PopJumpIfFalse for comparisons
  • Loading branch information
ShaharNaveh committed Dec 26, 2025
commit 582d1e03c6a1a78962c73714bb2599e52d3b5908
4 changes: 4 additions & 0 deletions crates/codegen/src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4115,10 +4115,14 @@ impl Compiler {
self.compile_addcompare(op);

// if comparison result is false, we break with this value; if true, try the next one.
/*
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what was the blocker of this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's the only reason why both opcodes stayed:/

This change caused regression for

def test_no_wraparound_jump(self):
# See https://bugs.python.org/issue46724
def while_not_chained(a, b, c):
while not (a < b < c):
pass
for instr in dis.Bytecode(while_not_chained):
self.assertNotEqual(instr.opname, "EXTENDED_ARG")

Not because it found an EXTENDED_ARG, but because iterating over dis.Bytecode(...) gave an error

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if that's because our test_compile is an old one, replacing it will be also good.

emit!(self, Instruction::CopyItem { index: 1 });
// emit!(self, Instruction::ToBool); // TODO: Uncomment this
emit!(self, Instruction::PopJumpIfFalse { target: cleanup });
emit!(self, Instruction::PopTop);
*/

emit!(self, Instruction::JumpIfFalseOrPop { target: cleanup });
}

self.compile_expression(last_comparator)?;
Expand Down
Loading