Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pack expansion closures, part 6 #73712

Merged
merged 8 commits into from
May 18, 2024

Conversation

slavapestov
Copy link
Member

@slavapestov slavapestov commented May 17, 2024

Follow-up to #73685.

This implements support for autoclosures, closures and local functions nested within a pack iteration for loop, in what I believe is full generality.

Some combinations of closures also work with pack expansion expressions, but not all; this part needs more work in the solver.

General idea:

  • Capture analysis records references to ElementArchetypeTypes that are defined outside of the scope of the current function.
  • SIL type lowering extends the generic signature of the closure or local function with new generic parameters corresponding to the captured local archetypes.
  • Interface types of AST declarations in local context may contain element archetypes; SIL type lowering maps them to interface types in the extended signature.
  • SILGen lowers the code using the old generic signature's primary archetypes and local archetypes, which are out of scope, as before. A post-pass rewrites SIL instructions, replacing the old primary archetypes and local archetypes with primary archetypes for the new signature.
  • SILGen rewrites substitution maps when calling a closure, forwarding substitutions for any local archetypes it captures.

When a closure doesn't capture any local archetypes, the extended generic signature is the same as the original generic signature, and we skip the substitution map transform, etc.

Fixes #66917.
Fixes #69947.
Fixes rdar://113505724.
Fixes rdar://122293832.
Fixes rdar://124329076.

@slavapestov slavapestov force-pushed the pack-expansion-closures-part-6 branch from 8631a24 to 4a5e905 Compare May 17, 2024 17:16
@slavapestov slavapestov force-pushed the pack-expansion-closures-part-6 branch 2 times, most recently from 0c5ef74 to 1368bc9 Compare May 17, 2024 20:26
@slavapestov slavapestov marked this pull request as ready for review May 17, 2024 20:26
@slavapestov
Copy link
Member Author

@swift-ci Please smoke test

@simanerush
Copy link
Member

Looks like this also resolves #73551 🙂

…losure

The generic environment introduced by a `for .. in` statement remains in
scope until the end of the statement. Copy and paste (ugh) the book-keeping
from ASTVerifier for this.
This implements support for autoclosures, closures and local functions
nested within a pack iteration for loop.

The combination of explicit closure expressions and pack expansion
expressions still needs some work.

Fixes apple#66917.
Fixes apple#69947.
Fixes rdar://113505724.
Fixes rdar://122293832.
Fixes rdar://124329076.
@slavapestov slavapestov force-pushed the pack-expansion-closures-part-6 branch from 1368bc9 to 4aa0008 Compare May 17, 2024 21:45
@slavapestov
Copy link
Member Author

@swift-ci Please test

@slavapestov
Copy link
Member Author

@swift-ci Please test source compatibility

@slavapestov slavapestov merged commit c7c244e into apple:main May 18, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants