Skip to content

Commit 1f1b1e6

Browse files
committed
adopt swift-collections
motivation: replace TSC versions of ordered collections with the new ones from swift-collections changes: pull in swift-collections as a dependency update bootstrap script adapt call-sites to swift-collections
1 parent 79dbcff commit 1f1b1e6

File tree

15 files changed

+74
-46
lines changed

15 files changed

+74
-46
lines changed

CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ string(COMPARE EQUAL ${CMAKE_SYSTEM_NAME} Windows CMAKE_INSTALL_DEFAULT)
3737
option(USE_CMAKE_INSTALL
3838
"Install build products using cmake's install() instead of the bootstrap script's install()"
3939
${CMAKE_INSTALL_DEFAULT})
40-
40+
4141
if(BUILD_SHARED_LIBS)
4242
set(CMAKE_POSITION_INDEPENDENT_CODE YES)
4343
endif()
@@ -53,6 +53,7 @@ if(FIND_PM_DEPS)
5353
find_package(ArgumentParser CONFIG REQUIRED)
5454
find_package(SwiftCrypto CONFIG REQUIRED)
5555
find_package(SwiftDriver CONFIG REQUIRED)
56+
find_package(SwiftCollections CONFIG REQUIRED)
5657
endif()
5758

5859
find_package(dispatch QUIET)

