Bytecode parity CFG normalization and jump cleanup (#7721)

* typealias reviews

* Bytecode parity - try/except block order, CFG reorder

Reorder try/except/else/finally to emit else+finally before
except handlers matching CPython layout. Add set_no_location
for cleanup blocks. Extend CFG reorder pass to handle true-path
jump-back for generators, break/continue, and assert in loops.
Add stop-iteration error handler awareness to block protection.

* Align CFG cleanup bytecode with CPython

* Unmark test_dis.test_findlabels expected failure

* Compute target predecessor flags in single pass

remove_nops and remove_redundant_nops_in_blocks repeated
has_jump_predecessor / has_plain_jump_predecessor / target lookups
per block, scanning all blocks each time. With ~200,000 if blocks
this became O(B^2 * I) and timed out test_compile.test_stack_overflow.
Fold the three flags into one O(B * I) pass via
compute_target_predecessor_flags.

* Address review feedback on slice folding, fallthrough, attr-chain

- try_fold_constant_slice now delegates to try_fold_constant_expr so
  slice bounds accept the same constants other folding paths do
  (unary-folded values, __debug__, etc.).
- remove_nops resolves fallthrough predecessors through empty blocks
  via next_nonempty_block before checking ends_with_for_cleanup.
- should_deopt_borrowed_attr_chain ReturnIter matcher now accepts
  Instruction::CallKw alongside Instruction::Call, matching the
  Call/CallKw treatment in the surrounding deopt trigger check.

* remove test
This commit is contained in:
Jeong, YunWon authored and GitHub committed 2026-04-30 23:30:27 +09:00
1 parent edb2cc48d2
commit c19af81e05
4 files changed
+3078 -485

No files matched your search

-1
View File
@@ -2410,7 +2410,6 @@ class TestFinderMethods(unittest.TestCase):
res = tuple(dis._find_store_names(code))
self.assertEqual(res, expected)
@unittest.expectedFailure # TODO: RUSTPYTHON
def test_findlabels(self):
labels = dis.findlabels(jumpy.__code__.co_code)
jumps = [
File diff suppressed because it is too large. Load diff
+1404 -132
View File
File diff suppressed because it is too large. Load diff
+1 -1
View File
@@ -1768,7 +1768,7 @@ impl SymbolTableBuilder {
}) => {
let Some(name_expr) = name.as_name_expr() else {
return Err(SymbolTableError {
error: "type alias expect name".to_owned(),
error: "type alias expects name".to_owned(),
location: Some(
self.source_file
.to_source_code()