Skip to content

Commit e6aaf46

Browse files
committed
Revert "Revert "adopt swift-collections (#3632)" (#3677)"
This reverts commit a468072.
1 parent d82f52a commit e6aaf46

File tree

13 files changed

+67
-35
lines changed

13 files changed

+67
-35
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 0.0.5:
174+
```sh
175+
$> git clone https://github.com/apple/swift-collections --branch 0.0.5
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
@@ -126,7 +126,10 @@ let package = Package(
126126

127127
.target(
128128
name: "Basics",
129-
dependencies: ["SwiftToolsSupport-auto"]),
129+
dependencies: [
130+
.product(name: "OrderedCollections", package: "swift-collections"),
131+
"SwiftToolsSupport-auto"
132+
]),
130133

131134
.target(
132135
/** The llbuild manifest model */
@@ -369,12 +372,14 @@ if ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] == nil {
369372
.package(url: "https://github.com/apple/swift-argument-parser.git", .upToNextMinor(from: "0.4.3")),
370373
.package(url: "https://github.com/apple/swift-driver.git", .branch(relatedDependenciesBranch)),
371374
.package(url: "https://github.com/apple/swift-crypto.git", .upToNextMinor(from: "1.1.4")),
375+
.package(url: "https://github.com/apple/swift-collections.git", .upToNextMinor(from: "1.0.0")),
372376
]
373377
} else {
374378
package.dependencies += [
375379
.package(path: "../swift-tools-support-core"),
376380
.package(path: "../swift-argument-parser"),
377381
.package(path: "../swift-driver"),
378382
.package(path: "../swift-crypto"),
383+
.package(path: "../swift-collections"),
379384
]
380385
}

Sources/Basics/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ add_library(Basics
1313
Dictionary+Extensions.swift
1414
DispatchTimeInterval+Extensions.swift
1515
Errors.swift
16+
Exports.swift
1617
FileSystem+Extensions.swift
1718
HTPClient+URLSession.swift
1819
HTTPClient.swift
@@ -23,6 +24,7 @@ add_library(Basics
2324
SQLiteBackedCache.swift
2425
Version+Extensions.swift)
2526
target_link_libraries(Basics PUBLIC
27+
SwiftCollections::OrderedCollections
2628
TSCBasic
2729
TSCUtility)
2830
target_link_libraries(Basics PRIVATE

Sources/Basics/Exports.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
This source file is part of the Swift.org open source project
3+
4+
Copyright (c) 2021 Apple Inc. and the Swift project authors
5+
Licensed under Apache License v2.0 with Runtime Library Exception
6+
7+
See http://swift.org/LICENSE.txt for license information
8+
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
9+
*/
10+
11+
import OrderedCollections
12+
13+
public typealias OrderedDictionary = OrderedCollections.OrderedDictionary
14+
public typealias OrderedSet = OrderedCollections.OrderedSet

Sources/Build/BuildPlan.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1986,7 +1986,7 @@ public class BuildPlan {
19861986
}
19871987

19881988
// Build cache
1989-
var cflagsCache: OrderedSet<String> = []
1989+
var cflagsCache: Basics.OrderedSet<String> = []
19901990
var libsCache: [String] = []
19911991
for tuple in ret {
19921992
for cFlag in tuple.cFlags {

Sources/PackageGraph/PackageGraph+Loading.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ fileprivate func findCycle(
619619
successors: (GraphLoadingNode) throws -> [GraphLoadingNode]
620620
) rethrows -> (path: [Manifest], cycle: [Manifest])? {
621621
// Ordered set to hold the current traversed path.
622-
var path = OrderedSet<Manifest>()
622+
var path = Basics.OrderedSet<Manifest>()
623623

624624
// Function to visit nodes recursively.
625625
// FIXME: Convert to stack.
@@ -628,7 +628,7 @@ fileprivate func findCycle(
628628
_ successors: (GraphLoadingNode) throws -> [GraphLoadingNode]
629629
) rethrows -> (path: [Manifest], cycle: [Manifest])? {
630630
// If this node is already in the current path then we have found a cycle.
631-
if !path.append(node.manifest) {
631+
if !path.append(node.manifest).inserted {
632632
let index = path.firstIndex(of: node.manifest)! // forced unwrap safe
633633
return (Array(path[path.startIndex..<index]), Array(path[index..<path.endIndex]))
634634
}

Sources/PackageGraph/Pubgrub/Incompatibility.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,20 @@ import PackageModel
1616
/// all be true at the same time. In dependency resolution, these are derived
1717
/// from version requirements and when running into unresolvable situations.
1818
public struct Incompatibility: Equatable, Hashable {
19-
public let terms: OrderedSet<Term>
19+
public let terms: Basics.OrderedSet<Term>
2020
public let cause: Cause
2121

22-
public init(terms: OrderedSet<Term>, cause: Cause) {
22+
public init(terms: Basics.OrderedSet<Term>, cause: Cause) {
2323
self.terms = terms
2424
self.cause = cause
2525
}
2626

2727
public init(_ terms: Term..., root: DependencyResolutionNode, cause: Cause = .root) throws {
28-
let termSet = OrderedSet(terms)
28+
let termSet = Basics.OrderedSet(terms)
2929
try self.init(termSet, root: root, cause: cause)
3030
}
3131

32-
public init(_ terms: OrderedSet<Term>, root: DependencyResolutionNode, cause: Cause) throws {
32+
public init(_ terms: Basics.OrderedSet<Term>, root: DependencyResolutionNode, cause: Cause) throws {
3333
if terms.isEmpty {
3434
self.init(terms: terms, cause: cause)
3535
return
@@ -43,7 +43,7 @@ public struct Incompatibility: Equatable, Hashable {
4343
terms = OrderedSet(terms.filter { !$0.isPositive || $0.node != root })
4444
}
4545

46-
let normalizedTerms = try normalize(terms: terms.contents)
46+
let normalizedTerms = try normalize(terms: terms.elements)
4747
assert(normalizedTerms.count > 0,
4848
"An incompatibility must contain at least one term after normalization.")
4949
self.init(terms: OrderedSet(normalizedTerms), cause: cause)
@@ -134,7 +134,7 @@ extension Incompatibility {
134134
/// requirements to a^1.5.0.
135135
fileprivate func normalize(terms: [Term]) throws -> [Term] {
136136

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

Sources/PackageGraph/Pubgrub/PartialSolution.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public struct PartialSolution {
2525

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

3030
/// Union of all negative assignments for a package.
3131
///

Sources/PackageGraph/Pubgrub/PubgrubDependencyResolver.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ public struct PubgrubDependencyResolver {
445445
/// If a conflict is found, the conflicting incompatibility is returned to
446446
/// resolve the conflict on.
447447
internal func propagate(state: State, node: DependencyResolutionNode) throws {
448-
var changed: OrderedSet<DependencyResolutionNode> = [node]
448+
var changed: Basics.OrderedSet<DependencyResolutionNode> = [node]
449449

450450
while !changed.isEmpty {
451451
let package = changed.removeFirst()
@@ -1214,7 +1214,7 @@ private final class PubGrubPackageContainer {
12141214
throw InternalError("Unexpected unversioned requirement: \(constraint)")
12151215
}
12161216
return try constraint.nodes().map { dependencyNode in
1217-
var terms: OrderedSet<Term> = []
1217+
var terms: Basics.OrderedSet<Term> = []
12181218
terms.append(Term(node, .exact(version)))
12191219
terms.append(Term(not: dependencyNode, vs))
12201220
return try Incompatibility(terms, root: root, cause: .dependency(node: node))
@@ -1228,7 +1228,7 @@ private final class PubGrubPackageContainer {
12281228
products: node.productFilter)
12291229

12301230
return try constraints.map { constraint in
1231-
var terms: OrderedSet<Term> = []
1231+
var terms: Basics.OrderedSet<Term> = []
12321232
let lowerBound = lowerBounds[constraint.package] ?? "0.0.0"
12331233
let upperBound = upperBounds[constraint.package] ?? Version(version.major + 1, 0, 0)
12341234
assert(lowerBound < upperBound)

0 commit comments

Comments
 (0)