Skip to content

Commit 53f09ee

Browse files
author
David Ungar
committed
use phase instead
1 parent b1c40b7 commit 53f09ee

File tree

4 files changed

+21
-60
lines changed

4 files changed

+21
-60
lines changed

Sources/SwiftDriver/IncrementalCompilation/InitialStateComputer.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,6 @@ extension IncrementalCompilationState.InitialStateComputer {
173173
return nil
174174
}
175175

176-
// Every external will be an addition to the graph, but may not cause
177-
// a recompile, so includeAddedExternals is false.
178176
var inputsInvalidatedByChangedExternals = Set<TypedVirtualPath>()
179177
for input in sourceFiles.currentInOrder {
180178
guard let invalidatedInputs = graph.collectInputsRequiringCompilationFromExternalsFoundByCompiling(input: input)

Sources/SwiftDriver/IncrementalCompilation/ModuleDependencyGraph.swift

Lines changed: 15 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,7 @@ extension ModuleDependencyGraph {
100100
return Set<TypedVirtualPath>()
101101
}
102102
return collectInputsRequiringCompilationAfterProcessing(
103-
dependencySource: getSource(for: input),
104-
includeAddedExternals: false)
103+
dependencySource: getSource(for: input))
105104
}
106105
}
107106

@@ -110,8 +109,7 @@ extension ModuleDependencyGraph {
110109
func collectNodesInvalidatedByChangedOrAddedExternals() -> Set<Node> {
111110
fingerprintedExternalDependencies.reduce(into: Set()) { invalidatedNodes, fed in
112111
invalidatedNodes.formUnion (
113-
self.collectNodesInvalidatedByProcessing(fingerprintedExternalDependency: fed,
114-
includeAddedExternals: true))
112+
self.collectNodesInvalidatedByProcessing(fingerprintedExternalDependency: fed))
115113
}
116114
}
117115
}
@@ -180,8 +178,7 @@ extension ModuleDependencyGraph {
180178
precondition(input.type == .swift)
181179
let dependencySource = getSource(for: input)
182180
return collectInputsRequiringCompilationAfterProcessing(
183-
dependencySource: dependencySource,
184-
includeAddedExternals: true)
181+
dependencySource: dependencySource)
185182
}
186183
}
187184

@@ -237,15 +234,9 @@ extension ModuleDependencyGraph {
237234

238235
/// Find all the inputs known to need recompilation as a consequence of reading a swiftdeps or swiftmodule
239236
/// `dependencySource` - The file to read containing dependency information
240-
/// `includeAddedExternals` - If `true` external dependencies read from the dependencySource cause inputs to be invalidated,
241-
/// even if the external file has not changed since the last build.
242-
/// (`false` when building a graph from swiftdeps, `true` when building a graph from rereading the result of a compilation,
243-
/// because in that case the added external is assumed to be caused by an `import` added to the source file.)
244-
/// `invalidatedOnlyByExternals` - Only return inputs invalidated because of external dependencies, vs invalidated by any dependency
245237
/// Returns `nil` on error
246238
private func collectInputsRequiringCompilationAfterProcessing(
247-
dependencySource: DependencySource,
248-
includeAddedExternals: Bool
239+
dependencySource: DependencySource
249240
) -> Set<TypedVirtualPath>? {
250241
guard let sourceGraph = dependencySource.read(in: info.fileSystem,
251242
reporter: info.reporter)
@@ -256,16 +247,12 @@ extension ModuleDependencyGraph {
256247
because: "malformed dependencies file '\(dependencySource.typedFile)'"))
257248
return nil
258249
}
259-
let results = Integrator.integrate(from: sourceGraph,
260-
into: self,
261-
includeAddedExternals: includeAddedExternals)
262-
263-
/// When reading from a swiftdeps file ( includeAddedExternals is false), any changed input files are
264-
/// computed separately. (TODO: fix this? by finding changed inputs in a callee?),
265-
/// so the only invalidates that matter are the ones caused by
266-
/// changed external dependencies.
267-
/// When reading a swiftdeps file after compiling, any invalidated node matters.
268-
let invalidatedNodes = includeAddedExternals
250+
let results = Integrator.integrate(from: sourceGraph, into: self)
251+
252+
/// If reading for the first time, the driver is compiling all outdated source files anyway, so only
253+
/// nodes invalidated by external dependencies matter.
254+
/// But when updating, all invalidations matter.
255+
let invalidatedNodes = phase.isUpdating
269256
? results.allInvalidatedNodes
270257
: results.nodesInvalidatedByUsingSomeExternal
271258

