8000 GH-131798: Remove guard for known type in TO_BOOL_STR by fluhus · Pull Request #131816 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

GH-131798: Remove guard for known type in TO_BOOL_STR #131816

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Mar 30, 2025
Prev Previous commit
Next Next commit
Add test for optimizer TOS string guard removal
  • Loading branch information
fluhus committed Mar 26, 2025
commit 64aa8ebc4d3c357c593b70d87fa76aa307ca2b56
18 changes: 18 additions & 0 deletions Lib/test/test_capi/test_opt.py
Original file line number Diff line number Diff line change
Expand Up @@ -1581,6 +1581,24 @@ def testfunc(n):
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

Expand Down
0