From 35efe77b5555a5c7c15b9d466674bcfd2d2d643e Mon Sep 17 00:00:00 2001 From: reidenong Date: Wed, 28 Jan 2026 15:35:09 +0800 Subject: [PATCH 1/3] Add predicate symbol to truthiness case-switch --- Python/optimizer_symbols.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Python/optimizer_symbols.c b/Python/optimizer_symbols.c index 51cf6e189f0f49..fbc686f0c7f143 100644 --- a/Python/optimizer_symbols.c +++ b/Python/optimizer_symbols.c @@ -113,6 +113,9 @@ _PyUOpSymPrint(JitOptRef ref) case JIT_SYM_COMPACT_INT: printf("", (void *)sym); break; + case JIT_SYM_PREDICATE_TAG: + printf("", (void *)sym); + break; default: printf("", sym->tag, (void *)sym); break; @@ -666,6 +669,7 @@ _Py_uop_sym_truthiness(JitOptContext *ctx, JitOptRef ref) case JIT_SYM_NON_NULL_TAG: case JIT_SYM_UNKNOWN_TAG: case JIT_SYM_COMPACT_INT: + case JIT_SYM_PREDICATE_TAG: return -1; case JIT_SYM_KNOWN_CLASS_TAG: /* TODO : From 22c34252a9e4ddf44e5bd6758b82519141a6ffb4 Mon Sep 17 00:00:00 2001 From: reidenong Date: Wed, 28 Jan 2026 21:31:23 +0800 Subject: [PATCH 2/3] Add predicate symbol unit tests --- Python/optimizer_symbols.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Python/optimizer_symbols.c b/Python/optimizer_symbols.c index fbc686f0c7f143..bdf1b860d4e789 100644 --- a/Python/optimizer_symbols.c +++ b/Python/optimizer_symbols.c @@ -1475,6 +1475,26 @@ _Py_uop_symbols_test(PyObject *Py_UNUSED(self), PyObject *Py_UNUSED(ignored)) _Py_uop_sym_apply_predicate_narrowing(ctx, ref, true); TEST_PREDICATE(!_Py_uop_sym_is_const(ctx, subject), "predicate narrowing incorrectly narrowed subject (inverted/true)"); + subject = _Py_uop_sym_new_unknown(ctx); + value = _Py_uop_sym_new_const(ctx, one_obj); + ref = _Py_uop_sym_new_predicate(ctx, subject, value, JIT_PRED_IS); + if (PyJitRef_IsNull(subject) || PyJitRef_IsNull(value) || PyJitRef_IsNull(ref)) { + goto fail; + } + TEST_PREDICATE(_Py_uop_sym_matches_type(ref, &PyBool_Type), "predicate is not boolean"); + TEST_PREDICATE(_Py_uop_sym_truthiness(ctx, ref) == -1, "predicate is not unknown"); + TEST_PREDICATE(_Py_uop_sym_is_const(ctx, ref) == false, "predicate is constant"); + TEST_PREDICATE(_Py_uop_sym_get_const(ctx, ref) == NULL, "predicate is not NULL"); + TEST_PREDICATE(_Py_uop_sym_is_const(ctx, value) == true, "value is not constant"); + TEST_PREDICATE(_Py_uop_sym_get_const(ctx, value) == one_obj, "value is not 1"); + _Py_uop_sym_set_const(ctx, ref, Py_False); + TEST_PREDICATE(_Py_uop_sym_matches_type(ref, &PyBool_Type), "predicate is not boolean"); + TEST_PREDICATE(_Py_uop_sym_truthiness(ctx, ref) == 0, "predicate is not False"); + TEST_PREDICATE(_Py_uop_sym_is_const(ctx, ref) == true, "predicate is not constant"); + TEST_PREDICATE(_Py_uop_sym_get_const(ctx, ref) == Py_False, "predicate is not False"); + TEST_PREDICATE(_Py_uop_sym_is_const(ctx, value) == true, "value is not constant"); + TEST_PREDICATE(_Py_uop_sym_get_const(ctx, value) == one_obj, "value is not 1"); + val_big = PyNumber_Lshift(_PyLong_GetOne(), PyLong_FromLong(66)); if (val_big == NULL) { goto fail; From 7d66b07b3610fac97dfb6c7982a9b92a3aa9c297 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Fri, 30 Jan 2026 15:54:51 +0000 Subject: [PATCH 3/3] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../2026-01-30-15-54-50.gh-issue-144280.kgiP5R.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Core_and_Builtins/2026-01-30-15-54-50.gh-issue-144280.kgiP5R.rst diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2026-01-30-15-54-50.gh-issue-144280.kgiP5R.rst b/Misc/NEWS.d/next/Core_and_Builtins/2026-01-30-15-54-50.gh-issue-144280.kgiP5R.rst new file mode 100644 index 00000000000000..d6a4203189063a --- /dev/null +++ b/Misc/NEWS.d/next/Core_and_Builtins/2026-01-30-15-54-50.gh-issue-144280.kgiP5R.rst @@ -0,0 +1 @@ +Fix a bug in JIT where the predicate symbol had no truthiness