Commit Graph

109 Commits

Author SHA1 Message Date
Mike Ash
8fbf0e07f3 [Concurrency] Fix asSerialExecutor() for complex equality.
Complex equality is encoded in the low bit of the witness table pointer. We need to mask off the low bits when bitcasting to an `any SerialExecutor`.

rdar://164005854
2025-11-06 13:20:56 -05:00
Guillaume Lessard
92b54e6434 [concurrency] fix availability of new executor symbols 2025-10-16 21:29:51 -07:00
Stephen Canon
dc04d4f0d4 Revert "[stdlib] Make PlatformExecutorFactory and ExecutorFactory deploy to 6.3 instead of 6.2." 2025-10-15 16:59:32 -04:00
Michael Gottesman
6f5a0c5b5a [stdlib] Make PlatformExecutorFactory and ExecutorFactory deploy to 6.3 instead of 6.2.
This code is public on main, but not on 6.2, so if one compiles a binary for 6.2
on main and then attempts to use a stdlib from a 6.2 aligned macOS, one gets an
ABI error since the type isn't there. Just mark these types as being available
in 6.3 so that way this is future proofed and allows for main binaries to run
against a 6.2 aligned macOS stdlib.
2025-10-13 09:35:46 -07:00
Valeriy Van
c53d71bb2a Fix typos 2025-10-04 12:53:44 +02:00
Alastair Houghton
6046286b58 [Concurrency] Updates after second SE pitch.
We no longer attempt to convert timestamps from the passed-in `Clock`
in order to allow any clock to work with any executor.  Instead,
executors that do not recognise a clock should call the `enqueue`
function on that `Clock`, which lets the `Clock` itself decide how
to proceed.

Additionally, rename `SchedulableExecutor` to `SchedulingExecutor`.
2025-08-26 09:38:11 +01:00
Gábor Horváth
35b5c817b2 Merge pull request #83520 from Xazax-hun/check-safety-function-types 2025-08-08 06:39:39 +01:00
Gabor Horvath
402ad33463 [StrictMemorySafety] Check the safety of return types of calls
Previously, we skipped checking the return type of a function for safety
as we expected to warn at the use of the returned value:

  let x = returnsUnsafe()
  usesUnsafe(x) // warn here

Unfortunately, this resulted in missing some unsafe constructs that can
introduce memory safety issues when the use of the return value had a
different shape resulting in false negatives for cases like:

  return returnsUnsafe()

or

  usesUnsafe(returnsUnsafe())

This PR changes the analysis to always take return types of function
calls into account.

rdar://157237301
2025-08-05 12:16:44 +01:00
Alastair Houghton
94058e5e68 [Concurrency] Fix availability problem with UnownedTaskExecutor.
a550080 added a call to the new initializer, but that call
came from a function annotated with `StdlibDeploymentTarget 6.2`,
rather than `SwiftStdlib 6.2`, while the initializer was set to
`SwiftStdlib 6.2`.  This will fail in some build configurations
(specifically where the target being built for is older than that
implied by `SwiftStdlib 6.2`).

rdar://157217460
2025-08-04 14:30:20 +01:00
Max Desiatov
7ec0837778 Embedded WASI: fix concurrency-deleted-method.swift test
The test was crashing due to `swift_unreachable("custom executors not supported in embedded Swift")` line in `swift_task_enqueueImpl`, as the corresponding non-embedded codepath was relying on an unspecialized generic function `_swift_task_enqueueOnExecutor` defined in `Executor.swift`. Unspecialized generics are unavailable in Embedded Swift, and such `@silgen_name` function can't be specialized when used from concurrency runtime code written in C/C++. We can redefine this function for Embedded Swift as using a class-bound existential instead, and re-enable this codepath with a slightly different call that avoids the use of unavailable `swift_getObjectType` function from the non-embedded runtime.
2025-07-31 16:00:40 +01:00
Alastair Houghton
a55008066d [Concurrency] Further improve performance.
Remove some reference counting traffic by using `Unowned*Executor`s.

Also, add a test to make sure we stay on the fast path.

rdar://156701386
2025-07-30 13:41:04 +01:00
Max Desiatov
31e92db5b2 Executor.swift: only enable MainActor in Embedded Swift for WASI 2025-07-24 16:03:06 +01:00
Max Desiatov
5c5358b5df Enable more MainActor code paths for Embedded Swift 2025-07-24 14:58:21 +01:00
Max Desiatov
5150a6b1eb Only enable MainActor for WASI with Embedded Swift 2025-07-21 15:42:15 +01:00
Max Desiatov
959e75bac0 Enable MainActor in embedded concurrency, add ExecutorImpl.cpp
`ExecutorImpl.cpp` should be moved from `SWIFT_RUNTIME_CONCURRENCY_NONEMBEDDED_C_SOURCES` to `SWIFT_RUNTIME_CONCURRENCY_C_SOURCES`. This way we can also include `ExecutorImpl.swift` and use `PlatformExecutorCooperative.swift` in embedded concurrency for WASI.
2025-07-21 15:21:54 +01:00
Alastair Houghton
42ca1b1cc8 Rename SwiftStdlibCurrentOS to StdlibDeploymentTarget.
`StdlibDeploymentTarget` seems to be a better name.

