summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2023-07-14 00:27:35 (GMT)
committerGitHub <noreply@github.com>2023-07-14 00:27:35 (GMT)
commit025995feadaeebeef5d808f2564f0fd65b704ea5 (patch)
tree209a28f3409c87d40a1af03a8dac92571e151078 /Lib
parent128a6c1d889639012c83c122b82c9cdf0b62d587 (diff)
downloadcpython-025995feadaeebeef5d808f2564f0fd65b704ea5.zip
cpython-025995feadaeebeef5d808f2564f0fd65b704ea5.tar.gz
cpython-025995feadaeebeef5d808f2564f0fd65b704ea5.tar.bz2
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.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_capi/test_misc.py47
1 files changed, 45 insertions, 2 deletions
diff --git a/Lib/test/test_capi/test_misc.py b/Lib/test/test_capi/test_misc.py
index abdf7ed..43c0446 100644
--- a/Lib/test/test_capi/test_misc.py
+++ b/Lib/test/test_capi/test_misc.py
@@ -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