[SE-0466] Don't infer @MainActor on types conforming to Sendable

When the default isolation is main-actor, don't infer @MainActor
for a type that conforms to a protocol P in its primary definition when
P inherits from Sendable. Such types should remain non-isolated
because they're highly unlikely to be able to implement the P
conformance (which cannot be isolated).

Put this feature behind a new experimental flag,
SendableProhibitsMainActorInference.

Implements rdar://151029300
This commit is contained in:
Doug Gregor
2025-05-12 22:22:25 -07:00
parent 5552d37668
commit ee9f6f8db7
4 changed files with 90 additions and 14 deletions

View File

@@ -532,6 +532,10 @@ EXPERIMENTAL_FEATURE(DefaultIsolationPerFile, false)
/// Enable @_lifetime attribute
SUPPRESSIBLE_EXPERIMENTAL_FEATURE(Lifetimes, true)
/// Disable @MainActor inference when the primary definition of a type conforms
/// to SendableMetatype (or Sendable).
EXPERIMENTAL_FEATURE(SendableProhibitsMainActorInference, true)
#undef EXPERIMENTAL_FEATURE_EXCLUDED_FROM_MODULE_INTERFACE
#undef EXPERIMENTAL_FEATURE
#undef UPCOMING_FEATURE