Skip to content

Commit a48848b

Browse files
replace TSC's OrderedSet and OrderedDictionary with Swift Collection's
Swift Collection's are better optimised and tested.
1 parent 62fef21 commit a48848b

File tree

6 files changed

+47
-16
lines changed

6 files changed

+47
-16
lines changed

Package.swift

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,14 +157,29 @@ let package = Package(
157157
.target(
158158
/** Package model conventions and loading support */
159159
name: "PackageLoading",
160-
dependencies: ["SwiftToolsSupport-auto", "Basics", "PackageModel", "SourceControl"]),
160+
dependencies: [
161+
"SwiftToolsSupport-auto",
162+
"Basics",
163+
"OrderedCollections",
164+
"PackageModel",
165+
"SourceControl",
166+
]
167+
),
161168

162169
// MARK: Package Dependency Resolution
163170

164171
.target(
165172
/** Data structures and support for complete package graphs */
166173
name: "PackageGraph",
167-
dependencies: ["SwiftToolsSupport-auto", "Basics", "PackageLoading", "PackageModel", "SourceControl"]),
174+
dependencies: [
175+
"SwiftToolsSupport-auto",
176+
"Basics",
177+
"OrderedCollections",
178+
"PackageLoading",
179+
"PackageModel",
180+
"SourceControl",
181+
]
182+
),
168183

169184
// MARK: Package Collections
170185

@@ -199,7 +214,17 @@ let package = Package(
199214
.target(
200215
/** Builds Modules and Products */
201216
name: "Build",
202-
dependencies: ["SwiftToolsSupport-auto", "Basics", "SPMBuildCore", "PackageGraph", "LLBuildManifest", "SwiftDriver", "SPMLLBuild"]),
217+
dependencies: [
218+
"SwiftToolsSupport-auto",
219+
"Basics",
220+
"OrderedCollections",
221+
"SPMBuildCore",
222+
"PackageGraph",
223+
"LLBuildManifest",
224+
"SwiftDriver",
225+
"SPMLLBuild",
226+
]
227+
),
203228
.target(
204229
/** Support for building using Xcode's build system */
205230
name: "XCBuildSupport",
@@ -359,15 +384,17 @@ if ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] == nil {
359384
// The 'swift-argument-parser' version declared here must match that
360385
// used by 'swift-driver' and 'sourcekit-lsp'. Please coordinate
361386
// dependency version changes here with those projects.
362-
.package(url: "https://github.com/apple/swift-argument-parser.git", .upToNextMinor(from: "0.4.3")),
387+
.package(url: "https://github.com/apple/swift-argument-parser.git", .upToNextMinor(from: Version(0, 4, 3))),
388+
.package(url: "https://github.com/apple/swift-collections.git", .exact(Version(0, 0, 3))),
389+
.package(url: "https://github.com/apple/swift-crypto.git", .upToNextMinor(from: Version(1, 1, 4))),
363390
.package(url: "https://github.com/apple/swift-driver.git", .branch(relatedDependenciesBranch)),
364-
.package(url: "https://github.com/apple/swift-crypto.git", .upToNextMinor(from: "1.1.4")),
365391
]
366392
} else {
367393
package.dependencies += [
368394
.package(path: "../swift-tools-support-core"),
369395
.package(path: "../swift-argument-parser"),
370-
.package(path: "../swift-driver"),
396+
.package(path: "../swift-collections"),
371397
.package(path: "../swift-crypto"),
398+
.package(path: "../swift-driver"),
372399
]
373400
}

Sources/Build/BuildPlan.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@
99
*/
1010

1111
import Basics
12-
import TSCBasic
13-
import TSCUtility
12+
import Foundation
13+
import OrderedCollections
1414
import PackageModel
1515
import PackageGraph
1616
import PackageLoading
17-
import Foundation
1817
import SPMBuildCore
1918
@_implementationOnly import SwiftDriver
19+
import TSCBasic
20+
import TSCUtility
2021

2122
extension String {
2223
fileprivate var asSwiftStringLiteralConstant: String {

Sources/PackageGraph/PackageGraph+Loading.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*/
1010

1111
import Basics
12+
import OrderedCollections
1213
import PackageLoading
1314
import PackageModel
1415
import SourceControl
@@ -612,7 +613,7 @@ fileprivate func findCycle(
612613
_ successors: (GraphLoadingNode) throws -> [GraphLoadingNode]
613614
) rethrows -> (path: [Manifest], cycle: [Manifest])? {
614615
// If this node is already in the current path then we have found a cycle.
615-
if !path.append(node.manifest) {
616+
if !path.append(node.manifest).inserted {
616617
let index = path.firstIndex(of: node.manifest)! // forced unwrap safe
617618
return (Array(path[path.startIndex..<index]), Array(path[index..<path.endIndex]))
618619
}

Sources/PackageGraph/Pubgrub/Incompatibility.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
/*
22
This source file is part of the Swift.org open source project
33

4-
Copyright (c) 2019 Apple Inc. and the Swift project authors
4+
Copyright (c) 2019 - 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

1111
import Basics
12-
import TSCBasic
12+
import OrderedCollections
1313
import PackageModel
14+
import TSCBasic
1415

1516
/// A set of terms that are incompatible with each other and can therefore not
1617
/// all be true at the same time. In dependency resolution, these are derived
@@ -43,7 +44,7 @@ public struct Incompatibility: Equatable, Hashable {
4344
terms = OrderedSet(terms.filter { !$0.isPositive || $0.node != root })
4445
}
4546

46-
let normalizedTerms = try normalize(terms: terms.contents)
47+
let normalizedTerms = try normalize(terms: terms.elements)
4748
assert(normalizedTerms.count > 0,
4849
"An incompatibility must contain at least one term after normalization.")
4950
self.init(terms: OrderedSet(normalizedTerms), cause: cause)

Sources/PackageGraph/Pubgrub/PubgrubDependencyResolver.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
This source file is part of the Swift.org open source project
33

4-
Copyright (c) 2019 Apple Inc. and the Swift project authors
4+
Copyright (c) 2019 - 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
@@ -10,6 +10,7 @@
1010

1111
import Basics
1212
import Dispatch
13+
import OrderedCollections
1314
import PackageModel
1415
import TSCBasic
1516
import TSCUtility

Sources/PackageLoading/PackageBuilder.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import Basics
1212
import Dispatch
13+
import OrderedCollections
1314
import PackageModel
1415
import TSCBasic
1516
import TSCUtility
@@ -1192,8 +1193,7 @@ public final class PackageBuilder {
11921193

11931194
/// Helper method to append to products array.
11941195
func append(_ product: Product) {
1195-
let inserted = products.append(KeyedPair(product, key: product.name))
1196-
if !inserted {
1196+
if !products.append(KeyedPair(product, key: product.name)).inserted {
11971197
diagnostics.emit(
11981198
.duplicateProduct(product: product),
11991199
location: self.diagnosticLocation

0 commit comments

Comments
 (0)