Skip to content

[5.7] New: Update incremental build hash to encode option arguments a… #1133

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
Jul 13, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,7 @@ import SwiftOptions
var parsedOptions = parsedOptionsArg
let hashInput = parsedOptions
.filter { $0.option.affectsIncrementalBuild && $0.option.kind != .input}
.map { $0.option.spelling }
.sorted()
.map { $0.description } // The description includes the spelling of the option itself and, if present, its argument(s).
.joined()
return SHA256().hash(hashInput).hexadecimalRepresentation
}
Expand Down
74 changes: 74 additions & 0 deletions Tests/SwiftDriverTests/IncrementalCompilationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,74 @@ extension IncrementalCompilationTests {
}
}

// MARK: - Incremental argument hashing tests
extension IncrementalCompilationTests {
func testNullBuildWhenAddingAndRemovingArgumentsNotAffectingIncrementalBuilds() throws {
// Adding, removing, or changing the arguments of options which don't affect incremental builds should result in a null build.
try buildInitialState(extraArguments: ["-driver-batch-size-limit", "5", "-debug-diagnostic-names"])
let driver = try checkNullBuild(extraArguments: ["-driver-batch-size-limit", "10", "-diagnostic-style", "swift"])
let mandatoryJobs = try XCTUnwrap(driver.incrementalCompilationState?.mandatoryJobsInOrder)
XCTAssertTrue(mandatoryJobs.isEmpty)
}

func testChangingOptionArgumentLeadsToRecompile() throws {
// If an option affects incremental builds, changing only the argument should trigger a full recompile.
try buildInitialState(extraArguments: ["-user-module-version", "1.0"])
try doABuild(
"change user module version",
checkDiagnostics: true,
extraArguments: ["-user-module-version", "1.1"],
whenAutolinking: autolinkLifecycleExpectedDiags
) {
enablingCrossModule
differentArgsPassed
disablingIncrementalDifferentArgsPassed
createdGraphFromSwiftdeps
findingBatchingCompiling("main", "other")
reading(deps: "main", "other")
schedLinking
}
}

func testOptionReorderingLeadsToRecompile() throws {
// Reordering options which affect incremental builds should trigger a full recompile.
try buildInitialState(extraArguments: ["-warnings-as-errors", "-no-warnings-as-errors"])
try doABuild(
"change user module version",
checkDiagnostics: true,
extraArguments: ["-no-warnings-as-errors", "-warnings-as-errors"],
whenAutolinking: autolinkLifecycleExpectedDiags
) {
enablingCrossModule
differentArgsPassed
disablingIncrementalDifferentArgsPassed
createdGraphFromSwiftdeps
findingBatchingCompiling("main", "other")
reading(deps: "main", "other")
schedLinking
}
}

func testArgumentReorderingLeadsToRecompile() throws {
// Reordering the arguments of an option which affect incremental builds should trigger a full recompile.
try buildInitialState(extraArguments: ["-Ifoo", "-Ibar"])
try doABuild(
"change user module version",
checkDiagnostics: true,
extraArguments: ["-Ibar", "-Ifoo"],
whenAutolinking: autolinkLifecycleExpectedDiags
) {
enablingCrossModule
differentArgsPassed
disablingIncrementalDifferentArgsPassed
createdGraphFromSwiftdeps
findingBatchingCompiling("main", "other")
reading(deps: "main", "other")
schedLinking
}
}
}

// MARK: - Incremental test stages
extension IncrementalCompilationTests {
/// Setup the initial post-build state.
Expand Down Expand Up @@ -1390,6 +1458,12 @@ extension DiagVerifiable {
@DiagsBuilder var disablingIncrementalCannotReadBuildRecord: [Diagnostic.Message] {
"Incremental compilation: Disabling incremental build: could not read build record"
}
@DiagsBuilder var differentArgsPassed: [Diagnostic.Message] {
"Incremental compilation: Incremental compilation has been disabled, because different arguments were passed to the compiler"
}
@DiagsBuilder var disablingIncrementalDifferentArgsPassed: [Diagnostic.Message] {
"Incremental compilation: Disabling incremental build: different arguments were passed to the compiler"
}
@DiagsBuilder var missingMainDependencyEntry: [Diagnostic.Message] {
.warning("ignoring -incremental; output file map has no master dependencies entry (\"swift-dependencies\" under \"\")")
}
Expand Down