-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Move OpArg to its own file
#6703
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move OpArg to its own file
#6703
Conversation
📝 WalkthroughWalkthroughReorganizes bytecode argument handling into a new Changes
Sequence Diagram(s)(Skipped — changes are API/module reorganization and encoding utilities without a multi-component runtime control flow requiring sequence visualization.) Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
crates/compiler-core/src/bytecode/instruction.rs
🧰 Additional context used
📓 Path-based instructions (1)
**/*.rs
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
**/*.rs: Follow the default rustfmt code style by runningcargo fmtto format Rust code
Always run clippy to lint code (cargo clippy) before completing tasks and fix any warnings or lints introduced by changes
Follow Rust best practices for error handling and memory management
Use the macro system (pyclass,pymodule,pyfunction, etc.) when implementing Python functionality in Rust
Files:
crates/compiler-core/src/bytecode/instruction.rs
🧬 Code graph analysis (1)
crates/compiler-core/src/bytecode/instruction.rs (1)
crates/compiler-core/src/bytecode/oparg.rs (14)
fmt(31-33)fmt(140-150)fmt(256-258)fmt(466-496)fmt(579-581)get(81-87)from_op_arg(8-8)from_op_arg(155-165)from_op_arg(185-187)from_op_arg(197-199)from_op_arg(245-247)from_op_arg(335-337)from_op_arg(532-538)from_op_arg(567-570)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
- GitHub Check: Ensure compilation on various targets
- GitHub Check: Run snippets and cpython tests (windows-2025)
- GitHub Check: Run rust tests (windows-2025)
- GitHub Check: Run tests under miri
- GitHub Check: Check Rust code with clippy
🔇 Additional comments (2)
crates/compiler-core/src/bytecode/instruction.rs (2)
866-905: LGTM! Well-designed zero-cost type-safe abstraction.The
Arg<T>wrapper usingPhantomData<T>provides compile-time type safety without runtime overhead. The API is clean with appropriate#[inline]hints for the hot-path accessors, and the unsafeget_uncheckedmethod has proper safety documentation.
907-919: LGTM!The trait implementations are appropriate for a zero-sized marker type.
PartialEqcorrectly returnstruefor all instances sinceArg<T>carries no runtime data—only type information viaPhantomData. TheDebugimplementation usingtype_name::<T>()provides helpful output for diagnostics.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
crates/compiler-core/src/bytecode.rs (1)
57-71: Consider a debug assertion for entry invariants.The
saturating_subon line 62 silently produces0ifentry.end < entry.start, which would result in an empty range being encoded. While this is safe, it could mask logic errors in callers.🔧 Optional: Add debug assertion
pub fn encode_exception_table(entries: &[ExceptionTableEntry]) -> alloc::boxed::Box<[u8]> { let mut data = Vec::new(); for entry in entries { + debug_assert!( + entry.end >= entry.start, + "ExceptionTableEntry end ({}) must be >= start ({})", + entry.end, + entry.start + ); let size = entry.end.saturating_sub(entry.start);
📜 Review details
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
crates/compiler-core/src/bytecode.rscrates/compiler-core/src/bytecode/instruction.rs
🧰 Additional context used
📓 Path-based instructions (1)
**/*.rs
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
**/*.rs: Follow the default rustfmt code style by runningcargo fmtto format Rust code
Always run clippy to lint code (cargo clippy) before completing tasks and fix any warnings or lints introduced by changes
Follow Rust best practices for error handling and memory management
Use the macro system (pyclass,pymodule,pyfunction, etc.) when implementing Python functionality in Rust
Files:
crates/compiler-core/src/bytecode/instruction.rscrates/compiler-core/src/bytecode.rs
🧬 Code graph analysis (1)
crates/compiler-core/src/bytecode.rs (2)
crates/compiler-core/src/bytecode/instruction.rs (4)
core(310-310)core(374-374)decode_load_super_attr_arg(929-934)encode_load_super_attr_arg(923-925)crates/vm/src/frame.rs (2)
core(410-410)core(1958-1958)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (11)
- GitHub Check: Run snippets and cpython tests (macos-latest)
- GitHub Check: Run rust tests (ubuntu-latest)
- GitHub Check: Run rust tests (macos-latest)
- GitHub Check: Run snippets and cpython tests (ubuntu-latest)
- GitHub Check: Check the WASM package and demo
- GitHub Check: Run rust tests (windows-2025)
- GitHub Check: Run snippets and cpython tests on wasm-wasi
- GitHub Check: Run snippets and cpython tests (windows-2025)
- GitHub Check: Run tests under miri
- GitHub Check: Ensure compilation on various targets
- GitHub Check: Check Rust code with clippy
🔇 Additional comments (7)
crates/compiler-core/src/bytecode/instruction.rs (3)
1-13: LGTM!The import reorganization correctly pulls in
PhantomDatafor the newArg<T>type and restructures the oparg-related imports to use the newopargmodule path. This aligns with the PR objective of movingOpArgto its own file.
865-919: Clean zero-sized type marker pattern forArg<T>.The implementation correctly uses
PhantomData<T>to create a zero-sized marker type that carries type information at compile time without runtime overhead. A few observations:
PartialEqreturningtruefor all instances is correct since the marker carries no runtime data.get()panics on invalid opargs viaunwrap(), which is appropriate as invalid bytecode is a bug.- The
unsafe get_uncheckedproperly forwards safety requirements to callers.
921-934: Bit-packing for LOAD_SUPER_ATTR looks correct.The encoding packs
load_methodin bit 0,has_classin bit 1, andname_idxin bits 2+. The decoding correctly extracts these values. This matches the usage instack_effect(line 614) andfmt_dis(line 802).crates/compiler-core/src/bytecode.rs (4)
11-11: LGTM!Addition of
memimport is necessary formem::size_ofandmem::discriminantusage in this file.
17-27: Clean module reorganization with maintained public API.The re-exports from
instructionand the newopargmodule preserve the existing public API surface while implementing the modular separation described in the PR objectives.
73-97: LGTM!The
find_exception_handlerfunction correctly implements linear search through the varint-encoded exception table, returning the first matching entry for the given offset. The range checkoffset >= start && offset < endcorrectly implements half-open interval semantics.
811-879: Good test coverage for exception table functionality.The tests cover:
- Round-trip encode/decode with multiple entries
- Empty table handling
- Single entry with boundary conditions (inclusive start, exclusive end)
youknowone
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
* Move OpArg to its own file * Fix merge * Fix more merge
Followup on #6693
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.