diff options
author | Guido van Rossum <guido@python.org> | 2023-07-12 17:23:59 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-12 17:23:59 (GMT) |
commit | dd1884dc5dc1a540c60e98ea1bc482a51d996564 (patch) | |
tree | 7b32b0062a4d1f3734c0a9b6ba4473e51fe4aa59 /Lib | |
parent | 7f55f58b6c97306da350f5b441d26f859e9d8f16 (diff) | |
download | cpython-dd1884dc5dc1a540c60e98ea1bc482a51d996564.zip cpython-dd1884dc5dc1a540c60e98ea1bc482a51d996564.tar.gz cpython-dd1884dc5dc1a540c60e98ea1bc482a51d996564.tar.bz2 |
gh-106529: Split FOR_ITER_RANGE into uops (#106638)
For an example of what this does for Tier 1 and Tier 2, see
https://github.com/python/cpython/issues/106529#issuecomment-1631649920
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_capi/test_misc.py | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/Lib/test/test_capi/test_misc.py b/Lib/test/test_capi/test_misc.py index 9c14a50..abdf7ed 100644 --- a/Lib/test/test_capi/test_misc.py +++ b/Lib/test/test_capi/test_misc.py @@ -2443,7 +2443,6 @@ class TestUops(unittest.TestCase): i += 1 opt = _testinternalcapi.get_uop_optimizer() - with temporary_optimizer(opt): testfunc(1000) @@ -2580,13 +2579,33 @@ class TestUops(unittest.TestCase): ex = get_first_executor(testfunc) self.assertIsNotNone(ex) - # for i, (opname, oparg) in enumerate(ex): - # print(f"{i:4d}: {opname:<20s} {oparg:4d}") uops = {opname for opname, _ in ex} # Since there is no JUMP_FORWARD instruction, # look for indirect evidence: the += operator self.assertIn("_BINARY_OP_ADD_INT", uops) + def test_for_iter_range(self): + def testfunc(n): + total = 0 + for i in range(n): + total += i + return total + # import dis; dis.dis(testfunc) + + opt = _testinternalcapi.get_uop_optimizer() + with temporary_optimizer(opt): + total = testfunc(10) + 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("_ITER_EXHAUSTED_RANGE", uops) + # Verification that the jump goes past END_FOR + # is done by manual inspection of the output + if __name__ == "__main__": unittest.main() |