Skip to content

Prohibit isolated conformances with Sendable(Metatype) constraints #79724

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

DougGregor
Copy link
Member

Isolated conformances can only safely be used in a manner that will never escape out of the isolation domain to which they are restricted. There are two rules governing this:

  1. The isolated conformance can only be referenced within the same isolation domain, e.g., a @MainActor conformance can only be referenced from @MainActor code.
  2. The isolated conformance cannot escape out of the domain, e.g., by being used in conjunction with generic code that treats the type as Sendable or whose metatype is Sendable.

This pull request implements the second rule by prohibiting isolated conformances from being used to satisfy constraints on generic parameters that conform to either Sendable or SendableMetatype. There are two places we need this same check: when checking the wellformedness of substitution maps in general (e.g., for forming types), and within the constraint system. The first is mostly straightforward, although there are gaps in this implementation that involve associated conformances.

Within the constraint system, we introduce a new kind of conformance constraint, a "nonisolated conforms-to" constraint, which can only be satisfied by nonisolated conformances. Introduce this constraint instead of the normal conforms-to constraint whenever the subject type is a type parameter that has either a Sendable or SendableMetatype constraint, i.e., when the type or its values can escape the current isolation domain.

Within the constraint system, introduce a new kind of conformance constraint,
a "nonisolated conforms-to" constraint, which can only be satisfied by
nonisolated conformances. Introduce this constraint instead of the normal
conforms-to constraint whenever the subject type is a type parameter that
has either a `Sendable` or `SendableMetatype` constraint, i.e., when the type
or its values can escape the current isolation domain.
@DougGregor DougGregor force-pushed the isolated-conformances-constraint-system branch from 189bebd to 6a4d1a4 Compare March 1, 2025 16:19
@DougGregor
Copy link
Member Author

@swift-ci please smoke test

@DougGregor DougGregor enabled auto-merge March 1, 2025 16:20
@DougGregor DougGregor merged commit ee2450f into swiftlang:main Mar 1, 2025
3 checks passed
@DougGregor DougGregor deleted the isolated-conformances-constraint-system branch March 2, 2025 01:07
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