◐ Shell
clean mode source ↗

Fix traceback by youknowone · Pull Request #6569 · RustPython/RustPython

📝 Walkthrough

Walkthrough

This PR changes per-instruction source tracking from a single SourceLocation to start/end SourceLocation pairs across codegen, IR, bytecode, marshal, VM construction, and traceback; it also adds a CompileOpts.debug_ranges flag and propagates it to linetable generation and VM settings.

Changes

Cohort / File(s) Summary
Codegen / Compilation
crates/codegen/src/compile.rs
StmtRaise now includes range; _emit computes and attaches both location and end_location to InstructionInfo; finalize_code is called with &CompileOpts; CompileOpts gains pub debug_ranges: bool and a manual Default.
IR & Linetable
crates/codegen/src/ir.rs
InstructionInfo gains pub end_location: SourceLocation; CodeInfo::finalize_code now accepts &CompileOpts; generate_linetable signature changed to accept &[(SourceLocation, SourceLocation)] and debug_ranges, and encoding now uses start/end data.
Bytecode representation
crates/compiler-core/src/bytecode.rs
CodeObject.locations changed to Box<[(SourceLocation, SourceLocation)]>; display and line-extraction updated to read the start location (.0).
Serialization / Marshal
crates/compiler-core/src/marshal.rs
Serialization/deserialization updated to read/write start/end pairs per entry (four u32s per instruction) and collect into Box<[(SourceLocation, SourceLocation)]>.
VM: code objects & construction
crates/vm/src/builtins/code.rs
PyCode/CodeObject construction adjusted to new locations type Box<[(SourceLocation, SourceLocation)]>, currently populated as duplicated (loc, loc) per instruction.
VM: frames & traceback
crates/vm/src/builtins/frame.rs, crates/vm/src/frame.rs
Frame location helpers destructure (loc, _end) and use start location for reporting; lasti-based offsets now use frame.lasti() * 2 for byte-offset mapping.
VM settings & CLI
crates/vm/src/vm/mod.rs, crates/vm/src/vm/setting.rs, src/settings.rs
New code_debug_ranges: bool setting (default true) with CLI flag --no_debug_ranges and PYTHONNODEBUGRANGES env var; propagated into CompileOpts.debug_ranges.
Examples & Misc
examples/dis.rs, .cspell.dict/*
Example usage updated to set debug_ranges: true; dictionary token PYTHONNODEBUGRANGES added.

Sequence Diagram(s)

(No sequence diagram generated — changes are data-shape and API propagation focused, not a new multi-component control flow requiring sequential visualization.)

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • code object linetable #6150: Modifies per-instruction location handling and linetable/IR APIs; strongly related to InstructionInfo and linetable changes.

Suggested reviewers

  • ShaharNaveh
  • coolreader18

Poem

🐰 I hopped through ranges, start and end in tow,
Each instruction wears a span, now watch it show,
Tracebacks trace finer, columns kept in sight,
I stitched the code with ranges — carrot-coded delight! 🥕

Pre-merge checks and finishing touches

❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 43.48% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Title check ❓ Inconclusive The PR title 'Fix traceback' is vague and does not clearly convey the specific nature of the change (adding end_location/end_lineno support for pytest compatibility). Consider a more specific title like 'Add end_lineno support to FrameSummary for pytest compatibility' to better reflect the primary change.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed The PR implements end_location tracking throughout the bytecode compilation and runtime stack, adding end_lineno attribute support to FrameSummary to fix the pytest AttributeError reported in issue #6548.
Out of Scope Changes check ✅ Passed All changes are scope-appropriate: bytecode location tracking (compile.rs, ir.rs, bytecode.rs, marshal.rs), runtime integration (vm/, frame.rs, builtins/), configuration flags, and supporting files are all necessary to implement end_location support for pytest compatibility.
✨ 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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.