Skip to content

(More) Declaration checker support for tuple conformances #68282

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
merged 11 commits into from
Sep 7, 2023

Conversation

slavapestov
Copy link
Contributor

@slavapestov slavapestov commented Sep 1, 2023

This PR implements a new syntax that doesn't require -parse-stdlib, suggested by @hborla. The nice thing is that we want it to just work anyway, even if/when a new syntax is added:

typealias MyTuple<each Horse> = (repeat each Horse)
extension MyTuple: P where repeat each Horse: P {...}

Or with requirement inference:

typealias MyTuple<each Horse: P> = (repeat each Horse)
extension MyTuple: P {...}

This PR also implements enforcement of various semantic restrictions:

  • Extended type must be (repeat each T) where T is the type parameter pack of the alias.

  • A tuple extension must define a conformance to exactly one protocol P, this conformance must be conditional, and there must be exactly one conditional requirement that is a pack conformance requirement of T to P. You cannot have extension Tuple: P where repeat each T: Q, because if T is replaced with a single scalar type X, we get X: P where X: Q, which is false in general unless P inherits from Q.

  • An associated type A must be witnessed by (repeat (each T).A) in the conformance; that is, we require that (repeat each T).A == (repeat (each T).A). This restriction is required for a similar reason, for coherence with the one-element vanishing substitution.

The above is not enough to ensure coherence. We also need to statically and dynamically unwrap one-element tuple conformances, and prevent devirtualization of certain calls. This will happen in a subsequent PR.

@slavapestov slavapestov force-pushed the sema-tuple-conformances branch from 6b993ea to 0819ec0 Compare September 6, 2023 03:11
@slavapestov slavapestov changed the title Declaration checker support for tuple conformances (More) Declaration checker support for tuple conformances Sep 6, 2023
@slavapestov slavapestov force-pushed the sema-tuple-conformances branch from 0819ec0 to 1a17547 Compare September 6, 2023 03:21
@slavapestov
Copy link
Contributor Author

@swift-ci Please smoke test

We want that (repeat each Element).[P]A == (repeat (each Element).[P]A),
where on the left is type witness projection from the tuple conformance,
and on the right is a tuple with a pack expansion.
@slavapestov slavapestov force-pushed the sema-tuple-conformances branch from 1a17547 to 7dacc5e Compare September 7, 2023 04:47
@slavapestov
Copy link
Contributor Author

@swift-ci Please smoke test

@slavapestov
Copy link
Contributor Author

@swift-ci Please test Windows

@slavapestov slavapestov merged commit 973a506 into swiftlang:main Sep 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant