Prohibit isolated conformances with Sendable(Metatype) constraints #79724
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
@MainActor
conformance can only be referenced from@MainActor
code.Sendable
or whose metatype isSendable
.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
orSendableMetatype
. 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
orSendableMetatype
constraint, i.e., when the type or its values can escape the current isolation domain.