Skip to content

Commit 8cf8e82

Browse files
author
David Ungar
committed
When reading priors, don't use nodes for removed inputs.
1 parent 9cc7ea6 commit 8cf8e82

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

Sources/SwiftDriver/IncrementalCompilation/ModuleDependencyGraph.swift

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,15 @@ extension ModuleDependencyGraph {
149149
invalidatedNodes.formUnion(self.integrateExternal(.known(fed)))
150150
}
151151
}
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+
}
152161
}
153162

154163
// MARK: - Scheduling the first wave
@@ -528,7 +537,9 @@ extension ModuleDependencyGraph {
528537
private var identifiers: [String] = [""]
529538
private var currentDefKey: DependencyKey? = nil
530539
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?] = []
532543

533544
init?(_ info: IncrementalCompilationState.IncrementalDependencyAndInputSetup) {
534545
self.fileSystem = info.fileSystem
@@ -541,8 +552,11 @@ extension ModuleDependencyGraph {
541552

542553
func finalizeGraph() -> ModuleDependencyGraph {
543554
for (dependencyKey, useID) in self.nodeUses {
555+
guard let use = self.potentiallyUsedNodes[useID] else {
556+
continue
557+
}
544558
let isNewUse = self.graph.nodeFinder
545-
.record(def: dependencyKey, use: self.allNodes[useID])
559+
.record(def: dependencyKey, use: use)
546560
assert(isNewUse, "Duplicate use def-use arc in graph?")
547561
}
548562
return self.graph
@@ -561,7 +575,12 @@ extension ModuleDependencyGraph {
561575
mutating func didExitBlock() throws {}
562576

563577
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)
565584
let oldNode = self.graph.nodeFinder.insert(newNode)
566585
assert(oldNode == nil,
567586
"Integrated the same node twice: \(oldNode!), \(newNode)")

Tests/SwiftDriverTests/IncrementalCompilationTests.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -796,12 +796,6 @@ extension IncrementalCompilationTests {
796796

797797
graph.verifyGraph()
798798
if removeInputFromInvocation {
799-
if afterRestoringBadPriors {
800-
// FIXME: Fix the driver
801-
print("*** WARNING: skipping checks, driver fails to cleaned out the graph ***",
802-
to: &stderrStream); stderrStream.flush()
803-
return graph
804-
}
805799
graph.ensureOmits(sourceBasenameWithoutExt: removedInput)
806800
graph.ensureOmits(name: topLevelName)
807801
}

0 commit comments

Comments
 (0)