-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[6.0] Support closures that capture opened pack element types #73541
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
Merged
slavapestov
merged 21 commits into
swiftlang:release/6.0
from
slavapestov:pack-expansion-closures-6.0
May 23, 2024
Merged
[6.0] Support closures that capture opened pack element types #73541
slavapestov
merged 21 commits into
swiftlang:release/6.0
from
slavapestov:pack-expansion-closures-6.0
May 23, 2024
Conversation
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
6a9ef4c
to
6181034
Compare
3b6a294
to
a203283
Compare
a203283
to
f6d6774
Compare
@swift-ci Please test |
@swift-ci Please test source compatibility |
(swift-distributed-actors fails with the same error in the baseline source compat run) |
On main I refactored it away, but here I'm just renaming the old one to avoid a name conflict.
The existing hasArchetype() is now deprecated. It is equivalent to: hasPrimaryArchetype() || hasLocalArchetype() Callers should be changed to check one or both of the above predicates in the most precise way possible.
We don't need to build a DenseMap here. More importantly, this changes the logic to avoid calling mapTypeOutOfContext() on element archetypes, instead doing the mapping directly.
…nresolved local archetypes We maintained a counter of the number of pending local archetypes that had not yet been defined. However, if an instruction that references a pending local archetype was deleted before the local archetype was defined, the counter would never decrement. Before reading the counter value, garbage collect any inserted placeholders that have no uses. These correspond to pending local archetypes that are no longer in use and will never be defined.
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 swiftlang#66917. Fixes swiftlang#69947. Fixes rdar://113505724. Fixes rdar://122293832. Fixes rdar://124329076.
f6d6774
to
4c36819
Compare
@swift-ci Please test |
hborla
approved these changes
May 22, 2024
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.
Partial 6.0 cherry-pick of #73712 and previous PRs.
Description: Closures can capture values of pack element type, which are introduced by a
repeat
expression or afor ... in repeat
loop. For example, here we accidentally capture a pack element type, because&&
takes an autoclosure:This would cause crashes and type checking errors. This PR implements the SIL lowering support for closures that capture pack elements. Some solver support is incomplete, however a bunch of cases now work.
Scope of the issue: Affects many users, and is even easier to hit now with
for ... in repeat
loops.Origination: This never worked.
Risk: I believe Low for code that doesn't use packs, Medium for code using packs. There's a bunch of stuff here:
for ... in repeat
loop. Some extra book-keeping that used to exist is now subsumed into my new logic. This might break existing code, but pack iteration is a new feature in 6.0. This change was separately reviewed onmain
by @simanerush.Reviewed by: review pending - @hborla @rjmccall @simanerush
Radar: rdar://113505724, rdar://122293832, rdar://124329076.