Skip to content

Commit b3648f0

Browse files
authored
gh-104584: Allow unspecialized instructions in superblocks (#106497)
This adds several of unspecialized opcodes to superblocks: TO_BOOL, BINARY_SUBSCR, STORE_SUBSCR, UNPACK_SEQUENCE, LOAD_GLOBAL, LOAD_ATTR, COMPARE_OP, BINARY_OP. While we may not want that eventually, for now this helps finding bugs. There is a rudimentary test checking for UNPACK_SEQUENCE. Once we're ready to undo this, that would be simple: just replace the call to variable_used_unspecialized with a call to variable_used (as shown in a comment). Or add individual opcdes to FORBIDDEN_NAMES_IN_UOPS.
1 parent 11038c5 commit b3648f0

File tree

4 files changed

+490
-128
lines changed

4 files changed

+490
-128
lines changed

Diff for: Lib/test/test_capi/test_misc.py

+28
Original file line numberDiff line numberDiff line change
@@ -2499,6 +2499,34 @@ def many_vars():
24992499
ex = get_first_executor(many_vars.__code__)
25002500
self.assertIn(("LOAD_FAST", 259), list(ex))
25012501

2502+
def test_unspecialized_unpack(self):
2503+
# An example of an unspecialized opcode
2504+
def testfunc(x):
2505+
i = 0
2506+
while i < x:
2507+
i += 1
2508+
a, b = {1: 2, 3: 3}
2509+
assert a == 1 and b == 3
2510+
i = 0
2511+
while i < x:
2512+
i += 1
2513+
2514+
opt = _testinternalcapi.get_uop_optimizer()
2515+
2516+
with temporary_optimizer(opt):
2517+
testfunc(10)
2518+
2519+
ex = None
2520+
for offset in range(0, len(testfunc.__code__.co_code), 2):
2521+
try:
2522+
ex = _testinternalcapi.get_executor(testfunc.__code__, offset)
2523+
break
2524+
except ValueError:
2525+
pass
2526+
self.assertIsNotNone(ex)
2527+
uops = {opname for opname, _ in ex}
2528+
self.assertIn("UNPACK_SEQUENCE", uops)
2529+
25022530

25032531
if __name__ == "__main__":
25042532
unittest.main()

0 commit comments

Comments
 (0)