Commit Graph

1608 Commits

Author SHA1 Message Date
Konrad `ktoso` Malawski
e7342eb878 Merge pull request #39365 from kateinoigakukun/katei/fix-coop-executor-part-2
[Concurrency] repair cooperative executor and its tests
2021-09-27 09:47:09 +09:00
Doug Gregor
aad7ad00ee Make sure we set configuration in back-deployed concurrency libraries. 2021-09-22 21:24:25 -07:00
Doug Gregor
4c9fb2899f Avoid including "llvm/Config/config.h" in the concurrency back-deploy library
We only build for one flavor of platforms anyway, and have generally avoided
these macros.
2021-09-22 21:17:44 -07:00
Doug Gregor
3c21857d7f Extend and test install_name symbols for back-deployed concurrency.
With these magic symbols, programs that link against the _Concurrency
module with a deployment target prior to iOS 15 / macOS 12 / watchOS 8
will reference `libswift_Concurrency.dylib` via rpath.

Fixes rdar://81187835.
2021-09-22 13:39:09 -07:00
Varun Gandhi
5743040cc0 Add magic symbols for concurrency. 2021-09-22 12:37:18 -07:00
Yuta Saito
1b56c037a3 [test] fix runtime unittests for single threaded runtime
Some headers switch their inline implementations based on
SWIFT_STDLIB_SINGLE_THREAD_RUNTIME definition.
This fixes linking failure while building runtime unittests
2021-09-19 14:37:29 +00:00
Yuta Saito
5da91ff702 [Concurrency] repair cooperative main executor
This patch repairs the build failure for cooperative executor.
And also fixed main executor to avoid assertion failure due to
`witnessTable == nullptr`
2021-09-19 12:47:07 +00:00
Arnold Schwaighofer
a1a9dd16ce Change the logic to exclude extended frame info on all platforms but darwin 2021-09-14 12:48:27 -07:00
Arnold Schwaighofer
2381233ac1 Add flag -swift-async-framepointer=auto,never,always to
control swift extended frame information emission

On linux we default to disable the extended frame info (since the system
libraries don't support it).

On darwin the default is to automatically choose based on the deployment target.

The Concurrency library explicitly forces extended frame information and the
back deployment library explicitly disables it.
2021-09-14 12:47:16 -07:00
Konrad `ktoso` Malawski
d853f9baef Merge pull request #39295 from ktoso/wip-dont-leak-queue-items 2021-09-14 23:01:16 +09:00
Konrad `ktoso` Malawski
11943005c3 [Concurrency] Call TaskGroupImpl destructor; stop leaking groups 2021-09-14 13:41:44 +09:00
Doug Gregor
136a40aaad Use private concurrent queues for back-deployed concurrency.
Older Dispatch versions have width-limited concurrent queues. While not
as good as the newly-introduced cooperative queues, they at least
address the thread-explosion problem, so use them in the back-deployed
concurrency libraries.

Implements rdar://81131034.
2021-09-13 15:20:06 -07:00
Wei Wang
3cc89bf1ed Fix a typo
Just reading the source and happens to encounter it.
2021-09-09 12:09:15 +09:00
Doug Gregor
22551cf517 Merge pull request #39158 from ktoso/wip-fix-group-leak
[Concurrency] Stop TaskGroup from holding onto Tasks forever (leaking)
2021-09-08 08:47:10 -07:00
Doug Gregor
9a7584750a Merge pull request #39197 from DougGregor/back-deploy-concurrency-no-fp-flag 2021-09-08 06:47:45 -07:00
Konrad `ktoso` Malawski
f336404ae9 [Concurrency] TaskGroup children remove their records as they complete
If we didn't do this (and we didn't), the tasks get released as we
perform the next() impl, and move the value from the ready task to the
waiting task. Then, the ready task gets destroyed.

But as the task group exists, it performs a cancelAll() and that
iterates over all records. Those records were not removed previously
(!!!) which meant we were pointing at now deallocated tasks.

Previously this worked because we didn't deallocate the tasks, so they
leaked, but we didn't crash. With the memory leak fixed, this began to
crash since we'd attempt to cancel already destroyed tasks.

Solution:
- Remove task records whenever they complete a waiting task.
- This can ONLY be done by the "group owning task" itself, becuause
  the contract of ONLY this task being allowed to modify records. o
  It MUST NOT be done by the completing tasks as they complete, as it
  would race with the owning task modifying this linked list of child
  tasks in the group record.
2021-09-04 20:09:55 +09:00
Konrad `ktoso` Malawski
d4ebc58754 [Concurrency] Fix group child tasks not being released
The proper handling of task group child tasks is that:
- if it completes a waiting task immediately, we don't need to retain it
  - we just move the value to the waiting task and can destroy the task
