Skip to content

Commit

Permalink
adopt Swift Collection's OrderedSet and OrderedDictionary
Browse files Browse the repository at this point in the history
They're better optimised and tested.
  • Loading branch information
WowbaggersLiquidLunch committed Jun 7, 2021
1 parent fc5b8a5 commit 92b5aab
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 352 deletions.
29 changes: 26 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@


import PackageDescription
import class Foundation.ProcessInfo

let package = Package(
name: "swift-tools-support-core",
Expand All @@ -28,7 +29,6 @@ let package = Package(
name: "TSCTestSupport",
targets: ["TSCTestSupport"]),
],
dependencies: [],
targets: [

// MARK: Tools support core targets
Expand All @@ -44,11 +44,21 @@ let package = Package(
.target(
/** TSCBasic support library */
name: "TSCBasic",
dependencies: ["TSCLibc", "TSCclibc"]),
dependencies: [
"TSCLibc",
"TSCclibc",
.product(name: "OrderedCollections", package: "swift-collections"),
]
),
.target(
/** Abstractions for common operations, should migrate to TSCBasic */
name: "TSCUtility",
dependencies: ["TSCBasic", "TSCclibc"]),
dependencies: [
"TSCBasic",
"TSCclibc",
.product(name: "OrderedCollections", package: "swift-collections"),
]
),

// MARK: Additional Test Dependencies

Expand All @@ -75,6 +85,19 @@ let package = Package(
]
)

/// When not using local dependencies, the branch to use for llbuild and TSC repositories.
let relatedDependenciesBranch = "main"

if ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] == nil {
package.dependencies += [
.package(url: "https://github.com/apple/swift-collections.git", .branch("main")),
]
} else {
package.dependencies += [
.package(path: "../swift-collections"),
]
}

// FIXME: conditionalise these flags since SwiftPM 5.3 and earlier will crash
// for platforms they don't know about.
#if os(Windows)
Expand Down
2 changes: 0 additions & 2 deletions Sources/TSCBasic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ add_library(TSCBasic
Lock.swift
OSLog.swift
ObjectIdentifierProtocol.swift
OrderedDictionary.swift
OrderedSet.swift
WritableByteStream.swift
Path.swift
PathShims.swift
Expand Down
8 changes: 5 additions & 3 deletions Sources/TSCBasic/GraphAlgorithms.swift
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
/*
This source file is part of the Swift.org open source project

Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
Copyright (c) 2014 - 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 OrderedCollections

public enum GraphError: Error {
/// A cycle was detected in the input.
case unexpectedCycle
Expand Down Expand Up @@ -69,7 +71,7 @@ public func topologicalSort<T: Hashable>(

// Otherwise, visit each adjacent node.
for succ in try successors(node) {
guard stack.append(succ) else {
guard stack.append(succ).inserted else {
// If the successor is already in this current stack, we have found a cycle.
//
// FIXME: We could easily include information on the cycle we found here.
Expand Down Expand Up @@ -120,7 +122,7 @@ public func findCycle<T: Hashable>(
// FIXME: Convert to stack.
func visit(_ node: T, _ successors: (T) throws -> [T]) rethrows -> (path: [T], cycle: [T])? {
// If this node is already in the current path then we have found a cycle.
if !path.append(node) {
if !path.append(node).inserted {
let index = path.firstIndex(of: node)!
return (Array(path[path.startIndex..<index]), Array(path[index..<path.endIndex]))
}
Expand Down
125 changes: 0 additions & 125 deletions Sources/TSCBasic/OrderedDictionary.swift

This file was deleted.

130 changes: 0 additions & 130 deletions Sources/TSCBasic/OrderedSet.swift

This file was deleted.

5 changes: 3 additions & 2 deletions Sources/TSCUtility/PkgConfig.swift
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
/*
This source file is part of the Swift.org open source project

Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
Copyright (c) 2014 - 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 TSCBasic
import Foundation
import OrderedCollections
import TSCBasic

public enum PkgConfigError: Swift.Error, CustomStringConvertible {
case couldNotFindConfigFile(name: String)
Expand Down
Loading

0 comments on commit 92b5aab

Please sign in to comment.