Skip to content

Commit 8f4220c

Browse files
authored
Merge pull request #80219 from xedin/rdar-145768557
[Concurrency] SE-0466: Replace `UnspecifiedMeansMainActorIsolated` flag with `-default-isolation`
2 parents 3cafdcd + e850f17 commit 8f4220c

11 files changed

+48
-24
lines changed

include/swift/Basic/Features.def

-3
Original file line numberDiff line numberDiff line change
@@ -465,9 +465,6 @@ EXPERIMENTAL_FEATURE(ImportNonPublicCxxMembers, true)
465465
// Isolated deinit
466466
SUPPRESSIBLE_LANGUAGE_FEATURE(IsolatedDeinit, 371, "isolated deinit")
467467

468-
// When a parameter has unspecified isolation, infer it as main actor isolated.
469-
EXPERIMENTAL_FEATURE(UnspecifiedMeansMainActorIsolated, false)
470-
471468
/// modify/read single-yield coroutines
472469
SUPPRESSIBLE_EXPERIMENTAL_FEATURE(CoroutineAccessors, true)
473470

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/AST/FeatureSet.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,6 @@ UNINTERESTING_FEATURE(StaticExclusiveOnly)
205205
UNINTERESTING_FEATURE(ExtractConstantsFromMembers)
206206
UNINTERESTING_FEATURE(GroupActorErrors)
207207
UNINTERESTING_FEATURE(SameElementRequirements)
208-
UNINTERESTING_FEATURE(UnspecifiedMeansMainActorIsolated)
209208

