Skip to content

Commit ff727b4

Browse files
committed
Use Hashes for swiftmodule incremental compilation
I missed this in my earlier work on using hashes for Swift Incremental compilation.
1 parent 22807ff commit ff727b4

File tree

1 file changed

+35
-3
lines changed

1 file changed

+35
-3
lines changed

Sources/SwiftDriver/IncrementalCompilation/FirstWaveComputer.swift

Lines changed: 35 additions & 3 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
206-
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 })
205+
// If all the modules are older than the outputs, we can skip
206+
let oldestOutputModTime = try emitModuleJob.outputs.map { try fileSystem.lastModificationTime(for: $0.file) }.min() ?? .distantPast
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 = emitModuleJob.inputs
216+
for input in inputs {
217+
guard let currentDate = buildRecordInfo.compilationInputModificationDates[input] else {
218+
reporter?.report("Missing file metadata for: \(input)")
219+
return false
220+
}
221+
222+
guard let currentHash = currentDate.hash else {
223+
reporter?.report("Missing file hash data for: \(input)")
224+
return false
225+
}
226+
227+
let inputInfos = buildRecord.inputInfos
228+
guard let 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)