Commit Graph

138 Commits

Author SHA1 Message Date
Konrad `ktoso` Malawski
54dec38a34 initial complete impl 2023-01-05 16:19:05 +09:00
Konrad `ktoso` Malawski
f8b85015c1 prepare flags
wip on options

implement discardResults as a flag passed to grout init
2023-01-05 16:19:05 +09:00
Konrad `ktoso` Malawski
1a3403524c [Concurrency] Optimize Void task group, to not store completed tasks anymore 2023-01-05 16:19:05 +09:00
Nate Chandler
c9d86eed75 [Freestanding] Disable child task priority spec.
Under the task-to-thread model, specifying a priority doesn't make
sense.

Here, variations of addTask and addTaskUnlessCancelled are introduced
which do not take a priority.  Additionally, the original functions are
made unavailable.
2022-10-18 11:25:10 -07:00
Rokhini Prabhu
a606892155 Task group children should be executed on parent task at time of await 2022-09-01 10:02:25 -07:00
Alex Martini
8556e8337a Merge pull request #60178 from amartini51/doc_fixes
Documentation fixes
2022-08-24 13:53:24 -07:00
Doug Gregor
cf9a7478c3 Apply @_unsafeInheritExecutor to with(Throwing)TaskGroup.
Fixes rdar://98461630.
2022-08-19 13:06:41 -07:00
Alex Martini
f8b716947d Add missing 'try' for throwing async code.
Fixes <rdar://97022479>
2022-07-21 11:25:39 -07:00
Jager-yoo
ce6005d870 [Concurrency] fix grammatically incorrect phrase 2022-06-04 14:50:09 +09:00
Josh Soref
7a57e7ce99 Spelling stdlib/public/concurrency (#42443)
* spelling: already

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: appropriate

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: asynchronous

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: cancel

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: divisible

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: execution

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: initialized

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: normally

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: preprocessed

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: priority

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: some

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: success

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: suspending

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: the

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: throws

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

Co-authored-by: Josh Soref <jsoref@users.noreply.github.com>
2022-04-21 11:12:57 -07:00
Rokhini Prabhu
835f274183 Make sure that cancelling a task group does not invoke cancellation
handler of parent task that created the group

Change comment in TaskGroup.swift to enforce that only parent task can
call cancelAll on the group

Add tests to verify mutating of task group in child tasks will fail

Radar-Id: rdar://problem/86346865
2021-12-17 18:35:39 -08:00
Doug Gregor
c4e8844fdb Merge pull request #40616 from DougGregor/concurrency-sendable-frozen-types 2021-12-17 16:47:40 -08:00
Doug Gregor
400404cf3a Explicit Sendable conformances for @frozen types
Task groups and `UnsafeCurrentTask` are non-`Sendable`.
`UnownedSerialExecutor` is always `Sendable`.

Fixes rdar://86496341.
2021-12-17 11:10:29 -08:00
Alex Martini
5d6c179df1 Add missing 'else' to guard statements.
Fixes <rdar://84895831>.
2021-12-07 12:09:14 -08:00
Alex Martini
3977d8ede8 Cherry pick Swift 5.5 doc changes in TaskGroup.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
Mike Ash
c60b68608c [Concurrency] Re-fix ABI regression in task groups due to Sendable requirements.
There was an attempted fix in bed3c4b313 but it had extra underscores at the start of the @_silgen_name identifiers.

rdar://83617067
2021-10-26 11:40:52 -04:00
Doug Gregor
bed3c4b313 Fix ABI regression in task groups due to Sendable requirements.
Top-level functions still encode inferred requirements in the mangled name.
In this case, `Sendable` has no ABI impact beyond the effect on the mangled
name, so fix the mangled names to maintain ABI.

Fixes rdar://83617067.
2021-10-12 15:26:19 -07:00
Doug Gregor
3723c2f685 Adopt Sendable in the Task APIs 2021-08-14 08:13:10 -07:00
Doug Gregor
9222bf2cf0 Make ThrowingTaskGroup.nextResult() non-throwing.
We erroneously marked this API as `throws`, even though it returns its
error via a `Result` instead. Remove the `throws` in a strange-looking
manner so that we maintain the existing ABI.

Fixes rdar://81585954.
2021-08-05 16:58:47 -07:00
Doug Gregor
59d1e61ac4 [SE-0304] Implement cancellable Task.sleep(nanoseconds:). 2021-07-08 09:46:07 -07:00
Doug Gregor
20c8bd12e8 [SE-0304] Add (Throwing)?TaskGroup.waitForAll()
Do this as a staged change to the ABI, introducing an underscored
`@usableFromInline` implementation to the ABI that we can rely on
later, and an `@_alwaysEmitIntoClient` version we can inline now.
2021-07-07 20:49:33 -07:00
Doug Gregor
04dd840ba3 [SE-0304] Replace the async operations in (Throwing)TaskGroup with addTask 2021-07-07 17:04:52 -07:00
Doug Gregor
819615eab1 Make Swift task-creation entry points always-emit-into-client.
The `swift_task_create` entry point is our general runtime ABI for
launching tasks. Make the various Swift APIs sitting on top of it
always-emit-into-client to take them out of the ABI. This reduces the
number of ABI entry points and allows us to make more ABI-compatible
changes to the Swift side.
2021-06-24 07:53:19 -07:00
Doug Gregor
e7e922ea77 Introduce a createAsyncTaskInGroup SIL builtin.
Rather than using group task options constructed from the Swift parts
of the _Concurrency library and passed through `createAsyncTask`'s
options, introduce a separate builtin that always takes a group. Move
the responsibility for creating the options structure into IRGen, so
we don't need to expose the TaskGroupTaskOptionRecord type in Swift.
2021-06-24 07:53:18 -07:00
Doug Gregor
29b45a3087 Use withUnsafePointer(to:) rather than withUnsafeBytes(of:) 2021-06-24 07:53:18 -07:00
Doug Gregor
a4af1a71f6 Use withUnsafeBytes(of:) properly for getting the address of a local variable 2021-06-24 07:53:18 -07:00
Doug Gregor
dafb574a35 Switch task group child task creation over to Builtin.createAsyncTask().
Extend the behavior of `swift_task_create_common` to also encompass
adding the pending group task (when requested) and attaching it to the
group.
2021-06-24 07:53:18 -07:00
swift-ci
9815b0475f Merge pull request #38072 from ktoso/wip-taskgroup-cancelled-async 2021-06-24 03:17:37 -07:00
Konrad `ktoso` Malawski
dd10132b12 [Concurrency] Cancelled group should only spawn already cancelled tasks 2021-06-24 09:22:45 +09:00
Doug Gregor
bd56877c36 Change the feature name for BuiltinTaskGroup.
The `createTaskGroup` builtin has changed its signature and now requires
a type metadata argument. Change the feature accordingly so that
compilers with the new and old versions have disjoint feature sets.

Fixes rdar://79561865.
2021-06-22 21:59:19 -07:00
Konrad `ktoso` Malawski
8536100354 [Concurrency] introduce task options, and change ABI to accept them
introduce new options parameter to all task spawning

[Concurrency] ABI for asynclet start to accept options

[Concurrency] fix unittest usages of changed task creation ABI

[Concurrency] introduce constants for parameter indexes in ownership

[Concurrency] fix test/SILOptimizer/closure_lifetime_fixup_concurrency.swift
2021-06-21 13:03:50 +09:00
Arnold Schwaighofer
10e3d2e3af Change _wait(_throwing) ABIs to reduce code size
Changes the task, taskGroup, asyncLet wait funtion call ABIs.

To reduce code size pass the context parameters and resumption function
as arguments to the wait function.

This means that the suspend point does not need to store parent context
and resumption to the suspend point's context.

```
  void swift_task_future_wait_throwing(
    OpaqueValue * result,
    SWIFT_ASYNC_CONTEXT AsyncContext *callerContext,
    AsyncTask *task,
    ThrowingTaskFutureWaitContinuationFunction *resume,
    AsyncContext *callContext);
```

The runtime passes the caller context to the resume entry point saving
the load of the parent context in the resumption function.

This patch adds a `Metadata *` field to `GroupImpl`. The await entry
pointer no longer pass the metadata pointer and there is a path through
the runtime where the task future is no longer available.
2021-06-08 10:41:26 -07: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
Fred Riss
bbda706393 [Concurrency] Add a unique Task ID to AsyncTask
This commit changes JobFlags storage to be 32bits, but leaves the runtime
API expressed in terms of size_t. This allows us to pack an Id in the
32bits we freed up.

The offset of this Id in the AsyncTask is an ABI constant. This way
introspection tools can extract the currently running task identifier
without any need for special APIs.
2021-05-11 08:28:17 -07:00
Doug Gregor
38b652db94 Add "async" aliases to task group "spawn" operations 2021-05-07 00:23:09 -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
Konrad `ktoso` Malawski
1cd7180382 [Concurrency] don't require Sendable (yet) on groups and locals 2021-05-03 10:52:06 +09:00
Doug Gregor
5cc451cae8 Merge pull request #37159 from DougGregor/concurrency-priority-cleanup 2021-04-30 07:01:56 -07:00
Doug Gregor
cdc6dbe11d [Concurrency] Deprecate Task.Priority.unspecified and use optionals instead 2021-04-29 22:16:02 -07:00
Konrad `ktoso` Malawski
58ea749304 [TaskLocal] Crash on inapropriate use within task group 2021-04-29 15:48:22 +09:00
Konrad `ktoso` Malawski
3d96d05546 [TaskLocals] property wrapper keys 2021-04-29 15:48:09 +09:00
Konrad `ktoso` Malawski
ba615029c7 [Concurrency] Store child record when async let child task spawned 2021-04-19 10:06:23 +09:00
Evan Wilde
6c7b2af580 Remove await from spawnUnlessCancelled
spawnUnlessCancelled is not an asynchronous function, so awaiting on it
in the standard library resulted in warnings.
2021-04-13 18:29:17 -07:00
John McCall
efeb818161 Clean up the TaskGroup ABI:
- stop storing the parent task in the TaskGroup at the .swift level
- make sure that swift_taskGroup_isCancelled is implied by the parent
  task being cancelled
- make the TaskGroup structs frozen
- make the withTaskGroup functions inlinable
- remove swift_taskGroup_create
- teach IRGen to allocate memory for the task group
- don't deallocate the task group in swift_taskGroup_destroy

To achieve the allocation change, introduce paired create/destroy builtins.

Furthermore, remove the _swiftRetain and _swiftRelease functions and
several calls to them.  Replace them with uses of the appropriate builtins.
I should probably change the builtins to return retained, since they're
working with a managed type, but I'll do that in a separate commit.
2021-04-09 03:06:31 -04:00
swift-ci
56b86b6cf1 Merge pull request #36766 from ktoso/wip-add-deprecated-shims-old-task-api 2021-04-06 00:50:33 -07:00
Konrad `ktoso` Malawski
d8b4e3c304 [Concurrency] add deprecated shim for Task.withGroup 2021-04-06 12:51:55 +09:00
Konrad `ktoso` Malawski
9949bf440d updated to latest Task APIs 2021-04-06 07:20:07 +09:00
Konrad `ktoso` Malawski
0857d0f62b remove last mention of spawnDetached 2021-04-03 10:08:11 +09:00
Konrad `ktoso` Malawski
a5ac6f06fa [Concurrency] detach, spawnUnlessCancelled, priority param cleanup 2021-04-03 09:54:42 +09:00