-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
523: perform `.closure` inference in `sempass2` r=zerbina a=zerbina ## Summary While the `lambdalifting` transformation is responsible for figuring out what inner procedures capture the content of which memory locations, semantic analysis already needs to know whether an inner procedure accesses its environment, as whether it does affects its calling convention (which is part of a procedure's type). `semCaptureSym` was responsible for detecting if usage of a symbol required a capture and for changing all relevant enclosing procedures between the to use the `.closure` calling convention, but the implementation had multiple issues. Instead, whether a procedure captures something is now detected during `sempass2`. Setting the calling convention is performed there too now. This fixes: - inner procedures using the `.closure` calling convention even if explicitly specified otherwise - tentative semantic analysis (such as `compiles` or analysis of argument expression during overload resolution) having side-effects because of `semCaptureSym` - symbols resulting from typed template/macro parameter expansion weren't considered by `semCaptureSym`, which in some cases caused procedures to not be updated to use the `.closure` calling convention, which then caused errors in the code-generator or backend compiler Detecting illegal captures now also happens in `sempass2` (instead of in `lambdalifting`), which means that they're now *always* reported and not only for alive code. A hint is now reported if a procedure uses the `.closure` calling convention but doesn't capture anything. ## Details - move illegal capture detection from `lambdalifting` into `sempass2` - detect whether a procedure captures something during `sempass2` instead of in `lambdalifting` - remove `semCaptureSym` and its usages - remove the `tfCapturesEnv` type flag. It's use case was detecting top-level closure procedures (can only be achieved via anonymous procedures), but a hidden environment parameter is added for them now, instead - report a dedicated error when attempting to capture a run-time value in a compile-time context Changes to `lambdalifting`: - remove the unused "in container" analysis - remove all logic for permanently changing a procedure's calling convention - run the pass on all non-`.closure` procedures (including top-level closure iterators) instead of only on top-level procedures. While this doesn't affect the result (all inner procedures that capture something are still lifted), it means less recursion depth and a smaller working set for each run, as well as less calls to `transformBody` (which translates to less work). ### Misc - change `rsemIllegalMemoryCapture` to use the `sym` field instead of `symbols` - move `isOwnedBy` from `vmgen.nim` to `ast_query.nim` Co-authored-by: zerbina <[email protected]>
- Loading branch information
Showing
17 changed files
with
414 additions
and
129 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.