compat: shadow numeric for control variables on 5.4+ - #1165
Merged
Conversation
Member
|
@JJH090501 Thank you! Rebased and merged! |
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.
Closes #1164. Option 1, as decided in the issue: mirror the
forinshadowrather than making numeric control variables const in all targets.
Problem
lua_compat.adjust_codeonly had aforincase, so plain (non-macro) code thatwrites to a numeric
forvariable type checks and then generates invalid Lua:Change
teal/ast.tl—fornum_modifies_control_varonNode.teal/check/visitors.tl— thefornumvisitor sets it fromhas_been_written_to, the same wayforindoes, so writes from nestedfunctions are covered too.
teal/gen/lua_compat.tl— afornumcase. The shadow construction that wasinlined in the
forincase is factored out intoshadow_control_var()andshared; the new case is six lines.
The shadow is a no-op in every target, since writing to a numeric
forvariablehas never affected the iteration:
Tests
spec/lang/code_gen/fornum_spec.lua, deliberately parallel toforin_spec.lua:no shadow on 5.3, a shadow on 5.4 when the body assigns, none when it does not,
a loop with an explicit step, an assignment made from a nested function, and
nested loops where only the inner one is written to.
make selfbuildclean,busted --suppress-pending spec/1932 → 1938. Thereproduction above was verified end to end on Lua 5.5.1.