Skip to content

Commit

Permalink
Merge pull request #1350 from artemcm/OnlySourceForWMOSupplements-Again
Browse files Browse the repository at this point in the history
In WMO, make sure the dummy "primary" compilation input is a Swift source file
  • Loading branch information
artemcm committed May 3, 2023
2 parents e992cd7 + 7bef081 commit 661d59f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
5 changes: 4 additions & 1 deletion Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,10 @@ extension Driver {
// To match the legacy driver behavior, make sure we add the first input file
// to the output file map if compiling without primary inputs (WMO), even
// if there aren't any corresponding outputs.
entries[inputFiles[0].fileHandle] = [:]
guard let firstSourceInputHandle = inputFiles.first(where:{ $0.type == .swift })?.fileHandle else {
fatalError("Formulating swift-frontend invocation without any input .swift files")
}
entries[firstSourceInputHandle] = [:]
}

for flaggedPair in flaggedInputOutputPairs {
Expand Down
5 changes: 3 additions & 2 deletions Sources/SwiftDriver/Jobs/Planning.swift
Original file line number Diff line number Diff line change
Expand Up @@ -329,10 +329,11 @@ extension Driver {
emitModuleTrace: Bool
) throws -> Job? {
guard case .singleCompile = compilerMode,
inputFiles.allSatisfy({ $0.type.isPartOfSwiftCompilation })
inputFiles.contains(where: { $0.type.isPartOfSwiftCompilation })
else { return nil }

if parsedOptions.hasArgument(.embedBitcode) {
if parsedOptions.hasArgument(.embedBitcode),
inputFiles.allSatisfy({ $0.type.isPartOfSwiftCompilation }) {
let compile = try compileJob(primaryInputs: [],
outputType: .llvmBitcode,
addJobOutputs: addJobOutputs,
Expand Down
21 changes: 21 additions & 0 deletions Tests/SwiftDriverTests/SwiftDriverTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2824,6 +2824,27 @@ final class SwiftDriverTests: XCTestCase {

}

func testWMOWithNonSourceInput() throws {
var driver1 = try Driver(args: [
"swiftc", "-whole-module-optimization", "danger.o", "foo.swift", "bar.swift", "wibble.swift", "-module-name", "Test",
"-driver-filelist-threshold=0"
])
let plannedJobs = try driver1.planBuild().removingAutolinkExtractJobs()
XCTAssertEqual(plannedJobs.count, 2)
let compileJob = plannedJobs[0]
XCTAssertEqual(compileJob.kind, .compile)
XCTAssert(compileJob.commandLine.contains(.flag("-supplementary-output-file-map")))
let argIdx = try XCTUnwrap(compileJob.commandLine.firstIndex(where: { $0 == .flag("-supplementary-output-file-map") }))
let supplOutputs = compileJob.commandLine[argIdx+1]
guard case let .path(path) = supplOutputs,
case let .fileList(_, fileList) = path,
case let .outputFileMap(outFileMap) = fileList else {
throw StringError("Unexpected argument for output file map")
}
let firstKey: String = try VirtualPath.lookup(XCTUnwrap(outFileMap.entries.keys.first)).description
XCTAssertEqual(firstKey, "foo.swift")
}

func testDashDashPassingDownInput() throws {
do {
var driver = try Driver(args: ["swiftc", "-module-name=ThisModule", "-wmo", "-num-threads", "4", "-emit-module", "-o", "test.swiftmodule", "--", "main.swift", "multi-threaded.swift"])
Expand Down

0 comments on commit 661d59f

Please sign in to comment.