Commit Graph

86 Commits

Author SHA1 Message Date
Alex Martini
699421c79b Cherry pick Swift 5.5 doc changes in PartialAsyncTask.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
Michael Gottesman
fc4d6c86ef [concurrency] Add UnownedJob._runSynchronously(on:) to support running a job synchronously on an executor.
I am going to use this to test that we propagate synchronous accesses into
asynchronous tasks access sets.

To ensure this is not ABI, I underscored/marked this as alwaysEmitIntoClient.
2021-07-22 13:25:10 -07:00
John McCall
0ce82d0755 Stage the swift_continuation_await ABI change.
Introduce a fake (but non-ABI) declaration to the swiftinterface
which marks that an SDK support swift_continuation_await, and then
only call it if that declaration exists, otherwise falling back
on the old atomic sequence.  Using that sequence will badly mess
up the runtime's tracking of task state, but it might still work,
and more importantly things will still build, which solves the
short-term problem.  Hopefully we can remove this hack soon.

Fixes rdar://problem/80787731.
2021-07-20 20:31:40 -04:00
Doug Gregor
1a024e96c8 Remove UnownedJob.run(). It never did anything anyway 2021-07-08 13:23:42 -07:00
Ben Rimmington
d3d87e8447 [Concurrency] Deprecate typealias PartialAsyncTask (#38042)
Deprecate typealias PartialAsyncTask, and move it into the "SourceCompatibilityShims.swift" file.
2021-06-23 21:16:17 +01:00
Doug Gregor
eda5b4daad [Concurrency] Alternative Task API.
The `Task` type has oscillated somewhat from being purely a namespace,
to having instances that are used (albeit rarely), back to purely
being a namespace that isn't used for all that many names. Many of the
names that used to be on Task have already been moved out, e.g., for
creating new detached tasks, creating new task groups, adding
cancellation handlers, etc.

Collapse `Task.Handle<Success, Failure>` into `Task<Success, Failure>`.
`Task.Handle` is the type that is most frequently referenced in the
concurrency library, so giving it the short name `Task` is most
appropriate. Replace the top-level async/detach functions with a
`Task` initializer and `Task.detached`, respectively.

The `Task` type can still act as a namespace for static operations
such as, e.g., `Task.isCancelled`. Do this with an extension of the
form:

    extension Task where Success == Never, Failure == Never { ... }

We've been accruing a number of compatibility shims. Move them all
into their own source file, deprecate them, and make them
always-emit-into-client so they don't have any ABI impact.
2021-05-18 14:36:21 -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
John McCall
186c53000d Introduce basic support for custom executors.
- Introduce an UnownedSerialExecutor type into the concurrency library.
- Create a SerialExecutor protocol which allows an executor type to
  change how it executes jobs.
- Add an unownedExecutor requirement to the Actor protocol.
- Change the ABI for ExecutorRef so that it stores a SerialExecutor
  witness table pointer in the implementation field.  This effectively
  makes ExecutorRef an `unowned(unsafe) SerialExecutor`, except that
  default actors are represented without a witness table pointer (just
  a bit-pattern).
- Synthesize the unownedExecutor method for default actors (i.e. actors
  that don't provide an unownedExecutor property).
- Make synthesized unownedExecutor properties `final`, and give them
  a semantics attribute specifying that they're for default actors.
- Split `Builtin.buildSerialExecutorRef` into a few more precise
  builtins.  We're not using the main-actor one yet, though.

Pitch thread:
  https://forums.swift.org/t/support-custom-executors-in-swift-concurrency/44425
2021-04-30 03:11:56 -04: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
Doug Gregor
492bca113d [Module interface] Retain #if's with feature checks in inline bodies. 2021-03-30 17:56:42 -07:00
John McCall
98711fd628 Revise the continuation ABI.
The immediate desire is to minimize the set of ABI dependencies
on the layout of an ExecutorRef.  In addition to that, however,
I wanted to generally reduce the code size impact of an unsafe
continuation since it now requires accessing thread-local state,
and I wanted resumption to not have to create unnecessary type
metadata for the value type just to do the initialization.

Therefore, I've introduced a swift_continuation_init function
which handles the default initialization of a continuation
and returns a reference to the current task.  I've also moved
the initialization of the normal continuation result into the
caller (out of the runtime), and I've moved the resumption-side
cmpxchg into the runtime (and prior to the task being enqueued).
2021-03-28 12:58:16 -04:00
Doug Gregor
32702203c5 Add UnsafeThrowingContinuation back as a deprecated typealias.
This helps migrate clients that reference this type.
Fixes rdar://75104903.
2021-03-05 12:21:54 -08: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
ca423f44dd Fix whitespace 2021-02-08 23:30:46 -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
Kavon Farvardin
fabd45e7c3 [concurrency] add resume<E: Error>(with: Result<T, E>) to UnsafeThrowingContinuation
A handy overload that allows one to return a Result<> to
a continuation without needing to manually unwrap it in client code.

Resolves rdar://71870249
2021-01-06 15:01:14 -08:00
Doug Gregor
3c38ffe0ea [Concurrency] await try -> try await
The `try await` ordering is both easier to read and indicates the order
of operations better, because the suspension point occurs first and
then one can observe a thrown error.
2020-12-23 13:21:59 -08:00
Doug Gregor
1a15eb1b7c [Concurrency] Remove extraneous copies of withUnsafe(Throwing)Continuation 2020-12-11 15:42:35 -08:00
Doug Gregor
cc2e32f2fa Merge pull request #34902 from jckarter/continuation-resume-operations
Concurrency: Implement `resume(returning:)` and `resume(throwing:)` for Unsafe*Continuation.
2020-12-07 20:59:03 -08:00
Joe Groff
185f44e2d3 Concurrency: Implement resume(returning:) and resume(throwing:) for Unsafe*Continuation. 2020-12-07 07:47:47 -08:00
Doug Gregor
06a712bff6 Merge pull request #34957 from rjmccall/partial-async-task-is-a-job
Freeze PartialAsyncTask as a Job*
2020-12-04 15:43:44 -08:00
Doug Gregor
18ef1869f3 [Concurrency] Diagnose "try await" with a Fix-It 2020-12-04 00:57:18 -08:00
John McCall
ee0bb0a2d5 Freeze PartialAsyncTask as a Job*.
Also fix the extra inhabitants of Builtin.RawUnsafeContinuation
and try to make adding types like this a little less boiler-plate
in the future.
2020-12-04 01:06:29 -05:00
Slava Pestov
9b3cd280b5 Concurrency: Implement high-level withUnsafe[Throwing]Continuation entry points
These functions call the corresponding built-ins,
wrapping the Builtin.RawUnsafeContinuation value
in an Unsafe[Throwing]Continuation<T>.
2020-12-01 20:05:17 -05:00
Slava Pestov
361eef2af0 Concurrency: Change Unsafe[Throwing]Continuation<T> to store a RawUnsafeContinuation 2020-12-01 20:04:11 -05:00
Joe Groff
f922eb237c Coalesce multiple Unsafe*Continuation definitions.
We somehow ended up with a set hidden in `Task` as well as a set at top level. SILGen currently
hooks into the top-level ones, so shed the `Task`-namespaced versions for now.
2020-11-19 09:05:11 -08:00
Joe Groff
368dc0f401 SILGen: Generate bodies for completion handler block impls 2020-11-10 16:36:50 -08:00
Joe Groff
f72afc8110 Merge pull request #34519 from jckarter/async-sil-tweaks
Async sil tweaks
2020-10-30 16:49:26 -07:00
Joe Groff
a9221219ab Make Unsafe*Continuation @frozen, so we can assume they're trivial 2020-10-30 11:08:24 -07:00
Konrad `ktoso` Malawski
9023e56bd9 [Concurrency] Add minimal placeholders for Task and UnsafeContinuation 2020-10-26 19:02:02 +09:00
Joe Groff
a664a33b52 SIL: Add instructions to represent async suspend points.
`get_async_continuation[_addr]` begins a suspend operation by accessing the continuation value that can resume
the task, which can then be used in a callback or event handler before executing `await_async_continuation` to
suspend the task.
2020-10-01 14:21:52 -07:00
Doug Gregor
9b0266cf6a [Concurrency] Stub out an experimental concurrency support library.
The experimental concurrency model will require a supporting runtime
and possibly end-user-visible library constructs. Introduce a stub of
such a library, enabled by a new `build-script` option
`--enable-experimental-concurrency`, so we have a place to put this
work.
2020-07-29 16:32:27 -07:00