Skip to content

Diagnose Availability for Parameterized Existential Types #58655

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 5, 2022

Conversation

CodaFi
Copy link
Contributor

@CodaFi CodaFi commented May 4, 2022

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 requested a review from rjmccall May 4, 2022 03:02
CodaFi added 2 commits May 3, 2022 23:35
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 force-pushed the proto-molecule branch from 28e31e1 to 5bcea41 Compare May 4, 2022 06:36
@CodaFi
Copy link
Contributor Author

CodaFi commented May 4, 2022

@swift-ci smoke test

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