mirror of
https://github.com/python/cpython.git
synced 2025-08-28 04:35:02 +00:00
gh-126835: Move constant subscript folding to CFG (#129568)
Move folding of constant subscription from AST optimizer to CFG. Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
This commit is contained in:
parent
bb5c6875d6
commit
0664c1af9b
6 changed files with 138 additions and 31 deletions
|
@ -567,25 +567,6 @@ fold_tuple(expr_ty node, PyArena *arena, _PyASTOptimizeState *state)
|
|||
return make_const(node, newval, arena);
|
||||
}
|
||||
|
||||
static int
|
||||
fold_subscr(expr_ty node, PyArena *arena, _PyASTOptimizeState *state)
|
||||
{
|
||||
PyObject *newval;
|
||||
expr_ty arg, idx;
|
||||
|
||||
arg = node->v.Subscript.value;
|
||||
idx = node->v.Subscript.slice;
|
||||
if (node->v.Subscript.ctx != Load ||
|
||||
arg->kind != Constant_kind ||
|
||||
idx->kind != Constant_kind)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
newval = PyObject_GetItem(arg->v.Constant.value, idx->v.Constant.value);
|
||||
return make_const(node, newval, arena);
|
||||
}
|
||||
|
||||
/* Change literal list or set of constants into constant
|
||||
tuple or frozenset respectively. Change literal list of
|
||||
non-constants into tuple.
|
||||
|
@ -822,7 +803,6 @@ astfold_expr(expr_ty node_, PyArena *ctx_, _PyASTOptimizeState *state)
|
|||
case Subscript_kind:
|
||||
CALL(astfold_expr, expr_ty, node_->v.Subscript.value);
|
||||
CALL(astfold_expr, expr_ty, node_->v.Subscript.slice);
|
||||
CALL(fold_subscr, expr_ty, node_);
|
||||
break;
|
||||
case Starred_kind:
|
||||
CALL(astfold_expr, expr_ty, node_->v.Starred.value);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue