GH-131798: Remove type checks for _TO_BOOL_STR (GH-131816)

This commit is contained in:
Amit Lavon 2025-03-30 16:07:25 -07:00 committed by GitHub
parent 39fa19a4cc
commit 685fd74f81
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 185 additions and 125 deletions

View file

@ -1581,6 +1581,24 @@ class TestUopsOptimization(unittest.TestCase):
self.assertNotIn("_COMPARE_OP_INT", uops)
self.assertIn("_POP_TWO_LOAD_CONST_INLINE_BORROW", uops)
def test_remove_guard_for_known_type_str(self):
def f(n):
for i in range(n):
false = i == TIER2_THRESHOLD
empty = "X"[:false]
empty += "" # Make JIT realize this is a string.
if empty:
return 1
return 0
res, ex = self._run_with_optimizer(f, TIER2_THRESHOLD)
self.assertEqual(res, 0)
self.assertIsNotNone(ex)
uops = get_opnames(ex)
self.assertIn("_TO_BOOL_STR", uops)
self.assertNotIn("_GUARD_TOS_UNICODE", uops)
def global_identity(x):
return x