- if we need to store the ready task and wait for a waiting task (for a
  task that hits `await group.next()`) then we need to retain the ready
  task.
  - as the waiting task arrives, we move the value from the ready task
    to the waiting task, and swift_release the ready task -- it will now
    be destroyed safely.
2021-09-04 20:00:39 +09:00
Mike Ash
09f3d9932a [Concurrency] Add availability checking when calling voucher_needs_adopt from the SDK. 2021-09-03 14:14:25 -04:00
Mike Ash
c4115ccbcb Merge pull request #39115 from mikeash/voucher-propagation
[Concurrency] Propagate Darwin vouchers across async tasks.
2021-09-03 11:09:27 -04:00
Doug Gregor
03956e0421 Make swift_async_extendedFramePointerFlags = 0 in back-deployed configurations.
`swift_async_extendedFramePointerFlags` is used in back-deployed
concurrency code as a mask to set the extended async frame info bit on
OS versions that understand it. Set this mask to zero in the
back-deployed libraries.
2021-09-02 16:10:51 -07:00
Mike Ash
a80a19b1e1 [Concurrency] Propagate Darwin vouchers across async tasks.
Darwin OSes support vouchers, which are key/value sets that can be adopted on a thread to influence its execution, or sent to another process. APIs like Dispatch propagate vouchers to worker threads when running async code. This change makes Swift Concurrency do the same.

The change consists of a few different parts:

1. A set of shims (in VoucherShims.h) which provides declarations for the necessary calls when they're not available from the SDK, and stub implementations for non-Darwin platforms.
2. One of Job's reserved fields is now used to store the voucher associated with a job.
3. Jobs grab the current thread's voucher when they're created.
4. A VoucherManager class manages adoption of vouchers when running a Job, and replacing vouchers in suspended tasks.
5. A VoucherManager instance is maintained in ExecutionTrackingInfo, and is updated as necessary throughout a Job/Task's lifecycle.

rdar://76080222
2021-09-02 17:45:28 -04:00
Doug Gregor
95d84d6581 Allow a Swift 5.5 compiler to process the new _Concurrency module.
Swift 5.5 does not implement support for structural types that are
Sendable, which breaks type checking of the newer _Concurrency module.
Work around the issue with an `#if` in the offending inline code.

