Skip to content

bpo-47009: Let PRECALL_NO_KW_LIST_APPEND do its own POP_TOP #32239

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -5040,15 +5040,15 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
PyObject *list = SECOND();
DEOPT_IF(!PyList_Check(list), PRECALL);
STAT_INC(PRECALL, hit);
SKIP_CALL();
// PRECALL + CALL + POP_TOP
JUMPBY(INLINE_CACHE_ENTRIES_PRECALL + 1 + INLINE_CACHE_ENTRIES_CALL + 1);
assert(next_instr[-1] == POP_TOP);
PyObject *arg = POP();
if (_PyList_AppendTakeRef((PyListObject *)list, arg) < 0) {
goto error;
}
STACK_SHRINK(2);
Py_DECREF(list);
STACK_SHRINK(1);
Py_INCREF(Py_None);
SET_TOP(Py_None);
Py_DECREF(callable);
NOTRACE_DISPATCH();
}
Expand Down
5 changes: 4 additions & 1 deletion Python/specialize.c
Original file line number Diff line number Diff line change
Expand Up @@ -1435,7 +1435,10 @@ specialize_method_descriptor(PyMethodDescrObject *descr, _Py_CODEUNIT *instr,
}
PyInterpreterState *interp = _PyInterpreterState_GET();
PyObject *list_append = interp->callable_cache.list_append;
if ((PyObject *)descr == list_append && oparg == 1) {
_Py_CODEUNIT next = instr[INLINE_CACHE_ENTRIES_PRECALL + 1
+ INLINE_CACHE_ENTRIES_CALL + 1];
bool pop = (_Py_OPCODE(next) == POP_TOP);
if ((PyObject *)descr == list_append && oparg == 1 && pop) {
_Py_SET_OPCODE(*instr, PRECALL_NO_KW_LIST_APPEND);
return 0;
}
Expand Down