Skip to content

Commit 0c62c5b

Browse files
authored
Update package to support Swift 6.0; Drop older than 5.7 (#44)
1 parent 89b1cd2 commit 0c62c5b

12 files changed

+18
-556
lines changed

Package.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:5.6
1+
// swift-tools-version:5.7
22

33
import PackageDescription
44

[email protected]

-43
This file was deleted.

[email protected]

-42
This file was deleted.

[email protected]

-42
This file was deleted.

[email protected]

-42
This file was deleted.

[email protected]

-43
This file was deleted.

Sources/ServiceContextModule/ServiceContext.swift

+13-16
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,6 @@
1313
//
1414
//===----------------------------------------------------------------------===//
1515

16-
#if swift(>=5.5) && canImport(_Concurrency)
17-
public typealias _ServiceContext_Sendable = Swift.Sendable
18-
#else
19-
public typealias _ServiceContext_Sendable = Any
20-
#endif
21-
2216
/// A `ServiceContext` is a heterogeneous storage type with value semantics for keyed values in a type-safe fashion.
2317
///
2418
/// Its values are uniquely identified via ``ServiceContextKey``s (by type identity). These keys also dictate the type of
@@ -71,8 +65,8 @@ public typealias _ServiceContext_Sendable = Any
7165
/// `ServiceContext` does not expose more functions on purpose to prevent abuse and treating it as too much of an
7266
/// arbitrary value smuggling container, but only make it convenient for tracing and instrumentation systems which need
7367
/// to access either specific or all items carried inside a baggage.
74-
public struct ServiceContext: _ServiceContext_Sendable {
75-
private var _storage = [AnyServiceContextKey: _ServiceContext_Sendable]()
68+
public struct ServiceContext: Sendable {
69+
private var _storage = [AnyServiceContextKey: Sendable]()
7670

7771
/// Internal on purpose, please use ``ServiceContext/TODO(_:function:file:line:)`` or ``ServiceContext/topLevel`` to create an "empty" baggage,
7872
/// which carries more meaning to other developers why an empty baggage was used.
@@ -157,7 +151,7 @@ extension ServiceContext {
157151

158152
/// Carried automatically by a "to do" baggage.
159153
/// It can be used to track where a baggage originated and which "to do" baggage must be fixed into a real one to avoid this.
160-
public struct TODOLocation: _ServiceContext_Sendable {
154+
public struct TODOLocation: Sendable {
161155
/// Source file location where the to-do ``ServiceContext`` was created
162156
public let file: String
163157
/// Source line location where the to-do ``ServiceContext`` was created
@@ -230,7 +224,6 @@ extension ServiceContext {
230224

231225
// MARK: - Propagating ServiceContext
232226

233-
#if swift(>=5.5) && canImport(_Concurrency)
234227
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
235228
extension ServiceContext {
236229
/// A `ServiceContext` is automatically propagated through task-local storage. This API enables binding a top-level `ServiceContext` and
@@ -251,15 +244,19 @@ extension ServiceContext {
251244
/// To access the task-local value, use `ServiceContext.current`.
252245
///
253246
/// SeeAlso: [Swift Task Locals](https://developer.apple.com/documentation/swift/tasklocal)
254-
#if swift(>=5.7)
255-
@_unsafeInheritExecutor // same as withValue declared in the stdlib; because we do not want to hop off the executor at all
256-
public static func withValue<T>(_ value: ServiceContext?, operation: () async throws -> T) async rethrows -> T {
247+
#if swift(>=6.0)
248+
public static func withValue<T>(_ value: ServiceContext?,
249+
isolation: isolated(any Actor)? = #isolation,
250+
operation: () async throws -> T) async rethrows -> T
251+
{
257252
try await ServiceContext.$current.withValue(value, operation: operation)
258253
}
259-
#else
254+
#endif
255+
256+
@available(*, deprecated, message: "Prefer withValue(_:isolation:operation:)")
257+
@_disfavoredOverload
258+
@_unsafeInheritExecutor // Deprecated trick to avoid executor hop here; 6.0 introduces the proper replacement: #isolation
260259
public static func withValue<T>(_ value: ServiceContext?, operation: () async throws -> T) async rethrows -> T {
261260
try await ServiceContext.$current.withValue(value, operation: operation)
262261
}
263-
#endif
264262
}
265-
#endif

Sources/ServiceContextModule/ServiceContextKey.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@
3939
/// }
4040
///
4141
/// This pattern allows library authors fine-grained control over which values may be set, and which only get by end-users.
42-
public protocol ServiceContextKey: _ServiceContext_Sendable {
42+
public protocol ServiceContextKey: Sendable {
4343
/// The type of value uniquely identified by this key.
44-
associatedtype Value: _ServiceContext_Sendable
44+
associatedtype Value: Sendable
4545

4646
/// The human-readable name of this key.
4747
/// This name will be used instead of the type name when a value is printed.
@@ -62,7 +62,7 @@ extension ServiceContextKey {
6262
}
6363

6464
/// A type-erased ``ServiceContextKey`` used when iterating through the ``ServiceContext`` using its `forEach` method.
65-
public struct AnyServiceContextKey: _ServiceContext_Sendable {
65+
public struct AnyServiceContextKey: Sendable {
6666
/// The key's type erased to `Any.Type`.
6767
public let keyType: Any.Type
6868

Tests/LinuxMain.swift

-42
This file was deleted.

Tests/ServiceContextTests/ServiceContextTests+XCTest.swift

-38
This file was deleted.

0 commit comments

Comments
 (0)