Skip to content

Commit 6bdbe86

Browse files
committed
finl
1 parent e6f3033 commit 6bdbe86

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

crates/codegen/src/compile.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2393,6 +2393,15 @@ impl Compiler {
23932393

23942394
self.pop_fblock(FBlockType::HandlerCleanup);
23952395

2396+
// Create a block for normal path continuation (after handler body succeeds)
2397+
let handler_normal_exit = self.new_block();
2398+
emit!(
2399+
self,
2400+
Instruction::Jump {
2401+
target: handler_normal_exit,
2402+
}
2403+
);
2404+
23962405
// CPython compile.c:3568-3577 - cleanup_end block for named handler
23972406
// IMPORTANT: In CPython, cleanup_end is within outer SETUP_CLEANUP scope (line 3506),
23982407
// so when RERAISE is executed, it goes to the cleanup block which does POP_EXCEPT.
@@ -2417,6 +2426,9 @@ impl Compiler {
24172426
);
24182427
}
24192428

2429+
// Switch to normal exit block - this is where handler body success continues
2430+
self.switch_to_block(handler_normal_exit);
2431+
24202432
// Now pop ExceptionHandler - the normal path continues from here
24212433
// CPython compile.c:3557-3558: POP_BLOCK (HandlerCleanup) then POP_BLOCK (SETUP_CLEANUP)
24222434
// followed by POP_EXCEPT at line 3559

crates/vm/src/frame.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,12 @@ impl ExecutingFrame<'_> {
393393
}
394394
}
395395

396-
vm.contextualize_exception(&exception);
396+
// Only contextualize exception for new raises, not re-raises
397+
// CPython only calls _PyErr_SetObject (which does chaining) on initial raise
398+
// RERAISE just propagates the exception without modifying __context__
399+
if !is_reraise {
400+
vm.contextualize_exception(&exception);
401+
}
397402

398403
// Use exception table for zero-cost exception handling (CPython 3.11+)
399404
// But first check if there's a handler in block stack (hybrid approach)

0 commit comments

Comments
 (0)