@@ -206,7 +206,7 @@ extension IncrementalCompilationState.IncrementalDependencyAndInputSetup {
206206 return readPriorGraphAndCollectInputsInvalidatedByChangedOrAddedExternals ( )
207207 }
208208 // Every external is added, but don't want to compile an unchanged input that has an import
209- // so just changed, not changedOrAdded
209+ // so just changed, not changedOrAdded.
210210 return buildInitialGraphFromSwiftDepsAndCollectInputsInvalidatedByChangedExternals ( )
211211 }
212212
@@ -230,7 +230,13 @@ extension IncrementalCompilationState.IncrementalDependencyAndInputSetup {
230230 }
231231 guard let graph = graphIfPresent
232232 else {
233- return buildInitialGraphFromSwiftDepsAndCollectInputsInvalidatedByChangedExternals ( )
233+ // Do not fall back to `buildInitialGraphFromSwiftDepsAndCollectInputsInvalidatedByChangedExternals`
234+ // because it would be unsound to read a `swiftmodule` file with only a partial set of integrated `swiftdeps`.
235+ // A fingerprint change in such a `swiftmodule` would not be able to propagate and invalidate a use
236+ // in a as-yet-unread swiftdeps file.
237+ //
238+ // Instead, just compile everything. It's OK to be unsound then because every file will be compiled anyway.
239+ return bulidEmptyGraphAndCompileEverything ( )
234240 }
235241 graph. dotFileWriter? . write ( graph)
236242
@@ -257,10 +263,7 @@ extension IncrementalCompilationState.IncrementalDependencyAndInputSetup {
257263 private func buildInitialGraphFromSwiftDepsAndCollectInputsInvalidatedByChangedExternals( )
258264 -> ( ModuleDependencyGraph , TransitivelyInvalidatedInputSet ) ?
259265 {
260- guard let graph = ModuleDependencyGraph ( self , . buildingWithoutAPrior)
261- else {
262- return nil
263- }
266+ let graph = ModuleDependencyGraph ( self , . buildingFromSwiftDeps)
264267 var inputsInvalidatedByChangedExternals = TransitivelyInvalidatedInputSet ( )
265268 for input in sourceFiles. currentInOrder {
266269 guard let invalidatedInputs =
@@ -273,4 +276,10 @@ extension IncrementalCompilationState.IncrementalDependencyAndInputSetup {
273276 reporter? . report ( " Created dependency graph from swiftdeps files " )
274277 return ( graph, inputsInvalidatedByChangedExternals)
275278 }
279+
280+ private func bulidEmptyGraphAndCompileEverything( )
281+ -> ( ModuleDependencyGraph , TransitivelyInvalidatedInputSet ) {
282+ let graph = ModuleDependencyGraph ( self , . buildingAfterEachCompilation)
283+ return ( graph, TransitivelyInvalidatedInputSet ( ) )
284+ }
276285}
0 commit comments