-
-
Notifications
You must be signed in to change notification settings - Fork 30.6k
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
gh-125063: Move slice constant-folding to AST #126830
Conversation
Constant slices are now handled in AST
self.assertInBytecode(code, 'LOAD_CONST', '\uffffx') | ||
self.assertNotInBytecode(code,'BINARY_SUBSCR') | ||
self.check_lnotab(code) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Strictly speaking this test doesn't belong in test_peepholer
now that the optimization is not part of the peephole optimiser.
Where are the other const folding tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, Irit.
This test should be re-written and placed in the test_ast/test_ast.py::ASTOptimiziationTests
I want to suggest the opposite: remove the AST optimizer altogether. The flowgraph optimizer has more information and can do a better job.
is compiled to
but it should be (and would be but for the AST optimizer) compiled to this:
There are a few changes that the AST optimizer does that the flowgraph optimizer doesn't, and they could all be easily add The AST optimizer converts |
One more example that is probably more relevant to this PR.
is currently compiled as:
we might want to compile it as:
This PR would prevent that. |
I concur with Mark. I would like to see the elimination of the ast optimizer, and I would be happy to do it. |
OK, so I'll close this then :) |
Thank you for your efforts, Petr! |
Generate slice constants in AST, rather than in codegen.
This could allow more optimizations in earlier steps, albeit in practice it probably only helps rare cases (e.g.
"abc"[:1]
->"a'
).Tests for the final result were added in GH-125064.