Skip to content

Commit a9bca03

Browse files
committed
Fix tests that checked for LOAD_FAST instructions that are now optimized to borrowed variants
1 parent bf19b7d commit a9bca03

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

Lib/test/test_peepholer.py

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -906,7 +906,7 @@ def test_load_fast_known_simple(self):
906906
def f():
907907
x = 1
908908
y = x + x
909-
self.assertInBytecode(f, 'LOAD_FAST_LOAD_FAST')
909+
self.assertInBytecode(f, 'LOAD_FAST_BORROW_LOAD_FAST_BORROW')
910910

911911
def test_load_fast_unknown_simple(self):
912912
def f():
@@ -927,27 +927,27 @@ def f():
927927
def test_load_fast_known_because_parameter(self):
928928
def f1(x):
929929
print(x)
930-
self.assertInBytecode(f1, 'LOAD_FAST')
930+
self.assertInBytecode(f1, 'LOAD_FAST_BORROW')
931931
self.assertNotInBytecode(f1, 'LOAD_FAST_CHECK')
932932

933933
def f2(*, x):
934934
print(x)
935-
self.assertInBytecode(f2, 'LOAD_FAST')
935+
self.assertInBytecode(f2, 'LOAD_FAST_BORROW')
936936
self.assertNotInBytecode(f2, 'LOAD_FAST_CHECK')
937937

938938
def f3(*args):
939939
print(args)
940-
self.assertInBytecode(f3, 'LOAD_FAST')
940+
self.assertInBytecode(f3, 'LOAD_FAST_BORROW')
941941
self.assertNotInBytecode(f3, 'LOAD_FAST_CHECK')
942942

943943
def f4(**kwargs):
944944
print(kwargs)
945-
self.assertInBytecode(f4, 'LOAD_FAST')
945+
self.assertInBytecode(f4, 'LOAD_FAST_BORROW')
946946
self.assertNotInBytecode(f4, 'LOAD_FAST_CHECK')
947947

948948
def f5(x=0):
949949
print(x)
950-
self.assertInBytecode(f5, 'LOAD_FAST')
950+
self.assertInBytecode(f5, 'LOAD_FAST_BORROW')
951951
self.assertNotInBytecode(f5, 'LOAD_FAST_CHECK')
952952

953953
def test_load_fast_known_because_already_loaded(self):
@@ -957,7 +957,7 @@ def f():
957957
print(x)
958958
print(x)
959959
self.assertInBytecode(f, 'LOAD_FAST_CHECK')
960-
self.assertInBytecode(f, 'LOAD_FAST')
960+
self.assertInBytecode(f, 'LOAD_FAST_BORROW')
961961

962962
def test_load_fast_known_multiple_branches(self):
963963
def f():
@@ -966,7 +966,7 @@ def f():
966966
else:
967967
x = 2
968968
print(x)
969-
self.assertInBytecode(f, 'LOAD_FAST')
969+
self.assertInBytecode(f, 'LOAD_FAST_BORROW')
970970
self.assertNotInBytecode(f, 'LOAD_FAST_CHECK')
971971

972972
def test_load_fast_unknown_after_error(self):
@@ -1010,27 +1010,27 @@ def f():
10101010
print(a00, a01, a62, a63)
10111011
print(a64, a65, a78, a79)
10121012

1013-
self.assertInBytecode(f, 'LOAD_FAST_LOAD_FAST', ("a00", "a01"))
1013+
self.assertInBytecode(f, 'LOAD_FAST_BORROW_LOAD_FAST_BORROW', ("a00", "a01"))
10141014
self.assertNotInBytecode(f, 'LOAD_FAST_CHECK', "a00")
10151015
self.assertNotInBytecode(f, 'LOAD_FAST_CHECK', "a01")
10161016
for i in 62, 63:
10171017
# First 64 locals: analyze completely
1018-
self.assertInBytecode(f, 'LOAD_FAST', f"a{i:02}")
1018+
self.assertInBytecode(f, 'LOAD_FAST_BORROW', f"a{i:02}")
10191019
self.assertNotInBytecode(f, 'LOAD_FAST_CHECK', f"a{i:02}")
10201020
for i in 64, 65, 78, 79:
10211021
# Locals >=64 not in the same basicblock
10221022
self.assertInBytecode(f, 'LOAD_FAST_CHECK', f"a{i:02}")
10231023
self.assertNotInBytecode(f, 'LOAD_FAST', f"a{i:02}")
10241024
for i in 70, 71:
10251025
# Locals >=64 in the same basicblock
1026-
self.assertInBytecode(f, 'LOAD_FAST', f"a{i:02}")
1026+
self.assertInBytecode(f, 'LOAD_FAST_BORROW', f"a{i:02}")
10271027
self.assertNotInBytecode(f, 'LOAD_FAST_CHECK', f"a{i:02}")
10281028
# del statements should invalidate within basicblocks.
10291029
self.assertInBytecode(f, 'LOAD_FAST_CHECK', "a72")
10301030
self.assertNotInBytecode(f, 'LOAD_FAST', "a72")
10311031
# previous checked loads within a basicblock enable unchecked loads
10321032
self.assertInBytecode(f, 'LOAD_FAST_CHECK', "a73")
1033-
self.assertInBytecode(f, 'LOAD_FAST', "a73")
1033+
self.assertInBytecode(f, 'LOAD_FAST_BORROW', "a73")
10341034

10351035
def test_setting_lineno_no_undefined(self):
10361036
code = textwrap.dedent("""\
@@ -1048,7 +1048,7 @@ def f():
10481048
ns = {}
10491049
exec(code, ns)
10501050
f = ns['f']
1051-
self.assertInBytecode(f, "LOAD_FAST")
1051+
self.assertInBytecode(f, "LOAD_FAST_BORROW")
10521052
self.assertNotInBytecode(f, "LOAD_FAST_CHECK")
10531053
co_code = f.__code__.co_code
10541054
def trace(frame, event, arg):
@@ -1060,7 +1060,7 @@ def trace(frame, event, arg):
10601060
sys.settrace(trace)
10611061
result = f()
10621062
self.assertIsNone(result)
1063-
self.assertInBytecode(f, "LOAD_FAST")
1063+
self.assertInBytecode(f, "LOAD_FAST_BORROW")
10641064
self.assertNotInBytecode(f, "LOAD_FAST_CHECK")
10651065
self.assertEqual(f.__code__.co_code, co_code)
10661066

@@ -1080,7 +1080,7 @@ def f():
10801080
ns = {}
10811081
exec(code, ns)
10821082
f = ns['f']
1083-
self.assertInBytecode(f, "LOAD_FAST")
1083+
self.assertInBytecode(f, "LOAD_FAST_BORROW")
10841084
self.assertNotInBytecode(f, "LOAD_FAST_CHECK")
10851085
co_code = f.__code__.co_code
10861086
def trace(frame, event, arg):
@@ -1094,7 +1094,7 @@ def trace(frame, event, arg):
10941094
sys.settrace(trace)
10951095
result = f()
10961096
self.assertEqual(result, 4)
1097-
self.assertInBytecode(f, "LOAD_FAST")
1097+
self.assertInBytecode(f, "LOAD_FAST_BORROW")
10981098
self.assertNotInBytecode(f, "LOAD_FAST_CHECK")
10991099
self.assertEqual(f.__code__.co_code, co_code)
11001100

@@ -1114,7 +1114,7 @@ def f():
11141114
ns = {}
11151115
exec(code, ns)
11161116
f = ns['f']
1117-
self.assertInBytecode(f, "LOAD_FAST")
1117+
self.assertInBytecode(f, "LOAD_FAST_BORROW")
11181118
self.assertNotInBytecode(f, "LOAD_FAST_CHECK")
11191119
co_code = f.__code__.co_code
11201120
def trace(frame, event, arg):
@@ -1128,7 +1128,7 @@ def trace(frame, event, arg):
11281128
sys.settrace(trace)
11291129
result = f()
11301130
self.assertEqual(result, 4)
1131-
self.assertInBytecode(f, "LOAD_FAST")
1131+
self.assertInBytecode(f, "LOAD_FAST_BORROW")
11321132
self.assertNotInBytecode(f, "LOAD_FAST_CHECK")
11331133
self.assertEqual(f.__code__.co_code, co_code)
11341134

@@ -1146,7 +1146,7 @@ def f():
11461146
ns = {}
11471147
exec(code, ns)
11481148
f = ns['f']
1149-
self.assertInBytecode(f, "LOAD_FAST")
1149+
self.assertInBytecode(f, "LOAD_FAST_BORROW")
11501150
self.assertNotInBytecode(f, "LOAD_FAST_CHECK")
11511151
return f
11521152

@@ -1160,7 +1160,7 @@ def trace(frame, event, arg):
11601160
return trace
11611161
sys.settrace(trace)
11621162
f()
1163-
self.assertInBytecode(f, "LOAD_FAST")
1163+
self.assertInBytecode(f, "LOAD_FAST_BORROW")
11641164
self.assertNotInBytecode(f, "LOAD_FAST_CHECK")
11651165

11661166
def test_initializing_local_does_not_add_check(self):
@@ -1173,7 +1173,7 @@ def trace(frame, event, arg):
11731173
return trace
11741174
sys.settrace(trace)
11751175
f()
1176-
self.assertInBytecode(f, "LOAD_FAST")
1176+
self.assertInBytecode(f, "LOAD_FAST_BORROW")
11771177
self.assertNotInBytecode(f, "LOAD_FAST_CHECK")
11781178

11791179

@@ -2325,9 +2325,9 @@ def test_list_to_tuple_get_iter(self):
23252325
]
23262326
expected_insts = [
23272327
("BUILD_LIST", 0, 1),
2328-
("LOAD_FAST", 0, 2),
2328+
("LOAD_FAST_BORROW", 0, 2),
23292329
("LIST_EXTEND", 1, 3),
2330-
("LOAD_FAST", 1, 4),
2330+
("LOAD_FAST_BORROW", 1, 4),
23312331
("LIST_EXTEND", 1, 5),
23322332
("NOP", None, 6), # ("CALL_INTRINSIC_1", INTRINSIC_LIST_TO_TUPLE, 6),
23332333
("GET_ITER", None, 7),

0 commit comments

Comments
 (0)