Skip to content

Commit

Permalink
replace TSC's OrderedSet and OrderedDictionary with Swift Collect…
Browse files Browse the repository at this point in the history
…ion's

Swift Collection's are better optimised and tested.
  • Loading branch information
WowbaggersLiquidLunch committed Jun 7, 2021
1 parent 62fef21 commit a48848b
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 16 deletions.
39 changes: 33 additions & 6 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,29 @@ let package = Package(
.target(
/** Package model conventions and loading support */
name: "PackageLoading",
dependencies: ["SwiftToolsSupport-auto", "Basics", "PackageModel", "SourceControl"]),
dependencies: [
"SwiftToolsSupport-auto",
"Basics",
"OrderedCollections",
"PackageModel",
"SourceControl",
]
),

// MARK: Package Dependency Resolution

.target(
/** Data structures and support for complete package graphs */
name: "PackageGraph",
dependencies: ["SwiftToolsSupport-auto", "Basics", "PackageLoading", "PackageModel", "SourceControl"]),
dependencies: [
"SwiftToolsSupport-auto",
"Basics",
"OrderedCollections",
"PackageLoading",
"PackageModel",
"SourceControl",
]
),

// MARK: Package Collections

Expand Down Expand Up @@ -199,7 +214,17 @@ let package = Package(
.target(
/** Builds Modules and Products */
name: "Build",
dependencies: ["SwiftToolsSupport-auto", "Basics", "SPMBuildCore", "PackageGraph", "LLBuildManifest", "SwiftDriver", "SPMLLBuild"]),
dependencies: [
"SwiftToolsSupport-auto",
"Basics",
"OrderedCollections",
"SPMBuildCore",
"PackageGraph",
"LLBuildManifest",
"SwiftDriver",
"SPMLLBuild",
]
),
.target(
/** Support for building using Xcode's build system */
name: "XCBuildSupport",
Expand Down Expand Up @@ -359,15 +384,17 @@ if ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] == nil {
// The 'swift-argument-parser' version declared here must match that
// used by 'swift-driver' and 'sourcekit-lsp'. Please coordinate
// dependency version changes here with those projects.
.package(url: "https://github.com/apple/swift-argument-parser.git", .upToNextMinor(from: "0.4.3")),
.package(url: "https://github.com/apple/swift-argument-parser.git", .upToNextMinor(from: Version(0, 4, 3))),
.package(url: "https://github.com/apple/swift-collections.git", .exact(Version(0, 0, 3))),
.package(url: "https://github.com/apple/swift-crypto.git", .upToNextMinor(from: Version(1, 1, 4))),
.package(url: "https://github.com/apple/swift-driver.git", .branch(relatedDependenciesBranch)),
.package(url: "https://github.com/apple/swift-crypto.git", .upToNextMinor(from: "1.1.4")),
]
} else {
package.dependencies += [
.package(path: "../swift-tools-support-core"),
.package(path: "../swift-argument-parser"),
.package(path: "../swift-driver"),
.package(path: "../swift-collections"),
.package(path: "../swift-crypto"),
.package(path: "../swift-driver"),
]
}
7 changes: 4 additions & 3 deletions Sources/Build/BuildPlan.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@
*/

import Basics
import TSCBasic
import TSCUtility
import Foundation
import OrderedCollections
import PackageModel
import PackageGraph
import PackageLoading
import Foundation
import SPMBuildCore
@_implementationOnly import SwiftDriver
import TSCBasic
import TSCUtility

extension String {
fileprivate var asSwiftStringLiteralConstant: String {
Expand Down
3 changes: 2 additions & 1 deletion Sources/PackageGraph/PackageGraph+Loading.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*/

import Basics
import OrderedCollections
import PackageLoading
import PackageModel
import SourceControl
Expand Down Expand Up @@ -612,7 +613,7 @@ fileprivate func findCycle(
_ successors: (GraphLoadingNode) throws -> [GraphLoadingNode]
) rethrows -> (path: [Manifest], cycle: [Manifest])? {
// If this node is already in the current path then we have found a cycle.
if !path.append(node.manifest) {
if !path.append(node.manifest).inserted {
let index = path.firstIndex(of: node.manifest)! // forced unwrap safe
return (Array(path[path.startIndex..<index]), Array(path[index..<path.endIndex]))
}
Expand Down
7 changes: 4 additions & 3 deletions Sources/PackageGraph/Pubgrub/Incompatibility.swift
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
/*
This source file is part of the Swift.org open source project

Copyright (c) 2019 Apple Inc. and the Swift project authors
Copyright (c) 2019 - 2021 Apple Inc. and the Swift project authors
Licensed under Apache License v2.0 with Runtime Library Exception

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

import Basics
import TSCBasic
import OrderedCollections
import PackageModel
import TSCBasic

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

let normalizedTerms = try normalize(terms: terms.contents)
let normalizedTerms = try normalize(terms: terms.elements)
assert(normalizedTerms.count > 0,
"An incompatibility must contain at least one term after normalization.")
self.init(terms: OrderedSet(normalizedTerms), cause: cause)
Expand Down
3 changes: 2 additions & 1 deletion Sources/PackageGraph/Pubgrub/PubgrubDependencyResolver.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
This source file is part of the Swift.org open source project

Copyright (c) 2019 Apple Inc. and the Swift project authors
Copyright (c) 2019 - 2021 Apple Inc. and the Swift project authors
Licensed under Apache License v2.0 with Runtime Library Exception

See http://swift.org/LICENSE.txt for license information
Expand All @@ -10,6 +10,7 @@

import Basics
import Dispatch
import OrderedCollections
import PackageModel
import TSCBasic
import TSCUtility
Expand Down
4 changes: 2 additions & 2 deletions Sources/PackageLoading/PackageBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import Basics
import Dispatch
import OrderedCollections
import PackageModel
import TSCBasic
import TSCUtility
Expand Down Expand Up @@ -1192,8 +1193,7 @@ public final class PackageBuilder {

/// Helper method to append to products array.
func append(_ product: Product) {
let inserted = products.append(KeyedPair(product, key: product.name))
if !inserted {
if !products.append(KeyedPair(product, key: product.name)).inserted {
diagnostics.emit(
.duplicateProduct(product: product),
location: self.diagnosticLocation
Expand Down

0 comments on commit a48848b

Please sign in to comment.