From 7812fb136c29757988c17880d9572b28e89722eb Mon Sep 17 00:00:00 2001 From: David Ungar Date: Mon, 15 Feb 2021 17:33:57 -0800 Subject: [PATCH] use reduce(into:) {} --- .../IncrementalCompilationState.swift | 8 ++--- .../ModuleDependencyGraph.swift | 29 ++++++++++--------- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/Sources/SwiftDriver/IncrementalCompilation/IncrementalCompilationState.swift b/Sources/SwiftDriver/IncrementalCompilation/IncrementalCompilationState.swift index debdc3d7a..c1aafef79 100644 --- a/Sources/SwiftDriver/IncrementalCompilation/IncrementalCompilationState.swift +++ b/Sources/SwiftDriver/IncrementalCompilation/IncrementalCompilationState.swift @@ -252,11 +252,9 @@ extension IncrementalCompilationState { guard job.kind == .compile else { return Set() } - return Set( - job.primaryInputs.flatMap { input in - collectInputsInvalidated(byCompiling: input) - } - ) + return job.primaryInputs.reduce(into: Set()) { invalidatedInputs, primaryInput in + invalidatedInputs.formUnion(collectInputsInvalidated(byCompiling: primaryInput)) + } .subtracting(job.primaryInputs) // have already compiled these } diff --git a/Sources/SwiftDriver/IncrementalCompilation/ModuleDependencyGraph.swift b/Sources/SwiftDriver/IncrementalCompilation/ModuleDependencyGraph.swift index 7891ef1bf..def258278 100644 --- a/Sources/SwiftDriver/IncrementalCompilation/ModuleDependencyGraph.swift +++ b/Sources/SwiftDriver/IncrementalCompilation/ModuleDependencyGraph.swift @@ -83,13 +83,14 @@ extension ModuleDependencyGraph { // MARK: - Getting a graph read from priors ready to use extension ModuleDependencyGraph { func collectNodesInvalidatedByChangedOrAddedExternals() -> Set { - let invalidatedNodes = fingerprintedExternalDependencies.lazy.flatMap { - self.collectNodesInvalidatedByProcessing(fingerprintedExternalDependency: $0, - includeAddedExternals: true) + fingerprintedExternalDependencies.reduce(into: Set()) { invalidatedNodes, fed in + invalidatedNodes.formUnion ( + self.collectNodesInvalidatedByProcessing(fingerprintedExternalDependency: fed, + includeAddedExternals: true)) } - return Set(invalidatedNodes) } } + // MARK: - Scheduling the first wave extension ModuleDependencyGraph { /// Find all the sources that depend on `sourceFile`. For some source files, these will be @@ -179,11 +180,13 @@ extension ModuleDependencyGraph { in: self, diagnosticEngine: info.diagnosticEngine) .tracedUses - let invalidatedSources = Set( - affectedNodes.compactMap { - $0.dependencySource.flatMap {$0.typedFile.type == .swiftDeps ? $0 : nil} - }) - return invalidatedSources + return affectedNodes.reduce(into: Set()) { + invalidatedSources, affectedNode in + if let source = affectedNode.dependencySource, + source.typedFile.type == .swiftDeps { + invalidatedSources.insert(source) + } + } } /// Given an external dependency & its fingerprint, find any nodes directly using that dependency. @@ -248,10 +251,10 @@ extension ModuleDependencyGraph { func collectInputsUsingTransitivelyInvalidated( nodes invalidatedNodes: Set ) -> Set { - let invalidatedInputs = - collectSwiftDepsUsingTransitivelyInvalidated(nodes: invalidatedNodes).lazy - .map(getInput(for:)) - return Set(invalidatedInputs) + collectSwiftDepsUsingTransitivelyInvalidated(nodes: invalidatedNodes) + .reduce(into: Set()) { invalidatedInputs, invalidatedSwiftDeps in + invalidatedInputs.insert(getInput(for: invalidatedSwiftDeps)) + } } }