Skip to content

Commit 5bc35e0

Browse files
committed
Clean up topologicalSort in PackageGraph
1 parent 52e6839 commit 5bc35e0

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

Sources/PackageGraph/ModulesGraph.swift

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import OrderedCollections
1414
import PackageLoading
1515
import PackageModel
16-
import TSCBasic
1716

1817
import protocol Basics.FileSystem
1918
import class Basics.ObservabilityScope
@@ -270,7 +269,7 @@ public struct ModulesGraph {
270269

271270
for module in rootModules where module.type == .executable {
272271
// Find all dependencies of this module within its package. Note that we do not traverse plugin usages.
273-
let dependencies = try topologicalSortIdentifiable(module.dependencies, successors: {
272+
let dependencies = try topologicalSort(module.dependencies, successors: {
274273
$0.dependencies.compactMap{ $0.module }.filter{ $0.type != .plugin }.map{ .module($0, conditions: []) }
275274
}).compactMap({ $0.module })
276275

@@ -403,7 +402,7 @@ enum GraphError: Error {
403402
///
404403
/// - Complexity: O(v + e) where (v, e) are the number of vertices and edges
405404
/// reachable from the input nodes via the relation.
406-
func topologicalSortIdentifiable<T: Identifiable>(
405+
fileprivate func topologicalSort<T: Identifiable>(
407406
_ nodes: [T], successors: (T) throws -> [T]
408407
) throws -> [T] {
409408
// Implements a topological sort via recursion and reverse postorder DFS.
@@ -497,3 +496,12 @@ public func loadModulesGraph(
497496
modulesFilter: nil
498497
)
499498
}
499+
500+
fileprivate extension Array {
501+
/// Create a dictionary with given sequence of elements.
502+
func spm_createDictionary<Key: Hashable, Value>(
503+
_ uniqueKeysWithValues: (Element) -> (Key, Value)
504+
) -> [Key: Value] {
505+
return Dictionary(uniqueKeysWithValues: self.map(uniqueKeysWithValues))
506+
}
507+
}

0 commit comments

Comments
 (0)