-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Parametrized protocol types #40714
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 16 commits into
swiftlang:main
from
slavapestov:parametrized-protocol-type
Jan 26, 2022
Merged
Parametrized protocol types #40714
slavapestov
merged 16 commits into
swiftlang:main
from
slavapestov:parametrized-protocol-type
Jan 26, 2022
Conversation
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
0965475
to
f158c70
Compare
f158c70
to
92cc0c9
Compare
And ban them in other inheritance clauses.
Previously we would resolve the constraint type of an `any` using TypeResolverContext::GenericRequirement, but this does not allow us to distinguish between parametrized protocol types in generic requirements (which are supported) from parametrized protocol types inside an `any`, like `any Sequence<Int>`, which is not supported for now.
1a97cb6
to
e0a7999
Compare
@DougGregor I'm curious if this Just Works with #40993... |
e0a7999
to
06e58d2
Compare
@swift-ci Please smoke test |
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.
This allows you to write constructs like
Sequence<Int>
in generic requirement-like contexts:where
clausesWith the first three, the new syntax is just sugar. With opaque result types though, it gives you the ability to express something that could not previously be expressed.
The protocol must declare a primary associated type (for now, using the
@_primaryAssociatedType
attribute; this part isn't final). Assuming that the primary associated type ofSequence
isElement
, the desugaring is thatT : Sequence<Int>
is equivalent toT : Sequence where T.Element == Int
.Note that currently, neither
Sequence
nor any other standard library type actually use this new attribute. You can only use it with your own protocols for now.This is all gated by the
-enable-parametrized-protocol-types
flag, since this is an unofficial feature. I'll send out an evolution pitch soon.