◐ Shell
clean mode source ↗

Macro for defining opcode & instruction enums by ShaharNaveh · Pull Request #7573 · 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 resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Replaces handwritten Instruction/PseudoInstruction enums and transmute-based conversions with a macro-generated Opcode/PseudoOpcode plus matching Instruction/PseudoInstruction enums, adds Display for opcodes, moves size assertions, updates opcode metadata generation, and re-exports the new opcode types. (≤50 words)

Changes

Cohort / File(s) Summary
Public API exports
crates/compiler-core/src/bytecode.rs
Added Opcode and PseudoOpcode to the public re-exports.
Macro-generated opcodes & instructions
crates/compiler-core/src/bytecode/instruction.rs
Replaced hand-written Instruction/PseudoInstruction and mem::transmute conversions with a define_opcodes! macro that generates Opcode/PseudoOpcode, macro-generated Instruction/PseudoInstruction enums (with #[repr(...)]), TryFrom/From conversions via match, as_instruction()/opcode() mappings, Display impls, removed direct mem::transmute and earlier core::mem import, and moved core::mem::size_of assertions to the file end.
Opcode metadata generator
scripts/generate_opcode_metadata.py
Changed name-casing logic (to_pascal_caseto_snake_case), added cpython_name field to Opcode NamedTuple, altered parsing to extract explicit Rust and CPython names, reworked enum-body extraction to track braces safely, and updated downstream code to use opcode.cpython_name.

Sequence Diagram(s)

(Skipped — changes are internal enum/macro generation without multi-component sequential runtime flow.)

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related issues

  • [RFC] Split oparg type from the opcode enum #6746: Related — introduces explicit Opcode/PseudoOpcode enums and match-based opcode↔instruction mappings, aligning with the RFC's separation goal though it doesn't implement AnyOparg/Instruction-struct splitting.

Poem

🐰
I hopped through enums, bytes, and code,
Macros stitched pathways down the road,
Matches chirp where transmutes fell,
Opcodes sparkle — sized and well,
A mellow hop for bytecode's ode! 🥕

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 12.50% 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 and concisely describes the primary change: introducing a macro for defining opcode and instruction enums, which aligns with the main refactoring in the PR.

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

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.