Skip to content

Commit 3fc18f3

Browse files
authored
Merge pull request swiftlang#39062 from DougGregor/concurrency-lib-sendable-part-deux
2 parents 9de5d6e + 51e4fd2 commit 3fc18f3

File tree

7 files changed

+10
-11
lines changed

7 files changed

+10
-11
lines changed

stdlib/public/Concurrency/AsyncStream.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,15 +175,15 @@ public struct AsyncStream<Element> {
175175
let storage: _AsyncStreamCriticalStorage<Optional<() async -> Element?>>
176176
= .create(produce)
177177
self.produce = {
178-
return await Task.withCancellationHandler {
179-
storage.value = nil
180-
onCancel?()
181-
} operation: {
178+
return await withTaskCancellationHandler {
182179
guard let result = await storage.value?() else {
183180
storage.value = nil
184181
return nil
185182
}
186183
return result
184+
} onCancel: {
185+
storage.value = nil
186+
onCancel?()
187187
}
188188
}
189189
}

stdlib/public/Concurrency/AsyncStreamBuffer.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ extension AsyncThrowingStream {
543543
}
544544

545545
// this is used to store closures; which are two words
546-
final class _AsyncStreamCriticalStorage<Contents> {
546+
final class _AsyncStreamCriticalStorage<Contents>: UnsafeSendable {
547547
var _value: Contents
548548
private init(_doNotCallMe: ()) {
549549
fatalError("_AsyncStreamCriticalStorage must be initialized by create")

stdlib/public/Concurrency/MainActor.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ import Swift
4545
@available(SwiftStdlib 5.5, *)
4646
extension MainActor {
4747
/// Execute the given body closure on the main actor.
48-
public static func run<T>(
48+
public static func run<T: Sendable>(
4949
resultType: T.Type = T.self,
5050
body: @MainActor @Sendable () throws -> T
5151
) async rethrows -> T {

stdlib/public/Concurrency/SourceCompatibilityShims.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,11 @@ public func async<T>(
155155
@available(SwiftStdlib 5.5, *)
156156
extension Task where Success == Never, Failure == Never {
157157
@available(*, deprecated, message: "`Task.Group` was replaced by `ThrowingTaskGroup` and `TaskGroup` and will be removed shortly.")
158-
public typealias Group<TaskResult> = ThrowingTaskGroup<TaskResult, Error>
158+
public typealias Group<TaskResult: Sendable> = ThrowingTaskGroup<TaskResult, Error>
159159

160160
@available(*, deprecated, message: "`Task.withGroup` was replaced by `withThrowingTaskGroup` and `withTaskGroup` and will be removed shortly.")
161161
@_alwaysEmitIntoClient
162-
public static func withGroup<TaskResult, BodyResult>(
162+
public static func withGroup<TaskResult: Sendable, BodyResult>(
163163
resultType: TaskResult.Type,
164164
returning returnType: BodyResult.Type = BodyResult.self,
165165
body: (inout Task.Group<TaskResult>) async throws -> BodyResult

stdlib/public/Concurrency/Task.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,7 @@ func _enqueueJobGlobalWithDelay(_ delay: UInt64, _ task: Builtin.Job)
756756
public func _asyncMainDrainQueue() -> Never
757757

758758
@available(SwiftStdlib 5.5, *)
759-
public func _runAsyncMain(_ asyncFun: @escaping () async throws -> ()) {
759+
public func _runAsyncMain(@_unsafeSendable _ asyncFun: @escaping () async throws -> ()) {
760760
Task.detached {
761761
do {
762762
#if !os(Windows)

stdlib/public/Concurrency/TaskCancellation.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ public func withTaskCancellationHandler<T>(
3232
operation: () async throws -> T,
3333
onCancel handler: @Sendable () -> Void
3434
) async rethrows -> T {
35-
let task = Builtin.getCurrentAsyncTask()
36-
3735
// unconditionally add the cancellation record to the task.
3836
// if the task was already cancelled, it will be executed right away.
3937
let record = _taskAddCancellationHandler(handler: handler)

stdlib/public/Concurrency/TaskLocal.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ public final class TaskLocal<Value: Sendable>: Sendable, CustomStringConvertible
188188
// the type-checker that this property-wrapper never wants to have an enclosing
189189
// instance (it is impossible to declare a property wrapper inside the `Never`
190190
// type).
191+
@available(*, unavailable, message: "property wrappers cannot be instance members")
191192
public static subscript(
192193
_enclosingInstance object: Never,
193194
wrapped wrappedKeyPath: ReferenceWritableKeyPath<Never, Value>,

0 commit comments

Comments
 (0)