GH-131798: Narrow types more aggressively in the JIT (GH-134373)

This commit is contained in:
Brandt Bucher 2025-05-20 18:09:51 -04:00 committed by GitHub
parent e1c0c451a2
commit 2f0570caf4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 180 additions and 88 deletions

View file

@ -2137,6 +2137,25 @@ class TestUopsOptimization(unittest.TestCase):
self.assertNotIn("_TO_BOOL_BOOL", uops)
self.assertIn("_GUARD_IS_TRUE_POP", uops)
def test_set_type_version_sets_type(self):
class C:
A = 1
def testfunc(n):
x = 0
c = C()
for _ in range(n):
x += c.A # Guarded.
x += type(c).A # Unguarded!
return x
res, ex = self._run_with_optimizer(testfunc, TIER2_THRESHOLD)
self.assertEqual(res, 2 * TIER2_THRESHOLD)
self.assertIsNotNone(ex)
uops = get_opnames(ex)
self.assertIn("_GUARD_TYPE_VERSION", uops)
self.assertNotIn("_CHECK_ATTR_CLASS", uops)
def global_identity(x):
return x