`AnyInstruction` helpers + doc imrovments by ShaharNaveh · Pull Request #7757 · RustPython/RustPython
Note
Reviews paused
It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.
Use the following commands to manage reviews:
@coderabbitai resumeto resume automatic reviews.@coderabbitai reviewto trigger a single review.
Use the checkboxes below for quick actions:
-
▶️ Resume reviews - 🔍 Trigger review
📝 Walkthrough
Walkthrough
Refactors bytecode/IR handling to use opcode-based APIs (real_opcode/pseudo_opcode) and by-value const fn helpers; updates codegen IR folding, peephole, swap/borrow/deopt, and CFG utilities to match/rewrite on Opcode/PseudoOpcode values and emit Opcode::... .into()/pseudo opcode replacements.
Changes
| Cohort / File(s) | Summary |
|---|---|
Bytecode instruction helpers crates/compiler-core/src/bytecode/instruction.rs |
Added pub const fn real_opcode(self) -> Option<Opcode> and pub const fn pseudo_opcode(self) -> Option<PseudoOpcode>. Converted PseudoInstruction::is_block_push, AnyInstruction::is_pop_block, and AnyInstruction::is_block_push to const fn taking self by value and updated implementations to use opcode matching. |
Codegen IR / peephole & CFG crates/codegen/src/ir.rs |
Replaced pattern-matching on constructed Instruction variants with opcode-based matching via instr.real_opcode() / instr.pseudo_opcode(). Updated constant folding, peephole rewrites, superinstruction emission, jump/branch folding (emit PseudoOpcode::Jump), borrow optimizations/deopts, swap/static-reordering helpers (is_swappable/stores_to) and related CFG/exception cleanup to operate on opcode values and emit Opcode::X.into(). Adjusted helper signatures and usages accordingly. |
Sequence Diagram(s)
(omitted)
Estimated code review effort
🎯 3 (Moderate) | ⏱️ ~20 minutes
Possibly related issues
- [RFC] Split oparg type from the opcode enum #6746 — Related to exposing opcode-level accessors and migrating logic from variant-destructuring to opcode-based handling.
Possibly related PRs
- Simplify
Intruction.deopt()#7615 — Refactors code to operate onOpcodevalues instead of constructing/matching fullInstructionvariants; strongly related. - Macro for defining opcode & instruction enums #7573 — Introduces/exports
Opcode/PseudoOpcodemappings used by opcode-based rewrites; likely a direct dependency. - Add InstructionMetadata::stack_effect_jump for branch stack effects #7585 — Modifies jump/branch handling and stack/branch reasoning that intersect with the opcode-based changes here.
Suggested reviewers
- coolreader18
- youknowone
Poem
🐰
I hop through opcodes, quiet and spry,
Folding bytes beneath a starlit sky.
Swaps reset, old patterns unwind,
Tiny paws leave tidy trails behind. 🥕
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
| Check name | Status | Explanation | Resolution |
|---|---|---|---|
| Title check | The PR title mentions 'doc improvements' but the actual changes are about refactoring instruction matching from variants to opcodes, with minor API additions. The title is misleading about the primary scope of changes. | Update the title to accurately reflect the main change, such as 'Refactor instruction matching to use opcode-based checks' or 'Use opcode-based matching in instruction optimizer'. |
✅ Passed checks (4 passed)
| Check name | Status | Explanation |
|---|---|---|
| Description Check | ✅ Passed | Check skipped - CodeRabbit’s high-level summary is enabled. |
| Docstring Coverage | ✅ Passed | Docstring coverage is 97.53% which is sufficient. The required threshold is 80.00%. |
| Linked Issues check | ✅ Passed | Check skipped because no linked issues were found for this pull request. |
| Out of Scope Changes check | ✅ Passed | Check skipped because no linked issues were found for this pull request. |
✏️ Tip: You can configure your own custom pre-merge checks in the settings.
✨ Finishing Touches
🧪 Generate unit tests (beta)
- Create PR with unit tests
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.