Skip to content

Commit 8623ee7

Browse files
committed
Better stats for call specialization failure for Python functions
1 parent e1eeb99 commit 8623ee7

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

Python/specialize.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -444,13 +444,13 @@ _PyCode_Quicken(PyCodeObject *code)
444444
/* Common */
445445

446446
#define SPEC_FAIL_OTHER 0
447-
#define SPEC_FAIL_NO_DICT 1
447+
#define SPEC_FAIL_CODE_VARARGS 1
448448
#define SPEC_FAIL_OVERRIDDEN 2
449449
#define SPEC_FAIL_OUT_OF_VERSIONS 3
450450
#define SPEC_FAIL_OUT_OF_RANGE 4
451451
#define SPEC_FAIL_EXPECTED_ERROR 5
452452
#define SPEC_FAIL_WRONG_NUMBER_ARGUMENTS 6
453-
#define SPEC_FAIL_CODE_COMPLEX_PARAMETERS 7
453+
#define SPEC_FAIL_CODE_VARKEYWORDS 7
454454
#define SPEC_FAIL_CODE_NOT_OPTIMIZED 8
455455

456456

@@ -489,6 +489,7 @@ _PyCode_Quicken(PyCodeObject *code)
489489
#define SPEC_FAIL_ATTR_CLASS_ATTR_SIMPLE 31
490490
#define SPEC_FAIL_ATTR_CLASS_ATTR_DESCRIPTOR 32
491491
#define SPEC_FAIL_ATTR_BUILTIN_CLASS_METHOD_OBJ 33
492+
#define SPEC_FAIL_ATTR_NO_DICT 34
492493

493494
/* Binary subscr and store subscr */
494495

@@ -629,7 +630,7 @@ specialize_module_load_attr(
629630
assert((owner->ob_type->tp_flags & Py_TPFLAGS_MANAGED_DICT) == 0);
630631
PyDictObject *dict = (PyDictObject *)m->md_dict;
631632
if (dict == NULL) {
632-
SPECIALIZATION_FAIL(LOAD_ATTR, SPEC_FAIL_NO_DICT);
633+
SPECIALIZATION_FAIL(LOAD_ATTR, SPEC_FAIL_ATTR_NO_DICT);
633634
return -1;
634635
}
635636
if (dict->ma_keys->dk_kind != DICT_KEYS_UNICODE) {
@@ -846,7 +847,7 @@ specialize_dict_access(
846847
PyManagedDictPointer *managed_dict = _PyObject_ManagedDictPointer(owner);
847848
PyDictObject *dict = managed_dict->dict;
848849
if (dict == NULL || !PyDict_CheckExact(dict)) {
849-
SPECIALIZATION_FAIL(base_op, SPEC_FAIL_NO_DICT);
850+
SPECIALIZATION_FAIL(base_op, SPEC_FAIL_ATTR_NO_DICT);
850851
return 0;
851852
}
852853
// We found an instance with a __dict__.
@@ -1455,8 +1456,11 @@ binary_subscr_fail_kind(PyTypeObject *container_type, PyObject *sub)
14551456
static int
14561457
function_kind(PyCodeObject *code) {
14571458
int flags = code->co_flags;
1458-
if ((flags & (CO_VARKEYWORDS | CO_VARARGS)) || code->co_kwonlyargcount) {
1459-
return SPEC_FAIL_CODE_COMPLEX_PARAMETERS;
1459+
if ((flags & CO_VARKEYWORDS) || code->co_kwonlyargcount) {
1460+
return SPEC_FAIL_CODE_VARKEYWORDS;
1461+
}
1462+
if (flags & CO_VARARGS) {
1463+
return SPEC_FAIL_CODE_VARARGS;
14601464
}
14611465
if ((flags & CO_OPTIMIZED) == 0) {
14621466
return SPEC_FAIL_CODE_NOT_OPTIMIZED;

0 commit comments

Comments
 (0)