Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimized ast #108

Closed
s-cork opened this issue Jul 24, 2021 · 1 comment
Closed

optimized ast #108

s-cork opened this issue Jul 24, 2021 · 1 comment

Comments

@s-cork
Copy link
Contributor

s-cork commented Jul 24, 2021

Before running the symtable in compile.c there is an ast optimization phase that we should explore.

It seems to do some code folding of literal values.

see ast_opt.c

@s-cork
Copy link
Contributor Author

s-cork commented Jul 24, 2021

python/cpython#2858
Problems with the c approach - they change the nodes inplace.
We can't really do that.
I mean we could - but it would be horrible

tests

I couldn't find any in python 🤷‍♂️ but this discussion about the above PR points to these tests
https://github.com/vstinner/fatoptimizer/blob/master/test_fatoptimizer.py

pypy has an interesting approach that allows for inplace mutation.
I think we should try this approach
https://github.com/mozillazg/pypy/blob/master/pypy/interpreter/astcompiler/optimize.py
https://github.com/mozillazg/pypy/blob/522cfbedda554843fd989f1b1214e61b47fce0ab/pypy/interpreter/astcompiler/ast.py

That approach might also be nice for other places we do walk the node tree

@s-cork s-cork closed this as completed Jul 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant