Commit 7704b71
committed
Rework exception compiler to use CFG-based handler analysis
Move exception handler tracking from compile-time fblock metadata to
a post-codegen CFG analysis pass, matching flowgraph.c's pipeline.
Compiler changes (compile.rs):
- Remove fb_handler, fb_stack_depth, fb_preserve_lasti from FBlockInfo
- Remove handler_stack_depth() and current_except_handler() helpers
- Emit SetupFinally/SetupCleanup/SetupWith/PopBlock pseudo instructions
instead of manually tracking handlers in fblocks
- Add dead blocks after raise/break/continue/return to prevent
dead code from corrupting the except stack
- Add missing PopTop after CallIntrinsic1 ImportStar
- Fix async comprehension SetupFinally/GetANext emission order
- Fix try-except* handler: move BUILD_LIST/COPY before handler loop
- Rework unwind_fblock for HandlerCleanup, TryExcept, FinallyTry,
FinallyEnd, and With/AsyncWith to emit proper PopBlock sequences
New CFG analysis passes (ir.rs):
- mark_except_handlers(): mark blocks targeted by SETUP_* instructions
- label_exception_targets(): walk CFG with except stack to set
per-instruction handler info and convert POP_BLOCK to NOP
- convert_pseudo_ops(): lower remaining pseudo ops after analysis
- Compute handler entry depth from SETUP_* type in max_stackdepth()
(SETUP_CLEANUP=+2, SETUP_FINALLY/SETUP_WITH=+1)
- Fix SEND jump_effect from -1 to 0 (receiver stays until END_SEND)
- Add underflow guard for handler stack_depth calculation
Instruction metadata (instruction.rs):
- SetupCleanup/SetupFinally/SetupWith now carry target: Arg<Label>
- Add is_block_push()/is_pop_block() to PseudoInstruction/AnyInstruction
- Fix LoadSpecial stack_effect from (2,2) to (1,1)
- Set Setup* stack_effect_info to (0,0) for fall-through consistency
Fixes 3 test_coroutines expectedFailures:
- test_with_8, test_for_assign_raising_stop_async_iteration{,_2}1 parent c6f7c6e commit 7704b71
File tree
5 files changed
+590
-426
lines changed- Lib/test
- crates
- codegen/src
- compiler-core/src/bytecode
- vm/src
5 files changed
+590
-426
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1364 | 1364 | | |
1365 | 1365 | | |
1366 | 1366 | | |
1367 | | - | |
1368 | 1367 | | |
1369 | 1368 | | |
1370 | 1369 | | |
| |||
2170 | 2169 | | |
2171 | 2170 | | |
2172 | 2171 | | |
2173 | | - | |
2174 | 2172 | | |
2175 | 2173 | | |
2176 | 2174 | | |
| |||
2204 | 2202 | | |
2205 | 2203 | | |
2206 | 2204 | | |
2207 | | - | |
2208 | 2205 | | |
2209 | 2206 | | |
2210 | 2207 | | |
| |||
0 commit comments