Optimized Rest Parameter -> Spread Operator#628
Closed
Conversation
Contributor
|
This optimization shouldn't be applied if it's used in the inner function: function foo(...a: any[]) {
function bar() {
print(...a);
}
}function foo(self, ...)
local function bar(self)
print(...)
end
end |
Contributor
|
It also shouldn't optimize it in try-catch function foo(...a: any[]) {
try {
print(...a);
} catch {}
}and expressions that require IIFE function foo(...a: any[]) {
const _ = (0, print(...a));
} |
Collaborator
Author
|
closing to open as a fresh PR since it's changed so radically |
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.
When a rest parameter is referenced with a spread operator, the transformed code packs and unpacks it:
=>
This PR optimizes this so that the elipsis operator is used instead.It also prevents generation of the temp local if it is not needed in the function.Update
Due to issues with the optimization being applied inside generated IIFE's, this PR has been updated to instead provide an explicit
@elipsisForwarddirective to apply this optimization.=>
The new directive can only be used on a function, and that function can only be used in a spread expression, and passed a rest argument.
You can also pass no argument, which is useful for accessing the file-scope elipsis:
=>