Skip to content

Commit 0d54cb4

Browse files
committed
[SE-0466] Add SWIFT_DEFAULT_ACTOR_ISOLATION build setting
This setting controls default actor isolation for unannotated code. Resolves: rdar://145751834
1 parent 2f36148 commit 0d54cb4

File tree

2 files changed

+104
-1
lines changed

2 files changed

+104
-1
lines changed

Sources/SWBUniversalPlatform/Specs/Swift.xcspec

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,22 @@
569569
Category = "Upcoming Features";
570570
Description = "Enables strict concurrency checking to produce warnings for possible data races. This is always 'complete' when in the Swift 6 language mode and produces errors instead of warnings.";
571571
},
572-
572+
{
573+
Name = "SWIFT_DEFAULT_ACTOR_ISOLATION";
574+
Type = Enumeration;
575+
Values = (
576+
nonisolated,
577+
MainActor
578+
);
579+
DefaultValue = "nonisolated";
580+
CommandLineArgs = {
581+
nonisolated = ();
582+
MainActor = ( "-default-isolation=MainActor" );
583+
};
584+
DisplayName = "Default Actor Isolation";
585+
Category = "Language";
586+
Description = "Controls default actor isolation for unannotated code. When set to 'MainActor', `@MainActor` isolation will be inferred by default to mitigate false-positive data-race safety errors in sequential code.";
587+
},
573588
{
574589
Name = "SWIFT_STRICT_MEMORY_SAFETY";
575590
Type = Boolean;

Tests/SWBTaskConstructionTests/SwiftTaskConstructionTests.swift

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3468,6 +3468,94 @@ fileprivate struct SwiftTaskConstructionTests: CoreBasedTests {
34683468
}
34693469
}
34703470

3471+
@Test(.requireSDKs(.macOS))
3472+
func defaultIsolationFlag() async throws {
3473+
try await withTemporaryDirectory { tmpDir in
3474+
let srcRoot = tmpDir.join("srcroot")
3475+
let testProject = try await TestProject(
3476+
"ProjectName",
3477+
sourceRoot: srcRoot,
3478+
groupTree: TestGroup(
3479+
"SomeFiles", path: "Sources",
3480+
children: [
3481+
TestFile("File1.swift"),
3482+
TestFile("File2.swift"),
3483+
TestFile("File3.swift"),
3484+
]),
3485+
targets: [
3486+
TestStandardTarget(
3487+
"Default",
3488+
type: .framework,
3489+
buildConfigurations: [
3490+
TestBuildConfiguration("Debug", buildSettings: [
3491+
"GENERATE_INFOPLIST_FILE": "YES",
3492+
"PRODUCT_NAME": "$(TARGET_NAME)",
3493+
"SWIFT_EXEC": swiftCompilerPath.str,
3494+
"SWIFT_VERSION": "5.0",
3495+
]),
3496+
],
3497+
buildPhases: [
3498+
TestSourcesBuildPhase([
3499+
TestBuildFile("File1.swift"),
3500+
]),
3501+
], dependencies: ["Nonisolated", "MainActor"]),
3502+
TestStandardTarget(
3503+
"Nonisolated",
3504+
type: .framework,
3505+
buildConfigurations: [
3506+
TestBuildConfiguration("Debug", buildSettings: [
3507+
"GENERATE_INFOPLIST_FILE": "YES",
3508+
"PRODUCT_NAME": "$(TARGET_NAME)",
3509+
"SWIFT_EXEC": swiftCompilerPath.str,
3510+
"SWIFT_VERSION": "5.0",
3511+
"SWIFT_DEFAULT_ACTOR_ISOLATION": "nonisolated",
3512+
]),
3513+
],
3514+
buildPhases: [
3515+
TestSourcesBuildPhase([
3516+
TestBuildFile("File2.swift"),
3517+
]),
3518+
]),
3519+
TestStandardTarget(
3520+
"MainActor",
3521+
type: .framework,
3522+
buildConfigurations: [
3523+
TestBuildConfiguration("Debug", buildSettings: [
3524+
"GENERATE_INFOPLIST_FILE": "YES",
3525+
"PRODUCT_NAME": "$(TARGET_NAME)",
3526+
"SWIFT_EXEC": swiftCompilerPath.str,
3527+
"SWIFT_VERSION": "5.0",
3528+
"SWIFT_DEFAULT_ACTOR_ISOLATION": "MainActor",
3529+
]),
3530+
],
3531+
buildPhases: [
3532+
TestSourcesBuildPhase([
3533+
TestBuildFile("File3.swift"),
3534+
]),
3535+
]),
3536+
])
3537+
3538+
let tester = try await TaskConstructionTester(getCore(), testProject)
3539+
await tester.checkBuild(BuildParameters(action: .install, configuration: "Debug"), runDestination: .macOS) { results in
3540+
results.checkTarget("Default") { target in
3541+
results.checkTask(.matchTarget(target), .matchRuleType("SwiftDriver Compilation")) { task in
3542+
task.checkCommandLineNoMatch([.prefix("-default-isolation")])
3543+
}
3544+
}
3545+
results.checkTarget("Nonisolated") { target in
3546+
results.checkTask(.matchTarget(target), .matchRuleType("SwiftDriver Compilation")) { task in
3547+
task.checkCommandLineNoMatch([.prefix("-default-isolation")])
3548+
}
3549+
}
3550+
results.checkTarget("MainActor") { target in
3551+
results.checkTask(.matchTarget(target), .matchRuleType("SwiftDriver Compilation")) { task in
3552+
task.checkCommandLineContains(["-default-isolation=MainActor"])
3553+
}
3554+
}
3555+
}
3556+
}
3557+
}
3558+
34713559
// Test frontend flag -library-level inference from the INSTALL_PATH.
34723560
@Test(.requireSDKs(.macOS))
34733561
func libraryLevel() async throws {

0 commit comments

Comments
 (0)