@@ -149,6 +149,15 @@ extension ModuleDependencyGraph {
149
149
invalidatedNodes. formUnion ( self . integrateExternal ( . known( fed) ) )
150
150
}
151
151
}
152
+
153
+ /// If the priors were read from an invocation containing a subsuequently removed input,
154
+ /// the nodes defining decls from that input must be culled.
155
+ fileprivate func isForRemovedInput( _ node: Node ) -> Bool {
156
+ guard let dependencySource = node. dependencySource else {
157
+ return false
158
+ }
159
+ return inputDependencySourceMap. inputIfKnown ( for: dependencySource) == nil
160
+ }
152
161
}
153
162
154
163
// MARK: - Scheduling the first wave
@@ -528,7 +537,9 @@ extension ModuleDependencyGraph {
528
537
private var identifiers : [ String ] = [ " " ]
529
538
private var currentDefKey : DependencyKey ? = nil
530
539
private var nodeUses : [ ( DependencyKey , Int ) ] = [ ]
531
- public private( set) var allNodes : [ Node ] = [ ]
540
+ /// Use nodes in def-use links are seliarized by index, so keep an array of all nodes read.
541
+ /// But, don't keep nodes that are for reomved inputs.
542
+ public private( set) var potentiallyUsedNodes : [ Node ? ] = [ ]
532
543
533
544
init ? ( _ info: IncrementalCompilationState . IncrementalDependencyAndInputSetup ) {
534
545
self . fileSystem = info. fileSystem
@@ -541,8 +552,11 @@ extension ModuleDependencyGraph {
541
552
542
553
func finalizeGraph( ) -> ModuleDependencyGraph {
543
554
for (dependencyKey, useID) in self . nodeUses {
555
+ guard let use = self . potentiallyUsedNodes [ useID] else {
556
+ continue
557
+ }
544
558
let isNewUse = self . graph. nodeFinder
545
- . record ( def: dependencyKey, use: self . allNodes [ useID ] )
559
+ . record ( def: dependencyKey, use: use )
546
560
assert ( isNewUse, " Duplicate use def-use arc in graph? " )
547
561
}
548
562
return self . graph
@@ -561,7 +575,12 @@ extension ModuleDependencyGraph {
561
575
mutating func didExitBlock( ) throws { }
562
576
563
577
private mutating func finalize( node newNode: Node ) {
564
- self . allNodes. append ( newNode)
578
+ if graph. isForRemovedInput ( newNode) {
579
+ // Preserve the mapping of Int to Node for reconstructing def-use links.
580
+ self . potentiallyUsedNodes. append ( nil )
581
+ return
582
+ }
583
+ self . potentiallyUsedNodes. append ( newNode)
565
584
let oldNode = self . graph. nodeFinder. insert ( newNode)
566
585
assert ( oldNode == nil ,
567
586
" Integrated the same node twice: \( oldNode!) , \( newNode) " )
0 commit comments