Skip to content

Commit f2de87c

Browse files
adopt Swift Collection's OrderedSet and OrderedDictionary
They're better optimised and tested.
1 parent 6017b48 commit f2de87c

File tree

7 files changed

+29
-361
lines changed

7 files changed

+29
-361
lines changed

Package.swift

+21-14
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ let package = Package(
4444
name: "TSCTestSupport",
4545
targets: ["TSCTestSupport"]),
4646
],
47-
dependencies: [],
4847
targets: [
4948

5049
// MARK: Tools support core targets
@@ -63,17 +62,23 @@ let package = Package(
6362
/** TSCBasic support library */
6463
name: "TSCBasic",
6564
dependencies: [
66-
"TSCLibc",
67-
"TSCclibc",
68-
.product(name: "SystemPackage", package: "swift-system"),
65+
"TSCLibc",
66+
"TSCclibc",
67+
.product(name: "OrderedCollections", package: "swift-collections"),
68+
.product(name: "SystemPackage", package: "swift-system"),
6969
],
7070
exclude: CMakeFiles + ["README.md"]),
7171
.target(
7272
/** Abstractions for common operations, should migrate to TSCBasic */
7373
name: "TSCUtility",
74-
dependencies: ["TSCBasic", "TSCclibc"],
74+
dependencies: [
75+
"TSCBasic",
76+
"TSCclibc",
77+
.product(name: "OrderedCollections", package: "swift-collections"),
78+
],
7579
exclude: CMakeFiles),
7680

81+
7782
// MARK: Additional Test Dependencies
7883

7984
.target(
@@ -102,17 +107,19 @@ let package = Package(
102107
)
103108

104109
/// When not using local dependencies, the branch to use for llbuild and TSC repositories.
105-
let relatedDependenciesBranch = "main"
110+
let relatedDependenciesBranch = "main"
106111

107-
if ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] == nil {
108-
package.dependencies += [
109-
.package(url: "https://github.com/apple/swift-system.git", .upToNextMinor(from: "1.1.1")),
110-
]
111-
} else {
112+
if ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] == nil {
112113
package.dependencies += [
113-
.package(path: "../swift-system"),
114-
]
115-
}
114+
.package(url: "https://github.com/apple/swift-collections.git", .branch("main")),
115+
.package(url: "https://github.com/apple/swift-system.git", .upToNextMinor(from: "1.1.1")),
116+
]
117+
} else {
118+
package.dependencies += [
119+
.package(path: "../swift-collections"),
120+
.package(path: "../swift-system"),
121+
]
122+
}
116123

117124
// FIXME: conditionalise these flags since SwiftPM 5.3 and earlier will crash
118125
// for platforms they don't know about.

Sources/TSCBasic/GraphAlgorithms.swift

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
/*
22
This source file is part of the Swift.org open source project
33

4-
Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
4+
Copyright (c) 2014 - 2021 Apple Inc. and the Swift project authors
55
Licensed under Apache License v2.0 with Runtime Library Exception
66

77
See http://swift.org/LICENSE.txt for license information
88
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
99
*/
1010

11+
import OrderedCollections
12+
1113
public enum GraphError: Error {
1214
/// A cycle was detected in the input.
1315
case unexpectedCycle
@@ -69,7 +71,7 @@ public func topologicalSort<T: Hashable>(
6971

7072
// Otherwise, visit each adjacent node.
7173
for succ in try successors(node) {
72-
guard stack.append(succ) else {
74+
guard stack.append(succ).inserted else {
7375
// If the successor is already in this current stack, we have found a cycle.
7476
//
7577
// FIXME: We could easily include information on the cycle we found here.
@@ -120,7 +122,7 @@ public func findCycle<T: Hashable>(
120122
// FIXME: Convert to stack.
121123
func visit(_ node: T, _ successors: (T) throws -> [T]) rethrows -> (path: [T], cycle: [T])? {
122124
// If this node is already in the current path then we have found a cycle.
123-
if !path.append(node) {
125+
if !path.append(node).inserted {
124126
let index = path.firstIndex(of: node)!
125127
return (Array(path[path.startIndex..<index]), Array(path[index..<path.endIndex]))
126128
}

Sources/TSCBasic/OrderedDictionary.swift

-125
This file was deleted.

Sources/TSCBasic/OrderedSet.swift

-130
This file was deleted.

Sources/TSCUtility/PkgConfig.swift

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
/*
22
This source file is part of the Swift.org open source project
33

4-
Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
4+
Copyright (c) 2014 - 2021 Apple Inc. and the Swift project authors
55
Licensed under Apache License v2.0 with Runtime Library Exception
66

77
See http://swift.org/LICENSE.txt for license information
88
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
99
*/
1010

11-
import TSCBasic
1211
import Foundation
12+
import OrderedCollections
13+
import TSCBasic
1314

1415
// deprecated 12/21, moved to SwiftPM
1516
@available(*, deprecated, message: "moved into SwiftPM")

0 commit comments

Comments
 (0)