Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Clean things up a bit
  • Loading branch information
brandtbucher committed Mar 6, 2022
commit 8f213801e50b519a5c27c789db4ed6554a6287db
12 changes: 5 additions & 7 deletions Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -4564,12 +4564,12 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
We'll be passing `oparg + 1` to call_function, to
make it accept the `self` as a first argument.
*/
int is_method = (PEEK(oparg + 2) != NULL);
int nargs = oparg + is_method;
int is_meth = is_method(stack_pointer, oparg);
int nargs = oparg + is_meth;
/* Move ownership of reference from stack to call_shape
* and make sure that NULL is cleared from stack */
PyObject *function = PEEK(nargs + 1);
if (!is_method && Py_TYPE(function) == &PyMethod_Type) {
if (!is_meth && Py_TYPE(function) == &PyMethod_Type) {
PyObject *meth = ((PyMethodObject *)function)->im_func;
PyObject *self = ((PyMethodObject *)function)->im_self;
Py_INCREF(meth);
Expand All @@ -4583,8 +4583,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
}

TARGET(PRECALL_BOUND_METHOD) {
int is_method = (PEEK(oparg + 2) != NULL);
DEOPT_IF(is_method, PRECALL);
DEOPT_IF(is_method(stack_pointer, oparg), PRECALL);
PyObject *function = PEEK(oparg + 1);
DEOPT_IF(Py_TYPE(function) != &PyMethod_Type, PRECALL);
STAT_INC(PRECALL, hit);
Expand All @@ -4600,8 +4599,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
}

TARGET(PRECALL_PYFUNC) {
int is_method = (PEEK(oparg + 2) != NULL);
int nargs = oparg + is_method;
int nargs = oparg + is_method(stack_pointer, oparg);
PyObject *function = PEEK(nargs + 1);
DEOPT_IF(Py_TYPE(function) != &PyFunction_Type, PRECALL);
STAT_INC(PRECALL, hit);
Expand Down
25 changes: 10 additions & 15 deletions Python/specialize.c
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ optimize(_Py_CODEUNIT *instructions, int len)
else {
assert(!_PyOpcode_InlineCacheEntries[opcode]);
switch (opcode) {
case JUMP_ABSOLUTE:
case JUMP_ABSOLUTE:
instructions[i] = _Py_MAKECODEUNIT(JUMP_ABSOLUTE_QUICK, oparg);
break;
case RESUME:
Expand Down Expand Up @@ -1475,10 +1475,6 @@ builtin_call_fail_kind(int ml_flags)
}
#endif

PyObject *builtin_isinstance = NULL;
PyObject *builtin_len = NULL;
PyObject *builtin_list_append = NULL;

static int
specialize_method_descriptor(PyMethodDescrObject *descr, _Py_CODEUNIT *instr,
int nargs, PyObject *kwnames, int oparg)
Expand All @@ -1488,14 +1484,6 @@ specialize_method_descriptor(PyMethodDescrObject *descr, _Py_CODEUNIT *instr,
SPECIALIZATION_FAIL(PRECALL, SPEC_FAIL_CALL_KWNAMES);
return -1;
}
if (builtin_list_append == NULL) {
builtin_list_append = _PyType_Lookup(&PyList_Type, &_Py_ID(append));
}
assert(builtin_list_append != NULL);
if (nargs == 2 && (PyObject *)descr == builtin_list_append && oparg == 1) {
*instr = _Py_MAKECODEUNIT(PRECALL_NO_KW_LIST_APPEND, _Py_OPARG(*instr));
return 0;
}

switch (descr->d_method->ml_flags &
(METH_VARARGS | METH_FASTCALL | METH_NOARGS | METH_O |
Expand All @@ -1511,9 +1499,16 @@ specialize_method_descriptor(PyMethodDescrObject *descr, _Py_CODEUNIT *instr,
}
case METH_O: {
if (nargs != 2) {
SPECIALIZATION_FAIL(PRECALL, SPEC_FAIL_OUT_OF_RANGE);
SPECIALIZATION_FAIL(PRECALL, SPEC_FAIL_WRONG_NUMBER_ARGUMENTS);
return -1;
}
PyInterpreterState *interp = _PyInterpreterState_GET();
PyObject *list_append = interp->callable_cache.list_append;
if ((PyObject *)descr == list_append && oparg == 1) {
*instr = _Py_MAKECODEUNIT(PRECALL_NO_KW_LIST_APPEND,
_Py_OPARG(*instr));
return 0;
}
*instr = _Py_MAKECODEUNIT(PRECALL_NO_KW_METHOD_DESCRIPTOR_O,
_Py_OPARG(*instr));
return 0;
Expand Down Expand Up @@ -1705,7 +1700,7 @@ _Py_Specialize_Precall(PyObject *callable, _Py_CODEUNIT *instr, int nargs,
fail = 0;
}
else {
SPECIALIZATION_FAIL(CALL, call_fail_kind(callable));
SPECIALIZATION_FAIL(PRECALL, call_fail_kind(callable));
fail = -1;
}
if (fail) {
Expand Down