@@ -54,24 +54,21 @@ import SwiftOptions
54
54
self . creationPhase = phase
55
55
}
56
56
57
- private func addMapEntry( _ input: TypedVirtualPath , _ dependencySource: DependencySource ) {
58
- assert ( input. type == . swift && dependencySource. typedFile. type == . swiftDeps)
59
- inputDependencySourceMap [ input] = dependencySource
60
- }
61
-
62
- @_spi ( Testing) public func getSource( for input: TypedVirtualPath ,
63
- function: String = #function,
64
- file: String = #file,
65
- line: Int = #line) -> DependencySource {
66
- guard let source = inputDependencySourceMap [ input] else {
57
+ @_spi ( Testing) public func getRequiredSource( for input: TypedVirtualPath ,
58
+ function: String = #function,
59
+ file: String = #file,
60
+ line: Int = #line) -> DependencySource {
61
+ guard let source = inputDependencySourceMap. getSourceIfKnown ( for: input)
62
+ else {
67
63
fatalError ( " \( input. file. basename) not found in inputDependencySourceMap, \( file) : \( line) in \( function) " )
68
64
}
69
65
return source
70
66
}
71
- @_spi ( Testing) public func getInput( for source: DependencySource ) -> TypedVirtualPath ? {
67
+
68
+ @_spi ( Testing) public func getNeededInput( for source: DependencySource ) -> TypedVirtualPath ? {
72
69
guard let input =
73
70
info. simulateGetInputFailure ? nil
74
- : inputDependencySourceMap [ source]
71
+ : inputDependencySourceMap. getInputIfKnown ( for : source)
75
72
else {
76
73
info. diagnosticEngine. emit ( warning: " Failed to find source file for ' \( source. file. basename) ', recovering with a full rebuild. Next build will be incremental. " )
77
74
info. reporter? . report (
@@ -148,7 +145,7 @@ extension ModuleDependencyGraph {
148
145
return TransitivelyInvalidatedInputSet ( )
149
146
}
150
147
return collectInputsRequiringCompilationAfterProcessing (
151
- dependencySource: getSource ( for: input) )
148
+ dependencySource: getRequiredSource ( for: input) )
152
149
}
153
150
}
154
151
@@ -170,17 +167,17 @@ extension ModuleDependencyGraph {
170
167
/// speculatively scheduled in the first wave.
171
168
func collectInputsInvalidatedBy( input: TypedVirtualPath
172
169
) -> TransitivelyInvalidatedInputArray {
173
- let changedSource = getSource ( for: input)
170
+ let changedSource = getRequiredSource ( for: input)
174
171
let allDependencySourcesToRecompile =
175
172
collectSwiftDepsUsing ( dependencySource: changedSource)
176
173
177
174
return allDependencySourcesToRecompile. compactMap {
178
175
depedencySource in
179
176
guard depedencySource != changedSource else { return nil }
180
- let dependentSource = inputDependencySourceMap [ depedencySource]
177
+ let dependentInput = inputDependencySourceMap. getInputIfKnown ( for : depedencySource)
181
178
info. reporter? . report (
182
- " Found dependent of \( input. file. basename) : " , dependentSource )
183
- return dependentSource
179
+ " Found dependent of \( input. file. basename) : " , dependentInput )
180
+ return dependentInput
184
181
}
185
182
}
186
183
@@ -197,7 +194,7 @@ extension ModuleDependencyGraph {
197
194
/// Does the graph contain any dependency nodes for a given source-code file?
198
195
func containsNodes( forSourceFile file: TypedVirtualPath ) -> Bool {
199
196
precondition ( file. type == . swift)
200
- guard let source = inputDependencySourceMap [ file] else {
197
+ guard let source = inputDependencySourceMap. getSourceIfKnown ( for : file) else {
201
198
return false
202
199
}
203
200
return containsNodes ( forDependencySource: source)
@@ -207,17 +204,47 @@ extension ModuleDependencyGraph {
207
204
return nodeFinder. findNodes ( for: source) . map { !$0. isEmpty}
208
205
?? false
209
206
}
210
-
211
- /// Return true on success
212
- func populateInputDependencySourceMap( ) -> Bool {
207
+
208
+ /// Returns: false on error
209
+ func populateInputDependencySourceMap(
210
+ `for` purpose: InputDependencySourceMap . AdditionPurpose
211
+ ) -> Bool {
213
212
let ofm = info. outputFileMap
214
- let de = info. diagnosticEngine
215
- return info. inputFiles. reduce ( true ) { okSoFar, input in
216
- ofm. getDependencySource ( for: input, diagnosticEngine: de)
217
- . map { source in addMapEntry ( input, source) ; return okSoFar } ?? false
213
+ let diags = info. diagnosticEngine
214
+ var allFound = true
215
+ for input in info. inputFiles {
216
+ if let source = ofm. getDependencySource ( for: input, diagnosticEngine: diags) {
217
+ inputDependencySourceMap. addEntry ( input, source, for: purpose)
218
+ }
219
+ else {
220
+ // Don't break in order to report all failures.
221
+ allFound = false
222
+ }
218
223
}
224
+ return allFound
219
225
}
220
226
}
227
+ extension OutputFileMap {
228
+ fileprivate func getDependencySource(
229
+ for sourceFile: TypedVirtualPath ,
230
+ diagnosticEngine: DiagnosticsEngine
231
+ ) -> DependencySource ? {
232
+ assert ( sourceFile. type == FileType . swift)
233
+ guard let swiftDepsPath = existingOutput ( inputFile: sourceFile. fileHandle,
234
+ outputType: . swiftDeps)
235
+ else {
236
+ // The legacy driver fails silently here.
237
+ diagnosticEngine. emit (
238
+ . remarkDisabled( " \( sourceFile. file. basename) has no swiftDeps file " )
239
+ )
240
+ return nil
241
+ }
242
+ assert ( VirtualPath . lookup ( swiftDepsPath) . extension == FileType . swiftDeps. rawValue)
243
+ let typedSwiftDepsFile = TypedVirtualPath ( file: swiftDepsPath, type: . swiftDeps)
244
+ return DependencySource ( typedSwiftDepsFile)
245
+ }
246
+ }
247
+
221
248
// MARK: - Scheduling the 2nd wave
222
249
extension ModuleDependencyGraph {
223
250
/// After `source` has been compiled, figure out what other source files need compiling.
@@ -227,7 +254,7 @@ extension ModuleDependencyGraph {
227
254
func collectInputsRequiringCompilation( byCompiling input: TypedVirtualPath
228
255
) -> TransitivelyInvalidatedInputSet ? {
229
256
precondition ( input. type == . swift)
230
- let dependencySource = getSource ( for: input)
257
+ let dependencySource = getRequiredSource ( for: input)
231
258
return collectInputsRequiringCompilationAfterProcessing (
232
259
dependencySource: dependencySource)
233
260
}
@@ -314,7 +341,7 @@ extension ModuleDependencyGraph {
314
341
) -> TransitivelyInvalidatedInputSet ? {
315
342
var invalidatedInputs = TransitivelyInvalidatedInputSet ( )
316
343
for invalidatedSwiftDeps in collectSwiftDepsUsingInvalidated ( nodes: directlyInvalidatedNodes) {
317
- guard let invalidatedInput = getInput ( for: invalidatedSwiftDeps)
344
+ guard let invalidatedInput = getNeededInput ( for: invalidatedSwiftDeps)
318
345
else {
319
346
return nil
320
347
}
@@ -392,27 +419,6 @@ extension ModuleDependencyGraph {
392
419
}
393
420
}
394
421
395
- extension OutputFileMap {
396
- fileprivate func getDependencySource(
397
- for sourceFile: TypedVirtualPath ,
398
- diagnosticEngine: DiagnosticsEngine
399
- ) -> DependencySource ? {
400
- assert ( sourceFile. type == FileType . swift)
401
- guard let swiftDepsPath = existingOutput ( inputFile: sourceFile. fileHandle,
402
- outputType: . swiftDeps)
403
- else {
404
- // The legacy driver fails silently here.
405
- diagnosticEngine. emit (
406
- . remarkDisabled( " \( sourceFile. file. basename) has no swiftDeps file " )
407
- )
408
- return nil
409
- }
410
- assert ( VirtualPath . lookup ( swiftDepsPath) . extension == FileType . swiftDeps. rawValue)
411
- let typedSwiftDepsFile = TypedVirtualPath ( file: swiftDepsPath, type: . swiftDeps)
412
- return DependencySource ( typedSwiftDepsFile)
413
- }
414
- }
415
-
416
422
// MARK: - tracking traced nodes
417
423
extension ModuleDependencyGraph {
418
424
@@ -537,10 +543,11 @@ extension ModuleDependencyGraph {
537
543
. record ( def: dependencyKey, use: self . allNodes [ useID] )
538
544
assert ( isNewUse, " Duplicate use def-use arc in graph? " )
539
545
}
540
- for (input, source) in inputDependencySourceMap {
541
- graph. addMapEntry ( input, source)
546
+ for (input, dependencySource) in inputDependencySourceMap {
547
+ graph. inputDependencySourceMap. addEntry ( input,
548
+ dependencySource,
549
+ for: . readingPriors)
542
550
}
543
-
544
551
return self . graph
545
552
}
546
553
@@ -836,7 +843,7 @@ extension ModuleDependencyGraph {
836
843
}
837
844
}
838
845
839
- for ( input, dependencySource) in graph . inputDependencySourceMap {
846
+ graph . inputDependencySourceMap . enumerateToSerializePriors { input, dependencySource in
840
847
self . addIdentifier ( input. file. name)
841
848
self . addIdentifier ( dependencySource. file. name)
842
849
}
@@ -981,7 +988,8 @@ extension ModuleDependencyGraph {
981
988
}
982
989
}
983
990
}
984
- for (input, dependencySource) in graph. inputDependencySourceMap {
991
+ graph. inputDependencySourceMap. enumerateToSerializePriors {
992
+ input, dependencySource in
985
993
serializer. stream. writeRecord ( serializer. abbreviations [ . mapNode] !) {
986
994
$0. append ( RecordID . mapNode)
987
995
$0. append ( serializer. lookupIdentifierCode ( for: input. file. name) )
@@ -1117,6 +1125,6 @@ extension ModuleDependencyGraph {
1117
1125
_ mockInput: TypedVirtualPath ,
1118
1126
_ mockDependencySource: DependencySource
1119
1127
) {
1120
- addMapEntry ( mockInput, mockDependencySource)
1128
+ inputDependencySourceMap . addEntry ( mockInput, mockDependencySource, for : . mocking )
1121
1129
}
1122
1130
}
0 commit comments