@@ -46,9 +46,12 @@ import SwiftOptions
4646 inputDependencySourceMap [ input] = dependencySource
4747 }
4848
49- @_spi ( Testing) public func getSource( for input: TypedVirtualPath ) -> DependencySource {
49+ @_spi ( Testing) public func getSource( for input: TypedVirtualPath ,
50+ function: String = #function,
51+ file: String = #file,
52+ line: Int = #line) -> DependencySource {
5053 guard let source = inputDependencySourceMap [ input] else {
51- fatalError ( " \( input. file) not found in map: \( inputDependencySourceMap) " )
54+ fatalError ( " \( input. file) not found in map: \( inputDependencySourceMap) , \( file ) : \( line ) in \( function ) " )
5255 }
5356 return source
5457 }
@@ -65,21 +68,14 @@ extension ModuleDependencyGraph {
6568 /// Integrates `input` as needed and returns any inputs that were invalidated by external dependencies
6669 /// When creating a graph from swiftdeps files, this operation is performed for each input.
6770 func collectInputsRequiringCompilationFromExternalsFoundByCompiling(
68- input: TypedVirtualPath ) -> Set < TypedVirtualPath > ? {
69- guard let dependencySource = info. outputFileMap. getDependencySource (
70- for: input,
71- diagnosticEngine: info. diagnosticEngine)
72- else {
73- return nil
74- }
75- addMapEntry ( input, dependencySource)
76-
71+ input: TypedVirtualPath
72+ ) -> Set < TypedVirtualPath > ? {
7773 // do not try to read swiftdeps of a new input
7874 if info. sourceFiles. isANewInput ( input. file) {
7975 return Set < TypedVirtualPath > ( )
8076 }
8177 return collectInputsRequiringCompilationAfterProcessing (
82- dependencySource: dependencySource ,
78+ dependencySource: getSource ( for : input ) ,
8379 includeAddedExternals: false )
8480 }
8581}
@@ -136,6 +132,16 @@ extension ModuleDependencyGraph {
136132 return nodeFinder. findNodes ( for: source) . map { !$0. isEmpty}
137133 ?? false
138134 }
135+
136+ /// Return true on success
137+ func populateInputDependencySourceMap( ) -> Bool {
138+ let ofm = info. outputFileMap
139+ let de = info. diagnosticEngine
140+ return info. inputFiles. reduce ( true ) { okSoFar, input in
141+ ofm. getDependencySource ( for: input, diagnosticEngine: de)
142+ . map { source in addMapEntry ( input, source) ; return okSoFar } ?? false
143+ }
144+ }
139145}
140146// MARK: - Scheduling the 2nd wave
141147extension ModuleDependencyGraph {
@@ -162,7 +168,7 @@ extension ModuleDependencyGraph {
162168 public func collectSwiftDepsUsingTransitivelyInvalidated< Nodes: Sequence > (
163169 nodes: Nodes
164170 ) -> Set < DependencySource >
165- where Nodes. Element == Node
171+ where Nodes. Element == Node
166172 {
167173 // Is this correct for the 1st wave after having read a prior?
168174 // Yes, because
@@ -174,9 +180,9 @@ extension ModuleDependencyGraph {
174180 diagnosticEngine: info. diagnosticEngine)
175181 . tracedUses
176182 let invalidatedSources = Set (
177- affectedNodes. compactMap {
178- $0. dependencySource. flatMap { $0. typedFile. type == . swiftDeps ? $0 : nil }
179- } )
183+ affectedNodes. compactMap {
184+ $0. dependencySource. flatMap { $0. typedFile. type == . swiftDeps ? $0 : nil }
185+ } )
180186 return invalidatedSources
181187 }
182188
@@ -197,8 +203,8 @@ extension ModuleDependencyGraph {
197203 fingerprint: fingerprintedExternalDependency. fingerprint,
198204 dependencySource: nil )
199205 return nodeFinder
200- . uses ( of: node)
201- . filter ( { use in isUntraced ( use) } )
206+ . uses ( of: node)
207+ . filter ( { use in isUntraced ( use) } )
202208 }
203209
204210 /// Find all the inputs known to need recompilation as a consequence of reading a swiftdeps or swiftmodule
@@ -223,8 +229,8 @@ extension ModuleDependencyGraph {
223229 return nil
224230 }
225231 let results = Integrator . integrate ( from: sourceGraph,
226- into: self ,
227- includeAddedExternals: includeAddedExternals)
232+ into: self ,
233+ includeAddedExternals: includeAddedExternals)
228234
229235 /// When reading from a swiftdeps file ( includeAddedExternals is false), any changed input files are
230236 /// computed separately. (TODO: fix this? by finding changed inputs in a callee?),
@@ -274,16 +280,16 @@ extension ModuleDependencyGraph {
274280 ( isNewToTheGraph || lazyModTimer. hasExternalFileChanged)
275281
276282 let invalidatedNodesFromIncrementalExternal = shouldTryToProcess
277- ? collectNodesInvalidatedByAttemptingToProcess (
278- fed, info, includeAddedExternals: includeAddedExternals)
279- : nil
283+ ? collectNodesInvalidatedByAttemptingToProcess (
284+ fed, info, includeAddedExternals: includeAddedExternals)
285+ : nil
280286
281287 let callerWantsTheseChanges = ( includeAddedExternals && isNewToTheGraph) ||
282288 lazyModTimer. hasExternalFileChanged
283289
284290 return !callerWantsTheseChanges
285- ? Set < Node > ( )
286- : invalidatedNodesFromIncrementalExternal ?? collectUntracedNodesDirectlyUsing ( fed)
291+ ? Set < Node > ( )
292+ : invalidatedNodesFromIncrementalExternal ?? collectUntracedNodesDirectlyUsing ( fed)
287293 }
288294
289295 private struct LazyModTimer {
@@ -312,6 +318,27 @@ extension ModuleDependencyGraph {
312318
313319}
314320
321+ extension OutputFileMap {
322+ fileprivate func getDependencySource(
323+ for sourceFile: TypedVirtualPath ,
324+ diagnosticEngine: DiagnosticsEngine
325+ ) -> DependencySource ? {
326+ assert ( sourceFile. type == FileType . swift)
327+ guard let swiftDepsPath = existingOutput ( inputFile: sourceFile. file,
328+ outputType: . swiftDeps)
329+ else {
330+ // The legacy driver fails silently here.
331+ diagnosticEngine. emit (
332+ . remarkDisabled( " \( sourceFile. file. basename) has no swiftDeps file " )
333+ )
334+ return nil
335+ }
336+ assert ( swiftDepsPath. extension == FileType . swiftDeps. rawValue)
337+ let typedSwiftDepsFile = TypedVirtualPath ( file: swiftDepsPath, type: . swiftDeps)
338+ return DependencySource ( typedSwiftDepsFile)
339+ }
340+ }
341+
315342// MARK: - tracking traced nodes
316343extension ModuleDependencyGraph {
317344
@@ -325,7 +352,7 @@ extension ModuleDependencyGraph {
325352 tracedNodes. insert ( n)
326353 }
327354 func ensureGraphWillRetraceDependents< Nodes: Sequence > ( of nodes: Nodes )
328- where Nodes. Element == Node
355+ where Nodes. Element == Node
329356 {
330357 nodes. forEach { tracedNodes. remove ( $0) }
331358 }
@@ -833,7 +860,7 @@ extension ModuleDependencyGraph {
833860 // dependencySource name
834861 . vbr( chunkBitWidth: 13 ) ,
835862 ] )
836- }
863+ }
837864
838865 private func abbreviate(
839866 _ record: RecordID ,
@@ -1044,9 +1071,9 @@ extension Diagnostic.Message {
10441071extension ModuleDependencyGraph {
10451072 func matches( _ other: ModuleDependencyGraph ) -> Bool {
10461073 guard nodeFinder. matches ( other. nodeFinder) ,
1047- tracedNodes. matches ( other. tracedNodes) ,
1048- inputDependencySourceMap. matches ( other. inputDependencySourceMap) ,
1049- fingerprintedExternalDependencies. matches ( other. fingerprintedExternalDependencies)
1074+ tracedNodes. matches ( other. tracedNodes) ,
1075+ inputDependencySourceMap. matches ( other. inputDependencySourceMap) ,
1076+ fingerprintedExternalDependencies. matches ( other. fingerprintedExternalDependencies)
10501077 else {
10511078 return false
10521079 }
@@ -1072,27 +1099,6 @@ extension Set where Element == FingerprintedExternalDependency {
10721099 }
10731100}
10741101
1075- extension OutputFileMap {
1076- fileprivate func getDependencySource(
1077- for sourceFile: TypedVirtualPath ,
1078- diagnosticEngine: DiagnosticsEngine
1079- ) -> DependencySource ? {
1080- assert ( sourceFile. type == FileType . swift)
1081- guard let swiftDepsPath = existingOutput ( inputFile: sourceFile. file,
1082- outputType: . swiftDeps)
1083- else {
1084- // The legacy driver fails silently here.
1085- diagnosticEngine. emit (
1086- . remarkDisabled( " \( sourceFile. file. basename) has no swiftDeps file " )
1087- )
1088- return nil
1089- }
1090- assert ( swiftDepsPath. extension == FileType . swiftDeps. rawValue)
1091- let typedSwiftDepsFile = TypedVirtualPath ( file: swiftDepsPath, type: . swiftDeps)
1092- return DependencySource ( typedSwiftDepsFile)
1093- }
1094- }
1095-
10961102/// This should be in a test file, but addMapEntry should be private.
10971103extension ModuleDependencyGraph {
10981104 func mockMapEntry(
0 commit comments