@@ -54,22 +54,20 @@ 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 ? {
72
- guard let input = inputDependencySourceMap [ source] else {
67
+
68
+ @_spi ( Testing) public func getNeededInput( for source: DependencySource ) -> TypedVirtualPath ? {
69
+ guard let input = inputDependencySourceMap. getInputIfKnown ( for: source)
70
+ else {
73
71
info. diagnosticEngine. emit ( warning: " Failed to find source file for ' \( source. file. basename) ', recovering with a full rebuild. Next build will be incremental. " )
74
72
return nil
75
73
}
@@ -143,7 +141,7 @@ extension ModuleDependencyGraph {
143
141
return TransitivelyInvalidatedInputSet ( )
144
142
}
145
143
return collectInputsRequiringCompilationAfterProcessing (
146
- dependencySource: getSource ( for: input) )
144
+ dependencySource: getRequiredSource ( for: input) )
147
145
}
148
146
}
149
147
@@ -165,17 +163,17 @@ extension ModuleDependencyGraph {
165
163
/// speculatively scheduled in the first wave.
166
164
func collectInputsInvalidatedBy( input: TypedVirtualPath
167
165
) -> TransitivelyInvalidatedInputArray {
168
- let changedSource = getSource ( for: input)
166
+ let changedSource = getRequiredSource ( for: input)
169
167
let allDependencySourcesToRecompile =
170
168
collectSwiftDepsUsing ( dependencySource: changedSource)
171
169
172
170
return allDependencySourcesToRecompile. compactMap {
173
171
depedencySource in
174
172
guard depedencySource != changedSource else { return nil }
175
- let dependentSource = inputDependencySourceMap [ depedencySource]
173
+ let dependentInput = inputDependencySourceMap. getInputIfKnown ( for : depedencySource)
176
174
info. reporter? . report (
177
- " Found dependent of \( input. file. basename) : " , dependentSource )
178
- return dependentSource
175
+ " Found dependent of \( input. file. basename) : " , dependentInput )
176
+ return dependentInput
179
177
}
180
178
}
181
179
@@ -192,7 +190,7 @@ extension ModuleDependencyGraph {
192
190
/// Does the graph contain any dependency nodes for a given source-code file?
193
191
func containsNodes( forSourceFile file: TypedVirtualPath ) -> Bool {
194
192
precondition ( file. type == . swift)
195
- guard let source = inputDependencySourceMap [ file] else {
193
+ guard let source = inputDependencySourceMap. getSourceIfKnown ( for : file) else {
196
194
return false
197
195
}
198
196
return containsNodes ( forDependencySource: source)
@@ -202,17 +200,47 @@ extension ModuleDependencyGraph {
202
200
return nodeFinder. findNodes ( for: source) . map { !$0. isEmpty}
203
201
?? false
204
202
}
205
-
206
- /// Return true on success
207
- func populateInputDependencySourceMap( ) -> Bool {
203
+
204
+ /// Returns: false on error
205
+ func populateInputDependencySourceMap(
206
+ `for` purpose: InputDependencySourceMap . AdditionPurpose
207
+ ) -> Bool {
208
208
let ofm = info. outputFileMap
209
- let de = info. diagnosticEngine
210
- return info. inputFiles. reduce ( true ) { okSoFar, input in
211
- ofm. getDependencySource ( for: input, diagnosticEngine: de)
212
- . map { source in addMapEntry ( input, source) ; return okSoFar } ?? false
209
+ let diags = info. diagnosticEngine
210
+ var allFound = true
211
+ for input in info. inputFiles {
212
+ if let source = ofm. getDependencySource ( for: input, diagnosticEngine: diags) {
213
+ inputDependencySourceMap. addEntry ( input, source, for: purpose)
214
+ }
215
+ else {
216
+ // Don't break in order to report all failures.
217
+ allFound = false
218
+ }
213
219
}
220
+ return allFound
214
221
}
215
222
}
223
+ extension OutputFileMap {
224
+ fileprivate func getDependencySource(
225
+ for sourceFile: TypedVirtualPath ,
226
+ diagnosticEngine: DiagnosticsEngine
227
+ ) -> DependencySource ? {
228
+ assert ( sourceFile. type == FileType . swift)
229
+ guard let swiftDepsPath = existingOutput ( inputFile: sourceFile. fileHandle,
230
+ outputType: . swiftDeps)
231
+ else {
232
+ // The legacy driver fails silently here.
233
+ diagnosticEngine. emit (
234
+ . remarkDisabled( " \( sourceFile. file. basename) has no swiftDeps file " )
235
+ )
236
+ return nil
237
+ }
238
+ assert ( VirtualPath . lookup ( swiftDepsPath) . extension == FileType . swiftDeps. rawValue)
239
+ let typedSwiftDepsFile = TypedVirtualPath ( file: swiftDepsPath, type: . swiftDeps)
240
+ return DependencySource ( typedSwiftDepsFile)
241
+ }
242
+ }
243
+
216
244
// MARK: - Scheduling the 2nd wave
217
245
extension ModuleDependencyGraph {
218
246
/// After `source` has been compiled, figure out what other source files need compiling.
@@ -222,7 +250,7 @@ extension ModuleDependencyGraph {
222
250
func collectInputsRequiringCompilation( byCompiling input: TypedVirtualPath
223
251
) -> TransitivelyInvalidatedInputSet ? {
224
252
precondition ( input. type == . swift)
225
- let dependencySource = getSource ( for: input)
253
+ let dependencySource = getRequiredSource ( for: input)
226
254
return collectInputsRequiringCompilationAfterProcessing (
227
255
dependencySource: dependencySource)
228
256
}
@@ -317,7 +345,8 @@ extension ModuleDependencyGraph {
317
345
) -> TransitivelyInvalidatedInputSet ? {
318
346
var invalidatedInputs = TransitivelyInvalidatedInputSet ( )
319
347
for invalidatedSwiftDeps in collectSwiftDepsUsingInvalidated ( nodes: directlyInvalidatedNodes) {
320
- guard let invalidatedInput = getInput ( for: invalidatedSwiftDeps) else {
348
+ guard let invalidatedInput = getNeededInput ( for: invalidatedSwiftDeps)
349
+ else {
321
350
return nil
322
351
}
323
352
invalidatedInputs. insert ( invalidatedInput)
@@ -394,27 +423,6 @@ extension ModuleDependencyGraph {
394
423
}
395
424
}
396
425
397
- extension OutputFileMap {
398
- fileprivate func getDependencySource(
399
- for sourceFile: TypedVirtualPath ,
400
- diagnosticEngine: DiagnosticsEngine
401
- ) -> DependencySource ? {
402
- assert ( sourceFile. type == FileType . swift)
403
- guard let swiftDepsPath = existingOutput ( inputFile: sourceFile. fileHandle,
404
- outputType: . swiftDeps)
405
- else {
406
- // The legacy driver fails silently here.
407
- diagnosticEngine. emit (
408
- . remarkDisabled( " \( sourceFile. file. basename) has no swiftDeps file " )
409
- )
410
- return nil
411
- }
412
- assert ( VirtualPath . lookup ( swiftDepsPath) . extension == FileType . swiftDeps. rawValue)
413
- let typedSwiftDepsFile = TypedVirtualPath ( file: swiftDepsPath, type: . swiftDeps)
414
- return DependencySource ( typedSwiftDepsFile)
415
- }
416
- }
417
-
418
426
// MARK: - tracking traced nodes
419
427
extension ModuleDependencyGraph {
420
428
@@ -539,10 +547,11 @@ extension ModuleDependencyGraph {
539
547
. record ( def: dependencyKey, use: self . allNodes [ useID] )
540
548
assert ( isNewUse, " Duplicate use def-use arc in graph? " )
541
549
}
542
- for (input, source) in inputDependencySourceMap {
543
- graph. addMapEntry ( input, source)
550
+ for (input, dependencySource) in inputDependencySourceMap {
551
+ graph. inputDependencySourceMap. addEntry ( input,
552
+ dependencySource,
553
+ for: . readingPriors)
544
554
}
545
-
546
555
return self . graph
547
556
}
548
557
@@ -838,7 +847,7 @@ extension ModuleDependencyGraph {
838
847
}
839
848
}
840
849
841
- for ( input, dependencySource) in graph . inputDependencySourceMap {
850
+ graph . inputDependencySourceMap . enumerateToSerializePriors { input, dependencySource in
842
851
self . addIdentifier ( input. file. name)
843
852
self . addIdentifier ( dependencySource. file. name)
844
853
}
@@ -983,7 +992,8 @@ extension ModuleDependencyGraph {
983
992
}
984
993
}
985
994
}
986
- for (input, dependencySource) in graph. inputDependencySourceMap {
995
+ graph. inputDependencySourceMap. enumerateToSerializePriors {
996
+ input, dependencySource in
987
997
serializer. stream. writeRecord ( serializer. abbreviations [ . mapNode] !) {
988
998
$0. append ( RecordID . mapNode)
989
999
$0. append ( serializer. lookupIdentifierCode ( for: input. file. name) )
@@ -1119,6 +1129,6 @@ extension ModuleDependencyGraph {
1119
1129
_ mockInput: TypedVirtualPath ,
1120
1130
_ mockDependencySource: DependencySource
1121
1131
) {
1122
- addMapEntry ( mockInput, mockDependencySource)
1132
+ inputDependencySourceMap . addEntry ( mockInput, mockDependencySource, for : . mocking )
1123
1133
}
1124
1134
}
0 commit comments