@@ -288,12 +275,9 @@ extension ModuleDependencyGraph {
288275

289276
/// Process a possibly-fingerprinted external dependency by reading and integrating, if applicable.
290277
/// Return the nodes thus invalidated.
291-
/// includeAddedExternals - return the changes arising merely because the external was new to the graph,
292-
/// as opposed to changes from changed externals.
293278
/// But always integrate, in order to detect future changes.
294279
func collectNodesInvalidatedByProcessing(
295-
fingerprintedExternalDependency fed: FingerprintedExternalDependency,
296-
includeAddedExternals: Bool)
280+
fingerprintedExternalDependency fed: FingerprintedExternalDependency)
297281
-> Set<Node> {
298282

299283
let isNewToTheGraph = fingerprintedExternalDependencies.insert(fed).inserted
@@ -308,11 +292,10 @@ extension ModuleDependencyGraph {
308292
(isNewToTheGraph || lazyModTimer.hasExternalFileChanged)
309293

310294
let invalidatedNodesFromIncrementalExternal = shouldTryToProcess
311-
? collectNodesInvalidatedByAttemptingToProcess(
312-
fed, info, includeAddedExternals: includeAddedExternals)
295+
? collectNodesInvalidatedByAttemptingToProcess(fed, info)
313296
: nil
314297

315-
let callerWantsTheseChanges = (includeAddedExternals && isNewToTheGraph) ||
298+
let callerWantsTheseChanges = (phase.isUpdating && isNewToTheGraph) ||
316299
lazyModTimer.hasExternalFileChanged
317300

318301
return !callerWantsTheseChanges
@@ -330,17 +313,12 @@ extension ModuleDependencyGraph {
330313

331314
private func collectNodesInvalidatedByAttemptingToProcess(
332315
_ fed: FingerprintedExternalDependency,
333-
_ info: IncrementalCompilationState.InitialStateComputer,
334-
includeAddedExternals: Bool
335-
) -> Set<Node>? {
316+
_ info: IncrementalCompilationState.InitialStateComputer) -> Set<Node>? {
336317
fed.incrementalDependencySource?
337318
.read(in: info.fileSystem, reporter: info.reporter)
338319
.map { unserializedDepGraph in
339320
info.reporter?.report("Integrating changes from: \(fed.externalDependency)")
340-
return Integrator.integrate(
341-
from: unserializedDepGraph,
342-
into: self,
343-
includeAddedExternals: includeAddedExternals)
321+
return Integrator.integrate(from: unserializedDepGraph, into: self)
344322
.allInvalidatedNodes
345323
}
346324
}

Sources/SwiftDriver/IncrementalCompilation/ModuleDependencyGraphParts/Integrator.swift

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,15 @@ extension ModuleDependencyGraph {
3131
/// the graph to be integrated into
3232
let destination: ModuleDependencyGraph
3333

34-
/// The graph already includes externalDeps from prior compilations
35-
let includeAddedExternals: Bool
36-
3734
/// Starts with all nodes in dependencySource. Nodes that persist will be removed.
3835
/// After integration is complete, contains the nodes that have disappeared.
3936
var disappearedNodes = [DependencyKey: Graph.Node]()
4037

4138
init(sourceGraph: SourceFileDependencyGraph,
42-
destination: ModuleDependencyGraph,
43-
includeAddedExternals: Bool)
39+
destination: ModuleDependencyGraph)
4440
{
4541
self.sourceGraph = sourceGraph
4642
self.destination = destination
47-
self.includeAddedExternals = includeAddedExternals
4843
self.disappearedNodes = destination.nodeFinder
4944
.findNodes(for: sourceGraph.dependencySource)
5045
?? [:]
@@ -64,12 +59,9 @@ extension ModuleDependencyGraph.Integrator {
6459
/// Common to scheduling both waves.
6560
/*@_spi(Testing)*/ public static func integrate(
6661
from g: SourceFileDependencyGraph,
67-
into destination: Graph,
68-
includeAddedExternals: Bool
62+
into destination: Graph
6963
) -> Results {
70-
var integrator = Self(sourceGraph: g,
71-
destination: destination,
72-
includeAddedExternals: includeAddedExternals)
64+
var integrator = Self(sourceGraph: g, destination: destination)
7365
integrator.integrate()
7466

7567
if destination.info.verifyDependencyGraphAfterEveryImport {
@@ -205,8 +197,7 @@ extension ModuleDependencyGraph.Integrator {
205197
moduleFileGraphUseNode moduleUseNode: Graph.Node) {
206198

207199
let invalidated = destination.collectNodesInvalidatedByProcessing(
208-
fingerprintedExternalDependency: fingerprintedExternalDependency,
209-
includeAddedExternals: includeAddedExternals)
200+
fingerprintedExternalDependency: fingerprintedExternalDependency)
210201
results.addNodesInvalidatedByUsingSomeExternal(invalidated)
211202
}
212203
}

Tests/SwiftDriverTests/ModuleDependencyGraphTests.swift

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -754,8 +754,7 @@ class ModuleDependencyGraphTests: XCTestCase {
754754
let graph = ModuleDependencyGraph(mock: de)
755755
_ = graph.getInvalidatedNodesForSimulatedLoad(
756756
0,
757-
[MockDependencyKind.nominal: ["A@1"]],
758-
includeAddedExternals: false)
757+
[MockDependencyKind.nominal: ["A@1"]])
759758
}
760759

761760
func testUseFingerprints() {
@@ -955,7 +954,6 @@ extension ModuleDependencyGraph {
955954
{
956955
_ = getInvalidatedNodesForSimulatedLoad(
957956
swiftDepsIndex, dependencyDescriptions,
958-
includeAddedExternals: false,
959957
interfaceHash,
960958
includePrivateDeps: includePrivateDeps,
961959
hadCompilationError: hadCompilationError)
@@ -971,7 +969,6 @@ extension ModuleDependencyGraph {
971969
let invalidatedNodes = getInvalidatedNodesForSimulatedLoad(
972970
swiftDepsIndex,
973971
dependencyDescriptions,
974-
includeAddedExternals: true,
975972
interfaceHash,
976973
includePrivateDeps: includePrivateDeps,
977974
hadCompilationError: hadCompilationError)
@@ -984,7 +981,6 @@ extension ModuleDependencyGraph {
984981
func getInvalidatedNodesForSimulatedLoad(
985982
_ swiftDepsIndex: Int,
986983
_ dependencyDescriptions: [MockDependencyKind: [String]],
987-
includeAddedExternals: Bool,
988984
_ interfaceHashIfPresent: String? = nil,
989985
includePrivateDeps: Bool = true,
990986
hadCompilationError: Bool = false
@@ -1003,9 +999,7 @@ extension ModuleDependencyGraph {
1003999
interfaceHash: interfaceHash,
10041000
dependencyDescriptions)
10051001

1006-
let results = Integrator.integrate(from: sfdg,
1007-
into: self,
1008-
includeAddedExternals: includeAddedExternals)
1002+
let results = Integrator.integrate(from: sfdg, into: self)
10091003

10101004
return results.allInvalidatedNodes
10111005
}

0 commit comments

Comments
 (0)