gh-126835: Move constant tuple folding from ast_opt to CFG (#130769)

This commit is contained in:
Yan Yanchii 2025-03-19 21:59:55 +01:00 committed by GitHub
parent 54efe296bc
commit 75103d975c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 264 additions and 172 deletions

View file

@ -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;
}