gh-106529: Split FOR_ITER_{LIST,TUPLE} into uops (#106696)

Also rename `_ITER_EXHAUSTED_XXX` to `_IS_ITER_EXHAUSTED_XXX` to make it clear this is a test.
This commit is contained in:
Guido van Rossum 2023-07-13 17:27:35 -07:00 committed by GitHub
parent 128a6c1d88
commit 025995fead
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 385 additions and 118 deletions

View file

@ -2590,7 +2590,6 @@ class TestUops(unittest.TestCase):
for i in range(n):
total += i
return total
# import dis; dis.dis(testfunc)
opt = _testinternalcapi.get_uop_optimizer()
with temporary_optimizer(opt):
@ -2602,7 +2601,51 @@ class TestUops(unittest.TestCase):
# for i, (opname, oparg) in enumerate(ex):
# print(f"{i:4d}: {opname:<20s} {oparg:3d}")
uops = {opname for opname, _ in ex}
self.assertIn("_ITER_EXHAUSTED_RANGE", uops)
self.assertIn("_IS_ITER_EXHAUSTED_RANGE", uops)
# Verification that the jump goes past END_FOR
# is done by manual inspection of the output
def test_for_iter_list(self):
def testfunc(a):
total = 0
for i in a:
total += i
return total
opt = _testinternalcapi.get_uop_optimizer()
with temporary_optimizer(opt):
a = list(range(10))
total = testfunc(a)
self.assertEqual(total, 45)
ex = get_first_executor(testfunc)
self.assertIsNotNone(ex)
# for i, (opname, oparg) in enumerate(ex):
# print(f"{i:4d}: {opname:<20s} {oparg:3d}")
uops = {opname for opname, _ in ex}
self.assertIn("_IS_ITER_EXHAUSTED_LIST", uops)
# Verification that the jump goes past END_FOR
# is done by manual inspection of the output
def test_for_iter_tuple(self):
def testfunc(a):
total = 0
for i in a:
total += i
return total
opt = _testinternalcapi.get_uop_optimizer()
with temporary_optimizer(opt):
a = tuple(range(10))
total = testfunc(a)
self.assertEqual(total, 45)
ex = get_first_executor(testfunc)
self.assertIsNotNone(ex)
# for i, (opname, oparg) in enumerate(ex):
# print(f"{i:4d}: {opname:<20s} {oparg:3d}")
uops = {opname for opname, _ in ex}
self.assertIn("_IS_ITER_EXHAUSTED_TUPLE", uops)
# Verification that the jump goes past END_FOR
# is done by manual inspection of the output