Skip to content

Make inner oparg values private#7050

Merged
youknowone merged 1 commit intoRustPython:mainfrom
ShaharNaveh:oparg-null-const-attr
Feb 8, 2026
Merged

Make inner oparg values private#7050
youknowone merged 1 commit intoRustPython:mainfrom
ShaharNaveh:oparg-null-const-attr

Conversation

@ShaharNaveh
Copy link
Contributor

@ShaharNaveh ShaharNaveh commented Feb 8, 2026

Summary by CodeRabbit

Refactor

  • Standardized bytecode instruction argument handling and conversion patterns for improved code consistency and maintainability across the compiler's internal architecture.

@ShaharNaveh ShaharNaveh marked this pull request as ready for review February 8, 2026 12:38
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 8, 2026

📝 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.

@youknowone youknowone enabled auto-merge (squash) February 8, 2026 14:36
@youknowone youknowone merged commit ea352cc into RustPython:main Feb 8, 2026
23 of 24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants