gh-126835: Disable tuple folding in the AST optimizer#128802
Conversation
|
Why have tests been removed from test_compile and test_peepholer? The tests in test_opcache should not be removed, but should be changed to keep the unpacking operation by moving the tuple out of the loop. for ...
a, b = 1, 2use t = 1, 2
for ...
a, b = t |
Sorry, something went wrong.
Thank you, for some reason I forgot about non-constant case... |
Sorry, something went wrong.
No. You can remove that test. Try to keep any tests that test behavior, but any that just test artifacts (like the test for
Yes, leave that for another PR. As an aside: |
Sorry, something went wrong.
I think we could do that in the follow-up PR. @markshannon do you think it's ok to merge this PR? This PR only removes parts of test_ast which are basically tests AST optimizations, and incorrect test in test_compile. Any other changes are simply commenting some parts of tests, which we can uncomment later when other optimizations will take place in CFG. |
Sorry, something went wrong.
This normally should not be done in the parser as the general idea is that the parser gives the most pure AST to the next step in the pipeline and every modification and optimisations happens there. There are many reasons for this but the classical one is to not make the life of formatters and similar tools hard and not to make unparsing harder. |
Sorry, something went wrong.
I guess you mean to use the word "hard" here. Otherwise, do the parser team make someone's life harder on purpose? 🤣 |
Sorry, something went wrong.
Haha, indeed! 😆
Maybe just our own life 😉 |
Sorry, something went wrong.
|
FYI, I plan to merge this tomorrow, as this PR is quite small and I don't see any points here which need further discussion. Mark's comments have already been addressed. |
Sorry, something went wrong.
iritkatriel
left a comment
There was a problem hiding this comment.
I think this PR will need documentation because ast.parse no longer optimises this, and it's part of the stdlib API. If the optimisations in final bytecode changed then it needs to be mentioned in WhatsNew.
Sorry, something went wrong.
|
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
Sorry, something went wrong.
…en to CFG (#129426) Codegen phase has an optimization that transforms ``` LOAD_CONST x LOAD_CONST y LOAD_CONXT z BUILD_LIST/BUILD_SET (3) ``` -> ``` BUILD_LIST/BUILD_SET (0) LOAD_CONST (x, y, z) LIST_EXTEND/SET_UPDATE 1 ``` This optimization has now been moved to CFG phase to make #128802 work. Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com> Co-authored-by: Yan Yanchii <yyanchiy@gmail.com>
… codegen to CFG (python#129426) Codegen phase has an optimization that transforms ``` LOAD_CONST x LOAD_CONST y LOAD_CONXT z BUILD_LIST/BUILD_SET (3) ``` -> ``` BUILD_LIST/BUILD_SET (0) LOAD_CONST (x, y, z) LIST_EXTEND/SET_UPDATE 1 ``` This optimization has now been moved to CFG phase to make python#128802 work. Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com> Co-authored-by: Yan Yanchii <yyanchiy@gmail.com>
WolframAlph
left a comment
There was a problem hiding this comment.
Thanks. I did a quick review and left some comments.
Sorry, something went wrong.
Sorry, something went wrong.
This disables tuple-folding in the AST optimizer which allows the flowgraph to optimize them instead.
Related comment: #126830 (comment)
I've done some local benchmarking with pyperf which showed some speedup for
unpack_sequencebut it'd be nice to have proper benchmarks for this :)cc @Eclips4