Fixes rdar://82602353.
2021-09-02 12:22:32 -07:00
Doug Gregor
d844d0b82b Merge pull request #39102 from DougGregor/back-deploy-standalone
Make the back-deployed concurrency dylibs depend only on what's available in older runtimes
2021-08-31 09:05:21 -07:00
Yuta Saito
f6f756e851 [Concurrency] repair cooperative global executor (#39092)
`SWIFT_STDLIB_SINGLE_THREADED_RUNTIME` mode has been broken for a long time.

This patch guards some includes and use of libdispatch headers so that platforms
that doesn't support libdispatch can build cooperative executor runtime.
And fixed missing implementations for cooperative mode.
2021-08-31 09:31:50 +01:00
Doug Gregor
6fd85ac7a3 Clone exclusivity save/restore for tasks into back-deployment library
The code that saves/restores the exclusivity checks for tasks was
newly introduced into the runtime. Clone that code into the back-
deployed version of the runtime.
2021-08-30 16:39:33 -07:00
Doug Gregor
2fe8d03599 Disable job-based dispatch integration in the back-deployed library. 2021-08-30 11:36:16 -07:00
Doug Gregor
599974367e Enable concurrency back-deployment in the compiler by default.
Remove the option that explicitly enables concurrency back-deployment,
and instead always enable its support in the compiler. Remove the use
of the extraneous CMake option as well.
2021-08-28 22:43:41 -07:00
Doug Gregor
b6f67135fc Merge pull request #39051 from DougGregor/concurrency-back-deploy-libraries
Add an option to build the concurrency library for back deployment.
2021-08-26 14:19:31 -07:00
Doug Gregor
51e4fd2342 Address a few more warnings in the concurrency library 2021-08-26 10:56:48 -07:00
Doug Gregor
4a63884026 Add missing Sendable requirements and a conformance 2021-08-26 10:56:48 -07:00
Doug Gregor
ebd7b49755 Build compiler, other libraries, and tests for back-deployed concurrency.
When build-script is given `--back-deploy-concurrency`, also use that
to build other parts of Swift with the back-deployed versions:

* The compiler allows async and actors to be defined with the
back-deployed availability, e.g., the same as `-Xfrontend
-enable-experimental-back-deploy-concurrency`. (The latter will go
away soon)
* The standard library unit testing framework and distributed actors
library are build with the older OS versions.
* The tests use the older OS versions, with some adjustments to make
them agnostic to the back-deployment setting.
2021-08-26 08:49:44 -07:00
Doug Gregor
f2995a3755 Optionally build the compiler and _Concurrency library for back deployment.
When enabling the build of the back-deployable concurrency library via
the build-script option `--back-deploy-concurrency`, also build the
compiler and (main) concurrency library to support older deployment targets.

Building the compiler for older deployment targets is effectively the
same as implicitly passing
`-Xfrontend -enable-experimental-back-deploy-concurrency`. That option
should probably go away.

Building the primary _Concurrency library for back-deployment means
setting the "SwiftStdlib 5.5" availability back to the earlier
deployment targets. This should have no effect on how the _Concurrency
library binary is built, but it does ensure that the right
availability annotations are in the _Concurrency module.
2021-08-26 08:49:44 -07:00
Doug Gregor
3f749dc13b Add an option to build the concurrency library for back deployment.
Introduce an additional build product to build-script to build
back-deployable concurrency libraries. These libraries would need to
be embedded in apps deployed prior to macOS 12/iOS 15 to support
concurrency.

The built-script option `--back-deploy-concurrency` can be provided to
build these back-deployment libraries. They are built in addition to
the normal concurrency libraries, as a separate product that installs
into `lib/swift-5.5/<platform>` within the toolchain. The macro
`SWIFT_CONCURRENCY_BACK_DEPLOYMENT` is set when building the
concurrency library, so that we can adapt the implementation to older
OS's.
2021-08-26 08:49:43 -07:00
swift-ci
45eaaa2398 Merge pull request #39042 from mikeash/swift-task-debug-printf-cleanup 2021-08-25 14:30:03 -07:00
Evan Wilde
5882e03a75 Merge pull request #38819 from etcwilde/ewilde/remove-runAsyncAndBlock-internals
Remove run async and block internals
2021-08-25 13:10:50 -07:00
Mike Ash
d5c0469f3e [Concurrency] Replace SWIFT_TASK_PRINTF_DEBUG with a SWIFT_TASK_DEBUG_LOG macro.
This macro takes the string and parameters directly, and is conditionally defined to either call fprintf or ignore its arguments. This makes the call sites a little more pleasant (no #if scattered about) and ensures every log includes the thread ID and a newline automatically.
2021-08-25 10:47:36 -04:00
Joe Groff
1007cc91a4 Merge pull request #38911 from jckarter/async-let-throw-completion-order
Concurrency: Don't rely on future wait context in asyncLet_finish.
2021-08-18 09:19:44 -07:00
Joe Groff
745467d71b Concurrency: Don't rely on future wait context in asyncLet_finish.
If a future task has already completed, then task_future_wait doesn't populate the future context,
but asyncLet_finish was inappropriately relying on it to recover the result buffer pointer to
destroy the value inside. There's room in asyncLet_finish's own context to put this pointer, so
do that instead. Fixes rdar://81481317.
2021-08-17 14:15:17 -07:00
Doug Gregor
a8d119a6de [SE-0311] Add Sendable requirement to TaskLocal.
This is part of SE-0311 that was not implemented.
Fixes rdar://77441933.
2021-08-16 14:19:08 -07:00
Doug Gregor
3723c2f685 Adopt Sendable in the Task APIs 2021-08-14 08:13:10 -07:00
Konrad `ktoso` Malawski
bf37ba6014 [Distributed] Don't duplicate hasUserDefinedInit entry, less guards 2021-08-12 19:35:01 +09:00
Konrad `ktoso` Malawski
829a5d6895 [Distributed] Review followup and cleanups 2021-08-12 14:09:03 +09:00
Konrad `ktoso` Malawski
9dcd6e43f3 [Distributed] implement more deinit tests 2021-08-12 14:09:03 +09:00
Konrad `ktoso` Malawski
a99e935050 [Distributed] implemented storing transport in resolve 2021-08-12 14:09:02 +09:00
Konrad `ktoso` Malawski
aaf81371ef [Distributed] work in progress SIL actorReady call 2021-08-12 14:09:02 +09:00
Konrad `ktoso` Malawski
7e0a3eba13 [Distributed] Implementing calling transport in resolve and assigning id/transp 2021-08-12 14:08:58 +09:00
Kavon Farvardin
d4c71943bd [distributed] working on runtime allocation function 2021-08-12 14:05:31 +09:00
Evan Wilde
19063508cc Remove AsyncCall.h
None of the function in AsyncCall are in use anymore so we can delete
it. This contained code for implementing swift asynchronous functions in
C++.
2021-08-09 16:40:35 -07:00
Evan Wilde
77cf7c6883 Remove old runAsyncAndBlock internals
runAsyncAndBlock has long been dead, I'm pulling out the machinery that
lives in the runtime that used to support it. This is the first layer
that can go away.
2021-08-09 14:54:05 -07:00
Varun Gandhi
79d45c0a96 Merge pull request #38477 from varungandhi-apple/vg-deprecate-old-sleep
[Concurrency] Deprecate Task.sleep(_:) in favor of Task.sleep(nanoseconds:).
2021-08-09 10:57:41 -07:00