Repository navigation
CALL_LIST_APPEND specialization can make no progress #141367
Description
Activity
- addedtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
on Nov 10, 2025 - addedinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
on Nov 10, 2025 @Fidget-Spinner , of course, I will take this, thanks.
Reacted by Ken JinI'm pretty sure 3.14 is affected too.
Actually, it isn't affected.
You can see your own comment on PR with this change:
#134240 (comment)So, basically, we should fix specialization on main branch only.
I'll create a PR soon.Reacted by Ken JinGreat observation, thanks!
@Fidget-Spinner , I've created a PR with your proposed solution, CI is green.
I've used_PyThreadState_GETinstead ofPyThreadState_GETbecause it's sligtly faster, IIUC.
And make test for bothlistandMyListappendspecialization.Rather than probing the stack
tstate->current_frame->stackpointer[-2], we should pass the arguments to_Py_Specialize_Call.
We also need to add an additional guard in_CALL_LIST_APPENDthatcallable == interp->callable_cache.list_append.Reacted by Mikhail EfimovRather than probing the stack
tstate->current_frame->stackpointer[-2], we should pass the arguments to_Py_Specialize_Call.Ok, I'll investigate this.
We also need to add an additional guard in
_CALL_LIST_APPENDthatcallable == interp->callable_cache.list_append.Do we really need this since
_GUARD_CALLABLE_LIST_APPENDis present?Maybe we should remove checking
DEOPT_IF(!PyList_CheckExact(self_o))in_GUARD_CALLABLE_LIST_APPENDbecause_GUARD_NOS_LISTis already used inCALL_LIST_APPENDmacro?Do we really need this since _GUARD_CALLABLE_LIST_APPEND is present?
No we don't. I was just looking at the uop, not the whole instruction.
Maybe we should remove checking DEOPT_IF(!PyList_CheckExact(self_o)) in _GUARD_CALLABLE_LIST_APPEND because _GUARD_NOS_LIST is already used in CALL_LIST_APPEND macro?
Yes, that makes sense.
Reacted by Mikhail EfimovWhile working on this issue I've found this PR:
https://github.com/python/cpython/pull/132018/files#diff-af5c4ee62cca27529efe0febc3babfd5745cc1ae48a280a58605a8c85ee38942R335Maybe we should change this test a little to use actual
SPECIALIZATION_THRESHOLDinstead of constant3?Maybe not for this PR, but if you open another PR to fix it I'd be open to merging.
Reacted by Mikhail Efimov
Bug report
Bug description:
CALL_LIST_APPENDrequiresselfto be aPyList_CheckExactinbytecodes.c. However, thespecialize.cdoesn't check that. This means there's a possible discrepancy between what we specialize for and what we deopt.The fix is to check that
selfis a list. It should be as simple asThe test case should be in
test_opcache.py, and test something likeand ensure that the append is not specialized to
CALL_LIST_APPEND.@efimov-mikhail can I let you take up this issue please? I'm pretty sure 3.14 is affected too.
CPython versions tested on:
CPython main branch, 3.15, 3.14
Operating systems tested on:
No response
Linked PRs