Skip to content

Commit 64aa8eb

Browse files
committed
Add test for optimizer TOS string guard removal
1 parent e1f788a commit 64aa8eb

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

Lib/test/test_capi/test_opt.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1581,6 +1581,24 @@ def testfunc(n):
15811581
self.assertNotIn("_COMPARE_OP_INT", uops)
15821582
self.assertIn("_POP_TWO_LOAD_CONST_INLINE_BORROW", uops)
15831583

1584+
def test_remove_guard_for_known_type_str(self):
1585+
def f(n):
1586+
for i in range(n):
1587+
false = i == TIER2_THRESHOLD
1588+
empty = "X"[:false]
1589+
empty += "" # Make JIT realize this is a string.
1590+
if empty:
1591+
return 1
1592+
return 0
1593+
1594+
res, ex = self._run_with_optimizer(f, TIER2_THRESHOLD)
1595+
self.assertEqual(res, 0)
1596+
self.assertIsNotNone(ex)
1597+
uops = get_opnames(ex)
1598+
self.assertIn("_TO_BOOL_STR", uops)
1599+
self.assertNotIn("_GUARD_TOS_UNICODE", uops)
1600+
1601+
15841602
def global_identity(x):
15851603
return x
15861604

0 commit comments

Comments
 (0)