[issue29469] AST-level Constant folding

Serhiy Storchaka report at bugs.python.org
Mon Jul 3 10:26:45 EDT 2017


Serhiy Storchaka added the comment:

In general the patch LGTM. I haven't found bugs.

I think that at this stage we can asdl_ct.py and ast_opt.ct and use just their result, ast_opt.c (maybe rename to optimize.c?) The grammar is not often changed, and in that case it would be not hard to modify the code manually. In any case compile.c should be modified manually. After removing no-op functions like astfold_operator() and inlining simple functions like astfold_arg() the code should be clearer.

Instead of converting all kinds of constants to Constant_kind, you could use is_const() and get_const_value() from compile.c.

I suggest to remove the parts of the peepholer that are superseeded by the AST optimizer.

As for preventing expensive calculations, there is a patch for the peepholer that does this. I wait on implementing the AST-level constant folding for adapting that patch for it.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue29469>
_______________________________________


More information about the Python-bugs-list mailing list