-
Notifications
You must be signed in to change notification settings - Fork 218
Incremental: Don't rebuild everything when only emitting the module #2102
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -434,8 +434,10 @@ extension Driver { | |||
|
|
||||
| assert(input.type.isPartOfSwiftCompilation) | ||||
| // We can skip the compile jobs if all we want is a module when it's | ||||
| // built separately. | ||||
| // built separately, unless we need per-file outputs like const values | ||||
| // that only compile jobs can produce. | ||||
| let canSkipIfOnlyModule = compilerOutputType == .swiftModule && emitModuleSeparately | ||||
| && !parsedOptions.hasArgument(.emitConstValues) | ||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there some classification that we can use? "like const values" ... are there other features would also require compile jobs?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 to this, this doesn't seem like a general approach, there are many other kinds of outputs which may be requested on a driver invocation which are only produced by object compilation (not emit-module) tasks. I think we should trust the We select the compiler output type here:
Based on which compilation "mode" flag is used. Admittedly this part of the driver logic seems quite messy because -emit-module seems to be considered a mode only if no other .modes flag was specified.
But, if we are in a An alternative would be to extend
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let me paraphrase you, and you can tell me if I have this right: Given the current implementation of Therefore one way of looking at is: When only specifying emit-module you are not really expecting to receive other outputs here, so we don't need to worry about them here. Option two would be to catch other outputs ( My opinion here is that it seems weird to make a change so that Swiftmodule is not be the 'primary output' in these cases - it really is the primary output! So I would be minded to 'trust' the compilerOutputType and remove this change. Does this make sense? |
||||
| try createAndAddCompileJob(primaryInput: input, | ||||
| emitModuleTrace: emitModuleTrace, | ||||
| canSkipIfOnlyModule: canSkipIfOnlyModule, | ||||
|
|
@@ -478,7 +480,7 @@ extension Driver { | |||
| ) throws { | ||||
| // We can skip the compile jobs if all we want is a module when it's | ||||
| // built separately. | ||||
| if parsedOptions.hasArgument(.driverExplicitModuleBuild), canSkipIfOnlyModule { return } | ||||
| if canSkipIfOnlyModule { return } | ||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a change I've wanted to make for a while since it is rather superfluous and leads to an odd difference between implicit and explicit builds. While I think we should do it, I am having a hard time remembering if this is still an assumption some part of
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This might break some assumptions but now that we've open sourced swift-build it's a lot easier to test. I'll try to take a closer look soon but I might not get to it until next week |
||||
| // If we are in the batch mode, the constructed jobs here will be batched | ||||
| // later. There is no need to produce cache key for the job. | ||||
| let compile = try compileJob(primaryInputs: [primaryInput], | ||||
|
|
||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -2026,7 +2026,7 @@ final class SwiftDriverTests: XCTestCase { | |||||
| "-output-file-map", outputFileMap.description]) | ||||||
| let plannedJobs = try driver.planBuild().removingAutolinkExtractJobs() | ||||||
|
|
||||||
| XCTAssertEqual(plannedJobs.count, 3) | ||||||
| XCTAssertEqual(plannedJobs.count, 1) | ||||||
| XCTAssertEqual(plannedJobs[0].kind, .emitModule) | ||||||
| try XCTAssertJobInvocationMatches(plannedJobs[0], .flag("-serialize-diagnostics-path"), .path(.absolute(.init(validating: "/build/Foo-test.dia")))) | ||||||
| } | ||||||
|
|
@@ -2051,7 +2051,7 @@ final class SwiftDriverTests: XCTestCase { | |||||
| XCTAssertTrue(driver.diagnosticEngine.diagnostics.isEmpty) | ||||||
|
|
||||||
| // Test the output path is correct for GeneratePCH job. | ||||||
| XCTAssertEqual(plannedJobs.count, 4) | ||||||
| XCTAssertEqual(plannedJobs.count, 2) | ||||||
| XCTAssertEqual(plannedJobs[0].kind, .generatePCH) | ||||||
| try XCTAssertJobInvocationMatches(plannedJobs[0], .flag("-o"), .path(.absolute(.init(validating: "/build/Foo-bridging-header.pch")))) | ||||||
|
|
||||||
|
|
@@ -3911,7 +3911,7 @@ final class SwiftDriverTests: XCTestCase { | |||||
| var driver = try Driver(args: ["swiftc", "-module-name=ThisModule", "main.swift", "multi-threaded.swift", "-emit-module", "-o", "test.swiftmodule", "-experimental-emit-module-separately"]) | ||||||
| let plannedJobs = try driver.planBuild().removingAutolinkExtractJobs() | ||||||
|
|
||||||
| XCTAssertEqual(plannedJobs.count, 3) | ||||||
| XCTAssertEqual(plannedJobs.count, 1) | ||||||
|
|
||||||
| XCTAssertEqual(plannedJobs[0].kind, .emitModule) | ||||||
| XCTAssertJobInvocationMatches(plannedJobs[0], .flag("-emit-abi-descriptor-path")) | ||||||
|
|
@@ -4636,8 +4636,8 @@ final class SwiftDriverTests: XCTestCase { | |||||
| // -experimental-emit-module-separately. | ||||||
| var driver = try Driver(args: ["swiftc", "foo.swift", "bar.swift", "-module-name", "Test", "-emit-module-path", rebase("Test.swiftmodule", at: root), "-experimental-emit-module-separately"]) | ||||||
| let plannedJobs = try driver.planBuild().removingAutolinkExtractJobs() | ||||||
| XCTAssertEqual(plannedJobs.count, 3) | ||||||
| XCTAssertEqual(Set(plannedJobs.map { $0.kind }), Set([.emitModule, .compile])) | ||||||
| XCTAssertEqual(plannedJobs.count, 1) | ||||||
| XCTAssertEqual(Set(plannedJobs.map { $0.kind }), Set([.emitModule])) | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not simplify this?
Suggested change
|
||||||
| XCTAssertTrue(plannedJobs[0].tool.name.contains("swift")) | ||||||
| XCTAssertEqual(plannedJobs[0].outputs.count, driver.targetTriple.isDarwin ? 4 : 3) | ||||||
| XCTAssertEqual(plannedJobs[0].outputs[0].file, .absolute(try .init(validating: rebase("Test.swiftmodule", at: root)))) | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand this - how is this different from L45-47?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this is meant to relax the check on this line, but it does make it fully redundant in the process.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ach, I forgot about this weirdness. Yes, it's redundant this way. Kicking myself.