-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Align opcode names in dis
#6526
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
Conversation
📝 WalkthroughWalkthroughRenamed the Changes
Sequence Diagram(s)sequenceDiagram
participant Codegen
participant Bytecode as Compiler-core
participant Runtime as VM/JIT
rect rgb(240,255,240)
Note over Codegen,Bytecode: Build-time phase
Codegen->>Bytecode: emit PopTop
end
rect rgb(240,240,255)
Note over Runtime: Runtime execution
Runtime->>Runtime: fetch PopTop
Runtime-->>Runtime: STACK.pop() (discard)
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 inconclusive)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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: 0
🧹 Nitpick comments (1)
crates/codegen/src/compile.rs (1)
1104-1115: Guard thecompile_block_exprassumption about trailing PopTop
compile_block_exprstill unconditionally pops the last instruction, assuming it’s thePopTopemitted for a trailingStmt::Expr. That was true before the rename, but it’s an implicit contract betweencompile_statementandcompile_block_expr. Consider asserting the last instruction isInstruction::PopTop(or otherwise checking) before popping to make future refactors safer.
📜 Review details
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (4)
crates/codegen/src/snapshots/rustpython_codegen__compile__tests__if_ands.snapis excluded by!**/*.snapcrates/codegen/src/snapshots/rustpython_codegen__compile__tests__if_mixed.snapis excluded by!**/*.snapcrates/codegen/src/snapshots/rustpython_codegen__compile__tests__if_ors.snapis excluded by!**/*.snapcrates/codegen/src/snapshots/rustpython_codegen__compile__tests__nested_double_async_with.snapis excluded by!**/*.snap
📒 Files selected for processing (3)
crates/codegen/src/compile.rscrates/compiler-core/src/bytecode.rscrates/vm/src/frame.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 Rust 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/codegen/src/compile.rscrates/vm/src/frame.rscrates/compiler-core/src/bytecode.rs
🧠 Learnings (1)
📚 Learning: 2025-09-03T13:15:23.436Z
Learnt from: youknowone
Repo: RustPython/RustPython PR: 6123
File: stdlib/src/contextvars.rs:128-134
Timestamp: 2025-09-03T13:15:23.436Z
Learning: Vec::pop_if was stabilized in Rust 1.86.0 (released April 3, 2025) and is available in standard library for conditionally removing the last element from a vector based on a predicate.
Applied to files:
crates/compiler-core/src/bytecode.rs
🧬 Code graph analysis (1)
crates/compiler-core/src/bytecode.rs (4)
crates/vm/src/frame.rs (4)
arg(2458-2459)func(2121-2122)name(1231-1231)name(2450-2450)crates/codegen/src/compile.rs (2)
name(897-899)varname(900-907)crates/codegen/src/ir.rs (1)
idx(45-47)crates/stdlib/src/re.rs (1)
end(378-385)
⏰ 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). (9)
- GitHub Check: Run snippets and cpython tests (windows-latest)
- GitHub Check: Run snippets and cpython tests (macos-latest)
- GitHub Check: Check the WASM package and demo
- GitHub Check: Check Rust code with clippy
- GitHub Check: Run rust tests (windows-latest)
- GitHub Check: Run rust tests (macos-latest)
- GitHub Check: Run snippets and cpython tests on wasm-wasi
- GitHub Check: Run tests under miri
- GitHub Check: Ensure compilation on various targets
🔇 Additional comments (4)
crates/vm/src/frame.rs (1)
1359-1363: LGTM! Clean alignment with CPython naming.The
PopTopinstruction handler correctly pops and discards the top-of-stack value. The implementation is straightforward, the comment is clear, and the semantics are unchanged from the previousPopvariant.crates/codegen/src/compile.rs (2)
1055-1093: PopTop replaces Pop cleanly for simple TOS discardsThe new
Instruction::PopTopusages here (REPL printing, import-from module pop, statement expr results,withwithoutas, non-simple annotated assigns, and generator comprehensions) are all straightforward “drop unused result” sites and remain stack-correct withstack_effect(PopTop) == -1. No functional change beyond the opcode rename.Also applies to: 1403-1412, 2050-2061, 2927-2957, 4190-4198, 4810-4833
3136-3710: Pattern-matching and control-flow cleanup PopTop sites remain stack-safeAll pattern/exception-related uses of
PopTop(pattern failure cleanups, wildcard/star captures, mapping/sequence/class patterns,Matchdefault/fallthrough handling, and chained-comparison early-exit cleanup) correctly discard subjects or intermediate values that are no longer needed. ThePatternContext.on_topaccounting plusstack_effect(PopTop) = -1stays consistent, so control-flow and stack behavior are preserved across the rename.Also applies to: 3793-3819, 3887-3894, 4125-4131
crates/compiler-core/src/bytecode.rs (1)
588-607: PopTop opcode semantics and disassembly alignment look correct
Instruction::PopTopis documented as a pureSTACK.pop()and hasstack_effect == -1, matching the oldPopbehavior.- The disassembler now prints
POP_TOP(and other opcodes in CPython-style ALL_CAPS), which aligns RustPython’sdisoutput with CPython without changing runtime behavior.- Enum ordering and
LAST_INSTRUCTION = Instruction::YieldValuestay intact, so the numeric opcode for this slot is preserved; only the variant name and displayed opname changed. This is a public API rename forInstruction, but internally everything remains consistent.Also applies to: 795-799, 1672-1797, 1867-1973
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/jit/src/instructions.rs (1)
580-583: LGTM! The opcode rename correctly aligns with CPython.The
PopTopinstruction is properly implemented - it pops the top value from the stack and returns successfully, matching the expected semantics.Consider adding stack underflow validation for consistency with other stack operations in this file (e.g., lines 279, 447, 555). Most other instructions that pop from the stack use
.ok_or(JitCompileError::BadBytecode)?to detect empty stack conditions.🔎 Optional defensive programming improvement
Instruction::PopTop => { - self.stack.pop(); + self.stack.pop().ok_or(JitCompileError::BadBytecode)?; Ok(()) }
📜 Review details
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
crates/jit/src/instructions.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 Rust 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/jit/src/instructions.rs
⏰ 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). (10)
- GitHub Check: Run snippets and cpython tests (ubuntu-latest)
- GitHub Check: Run snippets and cpython tests (windows-latest)
- GitHub Check: Run rust tests (windows-latest)
- 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: Check the WASM package and demo
- GitHub Check: Ensure compilation on various targets
- GitHub Check: Run tests under miri
- GitHub Check: Check Rust code with clippy
|
|
||
| match self { | ||
| BeforeAsyncWith => w!(BeforeAsyncWith), | ||
| BeforeAsyncWith => w!(BEFORE_ASYNC_WITH), |
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.
Is there reason to change the convention?
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.
Yes. Some tests are checking for the presents/absent of certain opcodes by name like:
RustPython/Lib/test/test_compile.py
Lines 1073 to 1081 in 61ddd98
| def test_no_wraparound_jump(self): | |
| # See https://bugs.python.org/issue46724 | |
| def while_not_chained(a, b, c): | |
| while not (a < b < c): | |
| pass | |
| for instr in dis.Bytecode(while_not_chained): | |
| self.assertNotEqual(instr.opname, "EXTENDED_ARG") |
And pretty much all tests under test_dis.py (which we have a VERY outdated version of ATM), aligning the names of the opcodes just increases our test coverage
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.
👍
Also renamed
Instruction:: Pop->Instruction::PopTopSummary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.