diff options
author | Yan Yanchii <yyanchiy@gmail.com> | 2025-03-19 20:59:55 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-03-19 20:59:55 (GMT) |
commit | 75103d975c33ab46f6eb64169eabfe68d806d7c5 (patch) | |
tree | bfc06cd26468069e3cdb369b4393eec58f521106 /Python/codegen.c | |
parent | 54efe296bc3f3e421b57d4487bb87ad4161600b2 (diff) | |
download | cpython-75103d975c33ab46f6eb64169eabfe68d806d7c5.zip cpython-75103d975c33ab46f6eb64169eabfe68d806d7c5.tar.gz cpython-75103d975c33ab46f6eb64169eabfe68d806d7c5.tar.bz2 |
gh-126835: Move constant tuple folding from ast_opt to CFG (#130769)
Diffstat (limited to 'Python/codegen.c')
-rw-r--r-- | Python/codegen.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/Python/codegen.c b/Python/codegen.c index e1f6474..44d23ca 100644 --- a/Python/codegen.c +++ b/Python/codegen.c @@ -1688,11 +1688,26 @@ codegen_typealias(compiler *c, stmt_ty s) return SUCCESS; } +static bool +is_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 false; + } + } + return true; +} + /* Return false if the expression is a constant value except named singletons. Return true otherwise. */ static bool check_is_arg(expr_ty e) { + if (e->kind == Tuple_kind) { + return !is_const_tuple(e->v.Tuple.elts); + } if (e->kind != Constant_kind) { return true; } |