210209
static bool usesFeatureSendingArgsAndResults(Decl *decl) {
211210
auto isFunctionTypeWithSending = [](Type type) {

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 -

lib/Sema/TypeCheckConcurrency.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -5798,7 +5798,7 @@ computeDefaultInferredActorIsolation(ValueDecl *value) {
57985798

57995799
// If we are required to use main actor... just use that.
58005800
if (!ignoreUnspecifiedMeansMainActorIsolated &&
5801-
ctx.LangOpts.hasFeature(Feature::UnspecifiedMeansMainActorIsolated))
5801+
ctx.LangOpts.DefaultIsolationBehavior == DefaultIsolation::MainActor)
58025802
if (auto result =
58035803
globalActorHelper(ctx.getMainActorType()->mapTypeOutOfContext()))
58045804
return *result;

test/Concurrency/Runtime/unspecified_is_main_actor.swift

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
// RUN: %target-run-simple-swift( -Xfrontend -disable-availability-checking -swift-version 6 -g -import-objc-header %S/Inputs/RunOnMainActor.h %import-libdispatch -enable-experimental-feature UnspecifiedMeansMainActorIsolated )
1+
// RUN: %target-run-simple-swift( -Xfrontend -disable-availability-checking -swift-version 6 -g -import-objc-header %S/Inputs/RunOnMainActor.h %import-libdispatch -Xfrontend -default-isolation=MainActor )
22

33
// REQUIRES: executable_test
44
// REQUIRES: concurrency
55
// REQUIRES: concurrency_runtime
66
// REQUIRES: libdispatch
77
// REQUIRES: asserts
8-
// REQUIRES: swift_feature_UnspecifiedMeansMainActorIsolated
98

109
// UNSUPPORTED: freestanding
1110

test/Concurrency/assume_mainactor.swift

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
// RUN: %target-swift-frontend -swift-version 6 -emit-silgen -enable-experimental-feature UnspecifiedMeansMainActorIsolated %s | %FileCheck %s
2-
// RUN: %target-swift-frontend -swift-version 6 -emit-sil -enable-experimental-feature UnspecifiedMeansMainActorIsolated %s -verify
3-
4-
// REQUIRES: swift_feature_UnspecifiedMeansMainActorIsolated
1+
// RUN: %target-swift-frontend -swift-version 6 -emit-silgen -default-isolation MainActor %s | %FileCheck %s
2+
// RUN: %target-swift-frontend -swift-version 6 -emit-sil -default-isolation MainActor %s -verify
53

64
// READ THIS! This test is meant to FileCheck the specific isolation when
7-
// UnspecifiedMeansMainActorIsolated is enabled. Please do not put other types
5+
// `-default-isolation` is set to `MainActor`. Please do not put other types
86
// of tests in here.
97

108
class Klass {

test/Concurrency/assume_mainactor_typechecker_errors.swift

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
// RUN: %target-swift-frontend -swift-version 6 -emit-sil -enable-experimental-feature UnspecifiedMeansMainActorIsolated %s -verify
2-
3-
// REQUIRES: swift_feature_UnspecifiedMeansMainActorIsolated
1+
// RUN: %target-swift-frontend -swift-version 6 -emit-sil -default-isolation MainActor %s -verify
42

53
// READ THIS! This test is meant to check the specific isolation when
6-
// UnspecifiedMeansMainActorIsolated is enabled in combination with validating
4+
// `-default-isolation` is set to `MainActor` in combination with validating
75
// behavior around explicitly non-Sendable types that trigger type checker
86
// specific errors. Please do not put other types of tests in here.
97

test/Concurrency/isolated_conformance_default_actor.swift

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
// RUN: %target-swift-frontend -typecheck -verify -target %target-swift-5.1-abi-triple -swift-version 6 -enable-experimental-feature IsolatedConformances -enable-experimental-feature UnspecifiedMeansMainActorIsolated %s
1+
// RUN: %target-swift-frontend -typecheck -verify -target %target-swift-5.1-abi-triple -swift-version 6 -enable-experimental-feature IsolatedConformances -default-isolation MainActor %s
22

33
// REQUIRES: swift_feature_IsolatedConformances
4-
// REQUIRES: swift_feature_UnspecifiedMeansMainActorIsolated
54
// REQUIRES: concurrency
65

76
nonisolated

test/Concurrency/swiftsettings_defaultIsolation.swift

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
// RUN: %target-swift-frontend -enable-experimental-feature SwiftSettings -c -verify -swift-version 6 -verify-additional-prefix nonisolated- -disable-availability-checking %s
22
// RUN: %target-swift-frontend -enable-experimental-feature SwiftSettings -c -verify -swift-version 6 -verify-additional-prefix main-actor- -disable-availability-checking -DSWIFT_SETTINGS_MAIN_ACTOR %s
3-
// RUN: %target-swift-frontend -enable-experimental-feature UnspecifiedMeansMainActorIsolated -enable-experimental-feature SwiftSettings -c -verify -swift-version 6 -disable-availability-checking -verify-additional-prefix main-actor- %s
4-
// RUN: %target-swift-frontend -enable-experimental-feature UnspecifiedMeansMainActorIsolated -enable-experimental-feature SwiftSettings -c -verify -swift-version 6 -disable-availability-checking -verify-additional-prefix nonisolated- -DSWIFT_SETTINGS_NONISOLATED %s
3+
// RUN: %target-swift-frontend -default-isolation MainActor -enable-experimental-feature SwiftSettings -c -verify -swift-version 6 -disable-availability-checking -verify-additional-prefix main-actor- %s
4+
// RUN: %target-swift-frontend -default-isolation MainActor -enable-experimental-feature SwiftSettings -c -verify -swift-version 6 -disable-availability-checking -verify-additional-prefix nonisolated- -DSWIFT_SETTINGS_NONISOLATED %s
55

66
// REQUIRES: asserts
77
// REQUIRES: concurrency
8-
// REQUIRES: swift_feature_UnspecifiedMeansMainActorIsolated
98
// REQUIRES: swift_feature_SwiftSettings
109

1110
#if SWIFT_SETTINGS_MAIN_ACTOR

0 commit comments

Comments
 (0)