Skip to content

Commit 52feebc

Browse files
author
David Ungar
committed
push down selection into integration
1 parent 2b22033 commit 52feebc

File tree

3 files changed

+46
-54
lines changed

3 files changed

+46
-54
lines changed

Sources/SwiftDriver/IncrementalCompilation/ModuleDependencyGraph.swift

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ extension ModuleDependencyGraph {
248248
private func collectInputsRequiringCompilationAfterProcessing(
249249
dependencySource: DependencySource
250250
) -> Set<TypedVirtualPath>? {
251+
assert(dependencySource.typedFile.type == .swiftDeps)
251252
guard let sourceGraph = dependencySource.read(in: info.fileSystem,
252253
reporter: info.reporter)
253254
else {
@@ -257,15 +258,7 @@ extension ModuleDependencyGraph {
257258
because: "malformed dependencies file '\(dependencySource.typedFile)'"))
258259
return nil
259260
}
260-
let results = Integrator.integrate(from: sourceGraph, into: self)
261-
262-
/// If reading for the first time, the driver is compiling all outdated source files anyway, so only
263-
/// nodes invalidated by external dependencies matter.
264-
/// But when updating, all invalidations matter.
265-
let invalidatedNodes = phase.isUpdating
266-
? results.all
267-
: results.usesOfSomeExternal
268-
261+
let invalidatedNodes = Integrator.integrate(from: sourceGraph, into: self)
269262
return collectInputsUsingTransitivelyInvalidated(nodes: invalidatedNodes)
270263
}
271264

@@ -344,10 +337,8 @@ extension ModuleDependencyGraph {
344337
.map { unserializedDepGraph in
345338
info.reporter?.report("Integrating changes from: \(fed.externalDependency)")
346339
return Integrator.integrate(from: unserializedDepGraph, into: self)
347-
.all
348340
}
349341
}
350-
351342
}
352343

