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.
I decided to close PR #449 simply because the diff to main became too high.
This PR adds support for compiling
ArrayPattern
,ObjectPattern
, andRestElement
constructs, along with related tests.Changes to the codebase have been kept as minimal as possible since, in most cases, we only need functions with plain parameters. That is why we now provide two constructors for the
Parameters
structure. The old constructor remains unchanged, while the new one includes an additional argument—patterns
—which stores the signature’s "structure" used for type inference and lifting.If I understand correctly,
JSTyper.swift
performs type inference both on the function's signature and on its inner outputs. In each case, a different view is required: A callee should see the parameters in the strict sense. For example, inthe function has two parameters: one is an array pattern and the other is an object pattern. However, within the function's scope, the parameters should be viewed in their destructured form—in this example, as a, b, c, and d. These destructured parameters are still typed as either plain (a single value), rest (an iterable), or opt (possibly undefined). These two views are toggled on and off using the outerView parameter in inferSubroutineParameterList.
CodeGenerators remain unchanged, simply the use case for these new Signatures is mainly for compilation, not for generation. I could write CodeGenerators that generates these functions along with suitable arguments if that is wanted.