Commit Graph

16 Commits

Author SHA1 Message Date
Alastair Houghton
28732f4a8b Revert "[Concurrency] Add underscore prefixes for not yet official API." 2025-05-20 15:44:26 +01:00
Alastair Houghton
c0ccdffeb7 [Concurrency] Add underscore prefixes for not yet official API.
Custom main and global executors work hasn't passed Swift Evolution yet,
so we need to avoid leaking it as API until it does.

To that end, underscore all the things.

rdar://151147606
2025-05-14 11:57:06 +01:00
Alastair Houghton
e843a24a99 [Concurrency] Fix issue with using Dispatch queues as executors.
We were failing to switch executors to Dispatch queues, where those
were being used as executors, which caused a variety of unusual
symptoms.

rdar://150310927
2025-04-30 14:18:42 +01:00
Konrad 'ktoso' Malawski
e1dc854f8f [Concurrency] Change isIsolatingCurrent... to return Bool?
This changes the isIsolatingCurrentContext function to return `Bool?`
and removes all the witness table trickery we did previously to detect
if it was implemented or not. This comes at a cost of trying to invoke
it always, before `checkIsolated`, but it makes for an simpler
implementation and more checkable even by third party Swift code which
may want to ask this question.

Along with the `withSerialExecutor` function, this now enables us to
check the isolation at runtime when we have an `any Actor` e.g. from
`#isolation`.

Updates SE-0471 according to
https://forums.swift.org/t/se-0471-improved-custom-serialexecutor-isolation-checking-for-concurrency-runtime/78834/
review discussions
2025-04-29 20:08:55 +09:00
Alastair Houghton
3d0d0b4328 [Concurrency] Make initial executor construction fully thread safe.
I had originally thought that we'd get away without this because the
executor construction generally happens in the async `main` function,
but of course if a program doesn't already use Swift Concurrency,
and someone uses it from a plug-in or library it loads, there's a
risk that we might have a race condition.

rdar://149346132
2025-04-17 21:48:42 +01:00
Alastair Houghton
0c96a257f6 [Concurrency] Fix task-to-thread model linking.
We need to provide some of the additional functions, as stubs, for
task-to-thread model.

rdar://141348916
2025-03-28 10:15:14 +00: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
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
c20aa667f2 [Concurrency] Disable various things for task-to-thread model.
When in task-to-thread model concurrency mode, there is no `MainActor`
and we cannot use `ExecutorJob`, so disable various things.

rdar://141348916
2025-03-19 11:15:00 +00:00
Alastair Houghton
a4f79f367a [Concurrency][Linux] Fix WASI build.
This doesn't actually add proper WASI support - it just fixes the
build so that we're no worse off than we were.

rdar://141348916
2025-03-14 14:57:15 +00:00
Alastair Houghton
fc67cc3b60 [Concurrency] Mark expressions as unsafe.
Also fix a missing availability annotation.

rdar://141348916
2025-03-13 13:37:43 +00:00
Alastair Houghton
b33666cf08 [Concurrency] Fixes from initial review.
Rename `DispatchTaskExecutor` to `DispatchGlobalTaskExecutor` as we
may want to use the former for an executor that runs things on an
arbitrary Dispatch queue.

Rename `DispatchExecutor` to `DispatchExecutorProtocol`; again, we
might want the name for something else.

Add `@Sendable` attribute to `registerEvent`.

Fix missing `extern "C" SWIFT_CC(swift)` on `_swift_exit` (merge
error).

Remove stray whitespace from `CMakeLists.txt`

rdar://141348916
2025-03-13 13:37:43 +00:00
Alastair Houghton
d14b9370fb [Concurrency] Don't use blocks.
We can't use blocks, because Swift doesn't support them on Linux or
Windows.  Instead, use a C function pointer, and box up the handler.

rdar://141348916
2025-03-13 13:37:43 +00:00
Alastair Houghton
ef0e09d0b7 [Concurrency][Embedded] Remove MainActor/MainExecutor everywhere.
Embedded Swift doesn't have MainActor, so remove it.

rdar://141348916
2025-03-13 13:37:43 +00:00
Alastair Houghton
55afa47bea [Concurrency] More work on the custom executor implementation.
Added an `-executor-factory` argument to the compiler to let you safely
specify the executors you wish to use (by naming a type that returns
them).

Also added some tests of the new functionality.

rdar://141348916
2025-03-13 13:34:41 +00: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