Skip to content

Commit 2221c14

Browse files
committed
[Frontend] SE-0466: Add -default-isolation frontend that accepts MainActor and nonisolated
1 parent f8ab391 commit 2221c14

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed

include/swift/Basic/LangOptions.h

+8
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@ namespace swift {
9696
TaskToThread,
9797
};
9898

99+
enum class DefaultIsolation : uint8_t {
100+
MainActor,
101+
Nonisolated
102+
};
103+
99104
/// Describes the code size optimization behavior for code associated with
100105
/// declarations that are marked unavailable.
101106
enum class UnavailableDeclOptimization : uint8_t {
@@ -632,6 +637,9 @@ namespace swift {
632637
/// Disables `DynamicActorIsolation` feature.
633638
bool DisableDynamicActorIsolation = false;
634639

640+
/// Defines the default actor isolation.
641+
DefaultIsolation DefaultIsolationBehavior = DefaultIsolation::Nonisolated;
642+
635643
/// Whether or not to allow experimental features that are only available
636644
/// in "production".
637645
#ifdef NDEBUG

include/swift/Option/Options.td

+9
Original file line numberDiff line numberDiff line change
@@ -985,6 +985,15 @@ def strict_concurrency : Joined<["-"], "strict-concurrency=">,
985985
"concurrency model, or 'complete' ('Sendable' and other checking is "
986986
"enabled for all code in the module)">;
987987

988+
def default_isolation : Separate<["-"], "default-isolation">,
989+
Flags<[FrontendOption]>,
990+
HelpText<"Specify the default actor isolation: MainActor or nonisolated. "
991+
"Defaults to nonisolated.">,
992+
MetaVarName<"MainActor|nonisolated">;
993+
def default_isolation_EQ : Joined<["-"], "default-isolation=">,
994+
Flags<[FrontendOption]>,
995+
Alias<default_isolation>;
996+
988997
def enable_experimental_feature :
989998
Separate<["-"], "enable-experimental-feature">,
990999
Flags<[FrontendOption, ModuleInterfaceOption]>,

lib/Frontend/CompilerInvocation.cpp

+21-3
Original file line numberDiff line numberDiff line change
@@ -969,9 +969,6 @@ static bool ParseEnabledFeatureArgs(LangOptions &Opts, ArgList &Args,
969969
if (Args.hasArg(OPT_strict_memory_safety))
970970
Opts.enableFeature(Feature::StrictMemorySafety);
971971

972-
if (Opts.hasFeature(Feature::UnspecifiedMeansMainActorIsolated))
973-
Opts.enableFeature(Feature::InferIsolatedConformances);
974-
975972
return HadError;
976973
}
977974

@@ -1817,6 +1814,27 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
18171814
Opts.DisableDynamicActorIsolation |=
18181815
Args.hasArg(OPT_disable_dynamic_actor_isolation);
18191816

1817+
if (const Arg *A = Args.getLastArg(options::OPT_default_isolation)) {
1818+
auto behavior =
1819+
llvm::StringSwitch<std::optional<DefaultIsolation>>(A->getValue())
1820+
.Case("MainActor", DefaultIsolation::MainActor)
1821+
.Case("nonisolated", DefaultIsolation::Nonisolated)
1822+
.Default(std::nullopt);
1823+
1824+
if (behavior) {
1825+
Opts.DefaultIsolationBehavior = *behavior;
1826+
} else {
1827+
Diags.diagnose(SourceLoc(), diag::error_invalid_arg_value,
1828+
A->getAsString(Args), A->getValue());
1829+
HadError = true;
1830+
}
1831+
} else {
1832+
Opts.DefaultIsolationBehavior = DefaultIsolation::Nonisolated;
1833+
}
1834+
1835+
if (Opts.DefaultIsolationBehavior == DefaultIsolation::MainActor)
1836+
Opts.enableFeature(Feature::InferIsolatedConformances);
1837+
18201838
#if !defined(NDEBUG) && SWIFT_ENABLE_EXPERIMENTAL_PARSER_VALIDATION
18211839
/// Enable round trip parsing via the new swift parser unless it is disabled
18221840
/// explicitly. The new Swift parser can have mismatches with C++ parser -

0 commit comments

Comments
 (0)