◐ Shell
clean mode source ↗

Move `Instruction` enum to its own file by ShaharNaveh · Pull Request #6693 · RustPython/RustPython

📝 Walkthrough

Walkthrough

The PR refactors the bytecode compilation system by extracting the Instruction enum from bytecode.rs into a dedicated module file (bytecode/instruction.rs), while simultaneously renaming the CopyItem opcode variant to Copy across the codebase. The public API for Instruction is preserved through re-export.

Changes

Cohort / File(s) Summary
Instruction enum extraction
crates/compiler-core/src/bytecode.rs, crates/compiler-core/src/bytecode/instruction.rs
Moved comprehensive Instruction enum and all associated implementations (~791 lines) from bytecode.rs into a new module file instruction.rs; preserved public API via pub use re-export in parent module. The new instruction.rs includes full enum definition with 1-byte opcode alignment, extensive pattern matching for stack effects, conversions (From<Instruction> for u8, TryFrom<u8> for Instruction), and formatting/disassembly logic.
Opcode variant rename (CopyItem → Copy)
crates/codegen/src/compile.rs, crates/vm/src/frame.rs
Updated all emission and execution sites to use Instruction::Copy instead of Instruction::CopyItem; variant behavior and argument structure remain functionally equivalent.
Opcode metadata generation
scripts/generate_opcode_metadata.py
Updated source path to read from bytecode/instruction.rs and removed special-case handling for "CopyItem" in cpython_name generation logic.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Possibly related PRs

Suggested reviewers

  • youknowone

Poem

🐰 We've shuffled the instructions neat,
From bytecode.rs to instruction's beat,
CopyItem → Copy, a rename so spry,
The enum's extracted, reaching up high!
Module-ized magic, refactored with care. ✨

🚥 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 accurately and concisely describes the main change: moving the Instruction enum to its own file, which aligns with the primary refactoring objective.
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.