Implement experimental feature InferIsolatedConformances

Introduce the experimental feature InferIsolatedConformances to align
with the upcoming feature proposed in SE-0470. This is a slight
generalization of the main-actor-specific inference that was already
in place for the default-main-actor mode from SE-0466. Note that, as
specified in SE-0470, InferIsolatedConformances is implied by the
default-main-actor mode.
This commit is contained in:
Doug Gregor
2025-03-21 11:41:46 -07:00
parent 2ce04930a4
commit 083194923c
4 changed files with 11 additions and 6 deletions

View File

@@ -496,7 +496,6 @@ SUPPRESSIBLE_EXPERIMENTAL_FEATURE(CustomAvailability, true)
/// Be strict about the Sendable conformance of metatypes. /// Be strict about the Sendable conformance of metatypes.
EXPERIMENTAL_FEATURE(StrictSendableMetatypes, true) EXPERIMENTAL_FEATURE(StrictSendableMetatypes, true)
/// Allow public enumerations to be extensible by default /// Allow public enumerations to be extensible by default
/// regardless of whether the module they are declared in /// regardless of whether the module they are declared in
/// is resilient or not. /// is resilient or not.
@@ -505,6 +504,9 @@ EXPERIMENTAL_FEATURE(ExtensibleEnums, true)
/// Allow isolated conformances. /// Allow isolated conformances.
EXPERIMENTAL_FEATURE(IsolatedConformances, true) EXPERIMENTAL_FEATURE(IsolatedConformances, true)
/// Infer conformance isolation on global-actor-conforming types.
EXPERIMENTAL_FEATURE(InferIsolatedConformances, true)
/// Allow SwiftSettings /// Allow SwiftSettings
EXPERIMENTAL_FEATURE(SwiftSettings, false) EXPERIMENTAL_FEATURE(SwiftSettings, false)

View File

@@ -331,6 +331,7 @@ UNINTERESTING_FEATURE(ReinitializeConsumeInMultiBlockDefer)
UNINTERESTING_FEATURE(SE427NoInferenceOnExtension) UNINTERESTING_FEATURE(SE427NoInferenceOnExtension)
UNINTERESTING_FEATURE(TrailingComma) UNINTERESTING_FEATURE(TrailingComma)
UNINTERESTING_FEATURE(RawIdentifiers) UNINTERESTING_FEATURE(RawIdentifiers)
UNINTERESTING_FEATURE(InferIsolatedConformances)
static ABIAttr *getABIAttr(Decl *decl) { static ABIAttr *getABIAttr(Decl *decl) {
if (auto pbd = dyn_cast<PatternBindingDecl>(decl)) if (auto pbd = dyn_cast<PatternBindingDecl>(decl))

View File

@@ -920,6 +920,9 @@ static bool ParseEnabledFeatureArgs(LangOptions &Opts, ArgList &Args,
if (Args.hasArg(OPT_strict_memory_safety)) if (Args.hasArg(OPT_strict_memory_safety))
Opts.enableFeature(Feature::StrictMemorySafety); Opts.enableFeature(Feature::StrictMemorySafety);
if (Opts.hasFeature(Feature::UnspecifiedMeansMainActorIsolated))
Opts.enableFeature(Feature::InferIsolatedConformances);
return HadError; return HadError;
} }

View File

@@ -7924,15 +7924,14 @@ ConformanceIsolationRequest::evaluate(Evaluator &evaluator, ProtocolConformance
if (getActorIsolation(rootNormal->getProtocol()).isActorIsolated()) if (getActorIsolation(rootNormal->getProtocol()).isActorIsolated())
return ActorIsolation::forNonisolated(false); return ActorIsolation::forNonisolated(false);
// In a context where we are inferring @MainActor, if the conforming type // If we are inferring isolated conformances and the conforming type is
// is on the main actor, then the conformance is, too. // isolated to a global actor,
auto nominal = dc->getSelfNominalTypeDecl(); auto nominal = dc->getSelfNominalTypeDecl();
if (ctx.LangOpts.hasFeature(Feature::UnspecifiedMeansMainActorIsolated) && if (ctx.LangOpts.hasFeature(Feature::InferIsolatedConformances) &&
nominal) { nominal) {
auto nominalIsolation = getActorIsolation(nominal); auto nominalIsolation = getActorIsolation(nominal);
if (nominalIsolation.isMainActor()) { if (nominalIsolation.isGlobalActor())
return nominalIsolation; return nominalIsolation;
}
} }
return ActorIsolation::forNonisolated(false); return ActorIsolation::forNonisolated(false);