CONTRIBUTING.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ Please refer to the [_Get Started_ guide](https://github.com/apple/swift/blob/ma
132132
Clone the following repositories beside the SwiftPM directory:
133133

134134
1. [swift-argument-parser] and check out tag with the [latest version](https://github.com/apple/swift-argument-parser/tags).
135-
135+
136136
For example, if the latest tag is 0.4.3:
137137
```sh
138138
$> git clone https://github.com/apple/swift-argument-parser --branch 0.4.3
@@ -150,7 +150,7 @@ Clone the following repositories beside the SwiftPM directory:
150150
```
151151

152152
4. [Yams] and checkout tag with the [latest version](https://github.com/jpsim/Yams.git/tags) before 5.0.0.
153-
153+
154154
For example, if the latest tag is 4.0.6:
155155
```sh
156156
$> git clone https://github.com/jpsim/yams --branch 4.0.6
@@ -162,13 +162,21 @@ Clone the following repositories beside the SwiftPM directory:
162162
```
163163

164164
6. [swift-crypto] and check out tag with the [latest version](https://github.com/apple/swift-crypto/tags).
165-
165+
166166
For example, if the latest tag is 1.1.6:
167167
```sh
168168
$> git clone https://github.com/apple/swift-crypto --branch 1.1.6
169169
```
170170

171+
7. [swift-collections] and check out tag with the [latest version](https://github.com/apple/swift-collections/tags).
172+
173+
For example, if the latest tag is 1.0.1:
174+
```sh
175+
$> git clone https://github.com/apple/swift-collections --branch 1.0.1
176+
```
177+
171178
[swift-argument-parser]: https://github.com/apple/swift-argument-parser
179+
[swift-collections]: https://github.com/apple/swift-collections
172180
[swift-crypto]: https://github.com/apple/swift-crypto
173181
[swift-driver]: https://github.com/apple/swift-driver
174182
[swift-llbuild]: https://github.com/apple/swift-llbuild
@@ -385,4 +393,3 @@ $> swift package update
385393
```
386394
Alternatively, if you are using Xcode, you can update to the latest version of all packages:
387395
**Xcode App** > *File* > *Swift Packages* > *Update to Latest Package Versions*
388-

Package.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,10 @@ let package = Package(
133133

134134
.target(
135135
name: "Basics",
136-
dependencies: ["SwiftToolsSupport-auto"]),
136+
dependencies: [
137+
.product(name: "OrderedCollections", package: "swift-collections"),
138+
"SwiftToolsSupport-auto"
139+
]),
137140

138141
.target(
139142
/** The llbuild manifest model */
@@ -378,12 +381,14 @@ if ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] == nil {
378381
.package(url: "https://github.com/apple/swift-argument-parser.git", .upToNextMinor(from: "0.4.3")),
379382
.package(url: "https://github.com/apple/swift-driver.git", .branch(relatedDependenciesBranch)),
380383
.package(url: "https://github.com/apple/swift-crypto.git", .upToNextMinor(from: minimumCryptoVersion)),
384+
.package(url: "https://github.com/apple/swift-collections.git", .upToNextMinor(from: "1.0.1")),
381385
]
382386
} else {
383387
package.dependencies += [
384388
.package(path: "../swift-tools-support-core"),
385389
.package(path: "../swift-argument-parser"),
386390
.package(path: "../swift-driver"),
387391
.package(path: "../swift-crypto"),
392+
.package(path: "../swift-collections"),
388393
]
389394
}

Sources/Basics/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ add_library(Basics
1414
DispatchTimeInterval+Extensions.swift
1515
EnvironmentVariables.swift
1616
Errors.swift
17+
Exports.swift
1718
FileSystem+Extensions.swift
1819
HTPClient+URLSession.swift
1920
HTTPClient.swift
@@ -25,6 +26,7 @@ add_library(Basics
2526
SQLiteBackedCache.swift
2627
Version+Extensions.swift)
2728
target_link_libraries(Basics PUBLIC
29+
SwiftCollections::OrderedCollections
2830
TSCBasic
2931
TSCUtility)
3032
target_link_libraries(Basics PRIVATE

Sources/Build/BuildPlan.swift

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

1111
import Basics
12-
import TSCBasic
13-
import TSCUtility
14-
import PackageModel
12+
import Foundation
13+
import OrderedCollections
1514
import PackageGraph
1615
import PackageLoading
17-
import Foundation
16+
import PackageModel
1817
import SPMBuildCore
1918
@_implementationOnly import SwiftDriver
19+
import TSCBasic
20+
import TSCUtility
2021

2122
extension String {
2223
fileprivate var asSwiftStringLiteralConstant: String {
@@ -1992,7 +1993,7 @@ public class BuildPlan {
19921993
}
19931994

19941995
// Build cache
1995-
var cflagsCache: OrderedSet<String> = []
1996+
var cflagsCache: OrderedCollections.OrderedSet<String> = []
19961997
var libsCache: [String] = []
19971998
for tuple in ret {
19981999
for cFlag in tuple.cFlags {

Sources/PackageGraph/PackageGraph+Loading.swift

Lines changed: 4 additions & 3 deletions
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 TSCBasic
@@ -20,7 +21,7 @@ extension PackageGraph {
2021
root: PackageGraphRoot,
2122
identityResolver: IdentityResolver,
2223
additionalFileRules: [FileRuleDescription] = [],
23-
externalManifests: OrderedDictionary<PackageIdentity, Manifest>,
24+
externalManifests: OrderedCollections.OrderedDictionary<PackageIdentity, Manifest>,
2425
requiredDependencies: Set<PackageReference> = [],
2526
unsafeAllowedPackages: Set<PackageReference> = [],
2627
binaryArtifacts: [BinaryArtifact] = [],
@@ -636,7 +637,7 @@ fileprivate func findCycle(
636637
successors: (GraphLoadingNode) throws -> [GraphLoadingNode]
637638
) rethrows -> (path: [Manifest], cycle: [Manifest])? {
638639
// Ordered set to hold the current traversed path.
639-
var path = OrderedSet<Manifest>()
640+
var path = OrderedCollections.OrderedSet<Manifest>()
640641

641642
// Function to visit nodes recursively.
642643
// FIXME: Convert to stack.
@@ -645,7 +646,7 @@ fileprivate func findCycle(
645646
_ successors: (GraphLoadingNode) throws -> [GraphLoadingNode]
646647
) rethrows -> (path: [Manifest], cycle: [Manifest])? {
647648
// If this node is already in the current path then we have found a cycle.
648-
if !path.append(node.manifest) {
649+
if !path.append(node.manifest).inserted {
649650
let index = path.firstIndex(of: node.manifest)! // forced unwrap safe
650651
return (Array(path[path.startIndex..<index]), Array(path[index..<path.endIndex]))
651652
}

Sources/PackageGraph/Pubgrub/Incompatibility.swift

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,28 @@
99
*/
1010

1111
import Basics
12+
import OrderedCollections
1213
import TSCBasic
1314
import PackageModel
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
1718
/// from version requirements and when running into unresolvable situations.
1819
public struct Incompatibility: Equatable, Hashable {
19-
public let terms: OrderedSet<Term>
20+
public let terms: OrderedCollections.OrderedSet<Term>
2021
public let cause: Cause
2122

22-
public init(terms: OrderedSet<Term>, cause: Cause) {
23+
public init(terms: OrderedCollections.OrderedSet<Term>, cause: Cause) {
2324
self.terms = terms
2425
self.cause = cause
2526
}
2627

2728
public init(_ terms: Term..., root: DependencyResolutionNode, cause: Cause = .root) throws {
28-
let termSet = OrderedSet(terms)
29+
let termSet = OrderedCollections.OrderedSet(terms)
2930
try self.init(termSet, root: root, cause: cause)
3031
}
3132

32-
public init(_ terms: OrderedSet<Term>, root: DependencyResolutionNode, cause: Cause) throws {
33+
public init(_ terms: OrderedCollections.OrderedSet<Term>, root: DependencyResolutionNode, cause: Cause) throws {
3334
if terms.isEmpty {
3435
self.init(terms: terms, cause: cause)
3536
return
@@ -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)
@@ -134,7 +135,7 @@ extension Incompatibility {
134135
/// requirements to a^1.5.0.
135136
fileprivate func normalize(terms: [Term]) throws -> [Term] {
136137

137-
let dict = try terms.reduce(into: OrderedDictionary<DependencyResolutionNode, (req: VersionSetSpecifier, polarity: Bool)>()) {
138+
let dict = try terms.reduce(into: OrderedCollections.OrderedDictionary<DependencyResolutionNode, (req: VersionSetSpecifier, polarity: Bool)>()) {
138139
res, term in
139140
// Don't try to intersect if this is the first time we're seeing this package.
140141
guard let previous = res[term.node] else {

Sources/PackageGraph/Pubgrub/PartialSolution.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 TSCBasic
1314
import struct TSCUtility.Version
1415

@@ -25,7 +26,7 @@ public struct PartialSolution {
2526

2627
/// The intersection of all positive assignments for each package, minus any
2728
/// negative assignments that refer to that package.
28-
public private(set) var _positive: OrderedDictionary<DependencyResolutionNode, Term> = [:]
29+
public private(set) var _positive: OrderedCollections.OrderedDictionary<DependencyResolutionNode, Term> = [:]
2930

3031
/// Union of all negative assignments for a package.
3132
///

Sources/PackageGraph/Pubgrub/PubgrubDependencyResolver.swift

Lines changed: 4 additions & 3 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
@@ -443,7 +444,7 @@ public struct PubgrubDependencyResolver {
443444
/// If a conflict is found, the conflicting incompatibility is returned to
444445
/// resolve the conflict on.
445446
internal func propagate(state: State, node: DependencyResolutionNode) throws {
446-
var changed: OrderedSet<DependencyResolutionNode> = [node]
447+
var changed: OrderedCollections.OrderedSet<DependencyResolutionNode> = [node]
447448

448449
while !changed.isEmpty {
449450
let package = changed.removeFirst()
@@ -1212,7 +1213,7 @@ private final class PubGrubPackageContainer {
12121213
throw InternalError("Unexpected unversioned requirement: \(constraint)")
12131214
}
12141215
return try constraint.nodes().map { dependencyNode in
1215-
var terms: OrderedSet<Term> = []
1216+
var terms: OrderedCollections.OrderedSet<Term> = []
12161217
terms.append(Term(node, .exact(version)))
12171218
terms.append(Term(not: dependencyNode, vs))
12181219
return try Incompatibility(terms, root: root, cause: .dependency(node: node))
@@ -1226,7 +1227,7 @@ private final class PubGrubPackageContainer {
12261227
products: node.productFilter)
12271228

12281229
return try constraints.map { constraint in
1229-
var terms: OrderedSet<Term> = []
1230+
var terms: OrderedCollections.OrderedSet<Term> = []
12301231
let lowerBound = lowerBounds[constraint.package] ?? "0.0.0"
12311232
let upperBound = upperBounds[constraint.package] ?? Version(version.major + 1, 0, 0)
12321233
assert(lowerBound < upperBound)

Sources/PackageLoading/PackageBuilder.swift

Lines changed: 3 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

@@ -1160,11 +1161,11 @@ public final class PackageBuilder {
11601161

11611162
/// Collects the products defined by a package.
11621163
private func constructProducts(_ targets: [Target]) throws -> [Product] {
1163-
var products = OrderedSet<KeyedPair<Product, String>>()
1164+
var products = OrderedCollections.OrderedSet<KeyedPair<Product, String>>()
11641165

11651166
/// Helper method to append to products array.
11661167
func append(_ product: Product) {
1167-
let inserted = products.append(KeyedPair(product, key: product.name))
1168+
let inserted = products.append(KeyedPair(product, key: product.name)).inserted
11681169
if !inserted {
11691170
self.observabilityScope.emit(.duplicateProduct(product: product))
11701171
}

0 commit comments

Comments
 (0)