bpo-29469: peephole: Remove const_stack#4879
Merged
methane merged 5 commits intopython:masterfrom Dec 18, 2017
Merged
Conversation
Constant folding was moved to AST optimizer. But compiler may emit LOAD_CONSTs + BUILD_TUPLE. For example, default arguments can be constant tuple if all arguments are constant. This commit makes peephole's tuple folding simple. It doesn't support nested tuples because nested tuples are folded by AST optimizer already.
2a0d3d4 to
915a1a4
Compare
Python/peephole.c
Outdated
| Py_ssize_t len_consts = PyList_GET_SIZE(consts); | ||
| Py_ssize_t i, pos; | ||
|
|
||
| for (i=0, pos=c_start; i<n; i++, pos++) { |
Member
There was a problem hiding this comment.
While we are here please add spaces around operators to conform PEP 8.
Member
serhiy-storchaka
left a comment
There was a problem hiding this comment.
Added few style comments.
Python/peephole.c
Outdated
| for (i=0 ; i<n ; i++) { | ||
| constant = objs[i]; | ||
|
|
||
| Py_ssize_t len_consts = PyList_GET_SIZE(consts); |
Member
There was a problem hiding this comment.
Why this have been moved? It is better to get a size just before calling PyList_Append() as in previous code.
Python/peephole.c
Outdated
| constant = objs[i]; | ||
|
|
||
| Py_ssize_t len_consts = PyList_GET_SIZE(consts); | ||
| Py_ssize_t i, pos; |
Member
There was a problem hiding this comment.
Why declarations were moved in the middle of the code?
Python/peephole.c
Outdated
| Py_ssize_t const_stack_top = -1; | ||
| Py_ssize_t const_stack_size = 0; | ||
| int in_consts = 0; /* whether we are in a LOAD_CONST sequence */ | ||
| unsigned int cumlc=0, lastlc=0; // Count runs of consecutive LOAD_CONSTs |
Member
|
This works, but I think the code can be simpler and more robust. |
Member
|
The code LGTM in any case (besides style nits). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Constant folding was moved to AST optimizer.
But compiler may emit LOAD_CONSTs + BUILD_TUPLE.
For example, default arguments can be constant tuple
if all arguments are constant.
This commit makes peephole's tuple folding simple.
It doesn't support nested tuples because nested
tuples are folded by AST optimizer already.
https://bugs.python.org/issue29469