summaryrefslogtreecommitdiffstats
path: root/Python/executor_cases.c.h
diff options
context:
space:
mode:
authorBrandt Bucher <brandtbucher@microsoft.com>2023-09-13 17:25:45 (GMT)
committerGitHub <noreply@github.com>2023-09-13 17:25:45 (GMT)
commit22e65eecaad3f5337862319687047afe9861e1ef (patch)
tree19089993cd9ec4d1930521c1c3df3cb22b0b9ddc /Python/executor_cases.c.h
parent987b4bc0870e1e29a88275dc3fa39bf2c3dcc763 (diff)
downloadcpython-22e65eecaad3f5337862319687047afe9861e1ef.zip
cpython-22e65eecaad3f5337862319687047afe9861e1ef.tar.gz
cpython-22e65eecaad3f5337862319687047afe9861e1ef.tar.bz2
GH-105848: Replace KW_NAMES + CALL with LOAD_CONST + CALL_KW (GH-109300)
Diffstat (limited to 'Python/executor_cases.c.h')
-rw-r--r--Python/executor_cases.c.h140
1 files changed, 119 insertions, 21 deletions
diff --git a/Python/executor_cases.c.h b/Python/executor_cases.c.h
index 8f3febe..befb972 100644
--- a/Python/executor_cases.c.h
+++ b/Python/executor_cases.c.h
@@ -2256,7 +2256,6 @@
self_or_null = stack_pointer[-1 - oparg];
callable = stack_pointer[-2 - oparg];
uint32_t func_version = (uint32_t)operand;
- ASSERT_KWNAMES_IS_NULL();
DEOPT_IF(!PyFunction_Check(callable), CALL);
PyFunctionObject *func = (PyFunctionObject *)callable;
DEOPT_IF(func->func_version != func_version, CALL);
@@ -2324,7 +2323,7 @@
break;
}
- case CALL_NO_KW_TYPE_1: {
+ case CALL_TYPE_1: {
PyObject **args;
PyObject *null;
PyObject *callable;
@@ -2332,7 +2331,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];
@@ -2347,7 +2345,7 @@
break;
}
- case CALL_NO_KW_STR_1: {
+ case CALL_STR_1: {
PyObject **args;
PyObject *null;
PyObject *callable;
@@ -2355,7 +2353,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);
@@ -2372,7 +2369,7 @@
break;
}
- case CALL_NO_KW_TUPLE_1: {
+ case CALL_TUPLE_1: {
PyObject **args;
PyObject *null;
PyObject *callable;
@@ -2380,7 +2377,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);
@@ -2411,7 +2407,38 @@
break;
}
- case CALL_NO_KW_BUILTIN_O: {
+ case CALL_BUILTIN_CLASS: {
+ PyObject **args;
+ PyObject *self_or_null;
+ PyObject *callable;
+ PyObject *res;
+ args = stack_pointer - oparg;
+ self_or_null = stack_pointer[-1 - oparg];
+ callable = stack_pointer[-2 - oparg];
+ int total_args = oparg;
+ if (self_or_null != NULL) {
+ args--;
+ total_args++;
+ }
+ 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, NULL);
+ /* Free the arguments. */
+ for (int i = 0; i < total_args; i++) {
+ Py_DECREF(args[i]);
+ }
+ Py_DECREF(tp);
+ if (res == NULL) { STACK_SHRINK(oparg); goto pop_2_error; }
+ STACK_SHRINK(oparg);
+ STACK_SHRINK(1);
+ stack_pointer[-1] = res;
+ CHECK_EVAL_BREAKER();
+ break;
+ }
+
+ case CALL_BUILTIN_O: {
PyObject **args;
PyObject *self_or_null;
PyObject *callable;
@@ -2420,7 +2447,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--;
@@ -2451,7 +2477,7 @@
break;
}
- case CALL_NO_KW_BUILTIN_FAST: {
+ case CALL_BUILTIN_FAST: {
PyObject **args;
PyObject *self_or_null;
PyObject *callable;
@@ -2460,7 +2486,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--;
@@ -2495,7 +2520,45 @@
break;
}
- case CALL_NO_KW_LEN: {
+ case CALL_BUILTIN_FAST_WITH_KEYWORDS: {
+ PyObject **args;
+ PyObject *self_or_null;
+ PyObject *callable;
+ PyObject *res;
+ args = stack_pointer - oparg;
+ self_or_null = stack_pointer[-1 - oparg];
+ callable = stack_pointer[-2 - oparg];
+ /* Builtin METH_FASTCALL | METH_KEYWORDS functions */
+ int total_args = oparg;
+ if (self_or_null != NULL) {
+ args--;
+ total_args++;
+ }
+ DEOPT_IF(!PyCFunction_CheckExact(callable), CALL);
+ DEOPT_IF(PyCFunction_GET_FLAGS(callable) !=
+ (METH_FASTCALL | METH_KEYWORDS), CALL);
+ STAT_INC(CALL, hit);
+ /* res = func(self, args, nargs, kwnames) */
+ _PyCFunctionFastWithKeywords cfunc =
+ (_PyCFunctionFastWithKeywords)(void(*)(void))
+ PyCFunction_GET_FUNCTION(callable);
+ res = cfunc(PyCFunction_GET_SELF(callable), args, total_args, NULL);
+ assert((res != NULL) ^ (_PyErr_Occurred(tstate) != NULL));
+
+ /* Free the arguments. */
+ for (int i = 0; i < total_args; i++) {
+ Py_DECREF(args[i]);
+ }
+ Py_DECREF(callable);
+ if (res == NULL) { STACK_SHRINK(oparg); goto pop_2_error; }
+ STACK_SHRINK(oparg);
+ STACK_SHRINK(1);
+ stack_pointer[-1] = res;
+ CHECK_EVAL_BREAKER();
+ break;
+ }
+
+ case CALL_LEN: {
PyObject **args;
PyObject *self_or_null;
PyObject *callable;
@@ -2503,7 +2566,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) {
@@ -2531,7 +2593,7 @@
break;
}
- case CALL_NO_KW_ISINSTANCE: {
+ case CALL_ISINSTANCE: {
PyObject **args;
PyObject *self_or_null;
PyObject *callable;
@@ -2539,7 +2601,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) {
@@ -2569,7 +2630,7 @@
break;
}
- case CALL_NO_KW_METHOD_DESCRIPTOR_O: {
+ case CALL_METHOD_DESCRIPTOR_O: {
PyObject **args;
PyObject *self_or_null;
PyObject *callable;
@@ -2577,7 +2638,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--;
@@ -2612,7 +2672,47 @@
break;
}
- case CALL_NO_KW_METHOD_DESCRIPTOR_NOARGS: {
+ case CALL_METHOD_DESCRIPTOR_FAST_WITH_KEYWORDS: {
+ PyObject **args;
+ PyObject *self_or_null;
+ PyObject *callable;
+ PyObject *res;
+ args = stack_pointer - oparg;
+ self_or_null = stack_pointer[-1 - oparg];
+ callable = stack_pointer[-2 - oparg];
+ int total_args = oparg;
+ if (self_or_null != NULL) {
+ args--;
+ total_args++;
+ }
+ PyMethodDescrObject *method = (PyMethodDescrObject *)callable;
+ DEOPT_IF(!Py_IS_TYPE(method, &PyMethodDescr_Type), CALL);
+ PyMethodDef *meth = method->d_method;
+ DEOPT_IF(meth->ml_flags != (METH_FASTCALL|METH_KEYWORDS), CALL);
+ PyTypeObject *d_type = method->d_common.d_type;
+ PyObject *self = args[0];
+ DEOPT_IF(!Py_IS_TYPE(self, d_type), CALL);
+ STAT_INC(CALL, hit);
+ int nargs = total_args - 1;
+ _PyCFunctionFastWithKeywords cfunc =
+ (_PyCFunctionFastWithKeywords)(void(*)(void))meth->ml_meth;
+ res = cfunc(self, args + 1, nargs, NULL);
+ assert((res != NULL) ^ (_PyErr_Occurred(tstate) != NULL));
+
+ /* Free the arguments. */
+ for (int i = 0; i < total_args; i++) {
+ Py_DECREF(args[i]);
+ }
+ Py_DECREF(callable);
+ if (res == NULL) { STACK_SHRINK(oparg); goto pop_2_error; }
+ STACK_SHRINK(oparg);
+ STACK_SHRINK(1);
+ stack_pointer[-1] = res;
+ CHECK_EVAL_BREAKER();
+ break;
+ }
+
+ case CALL_METHOD_DESCRIPTOR_NOARGS: {
PyObject **args;
PyObject *self_or_null;
PyObject *callable;
@@ -2620,7 +2720,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) {
@@ -2654,7 +2753,7 @@
break;
}
- case CALL_NO_KW_METHOD_DESCRIPTOR_FAST: {
+ case CALL_METHOD_DESCRIPTOR_FAST: {
PyObject **args;
PyObject *self_or_null;
PyObject *callable;
@@ -2662,7 +2761,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--;