summaryrefslogtreecommitdiffstats
path: root/Python/specialize.c
diff options
context:
space:
mode:
authorKen Jin <kenjin@python.org>2024-03-07 16:21:21 (GMT)
committerGitHub <noreply@github.com>2024-03-07 16:21:21 (GMT)
commit41457c7fdb04819d04a528b8dfa72c1aa5745cc9 (patch)
tree45a20bbed062946dae7b20c9fb616245b2751485 /Python/specialize.c
parent4298d69d4b2f7d0e9d93ad325238930bd6235dbf (diff)
downloadcpython-41457c7fdb04819d04a528b8dfa72c1aa5745cc9.zip
cpython-41457c7fdb04819d04a528b8dfa72c1aa5745cc9.tar.gz
cpython-41457c7fdb04819d04a528b8dfa72c1aa5745cc9.tar.bz2
gh-116381: Remove bad specializations, add fail stats (GH-116464)
* Remove bad specializations, add fail stats
Diffstat (limited to 'Python/specialize.c')
-rw-r--r--Python/specialize.c40
1 files changed, 26 insertions, 14 deletions
diff --git a/Python/specialize.c b/Python/specialize.c
index 5d339b8..b1f9eb7 100644
--- a/Python/specialize.c
+++ b/Python/specialize.c
@@ -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();
}
-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);
+#ifdef Py_STATS
+static int containsop_fail_kind(PyObject *value) {
if (PyUnicode_CheckExact(value)) {
- instr->op.code = CONTAINS_OP_STR;
- goto success;
+ return SPEC_FAIL_CONTAINS_OP_STR;
}
if (PyList_CheckExact(value)) {
- instr->op.code = CONTAINS_OP_LIST;
- goto success;
+ return SPEC_FAIL_CONTAINS_OP_LIST;
}
if (PyTuple_CheckExact(value)) {
- instr->op.code = CONTAINS_OP_TUPLE;
- goto success;
+ 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 (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);