Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more FOR_ITER specialization stats #32151

Merged
merged 8 commits into from
Jun 13, 2022
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 46 additions & 2 deletions Python/specialize.c
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,12 @@ initial_counter_value(void) {
#define SPEC_FAIL_COMPARE_OP_EXTENDED_ARG 24

/* FOR_ITER */
#define SPEC_FAIL_FOR_ITER_REVERSED 4
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The values below 8 are common, in the section marked /* Common */ above.
You can always raise SPECIALIZATION_FAILURE_KINDS if you need.

#define SPEC_FAIL_FOR_ITER_SQLITE 5
#define SPEC_FAIL_FOR_ITER_IO 6
#define SPEC_FAIL_FOR_ITER_CALLABLE 7
#define SPEC_FAIL_FOR_ITER_FILTER 8
#define SPEC_FAIL_FOR_ITER_ELEMENTTREE 9
#define SPEC_FAIL_FOR_ITER_GENERATOR 10
#define SPEC_FAIL_FOR_ITER_COROUTINE 11
#define SPEC_FAIL_FOR_ITER_ASYNC_GENERATOR 12
Expand All @@ -466,6 +472,11 @@ initial_counter_value(void) {
#define SPEC_FAIL_FOR_ITER_DICT_ITEMS 21
#define SPEC_FAIL_FOR_ITER_DICT_VALUES 22
#define SPEC_FAIL_FOR_ITER_ENUMERATE 23
#define SPEC_FAIL_FOR_ITER_MAP 24
#define SPEC_FAIL_FOR_ITER_ZIP 25
#define SPEC_FAIL_FOR_ITER_SEQ_ITER 26
#define SPEC_FAIL_FOR_ITER_LIST_REVERSED 27
#define SPEC_FAIL_FOR_ITER_BYTEARRAY 28

// UNPACK_SEQUENCE

Expand Down Expand Up @@ -2037,10 +2048,43 @@ int
if (t == &PyEnum_Type) {
return SPEC_FAIL_FOR_ITER_ENUMERATE;
}

if (strncmp(t->tp_name, "itertools", 8) == 0) {
if (t == &PyMap_Type) {
return SPEC_FAIL_FOR_ITER_MAP;
}
if (t == &PyZip_Type) {
return SPEC_FAIL_FOR_ITER_ZIP;
}
if (t == &PySeqIter_Type) {
return SPEC_FAIL_FOR_ITER_SEQ_ITER;
}
if (t == &PyListRevIter_Type) {
return SPEC_FAIL_FOR_ITER_LIST_REVERSED;
}
if (t == &PyByteArrayIter_Type) {
return SPEC_FAIL_FOR_ITER_BYTEARRAY;
}
if (t == &PyFilter_Type) {
return SPEC_FAIL_FOR_ITER_FILTER;
}
if (t == &PyReversed_Type) {
return SPEC_FAIL_FOR_ITER_REVERSED;
}
const char *name = t->tp_name;
if (strncmp(name, "_elementtree", 12) == 0) {
return SPEC_FAIL_FOR_ITER_ELEMENTTREE;
}
if (strncmp(name, "itertools", 9) == 0) {
return SPEC_FAIL_FOR_ITER_ITERTOOLS;
}
if (strncmp(name, "_io.", 4) == 0) {
return SPEC_FAIL_FOR_ITER_IO;
}
if (strncmp(name, "callable_iterator", 17) == 0) {
return SPEC_FAIL_FOR_ITER_CALLABLE;
}
if (strncmp(name, "sqlite3.", 8) == 0) {
return SPEC_FAIL_FOR_ITER_SQLITE;
}
return SPEC_FAIL_OTHER;
}

Expand Down