F2dace/fix local consts do block #2194
Open
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.
This PR fixes a bug in
_track_local_constants/exploit_locally_constant_variables()forBlock_Nonlabel_Do_ConstructandBlock_Label_Do_Constructloops. Instead of explicitly calling_track_local_constants()separately for each op in the do block, we let the recursive call iterate through the list by itself. This means that the buffer of locally constant variables persists between individual lines of the do block and something like the following works:The modification to
test_exploit_locally_constant_variables()checks for this condition. Additionally, the test checks whether unmodified constant variables set outside the loop are propagated inside, although this already worked before the fix.This PR also makes a similar simplification in the same function for
Assignment_Stmt. It is unnecessary to call_inject_knowns()individually for the left and right sides because this is already handled by_inject_knowns()itself. Note that this simplification is not a fix, so no additional tests are needed.All 49 tests in
ast_desugaring_test.pypass.