rdar://152498657
2025-06-04 10:40:19 +01:00
Alastair Houghton
d5ed335339 Merge pull request #81440 from al45tair/currentos-availability
[Concurrency][Stdlib] Add SwiftStdlibCurrentOS availability, use it.
2025-06-03 15:01:22 +01:00
Alastair Houghton
28732f4a8b Revert "[Concurrency] Add underscore prefixes for not yet official API." 2025-05-20 15:44:26 +01:00
Allan Shortlidge
a85caaf296 Concurrency: Address new -strict-memory-safety warnings. 2025-05-18 10:37:19 -07: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
28f96e64ab [Concurrency][Stdlib] Add SwiftStdlibCurrentOS availability, use it.
If you use SwiftStdlibCurrentOS availability, you will be able to
use new types and functions from within the implementation. This
works by, when appropriate, building with the CurrentOS availability
set to the current deployment target.

rdar://150944675
2025-05-12 12:07:24 +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
Doug Gregor
050a514588 [Strict memory safety] Update standard library for unsafe treated as a call effect 2025-04-25 21:54:23 -07:00
Konrad 'ktoso' Malawski
7112f7ea56 [Concurrency] Support ~Copyable in withSerialExecutor 2025-04-25 18:40:24 +09:00
Konrad 'ktoso' Malawski
fcbd7dbc0d [Concurrency] Support ~Copyable return type in withSerialExeutor 2025-04-25 18:40:24 +09:00
Konrad 'ktoso' Malawski
84764de38c [Concurrency] Fix code completion test given new actor method 2025-04-25 18:40:24 +09:00
Konrad 'ktoso' Malawski
20fe3b0dea [Concurrency] Offer way to get SerialExecutor from Actor 2025-04-25 18:40:23 +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
94b054479b [Concurrency] Remove -executor-factory option and replace with magic type.
We decided that using a magic typealias to set the executor factory was better
than using a compiler option. Remove the `-executor-factory` option, and replace
by looking up the `DefaultExecutorFactory` type, first in the main module, and
then if that fails in Concurrency.

rdar://149058236
2025-04-11 13:55:38 +01:00
Alastair Houghton
a418ce4931 [Concurrency] Fix some comments and a typo.
There were a couple of comments that needed updating, and a typo
in a function name.

rdar://141348916
2025-03-28 10:15:14 +00: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
d197f38226 [Concurrency] Make currentExecutor return a non-optional.
If we don't have any other executor to return, return the default
executor.

rdar://141348916
2025-03-13 13:37:43 +00:00
Alastair Houghton
00e7ef2d21 [Concurrency] Remove EventableExecutor, alter asSchedulable.
EventableExecutor is being removed, for now, but hopefully will
return in some form in the future.

The `asSchedulable` implementation needs to change for reasons of
ABI stability.

rdar://141348916
2025-03-13 13:37:43 +00:00
Alastair Houghton
444bbd5b00 [Concurrency] Update following pitch comments.
Remove `supportsScheduling` in favour of a type-based approach.

Update the storage for `ClockTraits` to `UInt32`.

Adjust ordering of executors for `currentExecutor`.

rdar://141348916
2025-03-13 13:37:43 +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
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
5ae6de288a [Concurrency] Fix potential ABI breakages.
Fix a couple of potential ABI breaks.  Also add the new functions and types
to the baseline lists.

rdar://141348916
2025-03-13 13:37:36 +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
Konrad `ktoso` Malawski
e056c63c89 [Concurrency] Implement isIsolatingCurrentContext requirement and mode (#79788) 2025-03-11 09:48:38 +09:00
Konrad `ktoso` Malawski
f55964df26 [Concurrency] Initial steps for startSynchronously for Task (#79608)
* [Concurrency] Initial steps for startSynchronously for Task

* [Concurrency] Rename to _startSynchronously while in development

* [Concurrency] StartSynchronously special executor to avoid switching

* startSynchronously bring back more info output

* [Concurrency] startSynchronously with more custom executor tests

* add missing ABI additions to test for x86

* [Concurrency] gyb generate _startSynchronously

* [Concurrency] %import dispatch for Linux startSynchronously test

* [Concurrency] Add TaskGroup.startTaskSynchronously funcs

* [Concurrency] DispatchSerialQueue does not exist on linux still
2025-02-27 02:34:33 -08:00
Doug Gregor
177d16ced8 Enable strict memory safety in the Concurrency module 2025-02-26 14:28:24 -08:00
Doug Gregor
3ab5456eae Mark SerialExecutor.asUnownedSerialExecutor unsafe so conformances don't need to be @unsafe
What we should actually do with SerialExecutor conformances is not yet clear, though.
2024-12-20 23:16:26 -08:00
Doug Gregor
9e09513514 Mark UnownedSerialExecutor as @unsafe 2024-12-20 07:35:35 -08:00
Mykola Pokhylets
5ac1cba8d1 Handle versioning of the IsolatedDeinit feature 2024-12-12 16:41:02 +09:00