Skip to content

Commit 5c1fd46

Browse files
ktosoDougGregor
authored andcommitted
[Concurrency] don't require Sendable (yet) on groups and locals
(cherry picked from commit 1cd7180)
1 parent 3cbec1c commit 5c1fd46

File tree

3 files changed

+8
-16
lines changed

3 files changed

+8
-16
lines changed

stdlib/public/Concurrency/TaskGroup.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import Swift
1818
@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
1919
extension Task {
2020
@available(*, deprecated, message: "`Task.Group` was replaced by `ThrowingTaskGroup` and `TaskGroup` and will be removed shortly.")
21-
public typealias Group<TaskResult: Sendable> = ThrowingTaskGroup<TaskResult, Error>
21+
public typealias Group<TaskResult> = ThrowingTaskGroup<TaskResult, Error>
2222

2323
@available(*, deprecated, message: "`Task.withGroup` was replaced by `withThrowingTaskGroup` and `withTaskGroup` and will be removed shortly.")
2424
public static func withGroup<TaskResult, BodyResult>(
@@ -81,7 +81,7 @@ extension Task {
8181
/// - once the `withTaskGroup` returns the group is guaranteed to be empty.
8282
@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
8383
@inlinable
84-
public func withTaskGroup<ChildTaskResult: Sendable, GroupResult>(
84+
public func withTaskGroup<ChildTaskResult, GroupResult>(
8585
of childTaskResultType: ChildTaskResult.Type,
8686
returning returnType: GroupResult.Type = GroupResult.self,
8787
body: (inout TaskGroup<ChildTaskResult>) async -> GroupResult
@@ -160,7 +160,7 @@ public func withTaskGroup<ChildTaskResult: Sendable, GroupResult>(
160160
/// - all tasks remaining in the group will be automatically cancelled.
161161
@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
162162
@inlinable
163-
public func withThrowingTaskGroup<ChildTaskResult: Sendable, GroupResult>(
163+
public func withThrowingTaskGroup<ChildTaskResult, GroupResult>(
164164
of childTaskResultType: ChildTaskResult.Type,
165165
returning returnType: GroupResult.Type = GroupResult.self,
166166
body: (inout ThrowingTaskGroup<ChildTaskResult, Error>) async throws -> GroupResult
@@ -197,7 +197,7 @@ public func withThrowingTaskGroup<ChildTaskResult: Sendable, GroupResult>(
197197
/// It is created by the `withTaskGroup` function.
198198
@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
199199
@frozen
200-
public struct TaskGroup<ChildTaskResult: Sendable> {
200+
public struct TaskGroup<ChildTaskResult> {
201201

202202
/// Group task into which child tasks offer their results,
203203
/// and the `next()` function polls those results from.
@@ -457,7 +457,7 @@ public struct TaskGroup<ChildTaskResult: Sendable> {
457457
/// It is created by the `withTaskGroup` function.
458458
@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
459459
@frozen
460-
public struct ThrowingTaskGroup<ChildTaskResult: Sendable, Failure: Error> {
460+
public struct ThrowingTaskGroup<ChildTaskResult, Failure: Error> {
461461

462462
/// Group task into which child tasks offer their results,
463463
/// and the `next()` function polls those results from.

stdlib/public/Concurrency/TaskLocal.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ import Swift
9696
/// value for lookups in the task local storage.
9797
@propertyWrapper
9898
@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
99-
public final class TaskLocal<Value: Sendable>: Sendable, CustomStringConvertible {
99+
// TODO: add Sendable enforcement when we're ready to do so rdar://77441933
100+
public final class TaskLocal<Value>: UnsafeSendable, CustomStringConvertible {
100101
let defaultValue: Value
101102

102103
public init(wrappedValue defaultValue: Value) {
@@ -207,7 +208,7 @@ extension UnsafeCurrentTask {
207208
/// This function MUST NOT be invoked by any other task than the current task
208209
/// represented by this object.
209210
@discardableResult
210-
public func withTaskLocal<Value: Sendable, R>(
211+
public func withTaskLocal<Value, R>(
211212
_ taskLocal: TaskLocal<Value>,
212213
boundTo valueDuringOperation: Value,
213214
operation: () throws -> R,

test/Concurrency/task_local.swift

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,6 @@ var global: Int = 0
2222

2323
class NotSendable {}
2424

25-
@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
26-
enum T2 {
27-
@TaskLocal // expected-error{{generic class 'TaskLocal' requires that 'NotSendable' conform to 'Sendable'}}
28-
static var notSendable: NotSendable?
29-
30-
@TaskLocal // expected-error{{generic class 'TaskLocal' requires that 'NotSendable' conform to 'Sendable'}}
31-
static var notSendable2: NotSendable = NotSendable()
32-
}
33-
3425
@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
3526
func test () async {
3627
TL.number = 10 // expected-error{{cannot assign to property: 'number' is a get-only property}}

0 commit comments

Comments
 (0)