Skip to content

Commit ed6e28f

Browse files
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 ed6e28f

File tree

5 files changed

+589
-426
lines changed

5 files changed

+589
-426
lines changed

Lib/test/test_coroutines.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1364,7 +1364,6 @@ async def foo():
13641364
self.fail('invalid asynchronous context manager did not fail')
13651365

13661366

1367-
@unittest.expectedFailure # TODO: RUSTPYTHON; AssertionError: "'async with' received an object from __aexit__ that does not implement __await__: int" does not match "'range_iterator' object is not callable"
13681367
def test_with_8(self):
13691368
CNT = 0
13701369

@@ -2170,7 +2169,6 @@ async def func(): pass
21702169
f"coroutine {coro_repr}")
21712170
self.assertIn("was never awaited", str(cm.unraisable.exc_value))
21722171

2173-
@unittest.expectedFailure # TODO: RUSTPYTHON; AssertionError: StopAsyncIteration not raised
21742172
def test_for_assign_raising_stop_async_iteration(self):
21752173
class BadTarget:
21762174
def __setitem__(self, key, value):
@@ -2204,7 +2202,6 @@ async def run_gen():
22042202
return 'end'
22052203
self.assertEqual(run_async(run_gen()), ([], 'end'))
22062204

2207-
@unittest.expectedFailure # TODO: RUSTPYTHON; AssertionError: StopAsyncIteration not raised
22082205
def test_for_assign_raising_stop_async_iteration_2(self):
22092206
class BadIterable:
22102207
def __iter__(self):

0 commit comments

Comments
 (0)