Skip to content

Commit d4052d8

Browse files
authored
Improve stats presentation for calls. (GH-100274)
1 parent 289c112 commit d4052d8

File tree

1 file changed

+22
-37
lines changed

1 file changed

+22
-37
lines changed

Python/specialize.c

Lines changed: 22 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -394,23 +394,21 @@ _PyCode_Quicken(PyCodeObject *code)
394394

395395
#define SPEC_FAIL_CALL_INSTANCE_METHOD 11
396396
#define SPEC_FAIL_CALL_CMETHOD 12
397-
#define SPEC_FAIL_CALL_PYCFUNCTION 13
398-
#define SPEC_FAIL_CALL_PYCFUNCTION_WITH_KEYWORDS 14
399-
#define SPEC_FAIL_CALL_PYCFUNCTION_FAST_WITH_KEYWORDS 15
400-
#define SPEC_FAIL_CALL_PYCFUNCTION_NOARGS 16
397+
#define SPEC_FAIL_CALL_CFUNC_VARARGS 13
398+
#define SPEC_FAIL_CALL_CFUNC_VARARGS_KEYWORDS 14
399+
#define SPEC_FAIL_CALL_CFUNC_FASTCALL_KEYWORDS 15
400+
#define SPEC_FAIL_CALL_CFUNC_NOARGS 16
401401
#define SPEC_FAIL_CALL_BAD_CALL_FLAGS 17
402-
#define SPEC_FAIL_CALL_CLASS 18
402+
#define SPEC_FAIL_CALL_CFUNC_METHOD_FASTCALL_KEYWORDS 18
403403
#define SPEC_FAIL_CALL_PYTHON_CLASS 19
404-
#define SPEC_FAIL_CALL_METHOD_DESCRIPTOR 20
404+
#define SPEC_FAIL_CALL_PEP_523 20
405405
#define SPEC_FAIL_CALL_BOUND_METHOD 21
406406
#define SPEC_FAIL_CALL_STR 22
407407
#define SPEC_FAIL_CALL_CLASS_NO_VECTORCALL 23
408408
#define SPEC_FAIL_CALL_CLASS_MUTABLE 24
409409
#define SPEC_FAIL_CALL_KWNAMES 25
410410
#define SPEC_FAIL_CALL_METHOD_WRAPPER 26
411411
#define SPEC_FAIL_CALL_OPERATOR_WRAPPER 27
412-
#define SPEC_FAIL_CALL_PYFUNCTION 28
413-
#define SPEC_FAIL_CALL_PEP_523 29
414412

415413
/* COMPARE_OP */
416414
#define SPEC_FAIL_COMPARE_OP_DIFFERENT_TYPES 12
@@ -1517,17 +1515,19 @@ builtin_call_fail_kind(int ml_flags)
15171515
switch (ml_flags & (METH_VARARGS | METH_FASTCALL | METH_NOARGS | METH_O |
15181516
METH_KEYWORDS | METH_METHOD)) {
15191517
case METH_VARARGS:
1520-
return SPEC_FAIL_CALL_PYCFUNCTION;
1518+
return SPEC_FAIL_CALL_CFUNC_VARARGS;
15211519
case METH_VARARGS | METH_KEYWORDS:
1522-
return SPEC_FAIL_CALL_PYCFUNCTION_WITH_KEYWORDS;
1520+
return SPEC_FAIL_CALL_CFUNC_VARARGS_KEYWORDS;
15231521
case METH_FASTCALL | METH_KEYWORDS:
1524-
return SPEC_FAIL_CALL_PYCFUNCTION_FAST_WITH_KEYWORDS;
1522+
return SPEC_FAIL_CALL_CFUNC_FASTCALL_KEYWORDS;
15251523
case METH_NOARGS:
1526-
return SPEC_FAIL_CALL_PYCFUNCTION_NOARGS;
1527-
/* This case should never happen with PyCFunctionObject -- only
1528-
PyMethodObject. See zlib.compressobj()'s methods for an example.
1529-
*/
1524+
return SPEC_FAIL_CALL_CFUNC_NOARGS;
15301525
case METH_METHOD | METH_FASTCALL | METH_KEYWORDS:
1526+
return SPEC_FAIL_CALL_CFUNC_METHOD_FASTCALL_KEYWORDS;
1527+
/* These cases should be optimized, but return "other" just in case */
1528+
case METH_O:
1529+
case METH_FASTCALL:
1530+
return SPEC_FAIL_OTHER;
15311531
default:
15321532
return SPEC_FAIL_CALL_BAD_CALL_FLAGS;
15331533
}
@@ -1698,33 +1698,18 @@ specialize_c_call(PyObject *callable, _Py_CODEUNIT *instr, int nargs,
16981698
static int
16991699
call_fail_kind(PyObject *callable)
17001700
{
1701-
if (PyCFunction_CheckExact(callable)) {
1702-
return SPEC_FAIL_CALL_PYCFUNCTION;
1703-
}
1704-
else if (PyFunction_Check(callable)) {
1705-
return SPEC_FAIL_CALL_PYFUNCTION;
1706-
}
1707-
else if (PyInstanceMethod_Check(callable)) {
1701+
assert(!PyCFunction_CheckExact(callable));
1702+
assert(!PyFunction_Check(callable));
1703+
assert(!PyType_Check(callable));
1704+
assert(!Py_IS_TYPE(callable, &PyMethodDescr_Type));
1705+
assert(!PyMethod_Check(callable));
1706+
if (PyInstanceMethod_Check(callable)) {
17081707
return SPEC_FAIL_CALL_INSTANCE_METHOD;
17091708
}
1710-
else if (PyMethod_Check(callable)) {
1711-
return SPEC_FAIL_CALL_BOUND_METHOD;
1712-
}
17131709
// builtin method
17141710
else if (PyCMethod_Check(callable)) {
17151711
return SPEC_FAIL_CALL_CMETHOD;
17161712
}
1717-
else if (PyType_Check(callable)) {
1718-
if (((PyTypeObject *)callable)->tp_new == PyBaseObject_Type.tp_new) {
1719-
return SPEC_FAIL_CALL_PYTHON_CLASS;
1720-
}
1721-
else {
1722-
return SPEC_FAIL_CALL_CLASS;
1723-
}
1724-
}
1725-
else if (Py_IS_TYPE(callable, &PyMethodDescr_Type)) {
1726-
return SPEC_FAIL_CALL_METHOD_DESCRIPTOR;
1727-
}
17281713
else if (Py_TYPE(callable) == &PyWrapperDescr_Type) {
17291714
return SPEC_FAIL_CALL_OPERATOR_WRAPPER;
17301715
}
@@ -1760,7 +1745,7 @@ _Py_Specialize_Call(PyObject *callable, _Py_CODEUNIT *instr, int nargs,
17601745
fail = specialize_method_descriptor((PyMethodDescrObject *)callable,
17611746
instr, nargs, kwnames);
17621747
}
1763-
else if (Py_TYPE(callable) == &PyMethod_Type) {
1748+
else if (PyMethod_Check(callable)) {
17641749
PyObject *func = ((PyMethodObject *)callable)->im_func;
17651750
if (PyFunction_Check(func)) {
17661751
fail = specialize_py_call((PyFunctionObject *)func,

0 commit comments

Comments
 (0)