Commit Graph

27 Commits

Author SHA1 Message Date
Alex Martini
2676e261fd Fix typo; add missing word. 2023-08-07 11:35:42 -07:00
Konrad `ktoso` Malawski
c446f4cb12 review followup 2023-03-03 13:37:57 +09:00
Konrad `ktoso` Malawski
8b2253cfbe [Concurrency] Fix continuation documentation about execution semantics 2023-03-03 09:45:55 +09:00
nate-chandler
9a7c0b9869 Revert "[Freestanding] Disable checked continuations." 2022-09-14 17:29:49 -07:00
Nate Chandler
c20bd86007 [Freestanding] Disable checked continuations.
In the task-to-thread model, there are no threading mechanisms by which
work could be offloaded onto another thread.  As such, callback based
asynchronous APIs which are not Swift async do not make sense.

rdar://99047747
2022-08-25 16:55:45 -07:00
Doug Gregor
ee4f6b1f75 Make CheckedContinuation and UnsafeContinuation unconditionally Sendable.
The continuation types were conditionally `Sendable` based on whether
the result type of the continuation was `Sendable`. However,
conceptually, the return value is never leaving the current task, so
it is never actually crossing concurrency boundaries. Therefore, we
can make the continuation types unconditionally `Sendable`.

Fixes rdar://98462858.
2022-08-19 13:06:41 -07:00
John McCall
84c74941dc 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`.
2022-02-14 20:46:03 -05:00
Šimon Javora
6c0c39ec44 [Docs] withCheckedThrowingContinuation body fix
`withCheckedThrowingContinuation`'s `body` says that it takes an `UnsafeContinuation`... seems like a copy/paste error.
2021-12-20 12:28:26 +01:00
najacque
57ad1f1c7d Merge pull request #40115 from amartini51/concurrency_docs_to_main
Cherry-pick concurrency docs
2021-12-07 11:59:56 -08:00
Doug Gregor
5a99ae485e Make (Unsafe|Checked)Continuation's Sendable conformance conditional.
Make the continuation type's conformances to the `Sendable` protocol
conditional on the sendability of the result yielded when the
resumption is performed. This ensures that one cannot silently escape
a continuation's result out of a task or actor, closing a safety hole
in Sendable checking.

Fixes rdar://85419546.
2021-11-15 16:41:07 -08:00
Doug Gregor
353daabf8d Replace UnsafeSendable with @unchecked Sendable in the standard library. 2021-11-12 07:56:10 -08:00
Alex Martini
c7aec3d6b7 Cherry pick Swift 5.5 doc changes in CheckedContinuation.swift 2021-11-09 17:23:38 -08:00
Karoy Lorentey
47956908b7 [Concurrency] SwiftStdlib 5.5 ⟹ SwiftStdlib 5.1 (usages)
The concurrency runtime now deploys back to macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, which corresponds to the 5.1 release of the stdlib.

Adjust macro usages accordingly.
2021-10-28 14:36:36 -07:00
Doug Gregor
60763a07e2 CheckedContinuation, UnsafeContinuation, and UnownedJob are Sendable
Fixes rdar://82909334.
2021-09-29 09:51:44 -07:00
Robert Widmann
15a552f11e [Gardening] Match Parameter Names To Doc Comments
Keep these names in sync so the documentation for these parameters
actually shows up in the IDE.
2021-06-24 20:30:44 -07:00
Alexis Laferrière
10d115bd5c [Concurrency] Use the SwiftStdlib 5.5 macro instead of 9999 versions 2021-05-04 09:30:58 -07:00
Mike Ash
1173b737aa [Concurrency] Add availability to Concurrency APIs.
This allows programs to target older OSes while using Concurrency behind an availability check. When targeting older OSes, the symbols are weak-linked and the compiler will require the use of Concurrency features to be guarded by an availability check.

rdar://75850003
2021-04-01 10:42:08 -04:00
Nate Cook
86b69b98cc Fix license headers in concurrency source files 2021-03-25 10:12:02 -05:00
Jonathan Grynspan
7e7215459f Remove _Continuation protocol and duplicate the relevant code. 2021-02-11 12:54:19 -05:00
Jonathan Grynspan
d8f7f20c4b [Concurrency] Simplify the type story for Continuation by eliminating Throwing variants
The goal of doing this is to reduce the amount of boilerplate and repeated code w.r.t. Continuation. Having just added `resume()` in four places, I got the sense that there was a lot of common code that was being duplicated. I removed the Throwing variants of these types (they can be expressed as Continuation<T, E:Error> instead of ThrowingContinuation<E>) and I broke out a significant amount of common code between CheckedContinuation and UnsafeContinuation into an implementation-only protocol to avoid repeating it. D.R.Y.

This change resolves rdar://74154769.
2021-02-10 12:09:33 -05:00
Jonathan Grynspan
6bddba2272 Merge pull request #35829 from grynspan/main
[Concurrency] Add `*Continuation.resume()` for continuations returning `Void`.

This change resolves rdar://74031110.
2021-02-09 12:16:05 -05:00
Jonathan Grynspan
49da0783ef Mark new function inlinable since it's trivial 2021-02-08 18:01:12 -05:00
Jonathan Grynspan
5db55aad1e Add *Continuation.resume() for continuations returning Void.
This change implements the changes proposed in swift-evolution PR #1264.
Existing test coverage should be sufficient here since the added function
simply calls into the existing `resume(returning:)` function.

This change resolves rdar://74031110.
2021-02-08 14:37:27 -05:00
Joe Groff
35802bfa36 CheckedContinuation: Add resume(with: Result) for parity with UnsafeContinuation 2021-02-05 11:52:45 -08:00
Joe Groff
49d4299ae0 Concurrency: Have CheckedContinuation trap on double resume. 2021-01-12 16:08:41 -08:00
Joe Groff
5f0974515d Make CheckedContinuation thread-safe and resilient. 2021-01-08 14:54:27 -08:00
Joe Groff
c151f4b02b Concurrency: Introduce a CheckedContinuation adapter.
To help catch runtime issues adopting `withUnsafeContinuation`, such as callback-based APIs that misleadingly
invoke their callback multiple times and/or not at all, provide a couple of classes that can take ownership of
a fresh `UnsafeContinuation` or `UnsafeThrowingContinuation`, and log attempts to resume the continuation multiple times
or discard the object without ever resuming the continuation.
2021-01-08 13:50:42 -08:00