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
- Sort
Instructionenum & related match arms #6322 — Modifies the sameInstructionenum variants and related emission/match arms alongsideCopyItem/Copychanges. - Remove
Rotate*&Duplicate*instructions #6303 — Overlapping bytecode instruction variant changes; previously introducedCopyItemlogic that this PR builds upon. - Assign opcode ids #6637 — Related enum restructuring and opcode variant renaming within the
Instructiondefinition and generation paths.
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.
Comment @coderabbitai help to get the list of available commands and usage tips.