8000 update peepholer test · python/cpython@7c9c69b · GitHub
[go: up one dir, main page]

Skip to content

Commit 7c9c69b

Browse files
committed
update peepholer test
1 parent 2ea8425 commit 7c9c69b

File tree

1 file changed

+33
-9
lines changed

1 file changed

+33
-9
lines changed

Lib/test/test_peepholer.py

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1650,33 +1650,37 @@ def test_optimize_unary_not(self):
16501650
# test folding
16511651
before = [
16521652
('LOAD_SMALL_INT', 1, 0),
1653+
('TO_BOOL', None, 0),
16531654
('UNARY_NOT', None, 0),
16541655
('RETURN_VALUE', None, 0),
16551656
]
16561657
after = [
1657-
('LOAD_CONST', 0, 0),
1658+
('LOAD_CONST', 1, 0),
16581659
('RETURN_VALUE', None, 0),
16591660
]
1660-
self.cfg_optimization_test(before, after, consts=[], expected_consts=[False])
1661+
self.cfg_optimization_test(before, after, consts=[], expected_consts=[True, False])
16611662

16621663
# test cancel out
16631664
before = [
1664-
('LOAD_SMALL_INT', 1, 0),
1665+
('LOAD_NAME', 0, 0),
1666+
('TO_BOOL', None, 0),
16651667
('UNARY_NOT', None, 0),
16661668
('UNARY_NOT', None, 0),
16671669
('UNARY_NOT', None, 0),
16681670
('UNARY_NOT', None, 0),
16691671
('RETURN_VALUE', None, 0),
16701672
]
16711673
after = [
1672-
('LOAD_SMALL_INT', 1, 0),
1674+
('LOAD_NAME', 0, 0),
1675+
('TO_BOOL', None, 0),
16731676
('RETURN_VALUE', None, 0),
16741677
]
16751678
self.cfg_optimization_test(before, after, consts=[], expected_consts=[])
16761679

16771680
# test eliminate to bool
16781681
before = [
16791682
('LOAD_NAME', 0, 0),
1683+
('TO_BOOL', None, 0),
16801684
('UNARY_NOT', None, 0),
16811685
('TO_BOOL', None, 0),
16821686
('TO_BOOL', None, 0),
@@ -1685,29 +1689,48 @@ def test_optimize_unary_not(self):
16851689
]
16861690
after = [
16871691
('LOAD_NAME', 0, 0),
1692+
('TO_BOOL', None, 0),
16881693
('UNARY_NOT', None, 0),
16891694
('RETURN_VALUE', None, 0),
16901695
]
16911696
self.cfg_optimization_test(before, after, consts=[], expected_consts=[])
16921697

1698+
# test folding & cancel out
1699+
before = [
1700+
('LOAD_SMALL_INT', 1, 0),
1701+
('TO_BOOL', None, 0),
1702+
('UNARY_NOT', None, 0),
1703+
('UNARY_NOT', None, 0),
1704+
('UNARY_NOT', None, 0),
1705+
('UNARY_NOT', None, 0),
1706+
('RETURN_VALUE', None, 0),
1707+
]
1708+
after = [
1709+
('LOAD_CONST', 0, 0),
1710+
('RETURN_VALUE', None, 0),
1711+
]
1712+
self.cfg_optimization_test(before, after, consts=[], expected_consts=[True])
1713+
16931714
# test folding & eliminate to bool
16941715
before = [
16951716
('LOAD_SMALL_INT', 1, 0),
1717+
('TO_BOOL', None, 0),
16961718
('UNARY_NOT', None, 0),
16971719
('TO_BOOL', None, 0),
16981720
('TO_BOOL', None, 0),
16991721
('TO_BOOL', None, 0),
17001722
('RETURN_VALUE', None, 0),
17011723
]
17021724
after = [
1703-
('LOAD_CONST', 0, 0),
1725+
('LOAD_CONST', 1, 0),
17041726
('RETURN_VALUE', None, 0),
17051727
]
1706-
self.cfg_optimization_test(before, after, consts=[], expected_consts=[False])
1728+
self.cfg_optimization_test(before, after, consts=[], expected_consts=[True, False])
17071729

1708-
# test cancel out & eliminate to bool (to bool stays)
1730+
# test cancel out & eliminate to bool (to bool stays as we are not iterating to a fixed point)
17091731
before = [
1710-
('LOAD_SMALL_INT', 1, 0),
1732+
('LOAD_NAME', 0, 0),
1733+
('TO_BOOL', None, 0),
17111734
('UNARY_NOT', None, 0),
17121735
('UNARY_NOT', None, 0),
17131736
('UNARY_NOT', None, 0),
@@ -1716,7 +1739,8 @@ def test_optimize_unary_not(self):
17161739
('RETURN_VALUE', None, 0),
17171740
]
17181741
after = [
1719-
('LOAD_SMALL_INT', 1, 0),
1742+
('LOAD_NAME', 0, 0),
1743+
('TO_BOOL', None, 0),
17201744
('TO_BOOL', None, 0),
17211745
('RETURN_VALUE', None, 0),
17221746
]

0 commit comments

Comments
 (0)
0