[SE-0466] Under main actor default isolation, explicit nonisolated is not special

Given an explicitly-nonisolated type such as

    nonisolated struct S { }

all extensions of S were also being treated as nonisolated. This meant
that being implicitly nonisolated (i.e., when you're using nonisolated
default isolation) was different from explicitly-writing nonisolated,
which is unfortunate and confusing. Align the rules, such that an
extension of S will get default isolation:

    extension S {
      func f() { } // @MainActor if we're in main actor default isolation
    }
This commit is contained in:
Doug Gregor
2025-07-24 22:52:15 -07:00
parent e65eecbadc
commit 436e965b66
5 changed files with 60 additions and 3 deletions

View File

@@ -1852,8 +1852,10 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
Opts.DefaultIsolationBehavior = DefaultIsolation::Nonisolated;
}
if (Opts.DefaultIsolationBehavior == DefaultIsolation::MainActor)
if (Opts.DefaultIsolationBehavior == DefaultIsolation::MainActor) {
Opts.enableFeature(Feature::InferIsolatedConformances);
Opts.enableFeature(Feature::NoExplicitNonIsolated);
}
#if !defined(NDEBUG) && SWIFT_ENABLE_EXPERIMENTAL_PARSER_VALIDATION
/// Enable round trip parsing via the new swift parser unless it is disabled