◐ Shell
clean mode source ↗

LoadClosure as pseudo op by youknowone · Pull Request #6789 · RustPython/RustPython

📝 Walkthrough

Walkthrough

The PR migrates the LoadClosure opcode from the concrete Instruction enum to the PseudoInstruction enum, updating bytecode emission, IR lowering, decoding logic, instruction metadata, and VM frame execution paths to accommodate this structural change.

Changes

Cohort / File(s) Summary
Bytecode Definition and Conversion
crates/compiler-core/src/bytecode/instruction.rs
Moves LoadClosure(Arg<NameIdx>) from Instruction to PseudoInstruction (discriminant 268); updates TryFrom bounds and removes LoadClosure handling from Instruction paths; removes stack effects and formatting for LoadClosure from Instruction, adds stack effect of 1 to PseudoInstruction.
Code Generation and IR Lowering
crates/codegen/src/compile.rs, crates/codegen/src/ir.rs
Updates closure variable emission to use PseudoInstruction::LoadClosure instead of Instruction::LoadClosure; adds IR lowering to convert PseudoInstruction::LoadClosure to LOAD_FAST with index adjusted by varnames count.
Opcode Metadata
crates/stdlib/src/opcode.rs
Removes LoadClosure(_) from the has_free instruction pattern match, no longer treating it as a free-variable instruction.
Frame Execution and Locals
crates/vm/src/frame.rs
Restructures frame locals initialization to combine varnames, cellvars, and freevars into a single fastlocals array with pre-filled cell objects; removes the Instruction::LoadClosure execution path from frame dispatch.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

Suggested reviewers

  • ShaharNaveh

Poem

🐰 A closure hops from Instruction's gate,
To Pseudo's burrow, a lighter fate!
Fastlocals swell with cells in place,
No more dispatch—just stack-bound grace.

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: moving LoadClosure from a regular Instruction to a PseudoInstruction, which is the primary focus across all modified files.

✏️ 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.