Skip to content

Commit 915fa72

Browse files
bnbarhamMaxDesiatovk-koheymnaruseRyu0118
authored
[6.0] Various low-risk cherry-picks (#7578)
*Explanation*: I went through the last few months of PRs to make sure anything relevant is cherry-picked. Most of these are NFC but cherry-picking will help with conflicts. The main are: * Better error message - #7419 * Fix for visionOS for `--build-system xcode` - #7448 * Package registry fix - #7454 * Manifest editing API for adding target dependencies - #7552 * Various sendable annotations *Scope*: Package manifests/graphs with duplicate product/target names. *Risk*: Very low *Reviewed By*: Various, mostly @MaxDesiatov --------- Co-authored-by: Max Desiatov <[email protected]> Co-authored-by: k-kohey <[email protected]> Co-authored-by: miharu <[email protected]> Co-authored-by: Ryu <[email protected]> Co-authored-by: Philipp Wallrich <[email protected]> Co-authored-by: Boris Bügling <[email protected]> Co-authored-by: coffmark <[email protected]> Co-authored-by: Doug Gregor <[email protected]>
1 parent 141aa08 commit 915fa72

35 files changed

+374
-263
lines changed

.swiftformat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## File options
22

3-
--swiftversion 5.7
3+
--swiftversion 5.9
44
--exclude .build
55

66
## Formatting options

Package.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ automatic linking type with `-auto` suffix appended to product's name.
7474
*/
7575
let autoProducts = [swiftPMProduct, swiftPMDataModelProduct]
7676

77-
7877
let packageModelResourcesSettings: [SwiftSetting]
7978
let packageModelResources: [Resource]
8079
if ProcessInfo.processInfo.environment["SWIFTPM_USE_LIBRARIES_METADATA"] == nil {
@@ -186,7 +185,10 @@ let package = Package(
186185
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
187186
.product(name: "SystemPackage", package: "swift-system"),
188187
],
189-
exclude: ["CMakeLists.txt", "Vendor/README.md"]
188+
exclude: ["CMakeLists.txt", "Vendor/README.md"],
189+
swiftSettings: [
190+
.enableExperimentalFeature("StrictConcurrency"),
191+
]
190192
),
191193

192194
.target(
@@ -717,7 +719,7 @@ package.targets.append(contentsOf: [
717719
name: "FunctionalPerformanceTests",
718720
dependencies: [
719721
"swift-package-manager",
720-
"SPMTestSupport"
722+
"SPMTestSupport",
721723
]
722724
),
723725
])

Sources/Basics/Archiver/Archiver.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import _Concurrency
1414

1515
/// The `Archiver` protocol abstracts away the different operations surrounding archives.
16-
public protocol Archiver {
16+
public protocol Archiver: Sendable {
1717
/// A set of extensions the current archiver supports.
1818
var supportedExtensions: Set<String> { get }
1919

@@ -27,7 +27,7 @@ public protocol Archiver {
2727
func extract(
2828
from archivePath: AbsolutePath,
2929
to destinationPath: AbsolutePath,
30-
completion: @escaping (Result<Void, Error>) -> Void
30+
completion: @escaping @Sendable (Result<Void, Error>) -> Void
3131
)
3232

3333
/// Asynchronously compress the contents of a directory to a destination archive.
@@ -40,7 +40,7 @@ public protocol Archiver {
4040
func compress(
4141
directory: AbsolutePath,
4242
to destinationPath: AbsolutePath,
43-
completion: @escaping (Result<Void, Error>) -> Void
43+
completion: @escaping @Sendable (Result<Void, Error>) -> Void
4444
)
4545

4646
/// Asynchronously validates if a file is an archive.
@@ -51,7 +51,7 @@ public protocol Archiver {
5151
@available(*, noasync, message: "Use the async alternative")
5252
func validate(
5353
path: AbsolutePath,
54-
completion: @escaping (Result<Bool, Error>) -> Void
54+
completion: @escaping @Sendable (Result<Bool, Error>) -> Void
5555
)
5656
}
5757

@@ -65,8 +65,8 @@ extension Archiver {
6565
from archivePath: AbsolutePath,
6666
to destinationPath: AbsolutePath
6767
) async throws {
68-
try await withCheckedThrowingContinuation {
69-
self.extract(from: archivePath, to: destinationPath, completion: $0.resume(with:))
68+
try await withCheckedThrowingContinuation { continuation in
69+
self.extract(from: archivePath, to: destinationPath, completion: { continuation.resume(with: $0) })
7070
}
7171
}
7272

@@ -79,8 +79,8 @@ extension Archiver {
7979
directory: AbsolutePath,
8080
to destinationPath: AbsolutePath
8181
) async throws {
82-
try await withCheckedThrowingContinuation {
83-
self.compress(directory: directory, to: destinationPath, completion: $0.resume(with:))
82+
try await withCheckedThrowingContinuation { continuation in
83+
self.compress(directory: directory, to: destinationPath, completion: { continuation.resume(with: $0) })
8484
}
8585
}
8686

@@ -91,8 +91,8 @@ extension Archiver {
9191
public func validate(
9292
path: AbsolutePath
9393
) async throws -> Bool {
94-
try await withCheckedThrowingContinuation {
95-
self.validate(path: path, completion: $0.resume(with:))
94+
try await withCheckedThrowingContinuation { continuation in
95+
self.validate(path: path, completion: { continuation.resume(with: $0) })
9696
}
9797
}
9898
}

Sources/Basics/Archiver/TarArchiver.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public struct TarArchiver: Archiver {
4747
public func extract(
4848
from archivePath: AbsolutePath,
4949
to destinationPath: AbsolutePath,
50-
completion: @escaping (Result<Void, Error>) -> Void
50+
completion: @escaping @Sendable (Result<Void, Error>) -> Void
5151
) {
5252
do {
5353
guard self.fileSystem.exists(archivePath) else {
@@ -84,7 +84,7 @@ public struct TarArchiver: Archiver {
8484
public func compress(
8585
directory: AbsolutePath,
8686
to destinationPath: AbsolutePath,
87-
completion: @escaping (Result<Void, Error>) -> Void
87+
completion: @escaping @Sendable (Result<Void, Error>) -> Void
8888
) {
8989
do {
9090
guard self.fileSystem.isDirectory(directory) else {
@@ -115,7 +115,7 @@ public struct TarArchiver: Archiver {
115115
}
116116
}
117117

118-
public func validate(path: AbsolutePath, completion: @escaping (Result<Bool, Error>) -> Void) {
118+
public func validate(path: AbsolutePath, completion: @escaping @Sendable (Result<Bool, Error>) -> Void) {
119119
do {
120120
guard self.fileSystem.exists(path) else {
121121
throw FileSystemError(.noEntry, path.underlying)

Sources/Basics/Archiver/UniversalArchiver.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public struct UniversalArchiver: Archiver {
7373
public func extract(
7474
from archivePath: AbsolutePath,
7575
to destinationPath: AbsolutePath,
76-
completion: @escaping (Result<Void, Swift.Error>) -> Void
76+
completion: @escaping @Sendable (Result<Void, Swift.Error>) -> Void
7777
) {
7878
do {
7979
let archiver = try archiver(for: archivePath)
@@ -86,7 +86,7 @@ public struct UniversalArchiver: Archiver {
8686
public func compress(
8787
directory: AbsolutePath,
8888
to destinationPath: AbsolutePath,
89-
completion: @escaping (Result<Void, Swift.Error>) -> Void
89+
completion: @escaping @Sendable (Result<Void, Swift.Error>) -> Void
9090
) {
9191
do {
9292
let archiver = try archiver(for: destinationPath)
@@ -98,7 +98,7 @@ public struct UniversalArchiver: Archiver {
9898

9999
public func validate(
100100
path: AbsolutePath,
101-
completion: @escaping (Result<Bool, Swift.Error>) -> Void
101+
completion: @escaping @Sendable (Result<Bool, Swift.Error>) -> Void
102102
) {
103103
do {
104104
let archiver = try archiver(for: path)

Sources/Basics/Archiver/ZipArchiver.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public struct ZipArchiver: Archiver, Cancellable {
3737
public func extract(
3838
from archivePath: AbsolutePath,
3939
to destinationPath: AbsolutePath,
40-
completion: @escaping (Result<Void, Error>) -> Void
40+
completion: @escaping @Sendable (Result<Void, Error>) -> Void
4141
) {
4242
do {
4343
guard self.fileSystem.exists(archivePath) else {
@@ -77,7 +77,7 @@ public struct ZipArchiver: Archiver, Cancellable {
7777
public func compress(
7878
directory: AbsolutePath,
7979
to destinationPath: AbsolutePath,
80-
completion: @escaping (Result<Void, Error>) -> Void
80+
completion: @escaping @Sendable (Result<Void, Error>) -> Void
8181
) {
8282
do {
8383
guard self.fileSystem.isDirectory(directory) else {
@@ -125,7 +125,7 @@ public struct ZipArchiver: Archiver, Cancellable {
125125
}
126126
}
127127

128-
public func validate(path: AbsolutePath, completion: @escaping (Result<Bool, Error>) -> Void) {
128+
public func validate(path: AbsolutePath, completion: @escaping @Sendable (Result<Bool, Error>) -> Void) {
129129
do {
130130
guard self.fileSystem.exists(path) else {
131131
throw FileSystemError(.noEntry, path.underlying)

Sources/Basics/AuthorizationProvider.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ import struct Foundation.URL
1717
import Security
1818
#endif
1919

20-
public protocol AuthorizationProvider {
21-
@Sendable
20+
public protocol AuthorizationProvider: Sendable {
2221
func authentication(for url: URL) -> (user: String, password: String)?
2322
}
2423

@@ -80,7 +79,7 @@ extension AuthorizationProvider {
8079

8180
// MARK: - netrc
8281

83-
public class NetrcAuthorizationProvider: AuthorizationProvider, AuthorizationWriter {
82+
public final class NetrcAuthorizationProvider: AuthorizationProvider, AuthorizationWriter {
8483
// marked internal for testing
8584
internal let path: AbsolutePath
8685
private let fileSystem: FileSystem
@@ -202,7 +201,7 @@ public class NetrcAuthorizationProvider: AuthorizationProvider, AuthorizationWri
202201
// MARK: - Keychain
203202

204203
#if canImport(Security)
205-
public class KeychainAuthorizationProvider: AuthorizationProvider, AuthorizationWriter {
204+
public final class KeychainAuthorizationProvider: AuthorizationProvider, AuthorizationWriter {
206205
private let observabilityScope: ObservabilityScope
207206

208207
private let cache = ThreadSafeKeyValueStore<String, (user: String, password: String)>()

Sources/Basics/Cancellator.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ import class TSCBasic.Thread
1818
import WinSDK
1919
#endif
2020

21-
public typealias CancellationHandler = (DispatchTime) throws -> Void
21+
public typealias CancellationHandler = @Sendable (DispatchTime) throws -> Void
2222

23-
public final class Cancellator: Cancellable {
23+
public final class Cancellator: Cancellable, Sendable {
2424
public typealias RegistrationKey = String
2525

2626
private let observabilityScope: ObservabilityScope?
@@ -119,7 +119,7 @@ public final class Cancellator: Cancellable {
119119
}
120120

121121
@discardableResult
122-
public func register(name: String, handler: @escaping () throws -> Void) -> RegistrationKey? {
122+
public func register(name: String, handler: @escaping @Sendable () throws -> Void) -> RegistrationKey? {
123123
self.register(name: name, handler: { _ in try handler() })
124124
}
125125

Sources/Basics/Concurrency/ConcurrencyHelpers.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ extension DispatchQueue {
4949

5050
/// Bridges between potentially blocking methods that take a result completion closure and async/await
5151
public func safe_async<T, ErrorType: Error>(
52-
_ body: @Sendable @escaping (@Sendable @escaping (Result<T, ErrorType>) -> Void) -> Void
52+
_ body: @escaping @Sendable (@escaping @Sendable (Result<T, ErrorType>) -> Void) -> Void
5353
) async throws -> T {
5454
try await withCheckedThrowingContinuation { continuation in
5555
// It is possible that body make block indefinitely on a lock, semaphore,
@@ -64,7 +64,7 @@ public func safe_async<T, ErrorType: Error>(
6464
}
6565

6666
/// Bridges between potentially blocking methods that take a result completion closure and async/await
67-
public func safe_async<T>(_ body: @escaping (@escaping (Result<T, Never>) -> Void) -> Void) async -> T {
67+
public func safe_async<T>(_ body: @escaping @Sendable (@escaping (Result<T, Never>) -> Void) -> Void) async -> T {
6868
await withCheckedContinuation { continuation in
6969
// It is possible that body make block indefinitely on a lock, semaphore,
7070
// or similar then synchronously call the completion handler. For full safety

Sources/Basics/Concurrency/TokenBucket.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public actor TokenBucket {
3030
/// invocations of `withToken` will suspend until a "free" token is available.
3131
/// - Parameter body: The closure to invoke when a token is available.
3232
/// - Returns: Resulting value returned by `body`.
33-
public func withToken<ReturnType>(
33+
public func withToken<ReturnType: Sendable>(
3434
_ body: @Sendable () async throws -> ReturnType
3535
) async rethrows -> ReturnType {
3636
await self.getToken()

Sources/Basics/FileSystem/FileSystem+Extensions.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import var TSCBasic.localFileSystem
2525
import protocol TSCBasic.WritableByteStream
2626

2727
public typealias FileSystem = TSCBasic.FileSystem
28-
public var localFileSystem = TSCBasic.localFileSystem
28+
public let localFileSystem = TSCBasic.localFileSystem
2929

3030
// MARK: - Custom path
3131

Sources/Basics/FileSystem/TemporaryFile.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public func withTemporaryDirectory<Result>(
3434
fileSystem: FileSystem = localFileSystem,
3535
dir: AbsolutePath? = nil,
3636
prefix: String = "TemporaryDirectory",
37-
_ body: @Sendable @escaping (AbsolutePath, @escaping (AbsolutePath) -> Void) async throws -> Result
37+
_ body: @escaping @Sendable (AbsolutePath, @escaping (AbsolutePath) -> Void) async throws -> Result
3838
) throws -> Task<Result, Error> {
3939
let temporaryDirectory = try createTemporaryDirectory(fileSystem: fileSystem, dir: dir, prefix: prefix)
4040

@@ -72,7 +72,7 @@ public func withTemporaryDirectory<Result>(
7272
dir: AbsolutePath? = nil,
7373
prefix: String = "TemporaryDirectory",
7474
removeTreeOnDeinit: Bool = false,
75-
_ body: @escaping (AbsolutePath) async throws -> Result
75+
_ body: @escaping @Sendable (AbsolutePath) async throws -> Result
7676
) throws -> Task<Result, Error> {
7777
try withTemporaryDirectory(fileSystem: fileSystem, dir: dir, prefix: prefix) { path, cleanup in
7878
defer { if removeTreeOnDeinit { cleanup(path) } }

Sources/Basics/HTTPClient/LegacyHTTPClient.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ public final class LegacyHTTPClient: Cancellable {
2525
public typealias Configuration = LegacyHTTPClientConfiguration
2626
public typealias Request = LegacyHTTPClientRequest
2727
public typealias Response = HTTPClientResponse
28-
public typealias Handler = (Request, ProgressHandler?, @escaping (Result<Response, Error>) -> Void) -> Void
29-
public typealias ProgressHandler = (_ bytesReceived: Int64, _ totalBytes: Int64?) throws -> Void
30-
public typealias CompletionHandler = (Result<HTTPClientResponse, Error>) -> Void
28+
public typealias Handler = (Request, ProgressHandler?, @escaping @Sendable (Result<Response, Error>) -> Void) -> Void
29+
public typealias ProgressHandler = @Sendable (_ bytesReceived: Int64, _ totalBytes: Int64?) throws -> Void
30+
public typealias CompletionHandler = @Sendable (Result<HTTPClientResponse, Error>) -> Void
3131

3232
public var configuration: LegacyHTTPClientConfiguration
3333
private let underlying: Handler
@@ -121,7 +121,7 @@ public final class LegacyHTTPClient: Cancellable {
121121
requestNumber: 0,
122122
observabilityScope: observabilityScope,
123123
progress: progress.map { handler in
124-
{ received, expected in
124+
{ @Sendable received, expected in
125125
// call back on the requested queue
126126
callbackQueue.async {
127127
do {
@@ -312,7 +312,7 @@ extension LegacyHTTPClient {
312312
headers: HTTPClientHeaders = .init(),
313313
options: Request.Options = .init(),
314314
observabilityScope: ObservabilityScope? = .none,
315-
completion: @escaping (Result<Response, Error>) -> Void
315+
completion: @Sendable @escaping (Result<Response, Error>) -> Void
316316
) {
317317
self.execute(
318318
Request(method: .head, url: url, headers: headers, body: nil, options: options),
@@ -326,7 +326,7 @@ extension LegacyHTTPClient {
326326
headers: HTTPClientHeaders = .init(),
327327
options: Request.Options = .init(),
328328
observabilityScope: ObservabilityScope? = .none,
329-
completion: @escaping (Result<Response, Error>) -> Void
329+
completion: @Sendable @escaping (Result<Response, Error>) -> Void
330330
) {
331331
self.execute(
332332
Request(method: .get, url: url, headers: headers, body: nil, options: options),
@@ -341,7 +341,7 @@ extension LegacyHTTPClient {
341341
headers: HTTPClientHeaders = .init(),
342342
options: Request.Options = .init(),
343343
observabilityScope: ObservabilityScope? = .none,
344-
completion: @escaping (Result<Response, Error>) -> Void
344+
completion: @Sendable @escaping (Result<Response, Error>) -> Void
345345
) {
346346
self.execute(
347347
Request(method: .put, url: url, headers: headers, body: body, options: options),
@@ -356,7 +356,7 @@ extension LegacyHTTPClient {
356356
headers: HTTPClientHeaders = .init(),
357357
options: Request.Options = .init(),
358358
observabilityScope: ObservabilityScope? = .none,
359-
completion: @escaping (Result<Response, Error>) -> Void
359+
completion: @Sendable @escaping (Result<Response, Error>) -> Void
360360
) {
361361
self.execute(
362362
Request(method: .post, url: url, headers: headers, body: body, options: options),
@@ -370,7 +370,7 @@ extension LegacyHTTPClient {
370370
headers: HTTPClientHeaders = .init(),
371371
options: Request.Options = .init(),
372372
observabilityScope: ObservabilityScope? = .none,
373-
completion: @escaping (Result<Response, Error>) -> Void
373+
completion: @Sendable @escaping (Result<Response, Error>) -> Void
374374
) {
375375
self.execute(
376376
Request(method: .delete, url: url, headers: headers, body: nil, options: options),
@@ -383,7 +383,7 @@ extension LegacyHTTPClient {
383383
// MARK: - LegacyHTTPClientConfiguration
384384

385385
public struct LegacyHTTPClientConfiguration {
386-
public typealias AuthorizationProvider = (URL) -> String?
386+
public typealias AuthorizationProvider = @Sendable (URL) -> String?
387387

388388
public var requestHeaders: HTTPClientHeaders?
389389
public var requestTimeout: DispatchTimeInterval?

0 commit comments

Comments
 (0)