Skip to content

Commit b666424

Browse files
committed
[Frontend] SE-0466: Add -default-isolation frontend that accepts MainActor and nonisolated
1 parent 7da2333 commit b666424

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 {
@@ -636,6 +641,9 @@ namespace swift {
636641
/// Disables `DynamicActorIsolation` feature.
637642
bool DisableDynamicActorIsolation = false;
638643

644+
/// Defines the default actor isolation.
645+
DefaultIsolation DefaultIsolationBehavior = DefaultIsolation::Nonisolated;
646+
639647
/// Whether or not to allow experimental features that are only available
640648
/// in "production".
641649
#ifdef NDEBUG

include/swift/Option/Options.td

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -995,6 +995,15 @@ def executor_factory_EQ : Joined<["-"], "executor-factory=">,
995995
Flags<[FrontendOption]>,
996996
Alias<executor_factory>;
997997

998+
def default_isolation : Separate<["-"], "default-isolation">,
999+
Flags<[FrontendOption]>,
1000+
HelpText<"Specify the default actor isolation: MainActor or nonisolated. "
1001+
"Defaults to nonisolated.">,
1002+
MetaVarName<"MainActor|nonisolated">;
1003+
def default_isolation_EQ : Joined<["-"], "default-isolation=">,
1004+
Flags<[FrontendOption]>,
1005+
Alias<default_isolation>;
1006+
9981007
def enable_experimental_feature :
9991008
Separate<["-"], "enable-experimental-feature">,
10001009
Flags<[FrontendOption, ModuleInterfaceOption]>,

lib/Frontend/CompilerInvocation.cpp

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

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

0 commit comments

Comments
 (0)