Skip to content

Commit 34b130d

Browse files
committed
Bytecode parity - iter folding, break/continue line, cold inlining
- Fold a constant list iterable into a constant tuple in for-loop iterable position, matching the CPython optimizer, and strip a redundant LIST_TO_TUPLE immediately before GET_ITER in the IR peephole pass. - Emit a Nop at the break/continue source range before unwinding so line events land on the break/continue statement instead of the following instruction. - Drop `propagate_disable_load_fast_borrow`; the forward propagation was over-zealous and the per-block inheritance in `new_block` plus the bare-except marker are enough. - Relax `inline_small_or_no_lineno_blocks` so small exit blocks at the tail of a cold block are always inlined, not just return epilogues. - Add codegen tests covering the LIST_TO_TUPLE/GET_ITER peephole and the late-CFG trace helper for a for-loop list-literal iterable.
1 parent 0a47dc2 commit 34b130d

16 files changed

Lines changed: 2105 additions & 557 deletions

‎Lib/test/test_compile.py‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1084,7 +1084,6 @@ def unused_block_while_else():
10841084
self.assertEqual('RETURN_VALUE', opcodes[-1].opname)
10851085
self.assertEqual(None, opcodes[-1].argval)
10861086

1087-
@unittest.expectedFailure # TODO: RUSTPYTHON; AssertionError: 3 != 8
10881087
def test_false_while_loop(self):
10891088
def break_in_while():
10901089
while False:

‎Lib/test/test_grammar.py‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,6 @@ def test_var_annot_syntax_errors(self):
304304
" nonlocal x\n"
305305
" x: int\n")
306306

307-
@unittest.expectedFailure # TODO: RUSTPYTHON
308307
def test_var_annot_basic_semantics(self):
309308
# execution order
310309
with self.assertRaises(ZeroDivisionError):

‎Lib/test/test_patma.py‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3448,7 +3448,6 @@ def f(command): # 0
34483448
self.assertListEqual(self._trace(f, "go x"), [1, 2, 4, 5])
34493449
self.assertListEqual(self._trace(f, "spam"), [1, 2, 4, 6, 7])
34503450

3451-
@unittest.expectedFailure # TODO: RUSTPYTHON
34523451
def test_default_capture(self):
34533452
def f(command): # 0
34543453
match command.split(): # 1
@@ -3463,7 +3462,6 @@ def f(command): # 0
34633462
self.assertListEqual(self._trace(f, "go x"), [1, 2, 4, 5])
34643463
self.assertListEqual(self._trace(f, "spam"), [1, 2, 4, 6, 7])
34653464

3466-
@unittest.expectedFailure # TODO: RUSTPYTHON
34673465
def test_no_default(self):
34683466
def f(command): # 0
34693467
match command.split(): # 1
@@ -3487,7 +3485,6 @@ def f(command): # 0
34873485
self.assertListEqual(self._trace(f, "go x"), [1, 2, 3])
34883486
self.assertListEqual(self._trace(f, "spam"), [1, 2, 3])
34893487

3490-
@unittest.expectedFailure # TODO: RUSTPYTHON
34913488
def test_only_default_capture(self):
34923489
def f(command): # 0
34933490
match command.split(): # 1

‎Lib/test/test_peepholer.py‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,7 @@ def test_constant_folding_binop(self):
441441
self.check_lnotab(code)
442442

443443

444+
@unittest.expectedFailure # TODO: RUSTPYTHON
444445
def test_constant_folding_remove_nop_location(self):
445446
sources = [
446447
"""
@@ -785,15 +786,13 @@ def f(a, b, c):
785786
c, b, a = a, b, c
786787
self.assertNotInBytecode(f, "SWAP")
787788

788-
@unittest.expectedFailure # TODO: RUSTPYTHON
789789
def test_static_swaps_match_mapping(self):
790790
for a, b, c in product("_a", "_b", "_c"):
791791
pattern = f"{{'a': {a}, 'b': {b}, 'c': {c}}}"
792792
with self.subTest(pattern):
793793
code = compile_pattern_with_fast_locals(pattern)
794794
self.assertNotInBytecode(code, "SWAP")
795795

796-
@unittest.expectedFailure # TODO: RUSTPYTHON
797796
def test_static_swaps_match_class(self):
798797
forms = [
799798
"C({}, {}, {})",
@@ -808,7 +807,6 @@ def test_static_swaps_match_class(self):
808807
code = compile_pattern_with_fast_locals(pattern)
809808
self.assertNotInBytecode(code, "SWAP")
810809

811-
@unittest.expectedFailure # TODO: RUSTPYTHON
812810
def test_static_swaps_match_sequence(self):
813811
swaps = {"*_, b, c", "a, *_, c", "a, b, *_"}
814812
forms = ["{}, {}, {}", "{}, {}, *{}", "{}, *{}, {}", "*{}, {}, {}"]

‎Lib/test/test_sys_settrace.py‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1957,8 +1957,6 @@ def test_jump_out_of_finally_block(output):
19571957
finally:
19581958
output.append(5)
19591959

1960-
# TODO: RUSTPYTHON
1961-
@unittest.expectedFailure
19621960
@jump_test(1, 5, [], (ValueError, "into an 'except'"))
19631961
def test_no_jump_into_bare_except_block(output):
19641962
output.append(1)
@@ -1967,8 +1965,6 @@ def test_no_jump_into_bare_except_block(output):
19671965
except:
19681966
output.append(5)
19691967

1970-
# TODO: RUSTPYTHON
1971-
@unittest.expectedFailure
19721968
@jump_test(1, 5, [], (ValueError, "into an 'except'"))
19731969
def test_no_jump_into_qualified_except_block(output):
19741970
output.append(1)

0 commit comments

Comments
 (0)