mirror of
https://github.com/python/cpython.git
synced 2025-08-30 05:35:08 +00:00
GH-105848: Replace KW_NAMES + CALL with LOAD_CONST + CALL_KW (GH-109300)
This commit is contained in:
parent
987b4bc087
commit
22e65eecaa
22 changed files with 719 additions and 508 deletions
173
Python/generated_cases.c.h
generated
173
Python/generated_cases.c.h
generated
|
@ -3688,13 +3688,6 @@
|
|||
DISPATCH();
|
||||
}
|
||||
|
||||
TARGET(KW_NAMES) {
|
||||
ASSERT_KWNAMES_IS_NULL();
|
||||
assert(oparg < PyTuple_GET_SIZE(FRAME_CO_CONSTS));
|
||||
kwnames = GETITEM(FRAME_CO_CONSTS, oparg);
|
||||
DISPATCH();
|
||||
}
|
||||
|
||||
TARGET(INSTRUMENTED_CALL) {
|
||||
int is_meth = PEEK(oparg + 1) != NULL;
|
||||
int total_args = oparg + is_meth;
|
||||
|
@ -3720,6 +3713,7 @@
|
|||
args = stack_pointer - oparg;
|
||||
self_or_null = stack_pointer[-1 - oparg];
|
||||
callable = stack_pointer[-2 - oparg];
|
||||
// oparg counts all of the args, but *not* self:
|
||||
int total_args = oparg;
|
||||
if (self_or_null != NULL) {
|
||||
args--;
|
||||
|
@ -3729,7 +3723,7 @@
|
|||
_PyCallCache *cache = (_PyCallCache *)next_instr;
|
||||
if (ADAPTIVE_COUNTER_IS_ZERO(cache->counter)) {
|
||||
next_instr--;
|
||||
_Py_Specialize_Call(callable, next_instr, total_args, kwnames);
|
||||
_Py_Specialize_Call(callable, next_instr, total_args);
|
||||
DISPATCH_SAME_OPARG();
|
||||
}
|
||||
STAT_INC(CALL, deferred);
|
||||
|
@ -3745,7 +3739,6 @@
|
|||
Py_DECREF(callable);
|
||||
callable = method;
|
||||
}
|
||||
int positional_args = total_args - KWNAMES_LEN();
|
||||
// Check if the call can be inlined or not
|
||||
if (Py_TYPE(callable) == &PyFunction_Type &&
|
||||
tstate->interp->eval_frame == NULL &&
|
||||
|
@ -3755,9 +3748,8 @@
|
|||
PyObject *locals = code_flags & CO_OPTIMIZED ? NULL : Py_NewRef(PyFunction_GET_GLOBALS(callable));
|
||||
_PyInterpreterFrame *new_frame = _PyEvalFramePushAndInit(
|
||||
tstate, (PyFunctionObject *)callable, locals,
|
||||
args, positional_args, kwnames
|
||||
args, total_args, NULL
|
||||
);
|
||||
kwnames = NULL;
|
||||
// Manipulate stack directly since we leave using DISPATCH_INLINED().
|
||||
STACK_SHRINK(oparg + 2);
|
||||
// The frame has stolen all the arguments from the stack,
|
||||
|
@ -3772,8 +3764,8 @@
|
|||
/* Callable is not a normal Python function */
|
||||
res = PyObject_Vectorcall(
|
||||
callable, args,
|
||||
positional_args | PY_VECTORCALL_ARGUMENTS_OFFSET,
|
||||
kwnames);
|
||||
total_args | PY_VECTORCALL_ARGUMENTS_OFFSET,
|
||||
NULL);
|
||||
if (opcode == INSTRUMENTED_CALL) {
|
||||
PyObject *arg = total_args == 0 ?
|
||||
&_PyInstrumentation_MISSING : args[0];
|
||||
|
@ -3791,7 +3783,6 @@
|
|||
}
|
||||
}
|
||||
}
|
||||
kwnames = NULL;
|
||||
assert((res != NULL) ^ (_PyErr_Occurred(tstate) != NULL));
|
||||
Py_DECREF(callable);
|
||||
for (int i = 0; i < total_args; i++) {
|
||||
|
@ -3839,7 +3830,6 @@
|
|||
callable = func;
|
||||
{
|
||||
uint32_t func_version = read_u32(&next_instr[1].cache);
|
||||
ASSERT_KWNAMES_IS_NULL();
|
||||
DEOPT_IF(!PyFunction_Check(callable), CALL);
|
||||
PyFunctionObject *func = (PyFunctionObject *)callable;
|
||||
DEOPT_IF(func->func_version != func_version, CALL);
|
||||
|
@ -3918,7 +3908,6 @@
|
|||
callable = stack_pointer[-2 - oparg];
|
||||
{
|
||||
uint32_t func_version = read_u32(&next_instr[1].cache);
|
||||
ASSERT_KWNAMES_IS_NULL();
|
||||
DEOPT_IF(!PyFunction_Check(callable), CALL);
|
||||
PyFunctionObject *func = (PyFunctionObject *)callable;
|
||||
DEOPT_IF(func->func_version != func_version, CALL);
|
||||
|
@ -3991,7 +3980,6 @@
|
|||
self_or_null = stack_pointer[-1 - oparg];
|
||||
callable = stack_pointer[-2 - oparg];
|
||||
uint32_t func_version = read_u32(&next_instr[1].cache);
|
||||
ASSERT_KWNAMES_IS_NULL();
|
||||
DEOPT_IF(tstate->interp->eval_frame, CALL);
|
||||
int argcount = oparg;
|
||||
if (self_or_null != NULL) {
|
||||
|
@ -4026,7 +4014,7 @@
|
|||
DISPATCH_INLINED(new_frame);
|
||||
}
|
||||
|
||||
TARGET(CALL_NO_KW_TYPE_1) {
|
||||
TARGET(CALL_TYPE_1) {
|
||||
PyObject **args;
|
||||
PyObject *null;
|
||||
PyObject *callable;
|
||||
|
@ -4034,7 +4022,6 @@
|
|||
args = stack_pointer - oparg;
|
||||
null = stack_pointer[-1 - oparg];
|
||||
callable = stack_pointer[-2 - oparg];
|
||||
ASSERT_KWNAMES_IS_NULL();
|
||||
assert(oparg == 1);
|
||||
DEOPT_IF(null != NULL, CALL);
|
||||
PyObject *obj = args[0];
|
||||
|
@ -4050,7 +4037,7 @@
|
|||
DISPATCH();
|
||||
}
|
||||
|
||||
TARGET(CALL_NO_KW_STR_1) {
|
||||
TARGET(CALL_STR_1) {
|
||||
PyObject **args;
|
||||
PyObject *null;
|
||||
PyObject *callable;
|
||||
|
@ -4058,7 +4045,6 @@
|
|||
args = stack_pointer - oparg;
|
||||
null = stack_pointer[-1 - oparg];
|
||||
callable = stack_pointer[-2 - oparg];
|
||||
ASSERT_KWNAMES_IS_NULL();
|
||||
assert(oparg == 1);
|
||||
DEOPT_IF(null != NULL, CALL);
|
||||
DEOPT_IF(callable != (PyObject *)&PyUnicode_Type, CALL);
|
||||
|
@ -4076,7 +4062,7 @@
|
|||
DISPATCH();
|
||||
}
|
||||
|
||||
TARGET(CALL_NO_KW_TUPLE_1) {
|
||||
TARGET(CALL_TUPLE_1) {
|
||||
PyObject **args;
|
||||
PyObject *null;
|
||||
PyObject *callable;
|
||||
|
@ -4084,7 +4070,6 @@
|
|||
args = stack_pointer - oparg;
|
||||
null = stack_pointer[-1 - oparg];
|
||||
callable = stack_pointer[-2 - oparg];
|
||||
ASSERT_KWNAMES_IS_NULL();
|
||||
assert(oparg == 1);
|
||||
DEOPT_IF(null != NULL, CALL);
|
||||
DEOPT_IF(callable != (PyObject *)&PyTuple_Type, CALL);
|
||||
|
@ -4102,7 +4087,7 @@
|
|||
DISPATCH();
|
||||
}
|
||||
|
||||
TARGET(CALL_NO_KW_ALLOC_AND_ENTER_INIT) {
|
||||
TARGET(CALL_ALLOC_AND_ENTER_INIT) {
|
||||
PyObject **args;
|
||||
PyObject *null;
|
||||
PyObject *callable;
|
||||
|
@ -4114,7 +4099,6 @@
|
|||
* 2. Pushes a shim frame to the frame stack (to cleanup after ``__init__``)
|
||||
* 3. Pushes the frame for ``__init__`` to the frame stack
|
||||
* */
|
||||
ASSERT_KWNAMES_IS_NULL();
|
||||
_PyCallCache *cache = (_PyCallCache *)next_instr;
|
||||
DEOPT_IF(null != NULL, CALL);
|
||||
DEOPT_IF(!PyType_Check(callable), CALL);
|
||||
|
@ -4188,14 +4172,11 @@
|
|||
args--;
|
||||
total_args++;
|
||||
}
|
||||
int kwnames_len = KWNAMES_LEN();
|
||||
DEOPT_IF(!PyType_Check(callable), CALL);
|
||||
PyTypeObject *tp = (PyTypeObject *)callable;
|
||||
DEOPT_IF(tp->tp_vectorcall == NULL, CALL);
|
||||
STAT_INC(CALL, hit);
|
||||
res = tp->tp_vectorcall((PyObject *)tp, args,
|
||||
total_args - kwnames_len, kwnames);
|
||||
kwnames = NULL;
|
||||
res = tp->tp_vectorcall((PyObject *)tp, args, total_args, NULL);
|
||||
/* Free the arguments. */
|
||||
for (int i = 0; i < total_args; i++) {
|
||||
Py_DECREF(args[i]);
|
||||
|
@ -4210,7 +4191,7 @@
|
|||
DISPATCH();
|
||||
}
|
||||
|
||||
TARGET(CALL_NO_KW_BUILTIN_O) {
|
||||
TARGET(CALL_BUILTIN_O) {
|
||||
PyObject **args;
|
||||
PyObject *self_or_null;
|
||||
PyObject *callable;
|
||||
|
@ -4219,7 +4200,6 @@
|
|||
self_or_null = stack_pointer[-1 - oparg];
|
||||
callable = stack_pointer[-2 - oparg];
|
||||
/* Builtin METH_O functions */
|
||||
ASSERT_KWNAMES_IS_NULL();
|
||||
int total_args = oparg;
|
||||
if (self_or_null != NULL) {
|
||||
args--;
|
||||
|
@ -4251,7 +4231,7 @@
|
|||
DISPATCH();
|
||||
}
|
||||
|
||||
TARGET(CALL_NO_KW_BUILTIN_FAST) {
|
||||
TARGET(CALL_BUILTIN_FAST) {
|
||||
PyObject **args;
|
||||
PyObject *self_or_null;
|
||||
PyObject *callable;
|
||||
|
@ -4260,7 +4240,6 @@
|
|||
self_or_null = stack_pointer[-1 - oparg];
|
||||
callable = stack_pointer[-2 - oparg];
|
||||
/* Builtin METH_FASTCALL functions, without keywords */
|
||||
ASSERT_KWNAMES_IS_NULL();
|
||||
int total_args = oparg;
|
||||
if (self_or_null != NULL) {
|
||||
args--;
|
||||
|
@ -4318,14 +4297,8 @@
|
|||
_PyCFunctionFastWithKeywords cfunc =
|
||||
(_PyCFunctionFastWithKeywords)(void(*)(void))
|
||||
PyCFunction_GET_FUNCTION(callable);
|
||||
res = cfunc(
|
||||
PyCFunction_GET_SELF(callable),
|
||||
args,
|
||||
total_args - KWNAMES_LEN(),
|
||||
kwnames
|
||||
);
|
||||
res = cfunc(PyCFunction_GET_SELF(callable), args, total_args, NULL);
|
||||
assert((res != NULL) ^ (_PyErr_Occurred(tstate) != NULL));
|
||||
kwnames = NULL;
|
||||
|
||||
/* Free the arguments. */
|
||||
for (int i = 0; i < total_args; i++) {
|
||||
|
@ -4341,7 +4314,7 @@
|
|||
DISPATCH();
|
||||
}
|
||||
|
||||
TARGET(CALL_NO_KW_LEN) {
|
||||
TARGET(CALL_LEN) {
|
||||
PyObject **args;
|
||||
PyObject *self_or_null;
|
||||
PyObject *callable;
|
||||
|
@ -4349,7 +4322,6 @@
|
|||
args = stack_pointer - oparg;
|
||||
self_or_null = stack_pointer[-1 - oparg];
|
||||
callable = stack_pointer[-2 - oparg];
|
||||
ASSERT_KWNAMES_IS_NULL();
|
||||
/* len(o) */
|
||||
int total_args = oparg;
|
||||
if (self_or_null != NULL) {
|
||||
|
@ -4378,7 +4350,7 @@
|
|||
DISPATCH();
|
||||
}
|
||||
|
||||
TARGET(CALL_NO_KW_ISINSTANCE) {
|
||||
TARGET(CALL_ISINSTANCE) {
|
||||
PyObject **args;
|
||||
PyObject *self_or_null;
|
||||
PyObject *callable;
|
||||
|
@ -4386,7 +4358,6 @@
|
|||
args = stack_pointer - oparg;
|
||||
self_or_null = stack_pointer[-1 - oparg];
|
||||
callable = stack_pointer[-2 - oparg];
|
||||
ASSERT_KWNAMES_IS_NULL();
|
||||
/* isinstance(o, o2) */
|
||||
int total_args = oparg;
|
||||
if (self_or_null != NULL) {
|
||||
|
@ -4417,14 +4388,13 @@
|
|||
DISPATCH();
|
||||
}
|
||||
|
||||
TARGET(CALL_NO_KW_LIST_APPEND) {
|
||||
TARGET(CALL_LIST_APPEND) {
|
||||
PyObject **args;
|
||||
PyObject *self;
|
||||
PyObject *callable;
|
||||
args = stack_pointer - oparg;
|
||||
self = stack_pointer[-1 - oparg];
|
||||
callable = stack_pointer[-2 - oparg];
|
||||
ASSERT_KWNAMES_IS_NULL();
|
||||
assert(oparg == 1);
|
||||
PyInterpreterState *interp = tstate->interp;
|
||||
DEOPT_IF(callable != interp->callable_cache.list_append, CALL);
|
||||
|
@ -4443,7 +4413,7 @@
|
|||
DISPATCH();
|
||||
}
|
||||
|
||||
TARGET(CALL_NO_KW_METHOD_DESCRIPTOR_O) {
|
||||
TARGET(CALL_METHOD_DESCRIPTOR_O) {
|
||||
PyObject **args;
|
||||
PyObject *self_or_null;
|
||||
PyObject *callable;
|
||||
|
@ -4451,7 +4421,6 @@
|
|||
args = stack_pointer - oparg;
|
||||
self_or_null = stack_pointer[-1 - oparg];
|
||||
callable = stack_pointer[-2 - oparg];
|
||||
ASSERT_KWNAMES_IS_NULL();
|
||||
int total_args = oparg;
|
||||
if (self_or_null != NULL) {
|
||||
args--;
|
||||
|
@ -4511,9 +4480,8 @@
|
|||
int nargs = total_args - 1;
|
||||
_PyCFunctionFastWithKeywords cfunc =
|
||||
(_PyCFunctionFastWithKeywords)(void(*)(void))meth->ml_meth;
|
||||
res = cfunc(self, args + 1, nargs - KWNAMES_LEN(), kwnames);
|
||||
res = cfunc(self, args + 1, nargs, NULL);
|
||||
assert((res != NULL) ^ (_PyErr_Occurred(tstate) != NULL));
|
||||
kwnames = NULL;
|
||||
|
||||
/* Free the arguments. */
|
||||
for (int i = 0; i < total_args; i++) {
|
||||
|
@ -4529,7 +4497,7 @@
|
|||
DISPATCH();
|
||||
}
|
||||
|
||||
TARGET(CALL_NO_KW_METHOD_DESCRIPTOR_NOARGS) {
|
||||
TARGET(CALL_METHOD_DESCRIPTOR_NOARGS) {
|
||||
PyObject **args;
|
||||
PyObject *self_or_null;
|
||||
PyObject *callable;
|
||||
|
@ -4537,7 +4505,6 @@
|
|||
args = stack_pointer - oparg;
|
||||
self_or_null = stack_pointer[-1 - oparg];
|
||||
callable = stack_pointer[-2 - oparg];
|
||||
ASSERT_KWNAMES_IS_NULL();
|
||||
assert(oparg == 0 || oparg == 1);
|
||||
int total_args = oparg;
|
||||
if (self_or_null != NULL) {
|
||||
|
@ -4572,7 +4539,7 @@
|
|||
DISPATCH();
|
||||
}
|
||||
|
||||
TARGET(CALL_NO_KW_METHOD_DESCRIPTOR_FAST) {
|
||||
TARGET(CALL_METHOD_DESCRIPTOR_FAST) {
|
||||
PyObject **args;
|
||||
PyObject *self_or_null;
|
||||
PyObject *callable;
|
||||
|
@ -4580,7 +4547,6 @@
|
|||
args = stack_pointer - oparg;
|
||||
self_or_null = stack_pointer[-1 - oparg];
|
||||
callable = stack_pointer[-2 - oparg];
|
||||
ASSERT_KWNAMES_IS_NULL();
|
||||
int total_args = oparg;
|
||||
if (self_or_null != NULL) {
|
||||
args--;
|
||||
|
@ -4613,6 +4579,105 @@
|
|||
DISPATCH();
|
||||
}
|
||||
|
||||
TARGET(INSTRUMENTED_CALL_KW) {
|
||||
int is_meth = PEEK(oparg + 2) != NULL;
|
||||
int total_args = oparg + is_meth;
|
||||
PyObject *function = PEEK(oparg + 3);
|
||||
PyObject *arg = total_args == 0 ? &_PyInstrumentation_MISSING
|
||||
: PEEK(total_args + 1);
|
||||
int err = _Py_call_instrumentation_2args(
|
||||
tstate, PY_MONITORING_EVENT_CALL,
|
||||
frame, next_instr - 1, function, arg);
|
||||
if (err) goto error;
|
||||
GO_TO_INSTRUCTION(CALL_KW);
|
||||
}
|
||||
|
||||
TARGET(CALL_KW) {
|
||||
PREDICTED(CALL_KW);
|
||||
PyObject *kwnames;
|
||||
PyObject **args;
|
||||
PyObject *self_or_null;
|
||||
PyObject *callable;
|
||||
PyObject *res;
|
||||
kwnames = stack_pointer[-1];
|
||||
args = stack_pointer - 1 - oparg;
|
||||
self_or_null = stack_pointer[-2 - oparg];
|
||||
callable = stack_pointer[-3 - oparg];
|
||||
// oparg counts all of the args, but *not* self:
|
||||
int total_args = oparg;
|
||||
if (self_or_null != NULL) {
|
||||
args--;
|
||||
total_args++;
|
||||
}
|
||||
if (self_or_null == NULL && Py_TYPE(callable) == &PyMethod_Type) {
|
||||
args--;
|
||||
total_args++;
|
||||
PyObject *self = ((PyMethodObject *)callable)->im_self;
|
||||
args[0] = Py_NewRef(self);
|
||||
PyObject *method = ((PyMethodObject *)callable)->im_func;
|
||||
args[-1] = Py_NewRef(method);
|
||||
Py_DECREF(callable);
|
||||
callable = method;
|
||||
}
|
||||
int positional_args = total_args - (int)PyTuple_GET_SIZE(kwnames);
|
||||
// Check if the call can be inlined or not
|
||||
if (Py_TYPE(callable) == &PyFunction_Type &&
|
||||
tstate->interp->eval_frame == NULL &&
|
||||
((PyFunctionObject *)callable)->vectorcall == _PyFunction_Vectorcall)
|
||||
{
|
||||
int code_flags = ((PyCodeObject*)PyFunction_GET_CODE(callable))->co_flags;
|
||||
PyObject *locals = code_flags & CO_OPTIMIZED ? NULL : Py_NewRef(PyFunction_GET_GLOBALS(callable));
|
||||
_PyInterpreterFrame *new_frame = _PyEvalFramePushAndInit(
|
||||
tstate, (PyFunctionObject *)callable, locals,
|
||||
args, positional_args, kwnames
|
||||
);
|
||||
Py_DECREF(kwnames);
|
||||
// Manipulate stack directly since we leave using DISPATCH_INLINED().
|
||||
STACK_SHRINK(oparg + 3);
|
||||
// The frame has stolen all the arguments from the stack,
|
||||
// so there is no need to clean them up.
|
||||
if (new_frame == NULL) {
|
||||
goto error;
|
||||
}
|
||||
frame->return_offset = 0;
|
||||
DISPATCH_INLINED(new_frame);
|
||||
}
|
||||
/* Callable is not a normal Python function */
|
||||
res = PyObject_Vectorcall(
|
||||
callable, args,
|
||||
positional_args | PY_VECTORCALL_ARGUMENTS_OFFSET,
|
||||
kwnames);
|
||||
if (opcode == INSTRUMENTED_CALL_KW) {
|
||||
PyObject *arg = total_args == 0 ?
|
||||
&_PyInstrumentation_MISSING : args[0];
|
||||
if (res == NULL) {
|
||||
_Py_call_instrumentation_exc2(
|
||||
tstate, PY_MONITORING_EVENT_C_RAISE,
|
||||
frame, next_instr-1, callable, arg);
|
||||
}
|
||||
else {
|
||||
int err = _Py_call_instrumentation_2args(
|
||||
tstate, PY_MONITORING_EVENT_C_RETURN,
|
||||
frame, next_instr-1, callable, arg);
|
||||
if (err < 0) {
|
||||
Py_CLEAR(res);
|
||||
}
|
||||
}
|
||||
}
|
||||
Py_DECREF(kwnames);
|
||||
assert((res != NULL) ^ (_PyErr_Occurred(tstate) != NULL));
|
||||
Py_DECREF(callable);
|
||||
for (int i = 0; i < total_args; i++) {
|
||||
Py_DECREF(args[i]);
|
||||
}
|
||||
if (res == NULL) { STACK_SHRINK(oparg); goto pop_3_error; }
|
||||
STACK_SHRINK(oparg);
|
||||
STACK_SHRINK(2);
|
||||
stack_pointer[-1] = res;
|
||||
CHECK_EVAL_BREAKER();
|
||||
DISPATCH();
|
||||
}
|
||||
|
||||
TARGET(INSTRUMENTED_CALL_FUNCTION_EX) {
|
||||
GO_TO_INSTRUCTION(CALL_FUNCTION_EX);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue