Commit Graph

23 Commits

Author SHA1 Message Date
Mike Ash
a62f08e050 [Concurrency] Add environment variable for disabling async stack slab allocator.
Add SWIFT_DEBUG_ENABLE_TASK_SLAB_ALLOCATOR, which is on by default. When turned off, async stack allocations call through to malloc/free. This allows memory debugging tools to be used on async stack allocations.
2025-11-07 22:48:41 -05:00
Alastair Houghton
b1c345f1be Merge pull request #80266 from al45tair/custom-executors-take2
[Concurrency] Provide a Swift interface for custom main and global executors.
2025-03-31 09:53:48 +01:00
Alastair Houghton
47fa71787f Revert "Merge pull request #80224 from glessard/revert-79789-custom-executors"
This reverts commit 06f6358067, reversing
changes made to 033f6679e8.
2025-03-28 10:15:07 +00:00
Nate Chandler
2af30b2f04 [NFC] CoroutineAccessors: Remove old runtime files
The functions are open-coded now.
2025-03-27 19:23:09 -07:00
Nate Chandler
f30d8a603c [CoroutineAccessors] Rehome runtime functions.
Put them where they're meant to be, in swiftCore.
2025-03-27 11:37:26 -07:00
Nate Chandler
0c2a38b10b [CoroutineAccessors] Directly reference allocators
Replace the call to a runtime function that looks up the allocator with
a direct reference to a just-emittedd sought-after global allocator.
2025-03-26 08:35:35 -07:00
Alastair Houghton
8b15b05c63 Revert "[Concurrency] Provide a Swift interface for custom main and global executors." 2025-03-22 02:38:11 -07:00
Alastair Houghton
090c375b7b [Concurrency] Swift interface for custom main and global executors.
Reorganise the Concurrency code so that it's possible to completely
implement executors (both main and global) in Swift.

Provide API to choose the desired executors for your application.

Also make `Task.Sleep` wait using the current executor, not the global
executor, and expose APIs on `Clock` to allow for conversion between
time bases.

rdar://141348916
2025-03-13 13:34:41 +00:00
Nate Chandler
d1f1b4c86b [CoroutineAccessors] Use swiftcorocc if available.
When it's available, use an open-coded allocator function that returns
an alloca without popping if the allocator is nullptr and otherwise
calls swift_coro_alloc.  When it's not available, use the malloc
allocator in the synchronous context.
2025-02-27 18:20:53 -08:00
Nate Chandler
dd8cbe3e0a [CoroutineAccessors] Use retcon.once variant.
Allocate a coroutine frame in the caller based on the size in the
corresponding "function pointer" and pass it along with an allocator to
the callee.
2025-02-27 07:53:58 -08:00
Kuba Mracek
d2dac4ed72 [Concurrency] Avoid relying on stderr, fprintf(), write() in Embedded Concurrency runtime 2024-10-14 13:36:14 -07:00
Kuba Mracek
280123cb10 [embedded] Add a test checking the dependencies of Embedded Concurrency runtime 2024-04-02 10:33:33 -07:00
John McCall
db3967f41d Future-proof the layout of AsyncTask. 2021-05-20 15:30:48 -04:00
Max Desiatov
7be99e4cbf Merge pull request #37084 from kateinoigakukun/katei/share-fatalerror-concurrency
Rename duplicated `swift::fatalError` in `swiftRuntime` and `swift_Concurrency`.

Both `swiftRuntime` and `swift_Concurrency` had `swift::fatalError` implementation, but it causes symbol conflict with the `-static-stdlib` flag.

This patch removes one of the implementations in `swift_Concurrency` to avoid conflicts. Also added a test case to ensure that linking the Concurrency module with `-static-stdlib` works.

This issue was found by SwiftWasm test cases.
2021-05-06 09:46:15 +01:00
Yuta Saito
709359cfab Rename duplicated swift::fatalError definition in swiftRuntime and swift_Concurrency
Both swiftRuntime and swift_Concurrency had swift::fatalError
implementation, but it causes symbol conflict when -static-stdlib.

This patch renames one of the impl in swift_Concurrency to avoid
conflict.
2021-04-28 23:52:18 +09:00
Erik Eckstein
075ad87a40 Concurrency: allocate an async-let task with its parent's stack allocator.
Also, do this for the initial slab for the task's allocator itself.
This avoids memory allocations for async-lets.
In case the async-task's memory demand does not exceed the initial slab size, it is now completely malloc-free.

The refcount bits of an async-let task are initialized to "immortal" so that ARC operations don't have an effect on the task.
2021-04-26 13:07:32 +02: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
Konrad `ktoso` Malawski
cdd136096f reworked includes to stop hitting undefined symbols 2021-02-25 15:15:02 +09:00
Konrad `ktoso` Malawski
a226259d84 [Concurrency] TaskGroup moves out of AsyncTask, non escaping body 2021-02-22 13:26:27 +09:00
Erik Eckstein
ec1490d06e [concurrency] Implement the Task allocator as bump-pointer allocator.
Use the StackAllocator as task allocator.

TODO: we could pass an initial pre-allocated first slab to the allocator, which is allocated on the stack or with the parent task's allocator.

rdar://problem/71157018
2020-12-09 22:22:28 +01:00
John McCall
76d8f03ba4 Make the task allocator verify stack discipline in the laziest possible way. 2020-10-22 00:53:16 -04:00
John McCall
b717c7d823 Prepare for a more real task-local alloocator implementation. 2020-10-22 00:53:16 -04:00
John McCall
c18331c837 Move swift_task_alloc/dealloc into the Concurrency library.
Also, rename them to follow the general namespacing scheme.
2020-10-22 00:53:15 -04:00