@@ -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.
@@ -489,7 +457,6 @@ extension ModuleDependencyGraph {
489
457
case useIDNode = 4
490
458
case externalDepNode = 5
491
459
case identifierNode = 6
492
- case mapNode = 7
493
460
494
461
/// The human-readable name of this record.
495
462
///
@@ -510,8 +477,6 @@ extension ModuleDependencyGraph {
510
477
return " EXTERNAL_DEP_NODE "
511
478
case . identifierNode:
512
479
return " IDENTIFIER_NODE "
513
- case . mapNode:
514
- return " MAP_NODE "
515
480
}
516
481
}
517
482
}
@@ -563,12 +528,15 @@ extension ModuleDependencyGraph {
563
528
private var identifiers : [ String ] = [ " " ]
564
529
private var currentDefKey : DependencyKey ? = nil
565
530
private var nodeUses : [ ( DependencyKey , Int ) ] = [ ]
566
- private var inputDependencySourceMap : [ ( TypedVirtualPath , DependencySource ) ] = [ ]
567
531
public private( set) var allNodes : [ Node ] = [ ]
568
532
569
- init ( _ info: IncrementalCompilationState . IncrementalDependencyAndInputSetup ) {
533
+ init ? ( _ info: IncrementalCompilationState . IncrementalDependencyAndInputSetup ) {
570
534
self . fileSystem = info. fileSystem
571
- self . graph = ModuleDependencyGraph ( info, . updatingFromAPrior)
535
+ guard let graph = ModuleDependencyGraph ( info, . updatingFromAPrior)
536
+ else {
537
+ return nil
538
+ }
539
+ self . graph = graph
572
540
}
573
541
574
542
func finalizeGraph( ) -> ModuleDependencyGraph {
@@ -577,11 +545,6 @@ extension ModuleDependencyGraph {
577
545
. record ( def: dependencyKey, use: self . allNodes [ useID] )
578
546
assert ( isNewUse, " Duplicate use def-use arc in graph? " )
579
547
}
580
- for (input, dependencySource) in inputDependencySourceMap {
581
- graph. inputDependencySourceMap. addEntry ( input,
582
- dependencySource,
583
- for: . readingPriors)
584
- }
585
548
return self . graph
586
549
}
587
550
@@ -671,27 +634,6 @@ extension ModuleDependencyGraph {
671
634
throw ReadError . malformedDependsOnRecord
672
635
}
673
636
self . nodeUses. append ( ( key, Int ( record. fields [ 0 ] ) ) )
674
- case . mapNode:
675
- guard record. fields. count == 2 ,
676
- record. fields [ 0 ] < identifiers. count,
677
- record. fields [ 1 ] < identifiers. count
678
- else {
679
- throw ReadError . malformedModuleDepGraphNodeRecord
680
- }
681
- let inputPathString = identifiers [ Int ( record. fields [ 0 ] ) ]
682
- let dependencySourcePathString = identifiers [ Int ( record. fields [ 1 ] ) ]
683
- let inputHandle = try VirtualPath . intern ( path: inputPathString)
684
- let inputPath = VirtualPath . lookup ( inputHandle)
685
- let dependencySourceHandle = try VirtualPath . intern ( path: dependencySourcePathString)
686
- let dependencySourcePath = VirtualPath . lookup ( dependencySourceHandle)
687
- guard inputPath. extension == FileType . swift. rawValue,
688
- dependencySourcePath. extension == FileType . swiftDeps. rawValue,
689
- let dependencySource = DependencySource ( dependencySourceHandle)
690
- else {
691
- throw ReadError . malformedMapRecord
692
- }
693
- let input = TypedVirtualPath ( file: inputHandle, type: . swift)
694
- inputDependencySourceMap. append ( ( input, dependencySource) )
695
637
case . externalDepNode:
696
638
guard record. fields. count == 2 ,
697
639
record. fields [ 0 ] < identifiers. count,
@@ -717,7 +659,9 @@ extension ModuleDependencyGraph {
717
659
}
718
660
}
719
661
720
- var visitor = Visitor ( info)
662
+ guard var visitor = Visitor ( info) else {
663
+ return nil
664
+ }
721
665
try Bitcode . read ( bytes: data, using: & visitor)
722
666
guard let major = visitor. majorVersion,
723
667
let minor = visitor. minorVersion,
@@ -815,7 +759,6 @@ extension ModuleDependencyGraph {
815
759
self . emitRecordID ( . useIDNode)
816
760
self . emitRecordID ( . externalDepNode)
817
761
self . emitRecordID ( . identifierNode)
818
- self . emitRecordID ( . mapNode)
819
762
}
820
763
}
821
764
@@ -877,11 +820,6 @@ extension ModuleDependencyGraph {
877
820
}
878
821
}
879
822
880
- graph. inputDependencySourceMap. enumerateToSerializePriors { input, dependencySource in
881
- self . addIdentifier ( input. file. name)
882
- self . addIdentifier ( dependencySource. file. name)
883
- }
884
-
885
823
for edF in graph. fingerprintedExternalDependencies {
886
824
self . addIdentifier ( edF. externalDependency. fileName)
887
825
}
@@ -953,13 +891,6 @@ extension ModuleDependencyGraph {
953
891
// identifier data
954
892
. blob
955
893
] )
956
- self . abbreviate ( . mapNode, [
957
- . literal( RecordID . mapNode. rawValue) ,
958
- // input name
959
- . vbr( chunkBitWidth: 13 ) ,
960
- // dependencySource name
961
- . vbr( chunkBitWidth: 13 ) ,
962
- ] )
963
894
}
964
895
965
896
private func abbreviate(
@@ -1022,15 +953,6 @@ extension ModuleDependencyGraph {
1022
953
}
1023
954
}
1024
955
}
1025
- graph. inputDependencySourceMap. enumerateToSerializePriors {
1026
- input, dependencySource in
1027
- serializer. stream. writeRecord ( serializer. abbreviations [ . mapNode] !) {
1028
- $0. append ( RecordID . mapNode)
1029
- $0. append ( serializer. lookupIdentifierCode ( for: input. file. name) )
1030
- $0. append ( serializer. lookupIdentifierCode ( for: dependencySource. file. name) )
1031
- }
1032
- }
1033
-
1034
956
for fingerprintedExternalDependency in graph. fingerprintedExternalDependencies {
1035
957
serializer. stream. writeRecord ( serializer. abbreviations [ . externalDepNode] !, {
1036
958
$0. append ( RecordID . externalDepNode)
@@ -1126,7 +1048,6 @@ fileprivate extension DependencyKey.Designator {
1126
1048
extension ModuleDependencyGraph {
1127
1049
func matches( _ other: ModuleDependencyGraph ) -> Bool {
1128
1050
guard nodeFinder. matches ( other. nodeFinder) ,
1129
- inputDependencySourceMap. matches ( other. inputDependencySourceMap) ,
1130
1051
fingerprintedExternalDependencies. matches ( other. fingerprintedExternalDependencies)
1131
1052
else {
1132
1053
return false
@@ -1141,24 +1062,8 @@ extension Set where Element == ModuleDependencyGraph.Node {
1141
1062
}
1142
1063
}
1143
1064
1144
- extension InputDependencySourceMap {
1145
- fileprivate func matches( _ other: Self ) -> Bool {
1146
- self == other
1147
- }
1148
- }
1149
-
1150
1065
extension Set where Element == FingerprintedExternalDependency {
1151
1066
fileprivate func matches( _ other: Self ) -> Bool {
1152
1067
self == other
1153
1068
}
1154
1069
}
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