@@ -49,40 +49,54 @@ final class ModuleDependencyGraph {
4949}
5050// MARK: - initial build only
5151extension ModuleDependencyGraph {
52+ /// Builds a graph
53+ /// Returns nil if some input has no place to put a swiftdeps file
54+ /// Returns a list of inputs whose swiftdeps files could not be read
5255 static func buildInitialGraph< Inputs: Sequence > (
5356 diagnosticEngine: DiagnosticsEngine ,
5457 inputs: Inputs ,
5558 outputFileMap: OutputFileMap ? ,
5659 parsedOptions: inout ParsedOptions ,
5760 remarkDisabled: ( String ) -> Diagnostic . Message ,
5861 reportIncrementalDecision: ( ( String , TypedVirtualPath ? ) -> Void ) ?
59- ) -> Self ?
62+ ) -> ( ModuleDependencyGraph , [ ( TypedVirtualPath , VirtualPath ) ] ) ?
6063 where Inputs. Element == TypedVirtualPath
6164 {
6265 let emitOpt = Option . driverEmitFineGrainedDependencyDotFileAfterEveryImport
6366 let veriOpt = Option . driverVerifyFineGrainedDependencyGraphAfterEveryImport
64- let r = Self (
67+ let graph = Self (
6568 diagnosticEngine: diagnosticEngine,
6669 reportIncrementalDecision: reportIncrementalDecision,
6770 emitDependencyDotFileAfterEveryImport: parsedOptions. contains ( emitOpt) ,
6871 verifyDependencyGraphAfterEveryImport: parsedOptions. contains ( veriOpt) )
69- for input in inputs {
70- guard let swiftDepsFile = outputFileMap? . existingOutput (
71- inputFile: input. file,
72- outputType: . swiftDeps)
72+
73+ let inputsAndSwiftdeps = inputs. map { input in
74+ ( input, outputFileMap? . existingOutput ( inputFile: input. file,
75+ outputType: . swiftDeps)
76+ )
77+ }
78+ for isd in inputsAndSwiftdeps where isd. 1 == nil {
79+ diagnosticEngine. emit (
80+ remarkDisabled ( " \( isd. 0 . file. basename) has no swiftDeps file " )
81+ )
82+ return nil
83+ }
84+ let inputsWithUnreadableSwiftDeps = inputsAndSwiftdeps. compactMap {
85+ input, swiftDepsFile -> ( TypedVirtualPath , VirtualPath ) ? in
86+ guard let swiftDepsFile = swiftDepsFile
7387 else {
74- diagnosticEngine. emit (
75- remarkDisabled ( " \( input. file. basename) has no swiftDeps file " )
76- )
7788 return nil
7889 }
7990 let swiftDeps = SwiftDeps ( swiftDepsFile)
80- r. sourceSwiftDepsMap [ input] = swiftDeps
81- _ = Integrator . integrate ( swiftDeps: swiftDeps,
82- into: r,
83- diagnosticEngine: diagnosticEngine)
91+ graph. sourceSwiftDepsMap [ input] = swiftDeps
92+ let changes = Integrator . integrate ( swiftDeps: swiftDeps,
93+ into: graph,
94+ input: input,
95+ reportIncrementalDecision: reportIncrementalDecision,
96+ diagnosticEngine: diagnosticEngine)
97+ return changes == nil ? ( input, swiftDepsFile) : nil
8498 }
85- return r
99+ return ( graph , inputsWithUnreadableSwiftDeps )
86100 }
87101}
88102// MARK: - Scheduling the first wave
@@ -129,17 +143,25 @@ extension ModuleDependencyGraph {
129143 func findSourcesToCompileAfterCompiling(
130144 _ source: TypedVirtualPath
131145 ) -> [ TypedVirtualPath ] ? {
132- findSourcesToCompileAfterIntegrating ( sourceSwiftDepsMap [ source] )
146+ findSourcesToCompileAfterIntegrating (
147+ input: source,
148+ swiftDeps: sourceSwiftDepsMap [ source] ,
149+ reportIncrementalDecision: reportIncrementalDecision
150+ )
133151 }
134152
135153 /// After a compile job has finished, read its swiftDeps file and return the source files needing
136154 /// recompilation.
137155 /// Return nil in case of an error.
138156 private func findSourcesToCompileAfterIntegrating(
139- _ swiftDeps: SwiftDeps
157+ input: TypedVirtualPath ,
158+ swiftDeps: SwiftDeps ,
159+ reportIncrementalDecision: ( ( String , TypedVirtualPath ) -> Void ) ?
140160 ) -> [ TypedVirtualPath ] ? {
141161 Integrator . integrate ( swiftDeps: swiftDeps,
142162 into: self ,
163+ input: input,
164+ reportIncrementalDecision: reportIncrementalDecision,
143165 diagnosticEngine: diagnosticEngine)
144166 . map {
145167 findSwiftDepsToRecompileWhenNodesChange ( $0)
0 commit comments