Skip to content

[Concurrency] don't require Sendable (yet) #37197

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions stdlib/public/Concurrency/TaskGroup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import Swift
@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
extension Task {
@available(*, deprecated, message: "`Task.Group` was replaced by `ThrowingTaskGroup` and `TaskGroup` and will be removed shortly.")
public typealias Group<TaskResult: Sendable> = ThrowingTaskGroup<TaskResult, Error>
public typealias Group<TaskResult> = ThrowingTaskGroup<TaskResult, Error>

@available(*, deprecated, message: "`Task.withGroup` was replaced by `withThrowingTaskGroup` and `withTaskGroup` and will be removed shortly.")
public static func withGroup<TaskResult, BodyResult>(
Expand Down Expand Up @@ -81,7 +81,7 @@ extension Task {
/// - once the `withTaskGroup` returns the group is guaranteed to be empty.
@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
@inlinable
public func withTaskGroup<ChildTaskResult: Sendable, GroupResult>(
public func withTaskGroup<ChildTaskResult, GroupResult>(
of childTaskResultType: ChildTaskResult.Type,
returning returnType: GroupResult.Type = GroupResult.self,
body: (inout TaskGroup<ChildTaskResult>) async -> GroupResult
Expand Down Expand Up @@ -160,7 +160,7 @@ public func withTaskGroup<ChildTaskResult: Sendable, GroupResult>(
/// - all tasks remaining in the group will be automatically cancelled.
@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
@inlinable
public func withThrowingTaskGroup<ChildTaskResult: Sendable, GroupResult>(
public func withThrowingTaskGroup<ChildTaskResult, GroupResult>(
of childTaskResultType: ChildTaskResult.Type,
returning returnType: GroupResult.Type = GroupResult.self,
body: (inout ThrowingTaskGroup<ChildTaskResult, Error>) async throws -> GroupResult
Expand Down Expand Up @@ -197,7 +197,7 @@ public func withThrowingTaskGroup<ChildTaskResult: Sendable, GroupResult>(
/// It is created by the `withTaskGroup` function.
@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
@frozen
public struct TaskGroup<ChildTaskResult: Sendable> {
public struct TaskGroup<ChildTaskResult> {

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

/// Group task into which child tasks offer their results,
/// and the `next()` function polls those results from.
Expand Down
5 changes: 3 additions & 2 deletions stdlib/public/Concurrency/TaskLocal.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ import Swift
/// value for lookups in the task local storage.
@propertyWrapper
@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
public final class TaskLocal<Value: Sendable>: Sendable, CustomStringConvertible {
// TODO: add Sendable enforcement when we're ready to do so rdar://77441933
public final class TaskLocal<Value>: UnsafeSendable, CustomStringConvertible {
let defaultValue: Value

public init(wrappedValue defaultValue: Value) {
Expand Down Expand Up @@ -207,7 +208,7 @@ extension UnsafeCurrentTask {
/// This function MUST NOT be invoked by any other task than the current task
/// represented by this object.
@discardableResult
public func withTaskLocal<Value: Sendable, R>(
public func withTaskLocal<Value, R>(
_ taskLocal: TaskLocal<Value>,
boundTo valueDuringOperation: Value,
operation: () throws -> R,
Expand Down
9 changes: 0 additions & 9 deletions test/Concurrency/task_local.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,6 @@ var global: Int = 0

class NotSendable {}

@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
enum T2 {
@TaskLocal // expected-error{{generic class 'TaskLocal' requires that 'NotSendable' conform to 'Sendable'}}
static var notSendable: NotSendable?

@TaskLocal // expected-error{{generic class 'TaskLocal' requires that 'NotSendable' conform to 'Sendable'}}
static var notSendable2: NotSendable = NotSendable()
}

@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
func test () async {
TL.number = 10 // expected-error{{cannot assign to property: 'number' is a get-only property}}
Expand Down