8000 gh-131738: optimize builtin any/all/tuple calls with a generator expression arg by iritkatriel · Pull Request #131737 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-131738: optimize builtin any/all/tuple calls with a generator expression arg #131737

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

Merged
merged 17 commits into from
Mar 28, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
add CONSTANT_BUILTIN_ALL/ANY/TUPLE oparg for LOAD_COMMON_CONST
  • Loading branch information
iritkatriel committed Mar 25, 2025
commit 8de72765c7953d81ee1ee157fd6f757a2f37ce50
2 changes: 1 addition & 1 deletion Include/internal/pycore_opcode_metadata.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion Include/internal/pycore_opcode_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ extern "C" {
/* Values used as the oparg for LOAD_COMMON_CONSTANT */
#define CONSTANT_ASSERTIONERROR 0
#define CONSTANT_NOTIMPLEMENTEDERROR 1
#define NUM_COMMON_CONSTANTS 2
#define CONSTANT_BUILTIN_TUPLE 2
#define CONSTANT_BUILTIN_ALL 3
#define CONSTANT_BUILTIN_ANY 4
#define NUM_COMMON_CONSTANTS 5

/* Values used in the oparg for RESUME */
#define RESUME_AT_FUNC_START 0
Expand Down< 10000 /tool-tip>
2 changes: 1 addition & 1 deletion Include/internal/pycore_uop_metadata.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Lib/opcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"HAVE_ARGUMENT", "EXTENDED_ARG", "hasarg", "hasconst", "hasname",
"hasjump", "hasjrel", "hasjabs", "hasfree", "haslocal", "hasexc"]

import builtins
import _opcode
from _opcode import stack_effect

Expand Down Expand Up @@ -38,7 +39,8 @@
_intrinsic_1_descs = _opcode.get_intrinsic1_descs()
_intrinsic_2_descs = _opcode.get_intrinsic2_descs()
_special_method_names = _opcode.get_special_method_names()
_common_constants = [AssertionError, NotImplementedError]
_common_constants = [AssertionError, NotImplementedError,
builtins.tuple, builtins.all, builtins.any]
_nb_ops = _opcode.get_nb_ops()

hascompare = [opmap["COMPARE_OP"]]
Expand Down
15 changes: 13 additions & 2 deletions Python/bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -1409,10 +1409,21 @@ dummy_func(
if (oparg == CONSTANT_ASSERTIONERROR) {
val = PyExc_AssertionError;
}
else {
assert(oparg == CONSTANT_NOTIMPLEMENTEDERROR);
else if (oparg == CONSTANT_NOTIMPLEMENTEDERROR) {
val = PyExc_NotImplementedError;
}
else if (oparg == CONSTANT_BUILTIN_TUPLE) {
val = (PyObject*)&PyTuple_Type;
}
else if (oparg == CONSTANT_BUILTIN_ALL) {
val = PyDict_GetItemWithError(builtins_dict, &_Py_ID(all));
}
else if (oparg == CONSTANT_BUILTIN_ANY) {
val = PyDict_GetItemWithError(builtins_dict, &_Py_ID(any));
}
else {
Py_UNREACHABLE();
}
value = PyStackRef_FromPyObjectImmortal(val);
}

Expand Down
27 changes: 25 additions & 2 deletions Python/executor_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 25 additions & 2 deletions Python/generated_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0