Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Keep except_handler blocks reachable in eliminate_unreachable_blocks
After convert_pseudo_ops lowers SETUP_FINALLY to a plain NOP, the only
remaining link from the try body to the except_handler block was the
per-instruction except_handler annotation. When earlier passes had
already removed every NOP that carried that annotation (e.g. an empty
try body with `pass`), the handler block became unreachable from the
entry block and its instructions were cleared, dropping the handler
entirely. Seed reachability with blocks already marked except_handler
so handler dispatch survives independent of the in-block annotation.

Also drop two expectedFailure markers in test_patma whose match-tracing
expectations now pass.
  • Loading branch information
youknowone committed May 19, 2026
commit f0f94ece5e25960407f5c4dc988a0b3b30ca081c
2 changes: 0 additions & 2 deletions Lib/test/test_patma.py
Original file line number Diff line number Diff line change
Expand Up @@ -3433,7 +3433,6 @@ def trace(frame, event, arg):
sys.settrace(old_trace)
return actual_linenos

@unittest.expectedFailure # TODO: RUSTPYTHON
def test_default_wildcard(self):
def f(command): # 0
match command.split(): # 1
Expand Down Expand Up @@ -3494,7 +3493,6 @@ def f(command): # 0
self.assertListEqual(self._trace(f, "go x"), [1, 2, 3])
self.assertListEqual(self._trace(f, "spam"), [1, 2, 3])

@unittest.expectedFailure # TODO: RUSTPYTHON
def test_unreachable_code(self):
def f(command): # 0
match command: # 1
Expand Down
7 changes: 7 additions & 0 deletions crates/codegen/src/ir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -906,6 +906,13 @@ impl CodeInfo {
fn eliminate_unreachable_blocks(&mut self) {
let mut reachable = vec![false; self.blocks.len()];
reachable[0] = true;
// Exception handler blocks remain reachable via runtime dispatch even
// after convert_pseudo_ops drops SETUP_FINALLY targets from the CFG.
for (i, block) in self.blocks.iter().enumerate() {
if block.except_handler {
reachable[i] = true;
}
}

// Fixpoint: only mark targets of already-reachable blocks
let mut changed = true;
Expand Down