353344
extension OutputFileMap {

Sources/SwiftDriver/IncrementalCompilation/ModuleDependencyGraphParts/Integrator.swift

Lines changed: 42 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ extension ModuleDependencyGraph {
2323
// Shorthands
2424
/*@_spi(Testing)*/ public typealias Graph = ModuleDependencyGraph
2525

26-
public private(set) var results = Results()
26+
public private(set) var invalidatedNodes = DirectlyInvalidatedNodes()
2727

2828
/// the graph to be integrated
2929
let sourceGraph: SourceFileDependencyGraph
@@ -48,6 +48,14 @@ extension ModuleDependencyGraph {
4848
var reporter: IncrementalCompilationState.Reporter? {
4949
destination.info.reporter
5050
}
51+
52+
var sourceType: FileType {
53+
sourceGraph.dependencySource.typedFile.type
54+
}
55+
56+
var isUpdating: Bool {
57+
destination.phase.isUpdating
58+
}
5159
}
5260
}
5361
// MARK: - integrate a graph
@@ -60,7 +68,7 @@ extension ModuleDependencyGraph.Integrator {
6068
/*@_spi(Testing)*/ public static func integrate(
6169
from g: SourceFileDependencyGraph,
6270
into destination: Graph
63-
) -> Results {
71+
) -> DirectlyInvalidatedNodes {
6472
var integrator = Self(sourceGraph: g, destination: destination)
6573
integrator.integrate()
6674

@@ -69,21 +77,21 @@ extension ModuleDependencyGraph.Integrator {
6977
}
7078
destination.dotFileWriter?.write(g)
7179
destination.dotFileWriter?.write(destination)
72-
return integrator.results
80+
return integrator.invalidatedNodes
7381
}
7482

7583
private mutating func integrate() {
7684
integrateEachSourceNode()
7785
handleDisappearedNodes()
7886
// Ensure transitive closure will get started.
79-
destination.ensureGraphWillRetrace(results.all)
87+
destination.ensureGraphWillRetrace(invalidatedNodes)
8088
}
8189
private mutating func integrateEachSourceNode() {
8290
sourceGraph.forEachNode { integrate(oneNode: $0) }
8391
}
8492
private mutating func handleDisappearedNodes() {
8593
for (_, node) in disappearedNodes {
86-
results.addDisappeared(node)
94+
addDisappeared(node)
8795
destination.nodeFinder.remove(node)
8896
}
8997
}
@@ -122,7 +130,7 @@ extension ModuleDependencyGraph.Integrator {
122130
disappearedNodes.removeValue(forKey: matchHere.key)
123131
if matchHere.fingerprint != integrand.fingerprint {
124132
matchHere.setFingerprint(integrand.fingerprint)
125-
results.addChanged(matchHere)
133+
addChanged(matchHere)
126134
reporter?.report("Fingerprint changed for \(matchHere)")
127135
}
128136
return matchHere
@@ -143,10 +151,7 @@ extension ModuleDependencyGraph.Integrator {
143151
.replace(expat,
144152
newDependencySource: sourceGraph.dependencySource,
145153
newFingerprint: integrand.fingerprint)
146-
if destination.phase.isUpdating {
147-
reporter?.report("Discovered a definition for \(integratedNode)")
148-
}
149-
results.addPatriated(integratedNode)
154+
addPatriated(integratedNode)
150155
return integratedNode
151156
}
152157

@@ -161,10 +166,7 @@ extension ModuleDependencyGraph.Integrator {
161166
dependencySource: sourceGraph.dependencySource)
162167
let oldNode = destination.nodeFinder.insert(newNode)
163168
assert(oldNode == nil, "Should be new!")
164-
if destination.phase.isUpdating {
165-
reporter?.report("New definition: \(newNode)")
166-
}
167-
results.addNew(newNode)
169+
addNew(newNode)
168170
return newNode
169171
}
170172

@@ -180,7 +182,7 @@ extension ModuleDependencyGraph.Integrator {
180182
use: moduleUseNode)
181183
if let externalDependency = def.key.designator.externalDependency,
182184
isNewUse {
183-
recordNodesInvalidatedByUsing(
185+
collectNodesInvalidatedByUsing(
184186
externalDependency: FingerprintedExternalDependency(externalDependency, def.fingerprint),
185187
moduleFileGraphUseNode: moduleUseNode)
186188
}
@@ -193,41 +195,41 @@ extension ModuleDependencyGraph.Integrator {
193195
// Remember the dependency for later processing in externalDependencies, and
194196
// also return it in results.
195197
// Also the use node has changed.
196-
private mutating func recordNodesInvalidatedByUsing(
198+
private mutating func collectNodesInvalidatedByUsing(
197199
externalDependency fingerprintedExternalDependency: FingerprintedExternalDependency,
198-
moduleFileGraphUseNode moduleUseNode: Graph.Node) {
199-
200+
moduleFileGraphUseNode moduleUseNode: Graph.Node
201+
) {
200202
let invalidated = destination.collectNodesInvalidatedByProcessing(
201203
fingerprintedExternalDependency: fingerprintedExternalDependency)
202-
results.addUsesOfSomeExternal(invalidated)
204+
collectUsesOfSomeExternal(invalidated)
203205
}
204206
}
205207

206208
// MARK: - Results {
207209
extension ModuleDependencyGraph.Integrator {
208210
/*@_spi(Testing)*/
209-
public struct Results {
210-
typealias Node = ModuleDependencyGraph.Node
211-
212-
private(set) var all = DirectlyInvalidatedNodes()
213-
private(set) var usesOfSomeExternal = DirectlyInvalidatedNodes()
214-
215-
mutating func addUsesOfSomeExternal(_ invalidated: DirectlyInvalidatedNodes)
216-
{
217-
all.formUnion(invalidated)
218-
usesOfSomeExternal.formUnion(invalidated)
219-
}
220-
mutating func addDisappeared(_ node: Node) {
221-
all.insert(node)
222-
}
223-
mutating func addChanged(_ node: Node) {
224-
all.insert(node)
225-
}
226-
mutating func addPatriated(_ node: Node) {
227-
all.insert(node)
211+
mutating func collectUsesOfSomeExternal(_ invalidated: DirectlyInvalidatedNodes)
212+
{
213+
invalidatedNodes.formUnion(invalidated)
214+
}
215+
mutating func addDisappeared(_ node: Graph.Node) {
216+
assert(isUpdating)
217+
invalidatedNodes.insert(node)
218+
}
219+
mutating func addChanged(_ node: Graph.Node) {
220+
assert(isUpdating)
221+
invalidatedNodes.insert(node)
222+
}
223+
mutating func addPatriated(_ node: Graph.Node) {
224+
if isUpdating {
225+
reporter?.report("Discovered a definition for \(node)")
226+
invalidatedNodes.insert(node)
228227
}
229-
mutating func addNew(_ node: Node) {
230-
all.insert(node)
228+
}
229+
mutating func addNew(_ node: Graph.Node) {
230+
if isUpdating {
231+
reporter?.report("New definition: \(node)")
232+
invalidatedNodes.insert(node)
231233
}
232234
}
233235
}

Tests/SwiftDriverTests/ModuleDependencyGraphTests.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -966,6 +966,7 @@ extension ModuleDependencyGraph {
966966
hadCompilationError: Bool = false)
967967
-> [Int]
968968
{
969+
phase = .updatingAfterCompilation
969970
let directlyIinvalidatedNodes = getDirectlyInvalidatedNodesForSimulatedLoad(
970971
swiftDepsIndex,
971972
dependencyDescriptions,
@@ -999,9 +1000,7 @@ extension ModuleDependencyGraph {
9991000
interfaceHash: interfaceHash,
10001001
dependencyDescriptions)
10011002

1002-
let results = Integrator.integrate(from: sfdg, into: self)
1003-
1004-
return results.all
1003+
return Integrator.integrate(from: sfdg, into: self)
10051004
}
10061005

10071006
func findUntracedSwiftDepsDependent(onExternal s: String) -> [Int] {

0 commit comments

Comments
 (0)