Skip to content

Commit 67aa280

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

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

include/swift/Basic/LangOptions.h

Lines changed: 8 additions & 0 deletions
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

Lines changed: 9 additions & 0 deletions
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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1817,6 +1817,24 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
18171817
Opts.DisableDynamicActorIsolation |=
18181818
Args.hasArg(OPT_disable_dynamic_actor_isolation);
18191819

1820+
if (const Arg *A = Args.getLastArg(options::OPT_default_isolation)) {
1821+
auto behavior =
1822+
llvm::StringSwitch<std::optional<DefaultIsolation>>(A->getValue())
1823+
.Case("MainActor", DefaultIsolation::MainActor)
1824+
.Case("nonisolated", DefaultIsolation::Nonisolated)
1825+
.Default(std::nullopt);
1826+
1827+
if (behavior) {
1828+
Opts.DefaultIsolationBehavior = *behavior;
1829+
} else {
1830+
Diags.diagnose(SourceLoc(), diag::error_invalid_arg_value,
1831+
A->getAsString(Args), A->getValue());
1832+
HadError = true;
1833+
}
1834+
} else {
1835+
Opts.DefaultIsolationBehavior = DefaultIsolation::Nonisolated;
1836+
}
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)