Skip to content

Commit 377eb6f

Browse files
authored
Merge pull request #442 from swiftlang/rdar-145751834
[SE-0466] Add SWIFT_DEFAULT_ACTOR_ISOLATION build setting
2 parents 4993822 + 0d54cb4 commit 377eb6f

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
@@ -3528,6 +3528,94 @@ fileprivate struct SwiftTaskConstructionTests: CoreBasedTests {
35283528
}
35293529
}
35303530

3531+
@Test(.requireSDKs(.macOS))
3532+
func defaultIsolationFlag() async throws {
3533+
try await withTemporaryDirectory { tmpDir in
3534+
let srcRoot = tmpDir.join("srcroot")
3535+
let testProject = try await TestProject(
3536+
"ProjectName",
3537+
sourceRoot: srcRoot,
3538+
groupTree: TestGroup(
3539+
"SomeFiles", path: "Sources",
3540+
children: [
3541+
TestFile("File1.swift"),
3542+
TestFile("File2.swift"),
3543+
TestFile("File3.swift"),
3544+
]),
3545+
targets: [
3546+
TestStandardTarget(
3547+
"Default",
3548+
type: .framework,
3549+
buildConfigurations: [
3550+
TestBuildConfiguration("Debug", buildSettings: [
3551+
"GENERATE_INFOPLIST_FILE": "YES",
3552+
"PRODUCT_NAME": "$(TARGET_NAME)",
3553+
"SWIFT_EXEC": swiftCompilerPath.str,
3554+
"SWIFT_VERSION": "5.0",
3555+
]),
3556+
],
3557+
buildPhases: [
3558+
TestSourcesBuildPhase([
3559+
TestBuildFile("File1.swift"),
3560+
]),
3561+
], dependencies: ["Nonisolated", "MainActor"]),
3562+
TestStandardTarget(
3563+
"Nonisolated",
3564+
type: .framework,
3565+
buildConfigurations: [
3566+
TestBuildConfiguration("Debug", buildSettings: [
3567+
"GENERATE_INFOPLIST_FILE": "YES",
3568+
"PRODUCT_NAME": "$(TARGET_NAME)",
3569+
"SWIFT_EXEC": swiftCompilerPath.str,
3570+
"SWIFT_VERSION": "5.0",
3571+
"SWIFT_DEFAULT_ACTOR_ISOLATION": "nonisolated",
3572+
]),
3573+
],
3574+
buildPhases: [
3575+
TestSourcesBuildPhase([
3576+
TestBuildFile("File2.swift"),
3577+
]),
3578+
]),
3579+
TestStandardTarget(
3580+
"MainActor",
3581+
type: .framework,
3582+
buildConfigurations: [
3583+
TestBuildConfiguration("Debug", buildSettings: [
3584+
"GENERATE_INFOPLIST_FILE": "YES",
3585+
"PRODUCT_NAME": "$(TARGET_NAME)",
3586+
"SWIFT_EXEC": swiftCompilerPath.str,
3587+
"SWIFT_VERSION": "5.0",
3588+
"SWIFT_DEFAULT_ACTOR_ISOLATION": "MainActor",
3589+
]),
3590+
],
3591+
buildPhases: [
3592+
TestSourcesBuildPhase([
3593+
TestBuildFile("File3.swift"),
3594+
]),
3595+
]),
3596+
])
3597+
3598+
let tester = try await TaskConstructionTester(getCore(), testProject)
3599+
await tester.checkBuild(BuildParameters(action: .install, configuration: "Debug"), runDestination: .macOS) { results in
3600+
results.checkTarget("Default") { target in
3601+
results.checkTask(.matchTarget(target), .matchRuleType("SwiftDriver Compilation")) { task in
3602+
task.checkCommandLineNoMatch([.prefix("-default-isolation")])
3603+
}
3604+
}
3605+
results.checkTarget("Nonisolated") { target in
3606+
results.checkTask(.matchTarget(target), .matchRuleType("SwiftDriver Compilation")) { task in
3607+
task.checkCommandLineNoMatch([.prefix("-default-isolation")])
3608+
}
3609+
}
3610+
results.checkTarget("MainActor") { target in
3611+
results.checkTask(.matchTarget(target), .matchRuleType("SwiftDriver Compilation")) { task in
3612+
task.checkCommandLineContains(["-default-isolation=MainActor"])
3613+
}
3614+
}
3615+
}
3616+
}
3617+
}
3618+
35313619
// Test frontend flag -library-level inference from the INSTALL_PATH.
35323620
@Test(.requireSDKs(.macOS))
35333621
func libraryLevel() async throws {

0 commit comments

Comments
 (0)