Skip to content

Commit 7812fb1

Browse files
author
David Ungar
committed
use reduce(into:) {}
1 parent 17bd7cf commit 7812fb1

File tree

2 files changed

+19
-18
lines changed

2 files changed

+19
-18
lines changed

Sources/SwiftDriver/IncrementalCompilation/IncrementalCompilationState.swift

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -252,11 +252,9 @@ extension IncrementalCompilationState {
252252
guard job.kind == .compile else {
253253
return Set<TypedVirtualPath>()
254254
}
255-
return Set(
256-
job.primaryInputs.flatMap { input in
257-
collectInputsInvalidated(byCompiling: input)
258-
}
259-
)
255+
return job.primaryInputs.reduce(into: Set()) { invalidatedInputs, primaryInput in
256+
invalidatedInputs.formUnion(collectInputsInvalidated(byCompiling: primaryInput))
257+
}
260258
.subtracting(job.primaryInputs) // have already compiled these
261259
}
262260

Sources/SwiftDriver/IncrementalCompilation/ModuleDependencyGraph.swift

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,14 @@ extension ModuleDependencyGraph {
8383
// MARK: - Getting a graph read from priors ready to use
8484
extension ModuleDependencyGraph {
8585
func collectNodesInvalidatedByChangedOrAddedExternals() -> Set<Node> {
86-
let invalidatedNodes = fingerprintedExternalDependencies.lazy.flatMap {
87-
self.collectNodesInvalidatedByProcessing(fingerprintedExternalDependency: $0,
88-
includeAddedExternals: true)
86+
fingerprintedExternalDependencies.reduce(into: Set()) { invalidatedNodes, fed in
87+
invalidatedNodes.formUnion (
88+
self.collectNodesInvalidatedByProcessing(fingerprintedExternalDependency: fed,
89+
includeAddedExternals: true))
8990
}
90-
return Set(invalidatedNodes)
9191
}
9292
}
93+
9394
// MARK: - Scheduling the first wave
9495
extension ModuleDependencyGraph {
9596
/// Find all the sources that depend on `sourceFile`. For some source files, these will be
@@ -179,11 +180,13 @@ extension ModuleDependencyGraph {
179180
in: self,
180181
diagnosticEngine: info.diagnosticEngine)
181182
.tracedUses
182-
let invalidatedSources = Set(
183-
affectedNodes.compactMap {
184-
$0.dependencySource.flatMap {$0.typedFile.type == .swiftDeps ? $0 : nil}
185-
})
186-
return invalidatedSources
183+
return affectedNodes.reduce(into: Set()) {
184+
invalidatedSources, affectedNode in
185+
if let source = affectedNode.dependencySource,
186+
source.typedFile.type == .swiftDeps {
187+
invalidatedSources.insert(source)
188+
}
189+
}
187190
}
188191

189192
/// Given an external dependency & its fingerprint, find any nodes directly using that dependency.
@@ -248,10 +251,10 @@ extension ModuleDependencyGraph {
248251
func collectInputsUsingTransitivelyInvalidated(
249252
nodes invalidatedNodes: Set<Node>
250253
) -> Set<TypedVirtualPath> {
251-
let invalidatedInputs =
252-
collectSwiftDepsUsingTransitivelyInvalidated(nodes: invalidatedNodes).lazy
253-
.map(getInput(for:))
254-
return Set(invalidatedInputs)
254+
collectSwiftDepsUsingTransitivelyInvalidated(nodes: invalidatedNodes)
255+
.reduce(into: Set()) { invalidatedInputs, invalidatedSwiftDeps in
256+
invalidatedInputs.insert(getInput(for: invalidatedSwiftDeps))
257+
}
255258
}
256259
}
257260

0 commit comments

Comments
 (0)