@@ -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 ,
@@ -190,46 +195,9 @@ extension ModuleDependencyGraph {
190
195
return nodeFinder. findNodes ( for: source) . map { !$0. isEmpty}
191
196
?? false
192
197
}
193
-
194
- /// - Returns: false on error
195
- func populateInputDependencySourceMap(
196
- `for` purpose: InputDependencySourceMap . AdditionPurpose
197
- ) -> Bool {
198
- let ofm = info. outputFileMap
199
- let diags = info. diagnosticEngine
200
- var allFound = true
201
- for input in info. inputFiles {
202
- if let source = ofm. dependencySource ( for: input, diagnosticEngine: diags) {
203
- inputDependencySourceMap. addEntry ( input, source, for: purpose)
204
- } else {
205
- // Don't break in order to report all failures.
206
- allFound = false
207
- }
208
- }
209
- return allFound
210
- }
211
- }
212
- extension OutputFileMap {
213
- fileprivate func dependencySource(
214
- for sourceFile: TypedVirtualPath ,
215
- diagnosticEngine: DiagnosticsEngine
216
- ) -> DependencySource ? {
217
- assert ( sourceFile. type == FileType . swift)
218
- guard let swiftDepsPath = existingOutput ( inputFile: sourceFile. fileHandle,
219
- outputType: . swiftDeps)
220
- else {
221
- // The legacy driver fails silently here.
222
- diagnosticEngine. emit (
223
- . remarkDisabled( " \( sourceFile. file. basename) has no swiftDeps file " )
224
- )
225
- return nil
226
- }
227
- assert ( VirtualPath . lookup ( swiftDepsPath) . extension == FileType . swiftDeps. rawValue)
228
- let typedSwiftDepsFile = TypedVirtualPath ( file: swiftDepsPath, type: . swiftDeps)
229
- return DependencySource ( typedSwiftDepsFile)
230
- }
231
198
}
232
199
200
+
233
201
// MARK: - Scheduling the 2nd wave
234
202
extension ModuleDependencyGraph {
235
203
/// After `source` has been compiled, figure out what other source files need compiling.
@@ -442,7 +410,6 @@ extension ModuleDependencyGraph {
442
410
case useIDNode = 4
443
411
case externalDepNode = 5
444
412
case identifierNode = 6
445
- case mapNode = 7
446
413
447
414
/// The human-readable name of this record.
448
415
///
@@ -463,8 +430,6 @@ extension ModuleDependencyGraph {
463
430
return " EXTERNAL_DEP_NODE "
464
431
case . identifierNode:
465
432
return " IDENTIFIER_NODE "
466
- case . mapNode:
467
- return " MAP_NODE "
468
433
}
469
434
}
470
435
}
@@ -516,12 +481,15 @@ extension ModuleDependencyGraph {
516
481
private var identifiers : [ String ] = [ " " ]
517
482
private var currentDefKey : DependencyKey ? = nil
518
483
private var nodeUses : [ ( DependencyKey , Int ) ] = [ ]
519
- private var inputDependencySourceMap : [ ( TypedVirtualPath , DependencySource ) ] = [ ]
520
484
public private( set) var allNodes : [ Node ] = [ ]
521
485
522
- init ( _ info: IncrementalCompilationState . IncrementalDependencyAndInputSetup ) {
486
+ init ? ( _ info: IncrementalCompilationState . IncrementalDependencyAndInputSetup ) {
523
487
self . fileSystem = info. fileSystem
524
- self . graph = ModuleDependencyGraph ( info, . updatingFromAPrior)
488
+ guard let graph = ModuleDependencyGraph ( info, . updatingFromAPrior)
489
+ else {
490
+ return nil
491
+ }
492
+ self . graph = graph
525
493
}
526
494
527
495
func finalizeGraph( ) -> ModuleDependencyGraph {
@@ -530,11 +498,6 @@ extension ModuleDependencyGraph {
530
498
. record ( def: dependencyKey, use: self . allNodes [ useID] )
531
499
assert ( isNewUse, " Duplicate use def-use arc in graph? " )
532
500
}
533
- for (input, dependencySource) in inputDependencySourceMap {
534
- graph. inputDependencySourceMap. addEntry ( input,
535
- dependencySource,
536
- for: . readingPriors)
537
- }
538
501
return self . graph
539
502
}
540
503
@@ -624,27 +587,6 @@ extension ModuleDependencyGraph {
624
587
throw ReadError . malformedDependsOnRecord
625
588
}
626
589
self . nodeUses. append ( ( key, Int ( record. fields [ 0 ] ) ) )
627
- case . mapNode:
628
- guard record. fields. count == 2 ,
629
- record. fields [ 0 ] < identifiers. count,
630
- record. fields [ 1 ] < identifiers. count
631
- else {
632
- throw ReadError . malformedModuleDepGraphNodeRecord
633
- }
634
- let inputPathString = identifiers [ Int ( record. fields [ 0 ] ) ]
635
- let dependencySourcePathString = identifiers [ Int ( record. fields [ 1 ] ) ]
636
- let inputHandle = try VirtualPath . intern ( path: inputPathString)
637
- let inputPath = VirtualPath . lookup ( inputHandle)
638
- let dependencySourceHandle = try VirtualPath . intern ( path: dependencySourcePathString)
639
- let dependencySourcePath = VirtualPath . lookup ( dependencySourceHandle)
640
- guard inputPath. extension == FileType . swift. rawValue,
641
- dependencySourcePath. extension == FileType . swiftDeps. rawValue,
642
- let dependencySource = DependencySource ( dependencySourceHandle)
643
- else {
644
- throw ReadError . malformedMapRecord
645
- }
646
- let input = TypedVirtualPath ( file: inputHandle, type: . swift)
647
- inputDependencySourceMap. append ( ( input, dependencySource) )
648
590
case . externalDepNode:
649
591
guard record. fields. count == 2 ,
650
592
record. fields [ 0 ] < identifiers. count,
@@ -670,7 +612,9 @@ extension ModuleDependencyGraph {
670
612
}
671
613
}
672
614
673
- var visitor = Visitor ( info)
615
+ guard var visitor = Visitor ( info) else {
616
+ return nil
617
+ }
674
618
try Bitcode . read ( bytes: data, using: & visitor)
675
619
guard let major = visitor. majorVersion,
676
620
let minor = visitor. minorVersion,
@@ -768,7 +712,6 @@ extension ModuleDependencyGraph {
768
712
self . emitRecordID ( . useIDNode)
769
713
self . emitRecordID ( . externalDepNode)
770
714
self . emitRecordID ( . identifierNode)
771
- self . emitRecordID ( . mapNode)
772
715
}
773
716
}
774
717
@@ -830,11 +773,6 @@ extension ModuleDependencyGraph {
830
773
}
831
774
}
832
775
833
- graph. inputDependencySourceMap. enumerateToSerializePriors { input, dependencySource in
834
- self . addIdentifier ( input. file. name)
835
- self . addIdentifier ( dependencySource. file. name)
836
- }
837
-
838
776
for edF in graph. fingerprintedExternalDependencies {
839
777
self . addIdentifier ( edF. externalDependency. fileName)
840
778
}
@@ -906,13 +844,6 @@ extension ModuleDependencyGraph {
906
844
// identifier data
907
845
. blob
908
846
] )
909
- self . abbreviate ( . mapNode, [
910
- . literal( RecordID . mapNode. rawValue) ,
911
- // input name
912
- . vbr( chunkBitWidth: 13 ) ,
913
- // dependencySource name
914
- . vbr( chunkBitWidth: 13 ) ,
915
- ] )
916
847
}
917
848
918
849
private func abbreviate(
@@ -975,15 +906,6 @@ extension ModuleDependencyGraph {
975
906
}
976
907
}
977
908
}
978
- graph. inputDependencySourceMap. enumerateToSerializePriors {
979
- input, dependencySource in
980
- serializer. stream. writeRecord ( serializer. abbreviations [ . mapNode] !) {
981
- $0. append ( RecordID . mapNode)
982
- $0. append ( serializer. lookupIdentifierCode ( for: input. file. name) )
983
- $0. append ( serializer. lookupIdentifierCode ( for: dependencySource. file. name) )
984
- }
985
- }
986
-
987
909
for fingerprintedExternalDependency in graph. fingerprintedExternalDependencies {
988
910
serializer. stream. writeRecord ( serializer. abbreviations [ . externalDepNode] !, {
989
911
$0. append ( RecordID . externalDepNode)
@@ -1079,7 +1001,6 @@ fileprivate extension DependencyKey.Designator {
1079
1001
extension ModuleDependencyGraph {
1080
1002
func matches( _ other: ModuleDependencyGraph ) -> Bool {
1081
1003
guard nodeFinder. matches ( other. nodeFinder) ,
1082
- inputDependencySourceMap. matches ( other. inputDependencySourceMap) ,
1083
1004
fingerprintedExternalDependencies. matches ( other. fingerprintedExternalDependencies)
1084
1005
else {
1085
1006
return false
@@ -1094,24 +1015,8 @@ extension Set where Element == ModuleDependencyGraph.Node {
1094
1015
}
1095
1016
}
1096
1017
1097
- extension InputDependencySourceMap {
1098
- fileprivate func matches( _ other: Self ) -> Bool {
1099
- self == other
1100
- }
1101
- }
1102
-
1103
1018
extension Set where Element == FingerprintedExternalDependency {
1104
1019
fileprivate func matches( _ other: Self ) -> Bool {
1105
1020
self == other
1106
1021
}
1107
1022
}
1108
-
1109
- /// This should be in a test file, but addMapEntry should be private.
1110
- extension ModuleDependencyGraph {
1111
- @_spi ( Testing) public func mockMapEntry(
1112
- _ mockInput: TypedVirtualPath ,
1113
- _ mockDependencySource: DependencySource
1114
- ) {
1115
- inputDependencySourceMap. addEntry ( mockInput, mockDependencySource, for: . mocking)
1116
- }
1117
- }
0 commit comments