From cc75b3d04c9c57d1421f17ccaa2b5fca2f9a6e7b Mon Sep 17 00:00:00 2001 From: Sacul0457Deve <183588943+Sacul0457@users.noreply.github.com.> Date: Sat, 11 Apr 2026 19:33:30 +0800 Subject: [PATCH 1/5] Fix _Py_uop_sym_get_type and update test --- Python/optimizer_symbols.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Python/optimizer_symbols.c b/Python/optimizer_symbols.c index 6230b8948697e2..11157483d63a97 100644 --- a/Python/optimizer_symbols.c +++ b/Python/optimizer_symbols.c @@ -783,6 +783,7 @@ _Py_uop_sym_get_type(JitOptRef ref) case JIT_SYM_NON_NULL_TAG: case JIT_SYM_UNKNOWN_TAG: case JIT_SYM_RECORDED_TYPE_TAG: + case JIT_SYM_RECORDED_GEN_FUNC_TAG: return NULL; case JIT_SYM_RECORDED_VALUE_TAG: if (sym->recorded_value.known_type) { @@ -804,8 +805,6 @@ _Py_uop_sym_get_type(JitOptRef ref) return &PyBool_Type; case JIT_SYM_COMPACT_INT: return &PyLong_Type; - case JIT_SYM_RECORDED_GEN_FUNC_TAG: - return &PyGen_Type; } Py_UNREACHABLE(); } @@ -2211,7 +2210,8 @@ _Py_uop_symbols_test(PyObject *Py_UNUSED(self), PyObject *Py_UNUSED(ignored)) /* Test that recorded type aren't treated as known values*/ JitOptRef rg1 = _Py_uop_sym_new_unknown(ctx); _Py_uop_sym_set_recorded_gen_func(ctx, rg1, func); - TEST_PREDICATE(_Py_uop_sym_matches_type(rg1, &PyGen_Type), "recorded gen func not treated as generator"); + TEST_PREDICATE(!_Py_uop_sym_matches_type(rg1, &PyGen_Type), "recorded gen func treated as generator"); + TEST_PREDICATE(_Py_uop_sym_get_probable_type(rg1) == NULL, "recorded gen func treated as generator"); TEST_PREDICATE(_Py_uop_sym_get_const(ctx, rg1) == NULL, "recorded gen func is treated as known value"); /* Test that setting type narrows correctly */ From c03a070f06f86f93cfcdf8b1204e289d607bb0ca Mon Sep 17 00:00:00 2001 From: Sacul0457Deve <183588943+Sacul0457@users.noreply.github.com.> Date: Sat, 11 Apr 2026 19:48:20 +0800 Subject: [PATCH 2/5] edit _Py_uop_sym_get_probable_type and update test --- Python/optimizer_symbols.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Python/optimizer_symbols.c b/Python/optimizer_symbols.c index 11157483d63a97..5504fe64b384f9 100644 --- a/Python/optimizer_symbols.c +++ b/Python/optimizer_symbols.c @@ -1,4 +1,4 @@ -#ifdef _Py_TIER2 +ifdef _Py_TIER2 #include "Python.h" @@ -829,7 +829,7 @@ _Py_uop_sym_get_probable_type(JitOptRef ref) case JIT_SYM_KNOWN_VALUE_TAG: return _Py_uop_sym_get_type(ref); case JIT_SYM_RECORDED_GEN_FUNC_TAG: - return NULL; + return &PyGen_Type; case JIT_SYM_RECORDED_VALUE_TAG: return Py_TYPE(sym->recorded_value.value); case JIT_SYM_RECORDED_TYPE_TAG: @@ -2211,7 +2211,7 @@ _Py_uop_symbols_test(PyObject *Py_UNUSED(self), PyObject *Py_UNUSED(ignored)) JitOptRef rg1 = _Py_uop_sym_new_unknown(ctx); _Py_uop_sym_set_recorded_gen_func(ctx, rg1, func); TEST_PREDICATE(!_Py_uop_sym_matches_type(rg1, &PyGen_Type), "recorded gen func treated as generator"); - TEST_PREDICATE(_Py_uop_sym_get_probable_type(rg1) == NULL, "recorded gen func treated as generator"); + TEST_PREDICATE(_Py_uop_sym_get_probable_type(rg1) == &PyGen_Type, "recorded gen func not treated as generator"); TEST_PREDICATE(_Py_uop_sym_get_const(ctx, rg1) == NULL, "recorded gen func is treated as known value"); /* Test that setting type narrows correctly */ From f9345a38bbcbcf83d06bb1cb66f6f6b867cc09b2 Mon Sep 17 00:00:00 2001 From: Sacul0457Deve <183588943+Sacul0457@users.noreply.github.com.> Date: Sat, 11 Apr 2026 19:48:52 +0800 Subject: [PATCH 3/5] forgot to add back the ifdef... --- Python/optimizer_symbols.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Python/optimizer_symbols.c b/Python/optimizer_symbols.c index 5504fe64b384f9..b27f58b3a3b43b 100644 --- a/Python/optimizer_symbols.c +++ b/Python/optimizer_symbols.c @@ -1,4 +1,4 @@ -ifdef _Py_TIER2 +#ifdef _Py_TIER2 #include "Python.h" From d84808301fe607bcfad77b975d4a962d07fd53aa Mon Sep 17 00:00:00 2001 From: Sacul0457Deve <183588943+Sacul0457@users.noreply.github.com.> Date: Sat, 11 Apr 2026 21:27:35 +0800 Subject: [PATCH 4/5] use rg2 and rg3 instead of rg1 where appropriate --- Python/optimizer_symbols.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Python/optimizer_symbols.c b/Python/optimizer_symbols.c index b27f58b3a3b43b..1382460502e0ab 100644 --- a/Python/optimizer_symbols.c +++ b/Python/optimizer_symbols.c @@ -2219,13 +2219,13 @@ _Py_uop_symbols_test(PyObject *Py_UNUSED(self), PyObject *Py_UNUSED(ignored)) JitOptRef rg2 = _Py_uop_sym_new_unknown(ctx); _Py_uop_sym_set_recorded_gen_func(ctx, rg2, func); _Py_uop_sym_set_type(ctx, rg2, &PyGen_Type); - TEST_PREDICATE(_Py_uop_sym_matches_type(rg1, &PyGen_Type), "recorded gen func not treated as generator"); + TEST_PREDICATE(!_Py_uop_sym_matches_type(rg2, &PyGen_Type), "recorded gen func treated as generator"); TEST_PREDICATE(_Py_uop_sym_get_const(ctx, rg2) == NULL, "known type is treated as known value"); JitOptRef rg3 = _Py_uop_sym_new_unknown(ctx); _Py_uop_sym_set_recorded_gen_func(ctx, rg3, func); _Py_uop_sym_set_type_version(ctx, rg3, PyGen_Type.tp_version_tag); - TEST_PREDICATE(_Py_uop_sym_matches_type(rg1, &PyGen_Type), "recorded gen func not treated as generator"); + TEST_PREDICATE(!_Py_uop_sym_matches_type(rg3, &PyGen_Type), "recorded gen func treated as generator"); TEST_PREDICATE(_Py_uop_sym_get_const(ctx, rg3) == NULL, "recorded value with type is treated as known"); /* Test contradictions */ From c76db655df0bf35d989f75fd648ad09cb519d95e Mon Sep 17 00:00:00 2001 From: Sacul0457Deve <183588943+Sacul0457@users.noreply.github.com.> Date: Sat, 11 Apr 2026 22:33:31 +0800 Subject: [PATCH 5/5] add more tests --- Python/optimizer_symbols.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Python/optimizer_symbols.c b/Python/optimizer_symbols.c index 1382460502e0ab..d0f33b80a570dd 100644 --- a/Python/optimizer_symbols.c +++ b/Python/optimizer_symbols.c @@ -2220,12 +2220,14 @@ _Py_uop_symbols_test(PyObject *Py_UNUSED(self), PyObject *Py_UNUSED(ignored)) _Py_uop_sym_set_recorded_gen_func(ctx, rg2, func); _Py_uop_sym_set_type(ctx, rg2, &PyGen_Type); TEST_PREDICATE(!_Py_uop_sym_matches_type(rg2, &PyGen_Type), "recorded gen func treated as generator"); + TEST_PREDICATE(_Py_uop_sym_get_probable_type(rg2) == &PyGen_Type, "recorded gen func not treated as generator"); TEST_PREDICATE(_Py_uop_sym_get_const(ctx, rg2) == NULL, "known type is treated as known value"); JitOptRef rg3 = _Py_uop_sym_new_unknown(ctx); _Py_uop_sym_set_recorded_gen_func(ctx, rg3, func); _Py_uop_sym_set_type_version(ctx, rg3, PyGen_Type.tp_version_tag); TEST_PREDICATE(!_Py_uop_sym_matches_type(rg3, &PyGen_Type), "recorded gen func treated as generator"); + TEST_PREDICATE(_Py_uop_sym_get_probable_type(rg3) == &PyGen_Type, "recorded gen func not treated as generator"); TEST_PREDICATE(_Py_uop_sym_get_const(ctx, rg3) == NULL, "recorded value with type is treated as known"); /* Test contradictions */