aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Python/ast_opt.c
diff options
context:
space:
mode:
authorYan Yanchii <yyanchiy@gmail.com>2025-03-19 21:59:55 +0100
committerGitHub <noreply@github.com>2025-03-19 20:59:55 +0000
commit75103d975c33ab46f6eb64169eabfe68d806d7c5 (patch)
treebfc06cd26468069e3cdb369b4393eec58f521106 /Python/ast_opt.c
parent54efe296bc3f3e421b57d4487bb87ad4161600b2 (diff)
downloadcpython-75103d975c33ab46f6eb64169eabfe68d806d7c5.tar.gz
cpython-75103d975c33ab46f6eb64169eabfe68d806d7c5.zip
gh-126835: Move constant tuple folding from ast_opt to CFG (#130769)
Diffstat (limited to 'Python/ast_opt.c')
-rw-r--r--Python/ast_opt.c39
1 files changed, 0 insertions, 39 deletions
diff --git a/Python/ast_opt.c b/Python/ast_opt.c
index 4a191e919e4..8ee322fdd15 100644
--- a/Python/ast_opt.c
+++ b/Python/ast_opt.c
@@ -390,44 +390,6 @@ fold_binop(expr_ty node, PyArena *arena, _PyASTOptimizeState *state)
return 1;
}
-static PyObject*
-make_const_tuple(asdl_expr_seq *elts)
-{
- for (Py_ssize_t i = 0; i < asdl_seq_LEN(elts); i++) {
- expr_ty e = (expr_ty)asdl_seq_GET(elts, i);
- if (e->kind != Constant_kind) {
- return NULL;
- }
- }
-
- PyObject *newval = PyTuple_New(asdl_seq_LEN(elts));
- if (newval == NULL) {
- return NULL;
- }
-
- for (Py_ssize_t i = 0; i < asdl_seq_LEN(elts); i++) {
- expr_ty e = (expr_ty)asdl_seq_GET(elts, i);
- PyObject *v = e->v.Constant.value;
- PyTuple_SET_ITEM(newval, i, Py_NewRef(v));
- }
- return newval;
-}
-
-static int
-fold_tuple(expr_ty node, PyArena *arena, _PyASTOptimizeState *state)
-{
- if (state->syntax_check_only) {
- return 1;
- }
- PyObject *newval;
-
- if (node->v.Tuple.ctx != Load)
- return 1;
-
- newval = make_const_tuple(node->v.Tuple.elts);
- return make_const(node, newval, arena);
-}
-
static int astfold_mod(mod_ty node_, PyArena *ctx_, _PyASTOptimizeState *state);
static int astfold_stmt(stmt_ty node_, PyArena *ctx_, _PyASTOptimizeState *state);
static int astfold_expr(expr_ty node_, PyArena *ctx_, _PyASTOptimizeState *state);
@@ -620,7 +582,6 @@ astfold_expr(expr_ty node_, PyArena *ctx_, _PyASTOptimizeState *state)
break;
case Tuple_kind:
CALL_SEQ(astfold_expr, expr, node_->v.Tuple.elts);
- CALL(fold_tuple, expr_ty, node_);
break;
case Name_kind:
if (state->syntax_check_only) {