Skip to content

[5.7] Diagnose Availability for Parameterized Existential Types #58900

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 4 commits into from
May 19, 2022

Conversation

CodaFi
Copy link
Contributor

@CodaFi CodaFi commented May 13, 2022

Cherry pick of #58655


Usages of parameterized existential types that involve runtime type metadata to resolve must be gated on the appropriate OS version in which those features have landed. This means the following usage classes must appear gated:

  • Checked casts (is, as?, as!)
  • As arguments to generic types (Foo<any P<T>>)
  • As type witnesses to protocol conformances
  • In erasure expressions (and optional-to-any erasure expressions)
  • In metatypes
  • Tuples

What does this leave?

  • Concrete usages
    • any P<T> as a parameter or result type
    • Any amount of optional types around existential types
    • Static casts (as)

It's worth calling out the fact that usages of parameterized existential types in tuples are banned but usages in struct members are not. This is due to the fact that Tuple identity and runtime layout is determined by a metadata query against each component type. Whereas for a struct, the opaque type layout does not depend upon the type metadata of the fields at runtime, and the identity of the struct is determined nominally rather than structurally.

Practically, this means that one can work around the lack of tuples by defining a struct with an equivalent type structure as fields:

struct AdHocEraser { var x: any P<T> }

rdar://92197245

CodaFi added 4 commits May 13, 2022 11:36
Usages of parameterized existential types that involve runtime type metadata to resolve must be gated on the appropriate OS version in which those features have landed. This means the following usage classes must appear gated:

- Checked casts (is, as?, as!)
- As arguments to generic types (Foo<any P<T>>)
- As type witnesses to protocol conformances
- In erasure expressions (and optional-to-any erasure expressions)
- In metatypes
- Tuples

What does this leave?

- Concrete usages
  - any P<T> as a parameter or result type
  - Any amount of optional types around existential types
  - Static casts (as)

It's worth calling out the fact that usages of parameterized existential types in tuples are banned but usages in struct members are not. This is due to the fact that Tuple identity and runtime layout is determined by a metadata query against each component type. Whereas for a struct, the opaque type layout does not depend upon the type metadata of the fields at runtime, and the identity of the struct is determined nominally rather than structurally.

Practically, this means that one can work around the lack of tuples by defining a struct with an equivalent type structure as fields:

struct AdHocEraser { var x: any P<T> }

rdar://92197245
@CodaFi CodaFi added the r5.7 label May 13, 2022
@CodaFi CodaFi requested a review from airspeedswift May 13, 2022 18:38
@CodaFi CodaFi requested a review from a team as a code owner May 13, 2022 18:38
@CodaFi
Copy link
Contributor Author

CodaFi commented May 13, 2022

@swift-ci test

@CodaFi CodaFi merged commit 8271718 into swiftlang:release/5.7-04182022 May 19, 2022
@CodaFi CodaFi deleted the rubber-eraser branch May 19, 2022 17:57
@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