Skip to content

Commit 84c7494

Browse files
committed
Make with*Continuation inherit the caller's executor.
Not inheriting the caller's executor is a major problem for these functions. Under SE-0338, treating them as non-isolated means that it's illegal to pass them anytthing non-Sendable from a different isolation context; since the function is declared to take a non-sendable function parameter, effectively, SE-0338 means that these functions can only be safely called from non-isolated contexts. That's not really acceptable, but it gets worse: since we haven't implemented the sendability rule for that yet, we're immediately bypassing isolation safety when using these functions with no warning. The `withCheckedContinuation` functions are not `@_alwaysEmitIntoClient` (an oversight in the initial release), and so we need to use the unsafe attribute on them. When we eventually implement a safe mechanism for this, we should make `@_alwaysEmitIntoClient` variants of these functions which use the new feature, and we can demote the existing functions to `internal @availableFromInline`. I've gone ahead and made `withChecked*Continuation` `@inlinable`.
1 parent b3b6701 commit 84c7494

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

stdlib/public/Concurrency/CheckedContinuation.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,8 @@ extension CheckedContinuation {
265265
/// - body: A closure that takes a `CheckedContinuation` parameter.
266266
/// You must resume the continuation exactly once.
267267
@available(SwiftStdlib 5.1, *)
268+
@_unsafeInheritExecutor // ABI compatibility with Swift 5.1
269+
@inlinable
268270
public func withCheckedContinuation<T>(
269271
function: String = #function,
270272
_ body: (CheckedContinuation<T, Never>) -> Void
@@ -287,6 +289,8 @@ public func withCheckedContinuation<T>(
287289
/// If `resume(throwing:)` is called on the continuation,
288290
/// this function throws that error.
289291
@available(SwiftStdlib 5.1, *)
292+
@_unsafeInheritExecutor // ABI compatibility with Swift 5.1
293+
@inlinable
290294
public func withCheckedThrowingContinuation<T>(
291295
function: String = #function,
292296
_ body: (CheckedContinuation<T, Error>) -> Void

stdlib/public/Concurrency/PartialAsyncTask.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ internal func _resumeUnsafeThrowingContinuationWithError<T>(
257257
///
258258
/// - Returns: The value passed to the continuation by the closure.
259259
@available(SwiftStdlib 5.1, *)
260+
@_unsafeInheritExecutor
260261
@_alwaysEmitIntoClient
261262
public func withUnsafeContinuation<T>(
262263
_ fn: (UnsafeContinuation<T, Never>) -> Void
@@ -277,6 +278,7 @@ public func withUnsafeContinuation<T>(
277278
/// If `resume(throwing:)` is called on the continuation,
278279
/// this function throws that error.
279280
@available(SwiftStdlib 5.1, *)
281+
@_unsafeInheritExecutor
280282
@_alwaysEmitIntoClient
281283
public func withUnsafeThrowingContinuation<T>(
282284
_ fn: (UnsafeContinuation<T, Error>) -> Void

0 commit comments

Comments
 (0)