Skip to content

[5.7][ASTPrinter] Print the desugared constraint type following the any keyword. #59077

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

Conversation

hborla
Copy link
Member

@hborla hborla commented May 25, 2022

Cherry-pick of #59041

  • Explanation: Currently, a protocol typealias with an underlying constraint type (i.e. a protocol or protocol composition) can be used as an existential type by accessing the alias through a type parameter, e.g.
protocol P1 {
  typealias A = P2
}

protocol P2 {}

func generic<T: P1>(value: (T) -> T.A) {} // okay

However, verifying that the underlying type of T.A is a constraint type is a circular computation in the general case, which is needed to use the any keyword. Resolving T.A where T is a type parameter needs a full generic signature to access the requirements on T, but a full generic signature needs the existential type verification.

This is an issue when T.A is written in source, and any is automatically printed in Swift interfaces. For now, simply print the underlying constraint type.

  • Scope: This change only affects Swift interfaces for resilient libraries using existential types via typealiases in public API.
  • Risk: Low.
  • Testing: Added new unit tests.
  • Reviewer: @slavapestov @tshortli

Resolves: rdar://93780361

@hborla hborla requested a review from a team as a code owner May 25, 2022 18:05
@hborla
Copy link
Member Author

hborla commented May 25, 2022

@swift-ci please test

@hborla hborla added the r5.7 label May 25, 2022
@hborla hborla merged commit fec9add into swiftlang:release/5.7 May 25, 2022
@hborla hborla deleted the 5.7-protocol-typealias-existential branch May 25, 2022 23:43
@AnthonyLatsis AnthonyLatsis added 🍒 release cherry pick Flag: Release branch cherry picks swift 5.7 labels Jan 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🍒 release cherry pick Flag: Release branch cherry picks swift 5.7
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants