Skip to content

Add -no-whole-module-optimization flag #64

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions Sources/SwiftDriver/Driver/Driver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ extension Driver {
// Some output flags affect the compiler mode.
if let outputOption = parsedOptions.getLast(in: .modes) {
switch outputOption.option {
case .emitPch, .emitImportedModules, .indexFile:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because this was here previously all the logic below around indexFile appeared to have never worked. This fixed this and added a test for it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops, thank you! -index-file hasn't really be implemented or tested.

case .emitPch, .emitImportedModules:
return .singleCompile

case .repl, .deprecatedIntegratedRepl, .lldbRepl:
Expand All @@ -740,13 +740,13 @@ extension Driver {
return parsedOptions.hasAnyInput ? .immediate : .repl
}

let requiresSingleCompile = parsedOptions.hasArgument(.wholeModuleOptimization, .indexFile)

let useWMO = parsedOptions.hasFlag(positive: .wholeModuleOptimization, negative: .noWholeModuleOptimization, default: false)
let hasIndexFile = parsedOptions.hasArgument(.indexFile)
let wantBatchMode = parsedOptions.hasFlag(positive: .enableBatchMode, negative: .disableBatchMode, default: false)

if requiresSingleCompile {
if useWMO || hasIndexFile {
if wantBatchMode {
let disablingOption: Option = parsedOptions.hasArgument(.wholeModuleOptimization) ? .wholeModuleOptimization : .indexFile
let disablingOption: Option = useWMO ? .wholeModuleOptimization : .indexFile
diagnosticsEngine.emit(.warn_ignoring_batch_mode(disablingOption))
}

Expand Down
2 changes: 2 additions & 0 deletions Sources/SwiftDriver/Options/Options.swift
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,7 @@ extension Option {
public static let warnSwift3ObjcInference: Option = Option("-warn-swift3-objc-inference", .flag, alias: Option.warnSwift3ObjcInferenceComplete, attributes: [.helpHidden, .frontend, .doesNotAffectIncrementalBuild])
public static let warningsAsErrors: Option = Option("-warnings-as-errors", .flag, attributes: [.frontend], helpText: "Treat warnings as errors")
public static let wholeModuleOptimization: Option = Option("-whole-module-optimization", .flag, attributes: [.frontend, .noInteractive], helpText: "Optimize input files together instead of individually")
public static let noWholeModuleOptimization: Option = Option("-no-whole-module-optimization", .flag, attributes: [.frontend, .noInteractive], helpText: "Disable optimizing input files together instead of individually")
public static let wmo: Option = Option("-wmo", .flag, alias: Option.wholeModuleOptimization, attributes: [.helpHidden, .frontend, .noInteractive])
public static let workingDirectoryEQ: Option = Option("-working-directory=", .joined, alias: Option.workingDirectory)
public static let workingDirectory: Option = Option("-working-directory", .separate, metaVar: "<path>", helpText: "Resolve file paths relative to the specified directory")
Expand Down Expand Up @@ -723,6 +724,7 @@ extension Option {
Option.noStdlibRpath,
Option.noToolchainStdlibRpath,
Option.nostdimport,
Option.noWholeModuleOptimization,
Option.numThreads,
Option.Onone,
Option.Oplayground,
Expand Down
35 changes: 34 additions & 1 deletion Tests/SwiftDriverTests/SwiftDriverTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,44 @@ final class SwiftDriverTests: XCTestCase {
let driver1 = try Driver(args: ["swiftc", "main.swift", "-whole-module-optimization"])
XCTAssertEqual(driver1.compilerMode, .singleCompile)

let driver2 = try Driver(args: ["swiftc", "main.swift", "-g"])
let driver2 = try Driver(args: ["swiftc", "main.swift", "-whole-module-optimization", "-no-whole-module-optimization"])
XCTAssertEqual(driver2.compilerMode, .standardCompile)

let driver3 = try Driver(args: ["swiftc", "main.swift", "-g"])
XCTAssertEqual(driver3.compilerMode, .standardCompile)
}
}

func testBatchModeDiagnostics() throws {
try assertNoDriverDiagnostics(args: "swiftc", "-enable-batch-mode") { driver in
switch driver.compilerMode {
case .batchCompile:
break
default:
XCTFail("Expected batch compile, got \(driver.compilerMode)")
}
}

try assertDriverDiagnostics(args: "swiftc", "-enable-batch-mode", "-whole-module-optimization") { driver, diagnostics in
XCTAssertEqual(driver.compilerMode, .singleCompile)
diagnostics.expect(.warning("ignoring '-enable-batch-mode' because '-whole-module-optimization' was also specified"))
}

try assertDriverDiagnostics(args: "swiftc", "-enable-batch-mode", "-whole-module-optimization", "-no-whole-module-optimization", "-index-file", "-module-name", "foo") { driver, diagnostics in
XCTAssertEqual(driver.compilerMode, .singleCompile)
diagnostics.expect(.warning("ignoring '-enable-batch-mode' because '-index-file' was also specified"))
}

try assertNoDriverDiagnostics(args: "swiftc", "-enable-batch-mode", "-whole-module-optimization", "-no-whole-module-optimization") { driver in
switch driver.compilerMode {
case .batchCompile:
break
default:
XCTFail("Expected batch compile, got \(driver.compilerMode)")
}
}
}

func testInputFiles() throws {
let driver1 = try Driver(args: ["swiftc", "a.swift", "/tmp/b.swift"])
XCTAssertEqual(driver1.inputFiles,
Expand Down