Skip to content

Commit 221c724

Browse files
committed
SE-0466: Add support for -default-isolation flag
1 parent 60522e2 commit 221c724

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift

+3
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,9 @@ extension Driver {
311311
if isFrontendArgSupported(.strictConcurrency) {
312312
try commandLine.appendLast(.strictConcurrency, from: &parsedOptions)
313313
}
314+
if isFrontendArgSupported(.defaultIsolation) {
315+
try commandLine.appendLast(.defaultIsolation, from: &parsedOptions)
316+
}
314317
if kind == .scanDependencies,
315318
isFrontendArgSupported(.experimentalClangImporterDirectCc1Scan) {
316319
try commandLine.appendAll(

Sources/SwiftOptions/Options.swift

+4
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ extension Option {
134134
public static let debugTimeFunctionBodies: Option = Option("-debug-time-function-bodies", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Dumps the time it takes to type-check each function body")
135135
public static let debuggerSupport: Option = Option("-debugger-support", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Process swift code as if running in the debugger")
136136
public static let debuggerTestingTransform: Option = Option("-debugger-testing-transform", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Instrument the code with calls to an intrinsic that record the expected values of local variables so they can be compared against the results from the debugger.")
137+
public static let defaultIsolationEQ: Option = Option("-default-isolation=", .joined, alias: Option.defaultIsolation, attributes: [.frontend])
138+
public static let defaultIsolation: Option = Option("-default-isolation", .separate, attributes: [.frontend], metaVar: "MainActor|nonisolated", helpText: "Specify the default actor isolation: MainActor or nonisolated. Defaults to nonisolated.")
137139
public static let defineAvailability: Option = Option("-define-availability", .separate, attributes: [.frontend, .noInteractive], metaVar: "<macro>", helpText: "Define an availability macro in the format 'macroName : iOS 13.0, macOS 10.15'")
138140
public static let defineDisabledAvailabilityDomain: Option = Option("-define-disabled-availability-domain", .separate, attributes: [.helpHidden, .frontend, .noInteractive], metaVar: "<domain>", helpText: "Defines a custom availability domain that is unavailable at compile time")
139141
public static let defineDynamicAvailabilityDomain: Option = Option("-define-dynamic-availability-domain", .separate, attributes: [.helpHidden, .frontend, .noInteractive], metaVar: "<domain>", helpText: "Defines a custom availability domain that can be enabled or disabled at runtime")
@@ -1079,6 +1081,8 @@ extension Option {
10791081
Option.debugTimeFunctionBodies,
10801082
Option.debuggerSupport,
10811083
Option.debuggerTestingTransform,
1084+
Option.defaultIsolationEQ,
1085+
Option.defaultIsolation,
10821086
Option.defineAvailability,
10831087
Option.defineDisabledAvailabilityDomain,
10841088
Option.defineDynamicAvailabilityDomain,

Tests/SwiftDriverTests/SwiftDriverTests.swift

+12
Original file line numberDiff line numberDiff line change
@@ -3935,6 +3935,18 @@ final class SwiftDriverTests: XCTestCase {
39353935
XCTAssertTrue(plannedJobs[0].commandLine.contains(.flag("-disable-dynamic-actor-isolation")))
39363936
}
39373937

3938+
func testDefaultIsolation() throws {
3939+
var driver = try Driver(args: ["swiftc", "test.swift", "-default-isolation", "MainActor"])
3940+
guard driver.isFrontendArgSupported(.defaultIsolation) else {
3941+
throw XCTSkip("Skipping: compiler does not support '-default-isolation'")
3942+
}
3943+
let plannedJobs = try driver.planBuild().removingAutolinkExtractJobs()
3944+
XCTAssertEqual(plannedJobs.count, 2)
3945+
XCTAssertEqual(plannedJobs[0].kind, .compile)
3946+
XCTAssertEqual(plannedJobs[1].kind, .link)
3947+
try XCTAssertJobInvocationMatches(plannedJobs[0], .flag("-default-isolation"), "MainActor")
3948+
}
3949+
39383950
func testImmediateMode() throws {
39393951
do {
39403952
var driver = try Driver(args: ["swift", "foo.swift"])

0 commit comments

Comments
 (0)