Skip to content

Commit abe868f

Browse files
committed
refactor
1 parent d52937f commit abe868f

File tree

1 file changed

+9
-25
lines changed

1 file changed

+9
-25
lines changed

Lib/test/test_capi/test_opt.py

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2958,6 +2958,10 @@ def testfunc(n):
29582958
self.assertEqual(res, sum(range(TIER2_THRESHOLD)))
29592959
uops = get_opnames(ex)
29602960
self.assertIn("_CALL_LIST_APPEND", uops)
2961+
# _GUARD_TYPE_VERSION resolves the list type from recorded type
2962+
# info, so these redundant guards are eliminated:
2963+
self.assertNotIn("_GUARD_NOS_LIST", uops)
2964+
self.assertNotIn("_GUARD_CALLABLE_LIST_APPEND", uops)
29612965

29622966
def test_call_list_append_pop_top(self):
29632967
def testfunc(n):
@@ -3990,6 +3994,11 @@ class A:
39903994
self.assertEqual(count_ops(ex, "_POP_TOP_NOP"), 1)
39913995

39923996
def test_to_bool_dict(self):
3997+
# TO_BOOL_GENERIC (tier1) expands to:
3998+
# _RECORD_TOS_TYPE + _GUARD_TYPE_VERSION + _TO_BOOL
3999+
# The optimizer resolves the dict type from recorded type info
4000+
# via _GUARD_TYPE_VERSION (even if the version cache has a
4001+
# collision), then specializes _TO_BOOL → _TO_BOOL_DICT.
39934002
def testfunc(n):
39944003
d = {"a": 1}
39954004
count = 0
@@ -4021,31 +4030,6 @@ def testfunc(n):
40214030
self.assertIn("_TO_BOOL_DICT", uops)
40224031
self.assertNotIn("_TO_BOOL", uops)
40234032

4024-
def test_guard_type_version_resolves_type_for_to_bool(self):
4025-
# Tests the _GUARD_TYPE_VERSION + _RECORD_TOS_TYPE flow:
4026-
# TO_BOOL_GENERIC records the type, then _GUARD_TYPE_VERSION
4027-
# resolves it (even if the version cache has a collision),
4028-
# enabling the optimizer to specialize _TO_BOOL → _TO_BOOL_DICT.
4029-
def testfunc(n):
4030-
d = {"key": "value"}
4031-
count = 0
4032-
for _ in range(n):
4033-
if d:
4034-
count += 1
4035-
d["key"] = "value" # mutation keeps dict non-trivial
4036-
return count
4037-
4038-
res, ex = self._run_with_optimizer(testfunc, TIER2_THRESHOLD)
4039-
self.assertEqual(res, TIER2_THRESHOLD)
4040-
self.assertIsNotNone(ex)
4041-
uops = get_opnames(ex)
4042-
# The optimizer should resolve the dict type from recorded type
4043-
# info and specialize _TO_BOOL into _TO_BOOL_DICT
4044-
self.assertIn("_TO_BOOL_DICT", uops)
4045-
self.assertNotIn("_TO_BOOL", uops)
4046-
# _GUARD_TYPE_VERSION should be present (guards the dict type)
4047-
self.assertIn("_GUARD_TYPE_VERSION", uops)
4048-
40494033
def test_attr_promotion_failure(self):
40504034
# We're not testing for any specific uops here, just
40514035
# testing it doesn't crash.

0 commit comments

Comments
 (0)