Skip to content

Conversation

@youknowone
Copy link
Member

@youknowone youknowone commented Jan 18, 2026

Summary by CodeRabbit

  • Refactor
    • Optimized internal bytecode instruction handling for closure variable loading, improving the compiler's variable scope management and frame initialization during runtime.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 18, 2026

📝 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.

@github-actions
Copy link
Contributor

Code has been automatically formatted

The code in this PR has been formatted using:

  • python scripts/generate_opcode_metadata.py
    Please pull the latest changes before pushing again:
git pull origin LoadClosure

@youknowone youknowone marked this pull request as ready for review January 18, 2026 17:37
@youknowone youknowone merged commit 130bb82 into RustPython:main Jan 18, 2026
13 checks passed
@youknowone youknowone deleted the LoadClosure branch January 18, 2026 17:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant