Skip to content

Commit 430ea32

Browse files
author
David Ungar
committed
When reading priors, don't use nodes for removed inputs.
1 parent f6ae539 commit 430ea32

File tree

2 files changed

+22
-19
lines changed

2 files changed

+22
-19
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 & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -796,22 +796,6 @@ extension IncrementalCompilationTests {
796796

797797
graph.verifyGraph()
798798
if removeInputFromInvocation {
799-
if afterRestoringBadPriors {
800-
// FIXME: Fix the driver
801-
// If you incrementally compile with a.swift and b.swift,
802-
// at the end, the driver saves a serialized `ModuleDependencyGraph`
803-
// contains nodes for declarations defined in both files.
804-
// If you then later remove b.swift and recompile, the driver will
805-
// see that a file was removed (via comparisons with the saved `BuildRecord`
806-
// and will delete the saved priors. However, if for some reason the
807-
// saved priors are not deleted, the driver will read saved priors
808-
// containing entries for the deleted file. This test simulates that
809-
// condition by restoring the deleted priors. The driver ought to be fixed
810-
// to cull any entries for removed files from the deserialized priors.
811-
print("*** WARNING: skipping checks, driver fails to cleaned out the graph ***",
812-
to: &stderrStream); stderrStream.flush()
813-
return graph
814-
}
815799
graph.ensureOmits(sourceBasenameWithoutExt: removedInput)
816800
graph.ensureOmits(name: topLevelName)
817801
}

0 commit comments

Comments
 (0)