◐ Shell
clean mode source ↗

Make inner oparg values private by ShaharNaveh · Pull Request #7050 · RustPython/RustPython

📝 Walkthrough

Walkthrough

This pull request refactors the OpArg and OpArgByte bytecode argument types by encapsulating their inner fields (making them private), introducing standardized public constructors (new and NULL constant), and updating all usage sites across the codebase to use the new API patterns. The changes affect code generation, bytecode instruction handling, and VM runtime layers without altering functional behavior.

Changes

Cohort / File(s) Summary
ByteCode Core API
crates/compiler-core/src/bytecode/oparg.rs
Encapsulated OpArg and OpArgByte fields (private), introduced pub const fn new() constructors and NULL constants, updated From trait implementations to use new() instead of direct construction.
Bytecode Instruction Layer
crates/compiler-core/src/bytecode/instruction.rs
Updated Arg<T> constructor and conversion methods to use OpArg::new() and explicit u32::from() conversions instead of accessing private fields directly.
Code Generation
crates/codegen/src/compile.rs, crates/codegen/src/ir.rs
Updated OpArg construction patterns across instruction emission and IR to use OpArg::new() and OpArg::NULL; replaced OpArg::null() calls and direct field access with new constructors.
VM Runtime
crates/vm/src/frame.rs
Updated yield value handling to use explicit u8::from() conversion instead of direct field access for OpArg argument extraction.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • youknowone

Poem

🐰 Hop, skip, and refactor with glee!
OpArg's fields now hidden, can't see—
With new() and NULL in place,
Constructors shine with encapsulated grace,
Bytecode arguments dance wild and free!

🚥 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 'Make inner oparg values private' is fully related to the main change, which refactors OpArg and OpArgByte by making their inner fields private and introducing new constructors and constants.
Docstring Coverage ✅ Passed Docstring coverage is 96.15% 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

No actionable comments were generated in the recent review. 🎉


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.