Skip to content

Commit d0dec97

Browse files
committed
Use Hashes for swiftmodule incremental compilation
I missed this in my earlier work on using hashes for Swift Incremental compilation. (#1923) Without this, we can have compiles that skip all recompilation save the emission of an identical Swiftmodule.
1 parent 0764248 commit d0dec97

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

Sources/SwiftDriver/IncrementalCompilation/FirstWaveComputer.swift

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,41 @@ extension IncrementalCompilationState.FirstWaveComputer {
202202
return false
203203
}
204204

205-
// Ensure that no output is older than any of the inputs
205+
// If all the modules are older than the outputs, we can skip
206206
let oldestOutputModTime: TimePoint = try emitModuleJob.outputs.map { try fileSystem.lastModificationTime(for: $0.file) }.min() ?? .distantPast
207-
return try emitModuleJob.inputs.swiftSourceFiles.allSatisfy({ try fileSystem.lastModificationTime(for: $0.typedFile.file) < oldestOutputModTime })
207+
let areModulesOlderThanOutput = try emitModuleJob.inputs.swiftSourceFiles.allSatisfy({ try fileSystem.lastModificationTime(for: $0.typedFile.file) < oldestOutputModTime })
208+
guard !areModulesOlderThanOutput else {
209+
return true
210+
}
211+
// If we are not using hashes, we cannot skip
212+
guard useHashes else {
213+
return false
214+
}
215+
let inputs:[TypedVirtualPath] = emitModuleJob.inputs
216+
for input:TypedVirtualPath in inputs {
217+
guard let currentDate:FileMetadata = buildRecordInfo.compilationInputModificationDates[input] else {
218+
reporter?.report("Missing file metadata for: \(input)")
219+
return false
220+
}
221+
222+
guard let currentHash:String = currentDate.hash else {
223+
reporter?.report("Missing file hash data for: \(input)")
224+
return false
225+
}
226+
227+
let inputInfos:[VirtualPath: InputInfo] = buildRecord.inputInfos
228+
guard let inputInfo:InputInfo = inputInfos[input.file] else {
229+
reporter?.report("Missing incremental info for: \(input)")
230+
return false
231+
}
232+
233+
if currentHash != inputInfo.hash {
234+
reporter?.report("Changed hash for: \(input)")
235+
return false
236+
}
237+
}
238+
return true
239+
208240
}
209241

210242
/// Figure out which compilation inputs are *not* mandatory at the start

0 commit comments

Comments
 (0)