@@ -24,7 +24,7 @@ import SwiftOptions
24
24
@_spi ( Testing) public var nodeFinder = NodeFinder ( )
25
25
26
26
/// Maps input files (e.g. .swift) to and from the DependencySource object.
27
- @_spi ( Testing) public private ( set ) var inputDependencySourceMap = InputDependencySourceMap ( )
27
+ @_spi ( Testing) public let inputDependencySourceMap : InputDependencySourceMap
28
28
29
29
// The set of paths to external dependencies known to be in the graph
30
30
public internal( set) var fingerprintedExternalDependencies = Set < FingerprintedExternalDependency > ( )
@@ -43,7 +43,7 @@ import SwiftOptions
43
43
/// Minimize the number of file system modification-time queries.
44
44
private var externalDependencyModTimeCache = [ ExternalDependency: Bool] ( )
45
45
46
- public init ( _ info: IncrementalCompilationState . IncrementalDependencyAndInputSetup ,
46
+ public init ? ( _ info: IncrementalCompilationState . IncrementalDependencyAndInputSetup ,
47
47
_ phase: Phase
48
48
) {
49
49
self . info = info
@@ -52,6 +52,11 @@ import SwiftOptions
52
52
: nil
53
53
self . phase = phase
54
54
self . creationPhase = phase
55
+ guard let inputDependencySourceMap = InputDependencySourceMap ( info)
56
+ else {
57
+ return nil
58
+ }
59
+ self . inputDependencySourceMap = inputDependencySourceMap
55
60
}
56
61
57
62
@_spi ( Testing) public func sourceRequired( for input: TypedVirtualPath ,
@@ -188,46 +193,9 @@ extension ModuleDependencyGraph {
188
193
return nodeFinder. findNodes ( for: source) . map { !$0. isEmpty}
189
194
?? false
190
195
}
191
-
192
- /// Returns: false on error
193
- func populateInputDependencySourceMap(
194
- `for` purpose: InputDependencySourceMap . AdditionPurpose
195
- ) -> Bool {
196
- let ofm = info. outputFileMap
197
- let diags = info. diagnosticEngine
198
- var allFound = true
199
- for input in info. inputFiles {
200
- if let source = ofm. dependencySource ( for: input, diagnosticEngine: diags) {
201
- inputDependencySourceMap. addEntry ( input, source, for: purpose)
202
- } else {
203
- // Don't break in order to report all failures.
204
- allFound = false
205
- }
206
- }
207
- return allFound
208
- }
209
- }
210
- extension OutputFileMap {
211
- fileprivate func dependencySource(
212
- for sourceFile: TypedVirtualPath ,
213
- diagnosticEngine: DiagnosticsEngine
214
- ) -> DependencySource ? {
215
- assert ( sourceFile. type == FileType . swift)
216
- guard let swiftDepsPath = existingOutput ( inputFile: sourceFile. fileHandle,
217
- outputType: . swiftDeps)
218
- else {
219
- // The legacy driver fails silently here.
220
- diagnosticEngine. emit (
221
- . remarkDisabled( " \( sourceFile. file. basename) has no swiftDeps file in the output file map " )
222
- )
223
- return nil
224
- }
225
- assert ( VirtualPath . lookup ( swiftDepsPath) . extension == FileType . swiftDeps. rawValue)
226
- let typedSwiftDepsFile = TypedVirtualPath ( file: swiftDepsPath, type: . swiftDeps)
227
- return DependencySource ( typedSwiftDepsFile)
228
- }
229
196
}
230
197
198
+
231
199
// MARK: - Scheduling the 2nd wave
232
200
extension ModuleDependencyGraph {
233
201
/// After `source` has been compiled, figure out what other source files need compiling.
@@ -566,9 +534,13 @@ extension ModuleDependencyGraph {
566
534
private var inputDependencySourceMap : [ ( TypedVirtualPath , DependencySource ) ] = [ ]
567
535
public private( set) var allNodes : [ Node ] = [ ]
568
536
569
- init ( _ info: IncrementalCompilationState . IncrementalDependencyAndInputSetup ) {
537
+ init ? ( _ info: IncrementalCompilationState . IncrementalDependencyAndInputSetup ) {
570
538
self . fileSystem = info. fileSystem
571
- self . graph = ModuleDependencyGraph ( info, . updatingFromAPrior)
539
+ guard let graph = ModuleDependencyGraph ( info, . updatingFromAPrior)
540
+ else {
541
+ return nil
542
+ }
543
+ self . graph = graph
572
544
}
573
545
574
546
func finalizeGraph( ) -> ModuleDependencyGraph {
@@ -577,11 +549,6 @@ extension ModuleDependencyGraph {
577
549
. record ( def: dependencyKey, use: self . allNodes [ useID] )
578
550
assert ( isNewUse, " Duplicate use def-use arc in graph? " )
579
551
}
580
- for (input, dependencySource) in inputDependencySourceMap {
581
- graph. inputDependencySourceMap. addEntry ( input,
582
- dependencySource,
583
- for: . readingPriors)
584
- }
585
552
return self . graph
586
553
}
587
554
@@ -717,7 +684,9 @@ extension ModuleDependencyGraph {
717
684
}
718
685
}
719
686
720
- var visitor = Visitor ( info)
687
+ guard var visitor = Visitor ( info) else {
688
+ return nil
689
+ }
721
690
try Bitcode . read ( bytes: data, using: & visitor)
722
691
guard let major = visitor. majorVersion,
723
692
let minor = visitor. minorVersion,
@@ -1152,13 +1121,3 @@ extension Set where Element == FingerprintedExternalDependency {
1152
1121
self == other
1153
1122
}
1154
1123
}
1155
-
1156
- /// This should be in a test file, but addMapEntry should be private.
1157
- extension ModuleDependencyGraph {
1158
- @_spi ( Testing) public func mockMapEntry(
1159
- _ mockInput: TypedVirtualPath ,
1160
- _ mockDependencySource: DependencySource
1161
- ) {
1162
- inputDependencySourceMap. addEntry ( mockInput, mockDependencySource, for: . mocking)
1163
- }
1164
- }
0 commit comments