gh-116381: Remove bad specializations, add fail stats (GH-116464)

* Remove bad specializations, add fail stats
This commit is contained in:
Ken Jin 2024-03-08 00:21:21 +08:00 committed by GitHub
parent 4298d69d4b
commit 41457c7fdb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
16 changed files with 125 additions and 320 deletions

View file

@ -600,6 +600,12 @@ _PyCode_Quicken(PyCodeObject *code)
#define SPEC_FAIL_TO_BOOL_SET 17
#define SPEC_FAIL_TO_BOOL_TUPLE 18
// CONTAINS_OP
#define SPEC_FAIL_CONTAINS_OP_STR 9
#define SPEC_FAIL_CONTAINS_OP_TUPLE 10
#define SPEC_FAIL_CONTAINS_OP_LIST 11
#define SPEC_FAIL_CONTAINS_OP_USER_CLASS 12
static int function_kind(PyCodeObject *code);
static bool function_check_args(PyObject *o, int expected_argcount, int opcode);
static uint32_t function_get_version(PyObject *o, int opcode);
@ -2562,34 +2568,40 @@ success:
cache->counter = adaptive_counter_cooldown();
}
#ifdef Py_STATS
static int containsop_fail_kind(PyObject *value) {
if (PyUnicode_CheckExact(value)) {
return SPEC_FAIL_CONTAINS_OP_STR;
}
if (PyList_CheckExact(value)) {
return SPEC_FAIL_CONTAINS_OP_LIST;
}
if (PyTuple_CheckExact(value)) {
return SPEC_FAIL_CONTAINS_OP_TUPLE;
}
if (PyType_Check(value)) {
return SPEC_FAIL_CONTAINS_OP_USER_CLASS;
}
return SPEC_FAIL_OTHER;
}
#endif // Py_STATS
void
_Py_Specialize_ContainsOp(PyObject *value, _Py_CODEUNIT *instr)
{
assert(ENABLE_SPECIALIZATION);
assert(_PyOpcode_Caches[CONTAINS_OP] == INLINE_CACHE_ENTRIES_COMPARE_OP);
_PyContainsOpCache *cache = (_PyContainsOpCache *)(instr + 1);
if (PyUnicode_CheckExact(value)) {
instr->op.code = CONTAINS_OP_STR;
goto success;
}
if (PyList_CheckExact(value)) {
instr->op.code = CONTAINS_OP_LIST;
goto success;
}
if (PyTuple_CheckExact(value)) {
instr->op.code = CONTAINS_OP_TUPLE;
goto success;
}
if (PyDict_CheckExact(value)) {
instr->op.code = CONTAINS_OP_DICT;
goto success;
}
if (PySet_CheckExact(value)) {
if (PySet_CheckExact(value) || PyFrozenSet_CheckExact(value)) {
instr->op.code = CONTAINS_OP_SET;
goto success;
}
SPECIALIZATION_FAIL(CONTAINS_OP, containsop_fail_kind(value));
STAT_INC(CONTAINS_OP, failure);
instr->op.code = CONTAINS_OP;
cache->counter = adaptive_counter_backoff(cache->counter);