Update opcode, dis from 3.14.2 by youknowone · Pull Request #6869 · RustPython/RustPython
Repository navigation
Update opcode, dis from 3.14.2 - #6869
Merged
youknowone merged 6 commits into RustPython:main from youknowone:opcode Jan 26, 2026
Merged
Update opcode, dis from 3.14.2 #6869 youknowone merged 6 commits into RustPython:main from youknowone:opcode
Conversation
youknowone
commented
Jan 25, 2026
·
edited by coderabbitai
Bot
Loading
Copy link Copy Markdown
Member
Summary by CodeRabbit
-
New Features
- Added a new public API to access bytecode data.
-
Refactor
- Improved code-generation pipeline with earlier optimizations and cleaner bytecode processing.
- Standardized resume instruction emission across scopes for more consistent behavior.
- Enhanced source-location/linetable tracking to improve debugging and error reporting.
✏️ Tip: You can customize this high-level summary in your review settings.
coderabbitai
Bot
commented
Jan 25, 2026
·
edited
Loading
Copy link Copy Markdown
Contributor
📝 Walkthrough
WalkthroughThis PR centralizes Resume emission into a new Changes
Sequence Diagram(s)(omitted) Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested reviewers
Poem🚥 Pre-merge checks | ✅ 2 | ❌ 1 ❌ Failed checks (1 warning)
✏️ 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. ❤️ ShareComment |
12b9e0e to
cd978d9
Compare
January 25, 2026 11:45 youknowone marked this pull request as ready for review January 25, 2026 12:16 coderabbitai
Bot
reviewed Jan 25, 2026
View reviewed changes
coderabbitai
Bot
left a comment
Copy link Copy Markdown
Contributor
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more .
Actionable comments posted: 3
🤖 Fix all issues with AI agentsIn `@crates/codegen/src/compile.rs`:
- Around line 1145-1187: emit_resume_for_scope currently resets
self.current_source_range to TextRange::default() before emitting RESUME, so
non-module scopes lose the actual definition line; update the call site (where
current_source_range is computed) to pass the real definition line into
emit_resume_for_scope (e.g., add a lineno: Option<u32> parameter) and inside
emit_resume_for_scope set lineno_override = Some(lineno) for non-module scopes
(or, alternatively, restore/populate self.current_source_range from that
definition range before emitting), ensuring the RESUME entry uses the correct
lineno; modify the emit_resume_for_scope signature and its callers accordingly
(refer to emit_resume_for_scope, current_source_range, and the RESUME
instruction emission).
In `@crates/codegen/src/ir.rs`:
- Around line 226-229: When handling a module-scope RESUME with lineno_override
== Some(0), you must also clear end_line and any column information so the
resulting LineTableLocation represents "no line" (line 0, no columns) per
CPython 3.13+ semantics. Update the code that constructs or pushes into
linetable_locations (and any related use of instructions/locations) to, when
lineno_override == Some(0), set start_line and end_line to 0 and clear/reset
start_col/end_col (or their equivalent fields in LineTableLocation) so no column
data is emitted for that entry.
In `@crates/stdlib/src/_opcode.rs`:
- Around line 328-343: The get_common_constants function currently swallows all
errors when calling vm.builtins.get_attr("all"/"any") via unwrap_or_else(|_|
vm.ctx.none()), which masks allocation/internal errors and diverges from frame
opcode behavior; change the signature of get_common_constants to return
PyResult<Vec<PyObjectRef>> (instead of Vec<...>) and propagate get_attr errors
with the ? operator so failures bubble up, or if the intent is to only treat
missing builtins as None explicitly, replace unwrap_or_else with .ok() and map
AttributeError to vm.ctx.none while still propagating other errors; update call
sites to handle the new PyResult as needed and reference get_common_constants,
get_attr, vm.builtins, vm.ctx.none, and VirtualMachine when making the change.
🧹 Nitpick comments (1) crates/codegen/src/ir.rs (1)Comment thread crates/codegen/src/ir.rs Comment on lines 226 to 229
171-186: Optimization helpers and finalize_code integration look good.The fold/convert/cleanup helpers keep the optimization pipeline readable. Operational note: after bytecode instruction changes, run a full clean build and remove any
.pycartifacts to avoid stale caches. Based on learnings, please runrm -r target/debug/build/rustpython-*and delete any.pycfiles.Also applies to: 444-521, 587-617, 619-679, 681-688
| let mut instructions = Vec::new(); | ||
| let mut locations = Vec::new(); | ||
| let mut linetable_locations: Vec<LineTableLocation> = Vec::new(); | ||
|
|
cd978d9 to
40e0a77
Compare
January 25, 2026 12:33 youknowone mentioned this pull request Jan 25, 2026 Update test_peepholer test_compiler_codegen test_compiler_assemble from 3.14.2 #6870 Merged youknowone force-pushed the opcode branch from
40e0a77 to
01e16dd
Compare
January 25, 2026 13:14 youknowone requested a review from ShaharNaveh January 25, 2026 13:15 coderabbitai
Bot
reviewed Jan 25, 2026
View reviewed changes
coderabbitai
Bot
left a comment
Copy link Copy Markdown
Contributor
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more .
Actionable comments posted: 1
🤖 Fix all issues with AI agentsIn `@crates/codegen/src/compile.rs`:
- Around line 1152-1188: The call to enter_scope is passing a byte-offset
(expr.range().start().to_u32()) which enter_scope treats as a line number and
corrupts the line table; locate the call site where enter_scope(...) is invoked
with expr.range().start().to_u32() (around the code that handles expression
scopes) and replace that argument with the actual source line number:
self.get_source_line_number().get().to_u32(), so enter_scope and downstream
SourceLocation creation receive a proper line number consistent with other
callers.
♻️ Duplicate comments (1) crates/codegen/src/ir.rs (1)youknowone and others added 6 commits January 26, 2026 10:40
335-344: Override end_line and columns when lineno_override is set to 0.When
🔧 Suggested fixlineno_override = Some(0)is set for module-scope RESUME, onlylineis overridden to 0 whileend_line,col, andend_colretain the actual source location. Per CPython 3.13+ semantics, line 0 represents "no line" (artificial instructions) and should have no meaningful column information.- let lt_loc = LineTableLocation { - line: info - .lineno_override - .unwrap_or_else(|| info.location.line.get() as i32), - end_line: info.end_location.line.get() as i32, - col: info.location.character_offset.to_zero_indexed() as i32, - end_col: info.end_location.character_offset.to_zero_indexed() as i32, - }; + let line_override = info.lineno_override; + let line = line_override.unwrap_or_else(|| info.location.line.get() as i32); + let (end_line, col, end_col) = if line_override == Some(0) { + // Line 0 = no location info per CPython semantics + (0, 0, 0) + } else { + ( + info.end_location.line.get() as i32, + info.location.character_offset.to_zero_indexed() as i32, + info.end_location.character_offset.to_zero_indexed() as i32, + ) + }; + let lt_loc = LineTableLocation { line, end_line, col, end_col };
get_common_constants
b4d09e0
reimpl smallint
9216500
emit RESUME
8c73f3c
Update opcode from v3.14.2
0b806b9
Update dis from v3.14.2
131c296
mark test_dis failures
4b823eb
youknowone
force-pushed
the
opcode
branch
from
01e16dd to
4b823eb
Compare
January 26, 2026 01:40
github-actions
Bot
commented
Jan 26, 2026
Copy link Copy Markdown
Contributor
📦 Library DependenciesThe following Lib/ modules were modified. Here are their dependencies: [+] lib: cpython/Lib/dis.py dependencies:
dependent tests: (49 tests)
[+] lib: cpython/Lib/opcode.py dependencies:
dependent tests: (34 tests)
[+] test: cpython/Lib/test/test_compile.py dependencies: dependent tests: (no tests depend on compile) [+] test: cpython/Lib/test/test_peepholer.py dependencies: dependent tests: (no tests depend on peepholer) Legend:
|
93b26bf
into
RustPython : main
Jan 26, 2026
youknowone
deleted the
opcode
branch
January 26, 2026 02:39
This was referenced Feb 7, 2026
Bytecode oparg optimization
#7032
Merged
Update test_sys from v3.14.3 and impl more sys module
#7075
Merged
This was referenced Feb 22, 2026
sys.monitoring
#7197
Closed
Instrumented instruction
#7212
Merged
This was referenced Mar 16, 2026
Upgrade test_code and fix code bugs
#7440
Merged
Bytecode parity
#7475
Merged
This was referenced Mar 27, 2026
Oparg resume depth
#7515
Merged
Compiler parity: docstring dedent, StopIteration wrapper, constant folding
#7530
Merged
Sign up for free
to join this conversation on GitHub .
Already have an account?
Sign in to comment