◐ Shell
clean mode source ↗

Remove ReturnConst/Break/Continue ops by youknowone · Pull Request #6816 · RustPython/RustPython

📝 Walkthrough

Walkthrough

This PR removes three specialized bytecode instruction variants (Break, Continue, and ReturnConst) from the instruction set and consolidates their functionality into generic alternatives (Jump for break/continue control flow, ReturnValue for constant returns), simplifying the bytecode instruction architecture.

Changes

Cohort / File(s) Summary
Instruction Definition
crates/compiler-core/src/bytecode/instruction.rs
Removes Break, Continue, and ReturnConst enum variants and all associated metadata handling (label arguments, unconditional branch detection, stack effect calculations, and disassembler formatting).
Code Generation
crates/codegen/src/compile.rs
Replaces emit_return_const() to load constants and emit ReturnValue instead; removes optimization in emit_return_value() that reused trailing LoadConst as ReturnConst; updates emit_jump() for break/continue to emit generic Jump to computed targets.
Opcode Predicates
crates/stdlib/src/opcode.rs
Updates has_const() to exclude ReturnConst from constant-returning opcodes; removes Break and Continue from has_jump() matching.
VM Runtime Execution
crates/vm/src/frame.rs
Removes Break and Continue variants from UnwindReason enum; deletes instruction handling for Break, Continue, and ReturnConst in execute_instruction(); eliminates break/continue unwinding paths.
JIT Instruction Handling
crates/jit/src/instructions.rs
Removes ReturnConst from instruction termination recognition and instruction emitter logic.
Test Utilities
crates/jit/tests/common.rs
Removes ReturnConst handling from annotation extraction and StackMachine execution flow.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • Instruction 3.14 #6805: Directly inverse operation—adds Break, Continue, and ReturnConst variants that this PR removes.
  • Bytecode pseudo opcodes #6715: Introduces PseudoInstruction and instruction enum consolidation that likely motivates this removal.
  • Fix opcode args #6649: Modifies the same opcode predicate functions (has_const, has_jump) in crates/stdlib/src/opcode.rs.

Suggested reviewers

  • ShaharNaveh

Poem

🐰 Hops along with glee,
Break and Continue—now set free!
ReturnConst fades from bytecode bright,
Jump and ReturnValue shine so right.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title precisely summarizes the main change: removing three instruction variants (ReturnConst, Break, Continue) from the bytecode instruction set across multiple crates.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.