Skip to content

Commit 1a868d1

Browse files
committed
gh-131798: Add _GET_ITER_TRAD to JIT optimizer
1 parent d61fcf8 commit 1a868d1

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

Lib/test/test_capi/test_opt.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,25 @@ def testfunc(n):
438438
self.assertNotIn("_GET_ITER", uops)
439439
self.assertNotIn("_GET_ITER_VIRTUAL", uops)
440440
self.assertNotIn("_GET_ITER_SELF", uops)
441+
self.assertNotIn("_GUARD_NOS_NULL", uops)
442+
443+
def test_get_iter_trad_for_iter_tier_two(self):
444+
d = {v: v for v in range(20)}
441445

446+
def testfunc(n):
447+
total = 0
448+
while n:
449+
n -= 1
450+
for _ in d:
451+
total += 1
452+
return total
453+
454+
self.assertEqual(testfunc(TIER2_THRESHOLD), TIER2_THRESHOLD * len(d))
455+
ex = get_first_executor(testfunc)
456+
self.assertIsNotNone(ex)
457+
uops = get_opnames(ex)
458+
self.assertIn("_FOR_ITER_TIER_TWO", uops)
459+
self.assertNotIn("_GET_ITER_TRAD", uops)
442460

443461
def test_for_iter_range(self):
444462
def testfunc(n):

Python/optimizer_bytecodes.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1443,6 +1443,12 @@ dummy_func(void) {
14431443
}
14441444
}
14451445

1446+
op(_GET_ITER_TRAD, (iterable -- iter, index_or_null)) {
1447+
(void)iterable;
1448+
iter = sym_new_not_null(ctx);
1449+
index_or_null = sym_new_null(ctx);
1450+
}
1451+
14461452
op(_GUARD_ITERATOR, (iterable -- iterable)) {
14471453
bool definite = true;
14481454
PyTypeObject *tp = sym_get_type(iterable);

Python/optimizer_cases.c.h

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)