Skip to content

Bytecode parity - exception#7557

Draft
youknowone wants to merge 6 commits intoRustPython:mainfrom
youknowone:bytecode-parity-exception
Draft

Bytecode parity - exception#7557
youknowone wants to merge 6 commits intoRustPython:mainfrom
youknowone:bytecode-parity-exception

Conversation

@youknowone
Copy link
Copy Markdown
Member

No description provided.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 3, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: 58420726-c9e3-43d5-98a7-7085c494daea

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@youknowone youknowone force-pushed the bytecode-parity-exception branch 2 times, most recently from 7e7e111 to a15185e Compare April 5, 2026 05:06
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 5, 2026

📦 Library Dependencies

The following Lib/ modules were modified. Here are their dependencies:

[x] test: cpython/Lib/test/test_compile.py (TODO: 27)
[x] test: cpython/Lib/test/test_compiler_assemble.py
[x] test: cpython/Lib/test/test_compiler_codegen.py
[x] test: cpython/Lib/test/test_peepholer.py (TODO: 20)

dependencies:

dependent tests: (no tests depend on compile)

Legend:

  • [+] path exists in CPython
  • [x] up-to-date, [ ] outdated

@youknowone youknowone force-pushed the bytecode-parity-exception branch 3 times, most recently from 11ad6f4 to 876791a Compare April 6, 2026 14:27
- ExceptionStack: init with base slot instead of empty vec
- with_frame_impl: save/restore exc_info value instead of
  push/pop slot, so callees see caller's handled exception
- Remove unused with_frame_exc
- resume_gen_frame: use push_exception/pop_exception methods
- codegen: move RERAISE inside cleanup handler's exception
  table range in finally blocks (both try-finally and
  try-except-finally), so POP_EXCEPT runs before re-raising
- Add eliminate_dead_stores pass before peephole_optimize:
  consecutive STORE_FAST to the same variable are replaced
  with POP_TOP (apply_static_swaps from CPython flowgraph.c)
- Remove 3 expectedFailure decorators in test_peepholer
  (test_load_fast_unknown_* now pass)
- Accept updated async_with snapshot
- Fix formatting in ir.rs, mod.rs, Python scripts
@youknowone youknowone force-pushed the bytecode-parity-exception branch from 876791a to 8b264e5 Compare April 6, 2026 14:28
RERAISE was popping `depth` extra values in addition to the exception,
causing stack underflow when unwinding through the exception table.

CPython spec: `inst(RERAISE, (values[oparg], exc -- values[oparg]))` —
only `exc` is consumed, `values[oparg]` stays on the stack so the outer
handler's exception-table unwind pops them down to its configured depth.

Without this fix, `async with` cleanup paths with nested exception
handlers crashed with `pop stackref but null found` at POP_EXCEPT.
- Add optimize_build_tuple_unpack (flowgraph.c): BUILD_TUPLE n +
  UNPACK_SEQUENCE n → NOP for n=1, or NOP + SWAP n for n=2/3.
- Add apply_static_swaps (flowgraph.c): eliminates SWAP by swapping
  target STORE_FAST/POP_TOP instructions in place. Checks line
  boundaries and detects store conflicts before reordering.
- Remove direct_name_unpack fast path from compile.rs. The general
  UNPACK path now produces the same bytecode via the new flowgraph
  optimizations.
- Drop expectedFailure on test_pack_unpack (now passes).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant