summaryrefslogtreecommitdiffstats
path: root/Python/codegen.c
diff options
context:
space:
mode:
authorKirill Podoprigora <kirill.bast9@mail.ru>2025-02-01 11:39:44 (GMT)
committerGitHub <noreply@github.com>2025-02-01 11:39:44 (GMT)
commit7d0521d5fc32f4837257e89e6ead652223ecfada (patch)
tree881e4082b7cc1d347ecd8408c464d4a4379b54b1 /Python/codegen.c
parentd89a5f6a6e65511a5f6e0618c4c30a7aa5aba56a (diff)
downloadcpython-7d0521d5fc32f4837257e89e6ead652223ecfada.zip
cpython-7d0521d5fc32f4837257e89e6ead652223ecfada.tar.gz
cpython-7d0521d5fc32f4837257e89e6ead652223ecfada.tar.bz2
gh-126835: Move optimization of constant sequence creation from codegen to CFG (#129426)
Codegen phase has an optimization that transforms ``` LOAD_CONST x LOAD_CONST y LOAD_CONXT z BUILD_LIST/BUILD_SET (3) ``` -> ``` BUILD_LIST/BUILD_SET (0) LOAD_CONST (x, y, z) LIST_EXTEND/SET_UPDATE 1 ``` This optimization has now been moved to CFG phase to make #128802 work. Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com> Co-authored-by: Yan Yanchii <yyanchiy@gmail.com>
Diffstat (limited to 'Python/codegen.c')
-rw-r--r--Python/codegen.c43
1 files changed, 0 insertions, 43 deletions
diff --git a/Python/codegen.c b/Python/codegen.c
index df3b5aa..0bf9526 100644
--- a/Python/codegen.c
+++ b/Python/codegen.c
@@ -201,9 +201,6 @@ static int codegen_subscript(compiler *, expr_ty);
static int codegen_slice_two_parts(compiler *, expr_ty);
static int codegen_slice(compiler *, expr_ty);
-static bool are_all_items_const(asdl_expr_seq *, Py_ssize_t, Py_ssize_t);
-
-
static int codegen_with(compiler *, stmt_ty, int);
static int codegen_async_with(compiler *, stmt_ty, int);
static int codegen_async_for(compiler *, stmt_ty);
@@ -3210,34 +3207,6 @@ starunpack_helper_impl(compiler *c, location loc,
int build, int add, int extend, int tuple)
{
Py_ssize_t n = asdl_seq_LEN(elts);
- if (!injected_arg && n > 2 && are_all_items_const(elts, 0, n)) {
- PyObject *folded = PyTuple_New(n);
- if (folded == NULL) {
- return ERROR;
- }
- for (Py_ssize_t i = 0; i < n; i++) {
- PyObject *val = ((expr_ty)asdl_seq_GET(elts, i))->v.Constant.value;
- PyTuple_SET_ITEM(folded, i, Py_NewRef(val));
- }
- if (tuple && !pushed) {
- ADDOP_LOAD_CONST_NEW(c, loc, folded);
- } else {
- if (add == SET_ADD) {
- Py_SETREF(folded, PyFrozenSet_New(folded));
- if (folded == NULL) {
- return ERROR;
- }
- }
- ADDOP_I(c, loc, build, pushed);
- ADDOP_LOAD_CONST_NEW(c, loc, folded);
- ADDOP_I(c, loc, extend, 1);
- if (tuple) {
- ADDOP_I(c, loc, CALL_INTRINSIC_1, INTRINSIC_LIST_TO_TUPLE);
- }
- }
- return SUCCESS;
- }
-
int big = n + pushed + (injected_arg ? 1 : 0) > STACK_USE_GUIDELINE;
int seen_star = 0;
for (Py_ssize_t i = 0; i < n; i++) {
@@ -3389,18 +3358,6 @@ codegen_set(compiler *c, expr_ty e)
BUILD_SET, SET_ADD, SET_UPDATE, 0);
}
-static bool
-are_all_items_const(asdl_expr_seq *seq, Py_ssize_t begin, Py_ssize_t end)
-{
- for (Py_ssize_t i = begin; i < end; i++) {
- expr_ty key = (expr_ty)asdl_seq_GET(seq, i);
- if (key == NULL || key->kind != Constant_kind) {
- return false;
- }
- }
- return true;
-}
-
static int
codegen_subdict(compiler *c, expr_ty e, Py_ssize_t begin, Py_ssize_t end)
{