Skip to content

Commit a7ff2ab

Browse files
author
David Ungar
authored
renamings (#493)
1 parent a840f39 commit a7ff2ab

File tree

6 files changed

+116
-114
lines changed

6 files changed

+116
-114
lines changed

Sources/SwiftDriver/IncrementalCompilation/IncrementalCompilationState.swift

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ extension IncrementalCompilationState {
442442
fileSystem: fileSystem,
443443
reporter: reporter)
444444

445-
let externallyChangedInputs = computeExternallyChangedInputs(
445+
let externallyChangedInputs = collectInputsInvalidatedByChangedExternals(
446446
buildTime: outOfDateBuildRecord.buildTime,
447447
fileSystem: fileSystem,
448448
moduleDependencyGraph: moduleDependencyGraph,
@@ -470,7 +470,7 @@ extension IncrementalCompilationState {
470470
// first wave, even though they may not require compilation.
471471
// Any such inputs missed, will be found by the rereading of swiftDeps
472472
// as each first wave job finished.
473-
let speculativeInputs = computeSpeculativeInputs(
473+
let speculativeInputs = collectInputsToBeSpeculativelyRecompiled(
474474
changedInputs: changedInputs,
475475
externalDependents: externallyChangedInputs,
476476
inputsMissingOutputs: Set(inputsMissingOutputs),
@@ -555,18 +555,18 @@ extension IncrementalCompilationState {
555555
}
556556

557557
/// Any files dependent on modified files from other modules must be compiled, too.
558-
private static func computeExternallyChangedInputs(
558+
private static func collectInputsInvalidatedByChangedExternals(
559559
buildTime: Date,
560560
fileSystem: FileSystem,
561561
moduleDependencyGraph: ModuleDependencyGraph,
562562
reporter: IncrementalCompilationState.Reporter?
563563
) -> [TypedVirtualPath] {
564564
var externalDependencySources = Set<DependencySource>()
565-
for extDepAndPrint in moduleDependencyGraph.fingerprintedExternalDependencies {
566-
let extDep = extDepAndPrint.externalDependency
565+
for fingerprintedExternalDependency in moduleDependencyGraph.fingerprintedExternalDependencies {
566+
let extDep = fingerprintedExternalDependency.externalDependency
567567
let extModTime = extDep.modTime(fileSystem) ?? Date.distantFuture
568568
if extModTime >= buildTime {
569-
for dependent in moduleDependencyGraph.untracedDependents(of: extDepAndPrint) {
569+
for dependent in moduleDependencyGraph.collectUntracedNodesDirectlyUsing(fingerprintedExternalDependency) {
570570
guard let dependencySource = dependent.dependencySource else {
571571
fatalError("Dependent \(dependent) does not have dependencies file!")
572572
}
@@ -586,7 +586,7 @@ extension IncrementalCompilationState {
586586
/// The needs[Non}CascadingBuild stuff was cargo-culted from the legacy driver.
587587
/// TODO: something better, e.g. return nothing here, but process changed dependencySource
588588
/// before the whole frontend job finished.
589-
private static func computeSpeculativeInputs(
589+
private static func collectInputsToBeSpeculativelyRecompiled(
590590
changedInputs: [ChangedInput],
591591
externalDependents: [TypedVirtualPath],
592592
inputsMissingOutputs: Set<TypedVirtualPath>,
@@ -605,7 +605,7 @@ extension IncrementalCompilationState {
605605
let cascadingFileSet = Set(cascadingChangedInputs).union(cascadingExternalDependents)
606606
for cascadingFile in cascadingFileSet {
607607
let dependentsOfOneFile = moduleDependencyGraph
608-
.findDependentSourceFiles(of: cascadingFile)
608+
.collectInputsTransitivelyInvalidatedBy(input: cascadingFile)
609609
for dep in dependentsOfOneFile where !cascadingFileSet.contains(dep) {
610610
if dependentFiles.insert(dep).0 {
611611
reporter?.report(
@@ -671,7 +671,7 @@ extension IncrementalCompilationState {
671671
/// If no more compiles are needed, return nil.
672672
/// Careful: job may not be primary.
673673

674-
public func getJobsDiscoveredToBeNeededAfterFinishing(
674+
public func collectJobsDiscoveredToBeNeededAfterFinishing(
675675
job finishedJob: Job, result: ProcessResult
676676
) throws -> [Job]? {
677677
return try confinementQueue.sync {
@@ -682,17 +682,17 @@ extension IncrementalCompilationState {
682682
}
683683

684684
// Find and deal with inputs that how need to be compiled
685-
let discoveredInputs = collectInputsDiscovered(from: finishedJob)
686-
assert(Set(discoveredInputs).isDisjoint(with: finishedJob.primaryInputs),
685+
let invalidatedInputs = collectInputsInvalidatedByRunning(finishedJob)
686+
assert(Set(invalidatedInputs).isDisjoint(with: finishedJob.primaryInputs),
687687
"Primaries should not overlap secondaries.")
688688

689689
if let reporter = self.reporter {
690-
for input in discoveredInputs {
690+
for input in invalidatedInputs {
691691
reporter.report(
692692
"Queuing because of dependencies discovered later:", input)
693693
}
694694
}
695-
let newJobs = try getJobsFor(discoveredCompilationInputs: discoveredInputs)
695+
let newJobs = try getJobs(for: invalidatedInputs)
696696
unfinishedJobs.formUnion(newJobs)
697697
if unfinishedJobs.isEmpty {
698698
// no more compilations are possible
@@ -703,15 +703,17 @@ extension IncrementalCompilationState {
703703
}
704704

705705
/// After `job` finished find out which inputs must compiled that were not known to need compilation before
706-
private func collectInputsDiscovered(from job: Job) -> [TypedVirtualPath] {
706+
private func collectInputsInvalidatedByRunning(_ job: Job) -> [TypedVirtualPath] {
707707
guard job.kind == .compile else {
708708
return []
709709
}
710710
return Array(
711711
Set(
712712
job.primaryInputs.flatMap {
713713
input -> [TypedVirtualPath] in
714-
if let found = moduleDependencyGraph.findSourcesToCompileAfterCompiling(input, on: self.driver.fileSystem) {
714+
if let found = moduleDependencyGraph.collectInputsInvalidated(
715+
byCompiling: input,
716+
on: self.driver.fileSystem) {
715717
return found
716718
}
717719
self.reporter?.report(
@@ -724,9 +726,9 @@ extension IncrementalCompilationState {
724726
.sorted {$0.file.name < $1.file.name}
725727
}
726728

727-
/// Find the jobs that now must be run that were not originally known to be needed.
728-
private func getJobsFor(
729-
discoveredCompilationInputs inputs: [TypedVirtualPath]
729+
/// Find the jobs that now must be run to compile the given inputs.
730+
private func getJobs(
731+
for inputs: [TypedVirtualPath]
730732
) throws -> [Job] {
731733
let unbatched = inputs.flatMap { input -> [Job] in
732734
if let group = skippedCompileGroups.removeValue(forKey: input) {

Sources/SwiftDriver/IncrementalCompilation/ModuleDependencyGraph.swift

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ extension ModuleDependencyGraph {
176176
else {
177177
return nil
178178
}
179-
return results.changedNodes.union(externallyCausedChanges)
179+
return results.allInvalidatedNodes.union(externallyCausedChanges)
180180
}
181181

182182
/// Returns changed nodes
@@ -194,7 +194,7 @@ extension ModuleDependencyGraph {
194194
externalDependency: edp,
195195
fileSystem: fileSystem)
196196
if let result = resultIfOK {
197-
changedNodes.formUnion(result.changedNodes)
197+
changedNodes.formUnion(result.allInvalidatedNodes)
198198
workList.formUnion(result.discoveredExternalDependencies)
199199
}
200200
else {
@@ -232,15 +232,15 @@ extension ModuleDependencyGraph {
232232
extension ModuleDependencyGraph {
233233
/// Find all the sources that depend on `sourceFile`. For some source files, these will be
234234
/// speculatively scheduled in the first wave.
235-
func findDependentSourceFiles(
236-
of sourceFile: TypedVirtualPath
235+
func collectInputsTransitivelyInvalidatedBy(
236+
input sourceFile: TypedVirtualPath
237237
) -> [TypedVirtualPath] {
238238
var allDependencySourcesToRecompile = Set<DependencySource>()
239239

240240
let dependencySource = inputDependencySourceMap[sourceFile]
241241

242242
for dependencySourceToRecompile in
243-
findSwiftDepsToRecompileWhenDependencySourceChanges( dependencySource ) {
243+
collectSwiftDepsTransitivelyUsing( dependencySource ) {
244244
if dependencySourceToRecompile != dependencySource {
245245
allDependencySourcesToRecompile.insert(dependencySourceToRecompile)
246246
}
@@ -255,73 +255,73 @@ extension ModuleDependencyGraph {
255255

256256
/// Find all the swiftDeps files that depend on `dependencySource`.
257257
/// Really private, except for testing.
258-
/*@_spi(Testing)*/ public func findSwiftDepsToRecompileWhenDependencySourceChanges(
258+
/*@_spi(Testing)*/ public func collectSwiftDepsTransitivelyUsing(
259259
_ dependencySource: DependencySource ) -> Set<DependencySource> {
260260
let nodes = nodeFinder.findNodes(for: dependencySource) ?? [:]
261261
/// Tests expect this to be reflexive
262-
return findSwiftDepsToRecompileWhenNodesChange(nodes.values)
262+
return collectSwiftDepsUsingTransitivelyInvalidated(nodes: nodes.values)
263263
}
264264
}
265265
// MARK: - Scheduling the 2nd wave
266266
extension ModuleDependencyGraph {
267267
/// After `source` has been compiled, figure out what other source files need compiling.
268268
/// Used to schedule the 2nd wave.
269269
/// Return nil in case of an error.
270-
func findSourcesToCompileAfterCompiling(
271-
_ source: TypedVirtualPath,
270+
func collectInputsInvalidated(
271+
byCompiling input: TypedVirtualPath,
272272
on fileSystem: FileSystem
273273
) -> [TypedVirtualPath]? {
274-
findSourcesToCompileAfterIntegrating(
275-
input: source,
276-
dependencySource: inputDependencySourceMap[source],
274+
collectInputsRequiringCompilation(
275+
byCompiling: input,
276+
dependencySource: inputDependencySourceMap[input],
277277
on: fileSystem)
278278
}
279279

280280
/// After a compile job has finished, read its swiftDeps file and return the source files needing
281281
/// recompilation.
282282
/// Return nil in case of an error.
283283
/// May return a source that has already been compiled.
284-
private func findSourcesToCompileAfterIntegrating(
285-
input: TypedVirtualPath,
284+
private func collectInputsRequiringCompilation(
285+
byCompiling: TypedVirtualPath,
286286
dependencySource: DependencySource,
287287
on fileSystem: FileSystem
288288
) -> [TypedVirtualPath]? {
289-
let swiftDeps = inputDependencySourceMap[input].typedFile
289+
let swiftDeps = inputDependencySourceMap[byCompiling].typedFile
290290
let changedNodesIfOK = integrate(swiftDeps: swiftDeps)
291291
guard let changedNodes = changedNodesIfOK else {
292292
return nil
293293
}
294-
return findSwiftDepsToRecompileWhenNodesChange(changedNodes)
294+
return collectSwiftDepsUsingTransitivelyInvalidated(nodes: changedNodes)
295295
.map { inputDependencySourceMap[$0] }
296296
}
297297
}
298298

299299
// MARK: - Scheduling either wave
300300
extension ModuleDependencyGraph {
301301
/// Find all the swiftDeps affected when the nodes change.
302-
/*@_spi(Testing)*/ public func findSwiftDepsToRecompileWhenNodesChange<Nodes: Sequence>(
303-
_ nodes: Nodes
302+
/*@_spi(Testing)*/ public func collectSwiftDepsUsingTransitivelyInvalidated<Nodes: Sequence>(
303+
nodes: Nodes
304304
) -> Set<DependencySource>
305305
where Nodes.Element == Node
306306
{
307-
let affectedNodes = Tracer.findPreviouslyUntracedUsesOf(
308-
defs: nodes,
307+
let affectedNodes = Tracer.collectPreviouslyUntracedNodesUsing(
308+
defNodes: nodes,
309309
in: self,
310310
diagnosticEngine: diagnosticEngine)
311311
.tracedUses
312312
return Set(affectedNodes.compactMap {$0.dependencySource})
313313
}
314314

315-
/*@_spi(Testing)*/ public func untracedDependents(
316-
of extDepAndPrint: FingerprintedExternalDependency
315+
/*@_spi(Testing)*/ public func collectUntracedNodesDirectlyUsing(
316+
_ fingerprintedExternalDependency: FingerprintedExternalDependency
317317
) -> [ModuleDependencyGraph.Node] {
318318
// These nodes will depend on the *interface* of the external Decl.
319-
let key = DependencyKey(interfaceFor: extDepAndPrint.externalDependency)
319+
let key = DependencyKey(interfaceFor: fingerprintedExternalDependency.externalDependency)
320320
// DependencySource is OK as a nil placeholder because it's only used to find
321321
// the corresponding implementation node and there won't be any for an
322322
// external dependency node.
323323
let node = Node(key: key,
324-
fingerprint: extDepAndPrint.fingerprint,
324+
fingerprint: fingerprintedExternalDependency.fingerprint,
325325
dependencySource: nil)
326326
return nodeFinder
327327
.orderedUses(of: node)

Sources/SwiftDriver/IncrementalCompilation/ModuleDependencyGraphParts/Integrator.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ extension ModuleDependencyGraph {
2424

2525
/*@_spi(Testing)*/
2626
public struct Results {
27-
var changedNodes = Set<Node>()
27+
var allInvalidatedNodes = Set<Node>()
2828
var discoveredExternalDependencies = Set<FingerprintedExternalDependency>()
2929
}
3030
public private(set) var results = Results()
@@ -80,14 +80,14 @@ extension ModuleDependencyGraph.Integrator {
8080
private mutating func integrate() {
8181
integrateEachSourceNode()
8282
handleDisappearedNodes()
83-
destination.ensureGraphWillRetraceDependents(of: results.changedNodes)
83+
destination.ensureGraphWillRetraceDependents(of: results.allInvalidatedNodes)
8484
}
8585
private mutating func integrateEachSourceNode() {
8686
sourceGraph.forEachNode { integrate(oneNode: $0) }
8787
}
8888
private mutating func handleDisappearedNodes() {
8989
for (_, node) in disappearedNodes {
90-
results.changedNodes.insert(node)
90+
results.allInvalidatedNodes.insert(node)
9191
destination.nodeFinder.remove(node)
9292
}
9393
}
@@ -125,7 +125,7 @@ extension ModuleDependencyGraph.Integrator {
125125
// Node was and still is. Do not remove it.
126126
disappearedNodes.removeValue(forKey: matchHere.key)
127127
if matchHere.fingerprint != integrand.fingerprint {
128-
results.changedNodes.insert(matchHere)
128+
results.allInvalidatedNodes.insert(matchHere)
129129
}
130130
return matchHere
131131
}
@@ -145,7 +145,7 @@ extension ModuleDependencyGraph.Integrator {
145145
.replace(expat,
146146
newDependencySource: sourceGraph.dependencySource,
147147
newFingerprint: integrand.fingerprint)
148-
results.changedNodes.insert(integratedNode)
148+
results.allInvalidatedNodes.insert(integratedNode)
149149
return integratedNode
150150
}
151151

@@ -160,7 +160,7 @@ extension ModuleDependencyGraph.Integrator {
160160
dependencySource: sourceGraph.dependencySource)
161161
let oldNode = destination.nodeFinder.insert(newNode)
162162
assert(oldNode == nil, "Should be new!")
163-
results.changedNodes.insert(newNode)
163+
results.allInvalidatedNodes.insert(newNode)
164164
return newNode
165165
}
166166

@@ -181,13 +181,13 @@ extension ModuleDependencyGraph.Integrator {
181181
return
182182
}
183183
// Check both in case we reread a prior ModDepGraph from a different mode
184-
let extDepAndPrint = FingerprintedExternalDependency(externalDependency,
184+
let fingerprintedExternalDependency = FingerprintedExternalDependency(externalDependency,
185185
def.fingerprint)
186-
let isKnown = destination.fingerprintedExternalDependencies.contains(extDepAndPrint)
186+
let isKnown = destination.fingerprintedExternalDependencies.contains(fingerprintedExternalDependency)
187187
guard !isKnown else {return}
188188

189-
results.discoveredExternalDependencies.insert(extDepAndPrint)
190-
results.changedNodes.insert(moduleUseNode)
189+
results.discoveredExternalDependencies.insert(fingerprintedExternalDependency)
190+
results.allInvalidatedNodes.insert(moduleUseNode)
191191
}
192192
}
193193
}

Sources/SwiftDriver/IncrementalCompilation/ModuleDependencyGraphParts/Tracer.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,21 @@ extension ModuleDependencyGraph.Tracer {
3737

3838
/// Find all uses of `defs` that have not already been traced.
3939
/// (If already traced, jobs have already been scheduled.)
40-
static func findPreviouslyUntracedUsesOf<Nodes: Sequence> (
41-
defs: Nodes,
40+
static func collectPreviouslyUntracedNodesUsing<Nodes: Sequence> (
41+
defNodes: Nodes,
4242
in graph: ModuleDependencyGraph,
4343
diagnosticEngine: DiagnosticsEngine
4444
) -> Self
4545
where Nodes.Element == ModuleDependencyGraph.Node
4646
{
47-
var tracer = Self(findingUsesOf: defs,
47+
var tracer = Self(collectingUsesOf: defNodes,
4848
in: graph,
4949
diagnosticEngine: diagnosticEngine)
50-
tracer.findPreviouslyUntracedDependents()
50+
tracer.collectPreviouslyUntracedDependents()
5151
return tracer
5252
}
5353

54-
private init<Nodes: Sequence>(findingUsesOf defs: Nodes,
54+
private init<Nodes: Sequence>(collectingUsesOf defs: Nodes,
5555
in graph: ModuleDependencyGraph,
5656
diagnosticEngine: DiagnosticsEngine)
5757
where Nodes.Element == ModuleDependencyGraph.Node
@@ -63,13 +63,13 @@ extension ModuleDependencyGraph.Tracer {
6363
self.diagnosticEngine = diagnosticEngine
6464
}
6565

66-
private mutating func findPreviouslyUntracedDependents() {
66+
private mutating func collectPreviouslyUntracedDependents() {
6767
for n in startingPoints {
68-
findNextPreviouslyUntracedDependent(of: n)
68+
collectNextPreviouslyUntracedDependent(of: n)
6969
}
7070
}
7171

72-
private mutating func findNextPreviouslyUntracedDependent(
72+
private mutating func collectNextPreviouslyUntracedDependent(
7373
of definition: ModuleDependencyGraph.Node
7474
) {
7575
guard graph.isUntraced(definition) else { return }
@@ -85,7 +85,7 @@ extension ModuleDependencyGraph.Tracer {
8585

8686
// If this use also provides something, follow it
8787
for use in graph.nodeFinder.orderedUses(of: definition) {
88-
findNextPreviouslyUntracedDependent(of: use)
88+
collectNextPreviouslyUntracedDependent(of: use)
8989
}
9090
traceDeparture(pathLengthAfterArrival);
9191
}

Sources/SwiftDriverExecution/MultiJobExecutor.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ public final class MultiJobExecutor {
218218
return
219219
}
220220
if let newJobs = try incrementalCompilationState?
221-
.getJobsDiscoveredToBeNeededAfterFinishing(job: job, result: result) {
221+
.collectJobsDiscoveredToBeNeededAfterFinishing(job: job, result: result) {
222222
let newJobIndices = Self.addJobs(newJobs, to: &jobs, producing: &producerMap)
223223
needInputFor(indices: newJobIndices)
224224
}

0 commit comments

Comments
 (0)