◐ Shell
clean mode source ↗

Newtype `LoadSuperAttr` oparg by ShaharNaveh · Pull Request #7002 · RustPython/RustPython

📝 Walkthrough

Walkthrough

The changes refactor super-attribute loading instruction handling by replacing low-level u32 encoding/decoding with a typed LoadSuperAttr struct using a builder pattern. This spans compiler codegen, bytecode definitions, and VM execution, removing old encode/decode helper functions and introducing a strongly-typed oparg representation.

Changes

Cohort / File(s) Summary
Oparg Type Definition
crates/compiler-core/src/bytecode/oparg.rs
Introduces new public LoadSuperAttr struct with three bit-field accessors (name_idx, is_load_method, has_class), a builder pattern via LoadSuperAttrBuilder, and trait implementations for OpArgType conversion and u32 interop.
Instruction Type Updates
crates/compiler-core/src/bytecode/instruction.rs
Changes LoadSuperAttr variant argument type from Arg to Arg, removes encode_load_super_attr_arg and decode_load_super_attr_arg functions, and updates display/serialization to use typed accessors.
Bytecode Exports
crates/compiler-core/src/bytecode.rs
Removes instruction re-exports for encode/decode_load_super_attr_arg and encode/decode_load_attr_arg; adds LoadSuperAttr to oparg public exports.
Codegen Integration
crates/codegen/src/compile.rs
Replaces four emit helpers (emit_load_super_attr, emit_load_super_method, emit_load_zero_super_attr, emit_load_zero_super_method) to construct LoadSuperAttr via builder instead of calling encode_load_super_attr_arg; imports LoadSuperAttr in public module.
VM Execution
crates/vm/src/frame.rs
Updates load_super_attr method signature to accept oparg: LoadSuperAttr instead of oparg: u32; refactors argument extraction to use LoadSuperAttr accessor methods (name_idx(), is_load_method(), has_class()).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

Suggested reviewers

  • youknowone

Poem

🐰 A builder so clean, no encode in sight,
LoadSuperAttr shines with typed delight!
From u32's murk to fields so bright,
Super attributes now structured just right. ✨

🚥 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 'Newtype LoadSuperAttr oparg' accurately summarizes the main change: introducing a newtype wrapper for the LoadSuperAttr opcode argument, which is reflected across all modified files.
Docstring Coverage ✅ Passed Docstring coverage is 95.65% 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
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.