Skip to content

Commit 92b5aab

Browse files
adopt Swift Collection's OrderedSet and OrderedDictionary
They're better optimised and tested.
1 parent fc5b8a5 commit 92b5aab

File tree

8 files changed

+34
-352
lines changed

8 files changed

+34
-352
lines changed

Package.swift

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313

1414
import PackageDescription
15+
import class Foundation.ProcessInfo
1516

1617
let package = Package(
1718
name: "swift-tools-support-core",
@@ -28,7 +29,6 @@ let package = Package(
2829
name: "TSCTestSupport",
2930
targets: ["TSCTestSupport"]),
3031
],
31-
dependencies: [],
3232
targets: [
3333

3434
// MARK: Tools support core targets
@@ -44,11 +44,21 @@ let package = Package(
4444
.target(
4545
/** TSCBasic support library */
4646
name: "TSCBasic",
47-
dependencies: ["TSCLibc", "TSCclibc"]),
47+
dependencies: [
48+
"TSCLibc",
49+
"TSCclibc",
50+
.product(name: "OrderedCollections", package: "swift-collections"),
51+
]
52+
),
4853
.target(
4954
/** Abstractions for common operations, should migrate to TSCBasic */
5055
name: "TSCUtility",
51-
dependencies: ["TSCBasic", "TSCclibc"]),
56+
dependencies: [
57+
"TSCBasic",
58+
"TSCclibc",
59+
.product(name: "OrderedCollections", package: "swift-collections"),
60+
]
61+
),
5262

5363
// MARK: Additional Test Dependencies
5464

@@ -75,6 +85,19 @@ let package = Package(
7585
]
7686
)
7787

88+
/// When not using local dependencies, the branch to use for llbuild and TSC repositories.
89+
let relatedDependenciesBranch = "main"
90+
91+
if ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] == nil {
92+
package.dependencies += [
93+
.package(url: "https://github.com/apple/swift-collections.git", .branch("main")),
94+
]
95+
} else {
96+
package.dependencies += [
97+
.package(path: "../swift-collections"),
98+
]
99+
}
100+
78101
// FIXME: conditionalise these flags since SwiftPM 5.3 and earlier will crash
79102
// for platforms they don't know about.
80103
#if os(Windows)

Sources/TSCBasic/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ add_library(TSCBasic
3232
Lock.swift
3333
OSLog.swift
3434
ObjectIdentifierProtocol.swift
35-
OrderedDictionary.swift
36-
OrderedSet.swift
3735
WritableByteStream.swift
3836
Path.swift
3937
PathShims.swift

Sources/TSCBasic/GraphAlgorithms.swift

Lines changed: 5 additions & 3 deletions
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

Lines changed: 0 additions & 125 deletions
This file was deleted.

Sources/TSCBasic/OrderedSet.swift

Lines changed: 0 additions & 130 deletions
This file was deleted.

Sources/TSCUtility/PkgConfig.swift

Lines changed: 3 additions & 2 deletions
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
public enum PkgConfigError: Swift.Error, CustomStringConvertible {
1516
case couldNotFindConfigFile(name: String)

0 commit comments

Comments
 (0)