GH-129386: Use symbolic constants for specialization tests (GH-129415)

This commit is contained in:
Brandt Bucher 2025-01-29 10:49:58 -08:00 committed by GitHub
parent 99ed3025fe
commit 002c4e2982
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 152 additions and 132 deletions

View file

@ -931,8 +931,6 @@ dis_extended_arg_quick_code = """\
"""% (extended_arg_quick.__code__.co_firstlineno,
extended_arg_quick.__code__.co_firstlineno + 1,)
ADAPTIVE_WARMUP_DELAY = 2
class DisTestBase(unittest.TestCase):
"Common utilities for DisTests and TestDisTraceback"
@ -1259,8 +1257,9 @@ class DisTests(DisTestBase):
self.assertIsNone(e.__context__)
@staticmethod
def code_quicken(f, times=ADAPTIVE_WARMUP_DELAY):
for _ in range(times):
def code_quicken(f):
_testinternalcapi = import_helper.import_module("_testinternalcapi")
for _ in range(_testinternalcapi.SPECIALIZATION_THRESHOLD):
f()
@cpython_only
@ -1306,7 +1305,7 @@ class DisTests(DisTestBase):
@requires_specialization
def test_loop_quicken(self):
# Loop can trigger a quicken where the loop is located
self.code_quicken(loop_test, 4)
self.code_quicken(loop_test)
got = self.get_disassembly(loop_test, adaptive=True)
jit = import_helper.import_module("_testinternalcapi").jit_enabled()
expected = dis_loop_test_quickened_code.format("JIT" if jit else "NO_JIT")
@ -1315,8 +1314,9 @@ class DisTests(DisTestBase):
@cpython_only
@requires_specialization
def test_loop_with_conditional_at_end_is_quickened(self):
_testinternalcapi = import_helper.import_module("_testinternalcapi")
def for_loop_true(x):
for i in range(10):
for _ in range(_testinternalcapi.SPECIALIZATION_THRESHOLD):
if x:
pass
@ -1325,7 +1325,7 @@ class DisTests(DisTestBase):
self.get_disassembly(for_loop_true, adaptive=True))
def for_loop_false(x):
for i in range(10):
for _ in range(_testinternalcapi.SPECIALIZATION_THRESHOLD):
if x:
pass
@ -1335,7 +1335,7 @@ class DisTests(DisTestBase):
def while_loop():
i = 0
while i < 10:
while i < _testinternalcapi.SPECIALIZATION_THRESHOLD:
i += 1
while_loop()