Skip to content

Commit 8c9ef8f

Browse files
authored
gh-100239: more stats for BINARY_OP/SUBSCR specialization (#132230)
1 parent 297e059 commit 8c9ef8f

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

Include/cpython/pystats.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
#define PYSTATS_MAX_UOP_ID 512
3333

34-
#define SPECIALIZATION_FAILURE_KINDS 44
34+
#define SPECIALIZATION_FAILURE_KINDS 50
3535

3636
/* Stats for determining who is calling PyEval_EvalFrame */
3737
#define EVAL_CALL_TOTAL 0

Python/specialize.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,12 @@ _PyCode_Quicken(_Py_CODEUNIT *instructions, Py_ssize_t size, int enable_counters
604604
#define SPEC_FAIL_BINARY_OP_SUBSCR_DEQUE 42
605605
#define SPEC_FAIL_BINARY_OP_SUBSCR_ENUMDICT 43
606606
#define SPEC_FAIL_BINARY_OP_SUBSCR_STACKSUMMARY 44
607+
#define SPEC_FAIL_BINARY_OP_SUBSCR_DEFAULTDICT 45
608+
#define SPEC_FAIL_BINARY_OP_SUBSCR_COUNTER 46
609+
#define SPEC_FAIL_BINARY_OP_SUBSCR_ORDEREDDICT 47
610+
#define SPEC_FAIL_BINARY_OP_SUBSCR_BYTES 48
611+
#define SPEC_FAIL_BINARY_OP_SUBSCR_STRUCTTIME 49
612+
#define SPEC_FAIL_BINARY_OP_SUBSCR_RANGE 50
607613

608614
/* Calls */
609615

@@ -2370,6 +2376,14 @@ binary_op_fail_kind(int oparg, PyObject *lhs, PyObject *rhs)
23702376
return SPEC_FAIL_BINARY_OP_SUBSCR_MAPPINGPROXY;
23712377
}
23722378

2379+
if (PyObject_TypeCheck(lhs, &PyBytes_Type)) {
2380+
return SPEC_FAIL_BINARY_OP_SUBSCR_BYTES;
2381+
}
2382+
2383+
if (PyObject_TypeCheck(lhs, &PyRange_Type)) {
2384+
return SPEC_FAIL_BINARY_OP_SUBSCR_RANGE;
2385+
}
2386+
23732387
if (strcmp(container_type->tp_name, "array.array") == 0) {
23742388
return SPEC_FAIL_BINARY_OP_SUBSCR_ARRAY;
23752389
}
@@ -2390,6 +2404,22 @@ binary_op_fail_kind(int oparg, PyObject *lhs, PyObject *rhs)
23902404
return SPEC_FAIL_BINARY_OP_SUBSCR_STACKSUMMARY;
23912405
}
23922406

2407+
if (strcmp(container_type->tp_name, "collections.defaultdict") == 0) {
2408+
return SPEC_FAIL_BINARY_OP_SUBSCR_DEFAULTDICT;
2409+
}
2410+
2411+
if (strcmp(container_type->tp_name, "Counter") == 0) {
2412+
return SPEC_FAIL_BINARY_OP_SUBSCR_COUNTER;
2413+
}
2414+
2415+
if (strcmp(container_type->tp_name, "collections.OrderedDict") == 0) {
2416+
return SPEC_FAIL_BINARY_OP_SUBSCR_ORDEREDDICT;
2417+
}
2418+
2419+
if (strcmp(container_type->tp_name, "time.struct_time") == 0) {
2420+
return SPEC_FAIL_BINARY_OP_SUBSCR_STRUCTTIME;
2421+
}
2422+
23932423
if (PySlice_Check(rhs)) {
23942424
return SPEC_FAIL_BINARY_OP_SUBSCR_OTHER_SLICE;
23952425
}

0 commit comments

Comments
 (0)