Skip to content
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

In WMO, make sure the dummy "primary" compilation input is a Swift source file #1346

Merged
merged 1 commit into from
May 1, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift
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")
Copy link
Member

Choose a reason for hiding this comment

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

I think I can hit this fatalError, though honestly, if we're even formulating FrontendJobs when we don't have any source inputs, something has probably gone wrong before this point.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My thinking is that, if anything, this will help catch such issues early. This code-path should not otherwise be taken if we don't have any source inputs, I don't think.

}
entries[firstSourceInputHandle] = [:]
}

for flaggedPair in flaggedInputOutputPairs {
Expand Down
21 changes: 21 additions & 0 deletions Tests/SwiftDriverTests/SwiftDriverTests.swift
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