diff --git a/stdlib/public/Concurrency/AsyncStream.swift b/stdlib/public/Concurrency/AsyncStream.swift index af4abb6888755..dcdb21aec93c0 100644 --- a/stdlib/public/Concurrency/AsyncStream.swift +++ b/stdlib/public/Concurrency/AsyncStream.swift @@ -175,15 +175,15 @@ public struct AsyncStream { let storage: _AsyncStreamCriticalStorage Element?>> = .create(produce) self.produce = { - return await Task.withCancellationHandler { - storage.value = nil - onCancel?() - } operation: { + return await withTaskCancellationHandler { guard let result = await storage.value?() else { storage.value = nil return nil } return result + } onCancel: { + storage.value = nil + onCancel?() } } } diff --git a/stdlib/public/Concurrency/AsyncStreamBuffer.swift b/stdlib/public/Concurrency/AsyncStreamBuffer.swift index a9e49c18f14c8..3e8f4233b470d 100644 --- a/stdlib/public/Concurrency/AsyncStreamBuffer.swift +++ b/stdlib/public/Concurrency/AsyncStreamBuffer.swift @@ -543,7 +543,7 @@ extension AsyncThrowingStream { } // this is used to store closures; which are two words -final class _AsyncStreamCriticalStorage { +final class _AsyncStreamCriticalStorage: UnsafeSendable { var _value: Contents private init(_doNotCallMe: ()) { fatalError("_AsyncStreamCriticalStorage must be initialized by create") diff --git a/stdlib/public/Concurrency/MainActor.swift b/stdlib/public/Concurrency/MainActor.swift index 482f335cf0f30..6220430eb1fc5 100644 --- a/stdlib/public/Concurrency/MainActor.swift +++ b/stdlib/public/Concurrency/MainActor.swift @@ -45,7 +45,7 @@ import Swift @available(SwiftStdlib 5.5, *) extension MainActor { /// Execute the given body closure on the main actor. - public static func run( + public static func run( resultType: T.Type = T.self, body: @MainActor @Sendable () throws -> T ) async rethrows -> T { diff --git a/stdlib/public/Concurrency/SourceCompatibilityShims.swift b/stdlib/public/Concurrency/SourceCompatibilityShims.swift index e798dd528959a..eaacf57bb0ddd 100644 --- a/stdlib/public/Concurrency/SourceCompatibilityShims.swift +++ b/stdlib/public/Concurrency/SourceCompatibilityShims.swift @@ -155,11 +155,11 @@ public func async( @available(SwiftStdlib 5.5, *) extension Task where Success == Never, Failure == Never { @available(*, deprecated, message: "`Task.Group` was replaced by `ThrowingTaskGroup` and `TaskGroup` and will be removed shortly.") - public typealias Group = ThrowingTaskGroup + public typealias Group = ThrowingTaskGroup @available(*, deprecated, message: "`Task.withGroup` was replaced by `withThrowingTaskGroup` and `withTaskGroup` and will be removed shortly.") @_alwaysEmitIntoClient - public static func withGroup( + public static func withGroup( resultType: TaskResult.Type, returning returnType: BodyResult.Type = BodyResult.self, body: (inout Task.Group) async throws -> BodyResult diff --git a/stdlib/public/Concurrency/Task.swift b/stdlib/public/Concurrency/Task.swift index 49780d723da9d..1f1bc5ad977c5 100644 --- a/stdlib/public/Concurrency/Task.swift +++ b/stdlib/public/Concurrency/Task.swift @@ -756,7 +756,7 @@ func _enqueueJobGlobalWithDelay(_ delay: UInt64, _ task: Builtin.Job) public func _asyncMainDrainQueue() -> Never @available(SwiftStdlib 5.5, *) -public func _runAsyncMain(_ asyncFun: @escaping () async throws -> ()) { +public func _runAsyncMain(@_unsafeSendable _ asyncFun: @escaping () async throws -> ()) { Task.detached { do { #if !os(Windows) diff --git a/stdlib/public/Concurrency/TaskCancellation.swift b/stdlib/public/Concurrency/TaskCancellation.swift index 9510c2f5e76d7..15755ddb9ab39 100644 --- a/stdlib/public/Concurrency/TaskCancellation.swift +++ b/stdlib/public/Concurrency/TaskCancellation.swift @@ -32,8 +32,6 @@ public func withTaskCancellationHandler( operation: () async throws -> T, onCancel handler: @Sendable () -> Void ) async rethrows -> T { - let task = Builtin.getCurrentAsyncTask() - // unconditionally add the cancellation record to the task. // if the task was already cancelled, it will be executed right away. let record = _taskAddCancellationHandler(handler: handler) diff --git a/stdlib/public/Concurrency/TaskLocal.swift b/stdlib/public/Concurrency/TaskLocal.swift index 8cd2a7a22652e..44a5948bb3173 100644 --- a/stdlib/public/Concurrency/TaskLocal.swift +++ b/stdlib/public/Concurrency/TaskLocal.swift @@ -188,6 +188,7 @@ public final class TaskLocal: Sendable, CustomStringConvertible // the type-checker that this property-wrapper never wants to have an enclosing // instance (it is impossible to declare a property wrapper inside the `Never` // type). + @available(*, unavailable, message: "property wrappers cannot be instance members") public static subscript( _enclosingInstance object: Never, wrapped wrappedKeyPath: ReferenceWritableKeyPath,