-
Notifications
You must be signed in to change notification settings - Fork 423
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dyno: Resolve nested functions without outer variables (#24523)
This PR adds support to the new compiler for resolving nested functions that do not contain any references to outer variables. To do so, it adds a new meta-type `OuterVariables`, which stores the outer variables used in a nested function as well as their mentions. Currently, both are stored in lexical order. Note that module-scope variables are not considered to be an outer variable for the purposes of this analysis, as they have an infinite lifetime. The set of outer variables is computed using a new query `computeOuterVariables`. This query is implemented by leveraging the `scopeResolveFunction` query, since that also necessitates full traversal of the function. Note that determination of outer variables for a given nested function 'NF' also requires us to call `computeOuterVariables` for any child functions of NF, so that we can propagate distant outer variables. The queries `resolveFunction` and `resolveConcreteFunction` as well as `instantiateSignature` have been adjusted. If a nested function does not capture outer variables, it can be resolved using the normal process. In this case, nesting of the function is just a syntactic convenience for the user, and does not affect the function's resolution at all. I've added a predicate `idIsNestedFunction` to the parsing queries header. I've also introduced a new `ID` method called `isSymbolDefiningScope`, which before was implicitly encoded in the test `id.postOrderId() == -1`. FUTURE WORK - We may not need to store mentions in `OuterVariables`, and we may not need to store variables in lexical order. In this case, the type can be simplified. I leave that as future work. - Nested functions that use outer variables will need to be resolved eventually, and the implementation will probably consist of a combination of: storing close outer variables (those defined in the scope of our immediate parent) in a function's `TypedFnSignature`, as well as passing in some sort of `CallContext` when resolving a call to a (potentially nested) function. The `CallContext` would include the types of outer variables represented in some form, as well as the current `PoiInfo`. This would enable us to instantiate the initial signature for a nested function and perform resolution as normal. Reviewed by @DanilaFe. Thanks!
- Loading branch information
Showing
11 changed files
with
575 additions
and
17 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.