Move `OpArg` to its own file by ShaharNaveh · Pull Request #6703 · RustPython/RustPython
📝 Walkthrough
Walkthrough
Reorganizes bytecode argument handling into a new bytecode::oparg module, adds generic Arg<T> in instruction, introduces ExceptionTableEntry plus encode_exception_table/find_exception_handler, and updates top-level public re-exports while removing legacy oparg symbols from the main module.
Changes
| Cohort / File(s) | Summary |
|---|---|
Bytecode root crates/compiler-core/src/bytecode.rs |
Added mod oparg; reworked public re-exports to expose instruction::{Arg, Instruction, decode_load_super_attr_arg, encode_load_super_attr_arg} and to re-export oparg types under crate::bytecode::oparg; added ExceptionTableEntry, encode_exception_table, and find_exception_handler; removed legacy oparg symbols from top-level exports. |
Instruction module crates/compiler-core/src/bytecode/instruction.rs |
Added pub struct Arg<T: OpArgType>(PhantomData<T>) with marker, new, new_single, get, try_get, get_unchecked; added encode_load_super_attr_arg / decode_load_super_attr_arg; imports updated to use oparg::.... |
New oparg module crates/compiler-core/src/bytecode/oparg.rs |
New module defining OpArgType trait, OpArgByte/OpArg/OpArgState, macros for enum generation, many OpArgType enums/bitflags (e.g., BinaryOperator, ComparisonOperator, RaiseKind, MakeFunctionFlags, UnpackExArgs, ConvertValueOparg, ResumeType, intrinsics), Display/From/Into impls and helpers for op-arg encoding/decoding. |
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
- Rework compiler about exception handling #6638 — modifies bytecode exception-table encoding/decoding and introduces/uses
ExceptionTableEntry/ encoding helpers. - Assign opcode ids #6637 — refactors oparg-related types and updates
Instructionvariants to useArg<T>/oparg types. - Super instructions #6694 — adds/uses
encode_load_super_attr_arg/decode_load_super_attr_argand related LoadSuper instruction handling.
Suggested reviewers
- youknowone
Poem
🐰 I hopped through bytes with eager cheer,
I tunneled opargs to a burrow near,
Arg wears a tiny PhantomData hat,
Exceptions boxed and mapped to a spot,
Bytecode burrow now tidy — munch the carrot, that!
🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
| Check name | Status | Explanation | Resolution |
|---|---|---|---|
| Title check | The PR title 'Move OpArg to its own file' does not accurately reflect the actual changes. While OpArg was moved, the PR involves extensive API reorganization, creating a new oparg module with many type re-exports, adding new public types (ExceptionTableEntry, Arg), and significantly restructuring the bytecode module's public surface (+10/-651 lines in bytecode.rs). |
Revise the title to better reflect the scope of changes, such as 'Reorganize bytecode module with new oparg module and public API restructuring' or 'Extract oparg types into new module with exception table support'. |
✅ Passed checks (2 passed)
| Check name | Status | Explanation |
|---|---|---|
| Description Check | ✅ Passed | Check skipped - CodeRabbit’s high-level summary is enabled. |
| Docstring Coverage | ✅ Passed | Docstring coverage is 100.00% 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
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 @coderabbitai help to get the list of available commands and usage tips.