GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — Align opcode names in `dis` by ShaharNaveh · Pull Request #6526 · RustPython/RustPython 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 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
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.
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
crates/codegen/src/snapshots/rustpython_codegen__compile__tests__if_ands.snap is excluded by !**/*.snapcrates/codegen/src/snapshots/rustpython_codegen__compile__tests__if_mixed.snap is excluded by !**/*.snapcrates/codegen/src/snapshots/rustpython_codegen__compile__tests__if_ors.snap is excluded by !**/*.snapcrates/codegen/src/snapshots/rustpython_codegen__compile__tests__nested_double_async_with.snap is excluded by !**/*.snapcrates/codegen/src/compile.rscrates/compiler-core/src/bytecode.rscrates/vm/src/frame.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.rsLearnt 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.rscrates/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)
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
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
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(()) }
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
crates/jit/src/instructions.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
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
|
||
| match self { | ||
| BeforeAsyncWith => w!(BeforeAsyncWith), | ||
| BeforeAsyncWith => w!(BEFORE_ASYNC_WITH), |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Is there reason to change the convention?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem 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
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
👍
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.