mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
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:
parent
128a6c1d88
commit
025995fead
6 changed files with 385 additions and 118 deletions
|
@ -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
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue