Skip to content

Schedule an emit-module-separately job even if an input is not compilable #1588

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 3 commits into from
May 1, 2024
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
4 changes: 2 additions & 2 deletions Sources/SwiftDriver/Jobs/EmitModuleJob.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ extension Driver {

// Add the inputs.
for input in self.inputFiles where input.type.isPartOfSwiftCompilation {
commandLine.append(.path(input.file))
try addPathArgument(input.file, to: &commandLine)
inputs.append(input)
}

Expand Down Expand Up @@ -136,7 +136,7 @@ extension Driver {
moduleOutputInfo: ModuleOutputInfo,
inputFiles: [TypedVirtualPath]) -> Bool {
if moduleOutputInfo.output == nil ||
!inputFiles.allSatisfy({ $0.type.isPartOfSwiftCompilation }) {
!inputFiles.contains(where: { $0.type.isPartOfSwiftCompilation }) {
return false
}

Expand Down
18 changes: 17 additions & 1 deletion Tests/SwiftDriverTests/SwiftDriverTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3096,7 +3096,7 @@ final class SwiftDriverTests: XCTestCase {
func testWMOWithNonSourceInputFirstAndModuleOutput() throws {
var driver1 = try Driver(args: [
"swiftc", "-wmo", "danger.o", "foo.swift", "bar.swift", "wibble.swift", "-module-name", "Test",
"-driver-filelist-threshold=0", "-emit-module", "-emit-library"
"-driver-filelist-threshold=0", "-emit-module", "-emit-library", "-no-emit-module-separately-wmo"
])
let plannedJobs = try driver1.planBuild().removingAutolinkExtractJobs()
XCTAssertEqual(plannedJobs.count, 2)
Expand Down Expand Up @@ -3504,6 +3504,22 @@ final class SwiftDriverTests: XCTestCase {
XCTAssertEqual(plannedJobs.count, 4)
XCTAssertEqual(Set(plannedJobs.map { $0.kind }), Set([.compile, .emitModule, .link]))
}

do {
// Schedule an emit-module separately job even if there are non-compilable inputs.
var driver = try Driver(args: ["swiftc", "foo.swift", "bar.dylib", "-emit-library", "foo.dylib", "-emit-module-path", "foo.swiftmodule"],
env: envVars)
let plannedJobs = try driver.planBuild()
XCTAssertEqual(plannedJobs.count, 3)
XCTAssertEqual(Set(plannedJobs.map { $0.kind }), Set([.compile, .emitModule, .link]))

let emitJob = try plannedJobs.findJob(.emitModule)
XCTAssertTrue(emitJob.commandLine.contains(try toPathOption("foo.swift")))
XCTAssertFalse(emitJob.commandLine.contains(try toPathOption("bar.dylib")))
Copy link
Member

Choose a reason for hiding this comment

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

Why is the dylib an input to the emit module job at all? This seems dangerously close to the behavior of the old driver, which would sometimes pass static archives to the frontend which ends in much sadness.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can imagine it being bad, but I think this is fine. Did you notice the XCTAssertFalse for bar.dylib?

Copy link
Member

Choose a reason for hiding this comment

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

Oh, no, sorry, misread it as XCTAssertTrue, which concerned me. You're good, carry on.


let linkJob = try plannedJobs.findJob(.link)
XCTAssertTrue(linkJob.commandLine.contains(try toPathOption("bar.dylib")))
}
}

func testEmitModuleSeparatelyWMO() throws {
Expand Down