Commit Graph

250 Commits

Author SHA1 Message Date
Konrad `ktoso` Malawski
d3c5ebc9b7 [AsyncLet] reimplemented with new ABI and builtins 2021-04-19 10:06:23 +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
9b82fec131 Merge pull request #36457 from etcwilde/ewilde/delete-runAsyncAndBlock
[Concurrency] Delete runAsyncAndBlock
2021-04-16 08:40:30 -07:00
Evan Wilde
9b15a9ffad Delete runAsyncAndBlock once and for all! 2021-04-14 15:04:56 -07:00
Konrad `ktoso` Malawski
5e0593f1d3 [Concurrency] detach should not take Failure type param 2021-04-15 06:59:35 +09:00
Doug Gregor
e77a27e8ed [Concurrency] Introduce runtime detection of data races.
Through various means, it is possible for a synchronous actor-isolated
function to escape to another concurrency domain and be called from
outside the actor. The problem existed previously, but has become far
easier to trigger now that `@escaping` closures and local functions
can be actor-isolated.

Introduce runtime detection of such data races, where a synchronous
actor-isolated function ends up being called from the wrong executor.
Do this by emitting an executor check in actor-isolated synchronous
functions, where we query the executor in thread-local storage and
ensure that it is what we expect. If it isn't, the runtime complains.
The runtime's complaints can be controlled with the environment
variable `SWIFT_UNEXPECTED_EXECUTOR_LOG_LEVEL`:

  0 - disable checking
  1 - warn when a data race is detected
  2 - error and abort when a data race is detected

At an implementation level, this introduces a new concurrency runtime
entry point `_checkExpectedExecutor` that checks the given executor
(on which the function should always have been called) against the
executor on which is called (which is in thread-local storage). There
is a special carve-out here for `@MainActor` code, where we check
against the OS's notion of "main thread" as well, so that `@MainActor`
code can be called via (e.g.) the Dispatch library's
`DispatchQueue.main.async`.

