Skip to content

Commit

Permalink
Merge pull request swiftlang#39062 from DougGregor/concurrency-lib-se…
Browse files Browse the repository at this point in the history
…ndable-part-deux
  • Loading branch information
swift-ci authored Aug 26, 2021
2 parents 9de5d6e + 51e4fd2 commit 3fc18f3
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 11 deletions.
8 changes: 4 additions & 4 deletions stdlib/public/Concurrency/AsyncStream.swift
Original file line number Diff line number Diff line change
Expand Up @@ -175,15 +175,15 @@ public struct AsyncStream<Element> {
let storage: _AsyncStreamCriticalStorage<Optional<() async -> 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?()
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/Concurrency/AsyncStreamBuffer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ extension AsyncThrowingStream {
}

// this is used to store closures; which are two words
final class _AsyncStreamCriticalStorage<Contents> {
final class _AsyncStreamCriticalStorage<Contents>: UnsafeSendable {
var _value: Contents
private init(_doNotCallMe: ()) {
fatalError("_AsyncStreamCriticalStorage must be initialized by create")
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/Concurrency/MainActor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(
public static func run<T: Sendable>(
resultType: T.Type = T.self,
body: @MainActor @Sendable () throws -> T
) async rethrows -> T {
Expand Down
4 changes: 2 additions & 2 deletions stdlib/public/Concurrency/SourceCompatibilityShims.swift
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,11 @@ public func async<T>(
@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<TaskResult> = ThrowingTaskGroup<TaskResult, Error>
public typealias Group<TaskResult: Sendable> = ThrowingTaskGroup<TaskResult, Error>

@available(*, deprecated, message: "`Task.withGroup` was replaced by `withThrowingTaskGroup` and `withTaskGroup` and will be removed shortly.")
@_alwaysEmitIntoClient
public static func withGroup<TaskResult, BodyResult>(
public static func withGroup<TaskResult: Sendable, BodyResult>(
resultType: TaskResult.Type,
returning returnType: BodyResult.Type = BodyResult.self,
body: (inout Task.Group<TaskResult>) async throws -> BodyResult
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/Concurrency/Task.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 0 additions & 2 deletions stdlib/public/Concurrency/TaskCancellation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ public func withTaskCancellationHandler<T>(
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)
Expand Down
1 change: 1 addition & 0 deletions stdlib/public/Concurrency/TaskLocal.swift
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ public final class TaskLocal<Value: Sendable>: 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<Never, Value>,
Expand Down

0 comments on commit 3fc18f3

Please sign in to comment.