The new SIL instruction `extract_executor` performs the lowering of an
actor down to its executor, which is implicit in the `hop_to_executor`
instruction. Extend the LowerHopToExecutor pass to perform said
lowering.
2021-04-12 15:19:51 -07:00
swift-ci
5db3caf9cc Merge pull request #36855 from apple/ktoso-patch-3 2021-04-09 19:53:03 -07:00
Konrad `ktoso` Malawski
34d1e27565 [Concurrency] runDetached shim must be static 2021-04-10 08:54:41 +09: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
39e97c57f2 [Concurrency] add deprecated shim for runDetached 2021-04-06 11:17:25 +09:00
Konrad `ktoso` Malawski
9949bf440d updated to latest Task APIs 2021-04-06 07:20:07 +09:00
Konrad `ktoso` Malawski
fde8098a37 [Concurrency] remove workaround for void task handles rdar://74957357 2021-04-05 16:59:00 +09:00
Konrad `ktoso` Malawski
a180f532b5 [Concurrency] Simple Task.yield implementation 2021-04-05 16:59:00 +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
Konrad `ktoso` Malawski
34f8e768b5 spawnDetached to detach, non-suspending group.spawn, spawnUnlessCancelled 2021-04-03 09:53:32 +09:00
Konrad `ktoso` Malawski
6e746304e1 [Concurrency] Update Task and Group APIs based on Review 1 2021-04-03 09:52:03 +09: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
Dario Rexin
3daf37f221 [Concurrency] Use correct type for Task.Handle in Task.sleep (#36654) 2021-03-31 12:45:44 -07:00
Doug Gregor
46c9de8ba8 [Concurrency] Work around issue with old compilers and newer _Concurrency lib
Fixes rdar://75996690.
2021-03-30 16:27:08 -07:00
Joe Groff
698a975a23 Merge pull request #36586 from jckarter/owned-task-spawn-closures
Allow closures to be `__owned` or `__shared`, and make task spawning closures `__owned`
2021-03-25 16:02:07 -07:00
Joe Groff
c6691f3919 Allow closures to be __owned or __shared, and make task spawning closures __owned 2021-03-25 11:36:33 -07:00
Nate Cook
86b69b98cc Fix license headers in concurrency source files 2021-03-25 10:12:02 -05:00
Konrad `ktoso` Malawski
92933a17f2 Merge pull request #36297 from apple/ktoso-patch-3
[Concurrency] remove Task.hasTaskLocalValues, they all do
2021-03-21 22:58:24 +09:00
Doug Gregor
52096a640e SE-0302: Rename ConcurrentValue/@concurrent to Sendable/@Sendable. 2021-03-18 23:48:21 -07:00
John McCall
6c879d6fd3 Change the async ABI to not pass the active task and executor.
Most of the async runtime functions have been changed to not
expect the task and executor to be passed in.  When knowing the
task and executor is necessary, there are runtime functions
available to recover them.

The biggest change I had to make to a runtime function signature
was to swift_task_switch, which has been altered to expect to be
passed the context and resumption function instead of requiring
the caller to park the task.  This has the pleasant consequence
of allowing the implementation to very quickly turn around when
it recognizes that the current executor is satisfactory.  It does
mean that on arm64e we have to sign the continuation function
pointer as an argument and then potentially resign it when
assigning into the task's resume slot.

rdar://70546948
2021-03-16 22:52:54 -04:00
Arnold Schwaighofer
a17de090b6 SILGen: Fix emitBuiltinCreateAsyncTaskFuture
We need to re-abstract the function argument.
I think this should fix rdar://74957357.
2021-03-11 06:44:02 -08:00
Konrad `ktoso` Malawski
0ec038c449 [Concurrency] remove Task.hasTaskLocalValues, they all do 2021-03-05 10:11:29 +09:00
Dario Rexin
54e78cc015 Fix after rebase 2021-03-04 09:37:59 -08:00
Dario Rexin
4bb52ccfbd Workaround for rdar://74957357 2021-03-04 09:37:59 -08:00
Dario Rexin
af4b6bc068 [Concurrency] Add asynchronous Task.sleep function 2021-03-04 09:37:58 -08:00
Evan Wilde
2ee7a322a5 Merge pull request #36239 from etcwilde/ewilde/run-async-main-on-main-thread
[Concurrency] Run async main code on main thread
2021-03-03 09:47:18 -08:00
Evan Wilde
a643fe418e Run async main code on main thread
This patch moves the actual running of the main code onto the main
thread by making it part of the main actor. This should be more
consistent with what folks are expecting.
2021-03-02 22:36:12 -08:00
Konrad `ktoso` Malawski
550018574a [Concurrency] remove unimplemented Task APIs: yield, startingOn 2021-03-03 14:31:01 +09:00
Konrad `ktoso` Malawski
d7169edc21 [TaskLocals] Cleanly separate locals impl from Task, no need for fragment 2021-03-02 00:54:47 +09:00
Konrad `ktoso` Malawski
599572ba54 cleanups of tests after merge 2021-02-25 14:24:43 +09:00
Konrad `ktoso` Malawski
6e525d7469 Merge branch 'main' into wip-no-escape-group 2021-02-25 10:37:20 +09:00
Konrad `ktoso` Malawski
dd9a9a6436 [Concurrency] Task APIs use thread-local ActiveTask now 2021-02-24 19:19:44 +09:00
Konrad `ktoso` Malawski
6f4fca8721 Merge branch 'main' into wip-no-escape-group 2021-02-24 08:59:53 +09:00
John McCall
2012195cd5 Alter the runtime interface for awaiting futures and task groups.
First, just call an async -> T function instead of forcing the caller
to piece together which case we're in and perform its own copy.  This
ensures that the task is actually kept alive properly.

Second, now that we no longer implicitly depend on the waiting tasks
being run synchronously, go ahead and schedule them to run on the
global executor.

This solves some problems which were blocking the work on TLS-ifying
the task/executor state.
2021-02-21 23:48:13 -05:00
Konrad `ktoso` Malawski
a226259d84 [Concurrency] TaskGroup moves out of AsyncTask, non escaping body 2021-02-22 13:26:27 +09:00
Konrad `ktoso` Malawski
40b6b18945 [Concurrency] implement withCancellationHandler via records 2021-02-18 17:27:15 +09:00
swift-ci
c19375790a Merge pull request #35977 from DougGregor/discardable-run-detached 2021-02-15 14:51:51 -08:00
Doug Gregor
6a5dfb8aa4 Mark Task.runDetached as @discardableResult.
Often, this API is used for its side effects and nobody cares about the
handle.
2021-02-15 12:21:49 -08:00
Konrad `ktoso` Malawski
d2bd6abe61 [Concurrency] TaskLocals allow configuring inheritance: never 2021-02-13 20:09:11 +09:00
Konrad `ktoso` Malawski
b811b12246 [Concurrency] TaskLocals lookup "skip" optimization 2021-02-13 10:39:22 +09:00
Konrad `ktoso` Malawski
1044723787 [Concurrency] Initial Task Local Values implementation 2021-02-13 10:39:22 +09:00
Evan
e813bbea76 Merge pull request #35911 from etcwilde/ewilde/deprecate-runAsyncAndBlock
Deprecate runAsyncAndBlock API
2021-02-12 09:51:04 -08:00