Commit Graph

93 Commits

Author SHA1 Message Date
Eric Miotto
c9345a38c4 [Concurrency] Add availability to one of the ExecutorJob extensions
Without this, we may fail building Concurrency when enforcing strict
availability.

Addresses rdar://159473855
2025-08-29 15:09:46 -07:00
Eric Miotto
173c5ff2a4 [Concurrency] Change availability for a TaskPriority extension
We need the `init?(JobPriority)` constructor to be
`StdlibDeploymentTarget 5.9`
so the compiler will not complain when we reference it
 from `ExecutorJob.createTrampoline` when building the standard library
without strict availability.

Addresses rdar://159397287
2025-08-28 15:34:10 -07:00
Alastair Houghton
250458f9f6 [Concurrency] Add a couple of comments.
Add some documentation comments to the Dispatch and CF executors,
and update the comments for the allocation and private data APIs.
2025-08-26 09:38:13 +01: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
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
79f746e62d [Concurrency] Don't use ExecutorJob for task-to-thread model.
Task-to-thread model doesn't have `ExecutorJob`, so we can't use it;
however, we probably also don't need `_swift_createJobForTestingOnly`
there so just `#if` it out in that case.

rdar://155054460
2025-07-07 11:43:53 +01:00
Alastair Houghton
26878c98de [Concurrency] Add functions to allow testing of external executors.
Added a couple of functions to allow for the testing of executors that
aren't implemented inside the concurrency runtime itself.

rdar://154195821
2025-07-01 16:48:03 +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
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
Doug Gregor
050a514588 [Strict memory safety] Update standard library for unsafe treated as a call effect 2025-04-25 21:54:23 -07:00
Alastair Houghton
6e28716319 [Concurrency] Address some review comments.
Tweaked diagnostic to use a string instead of a type.  Renamed the
feature in `FeatureAvailability.def` (and added the `TaskExecutor`
feature to 6.2).  Also fixed the `swift_getActiveExecutor()`
function to return the main executor only when on the main thread.

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
0da95eb20d [Concurrency] Fix some warnings, use typed throws.
Fix a couple of `unsafe` warnings.

Also update `withUnsafeExecutorPrivateData` to use typed throws instead of
`rethrow`.

rdar://141348916
2025-03-18 18:37:31 +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
229865192f [Concurrency] Rename ExecutorJob back to PartialAsyncTask.
The rename appears to have had some kind of potentially ABI breaking
consequence.

rdar://141348916
2025-03-13 13:37:43 +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
Doug Gregor
177d16ced8 Enable strict memory safety in the Concurrency module 2025-02-26 14:28:24 -08:00
Allan Shortlidge
ba3cd79b6f Concurrency: Remove superflous _SwiftConcurrencyShims imports.
The `_SwiftConcurrencyShims` module was imported `@_implementationOnly` which
was causing warnings to be emitted during the stdlib build. The module
currently serves no purpose; the only declaration it contains is a defunct
`_SwiftContext` struct which is not referenced by anything. The module needs to
continue to exist for source compatibility, though, since it is part of the
toolchain and imported publicly from other modules.
2024-09-09 12:20:13 -07:00
Doug Gregor
8378562e12 Adopt @unsafe throughout the standard library
Annotate all of the `Unsafe*` types and `unsafe` functions in the standard
library (including concurrency, synchronization, etc.) as `@unsafe`. Add a
few tests to ensure that we detect uses of these types in clients that
have disabled unsafe code.
2024-08-19 14:33:09 -07:00
Kavon Farvardin
2557ba96c8 Noncopyable: deprecate '@_moveOnly' attribute
This hidden attribute is a leftover from before the '~Copyable' syntax.

rdar://130526083
2024-07-23 11:05:33 -07:00
Doug Gregor
a2038f92f8 Address code review feedback and fix rebase typo in a test 2024-07-09 08:13:24 -07:00
Doug Gregor
a2b2324e7f Use @_unsafeInheritExecutor forms of with*Continuation from @_unsafeInheritExecutor functions
The move from `@_unsafeInheritExecutor` to `#isolation` for the
with*Continuation breaks code that is using `@_unsafeInheritExecutor` and
calling these APIs. This originally caused silent breakage (which manifest
as runtime crashes), and is now detected by the compiler as an error.

However, despite `@_unsafeInheritExecutor` being an unsafe,
not-intended-to-be-user-facing feature, it is indeed being used, along
with these APIs. Introduce _unsafeInheritExecutor_-prefixed versions of
the `with*Continuation` and `withTaskCancellationHandler` APIs into
the _Concurrency library that use `@_unsafeInheritExecutor`. Then,
teach the type checker to swap in these
_unsafeInheritExecutor_-prefixed versions in lieu of the originals
when they are called from an `@_unsafeInheritExecutor` function. This
allows existing code using `@_unsafeInheritExecutor` with these APIs
to continue working as it has before, albeit with a warning that
`@_unsafeInheritExecutor` has been removed.

Fixes rdar://131151376.
2024-07-08 23:35:37 -07:00
Konrad `ktoso` Malawski
b9369bf0b7 [Concurrency] Fix default actor isolation issue in face of TaskExecutor preference (#74658)
* [Concurrency] Fix task excutor handling of default actor isolation

The task executor API did not properly account for taking the default
actor locking into account when running code on it, we just took the job
and ran it without checking with the serial executor at all, which
resulted in potential concurrent executions inside the actor --
violating actor isolation.

Here we change the TaskExecutor enqueue API to accept the "target"
serial executor, which in practice will be either generic or a specific
default actor, and coordinate with it when we perform a
runSynchronously.

The SE proposal needs to be amended to showcase this new API, however
without this change we are introducing races so we must do this before
the API is stable.

* Remove _swift_task_enqueueOnTaskExecutor as we don't use it anymore

* no need for the new protocol requirement

* remove the enqueue(_ job: UnownedJob, isolatedTo unownedSerialExecutor: UnownedSerialExecutor)

Thankfully we dont need it after all

* Don't add swift_defaultActor_enqueue_withTaskExecutor and centralize the task executor getting to enqueue()

* move around extern definitions
2024-07-01 16:42:27 +09:00
Michael Gottesman
5db3b70c65 [concurrency] Update withUnsafe{,Throwing}Continuation to have a sending result.
rdar://129299180
2024-06-05 12:50:59 -07:00
Konrad `ktoso` Malawski
fb4ffb43db [Concurrency] Add missing runSynchronously to ExecutorJob (#72899) 2024-04-08 13:41:08 +09:00
Konrad `ktoso` Malawski
dfcf1054dd [Concurrency] Remove _unsafeInheritExecutor from public APIs, use #isolation (#72578) 2024-04-05 03:57:54 -07:00
Holly Borla
5d9ad87a82 [Concurrency] Task executors are available in Swift 6.0. 2024-03-13 09:56:24 -07:00
Konrad `ktoso` Malawski
1dec00a420 [TaskExecutors] Task initializer and withTaskExecutor parameter changes (#70783) 2024-01-20 11:03:26 +09:00
Konrad `ktoso` Malawski
828f589be4 Initial Task Executor implementation Task(on:), addTask(on:) etc. (#68793)
Co-authored-by: John McCall <rjmccall@gmail.com>
2023-12-12 17:14:24 +09:00
Konrad `ktoso` Malawski
f58a46fece Merge pull request #69671 from Jager-yoo/typos-concurrency 2023-11-27 13:38:23 +09:00
Choo Hyun Ho
36e01c23ae stdlib/Concurrency/PartialAsyncTask.swift: Correct typos (#69880) 2023-11-15 07:01:57 -08:00
Jaeho Yoo
391eee0625 [Concurrency] Fix some typos in PartialAsyncTask 2023-11-07 01:16:37 +09:00
Kuba Mracek
df5879746c [embedded] Use async main in the test 2023-10-06 20:32:21 -07:00
Alex Martini
2676e261fd Fix typo; add missing word. 2023-08-07 11:35:42 -07:00
Konrad `ktoso` Malawski
da6f08a24e [Concurrency] Adopt stable keyword consuming instead of __owned
add test for warnings emitted when missing consuming attribute

use -emit-sil in mock SDK tests for better coverage
2023-05-11 15:18:54 +02:00
Konrad `ktoso` Malawski
ca2987cd83 [Concurrency] Easier to handle deprecation of Job and friends 2023-05-09 14:38:15 +09:00
Kavon Farvardin
8511317a97 Replace additional uses of noncopyable metatypes. 2023-05-04 11:44:27 -07:00
Kavon Farvardin
103bd043cd Revert "Revert "Prevent noncopyable metatypes from being converted to Any""
This reverts commit 1a3b42cd63.
2023-05-04 11:38:00 -07:00
Hamish Knight
1a3b42cd63 Revert "Prevent noncopyable metatypes from being converted to Any" 2023-05-04 12:10:10 +01:00
Kavon Farvardin
1df3912794 Merge pull request #65606 from kavon/noncopyable-metatypes
Prevent noncopyable metatypes from being converted to `Any`
2023-05-03 22:05:17 -07:00
Kavon Farvardin
4710fc675b Prevent noncopyable metatypes from being converted to Any
These metatypes are a gateway to more incorrect
uses of these noncopyable values because we don't
yet have the corresponding runtime support yet.
The other use cases of using metatypes of
noncopyable types in generics is not high enough to
warrant people using them yet.

resolves rdar://106452518
2023-05-03 10:23:11 -07:00
Konrad `ktoso` Malawski
8d6980ec10 [Executors] Make move to ExecutorJob binary compatible; deprecate Job 2023-05-02 14:44:11 +09:00
Kavon Farvardin
8f13679582 add missing rename of Job -> ExecutorJob 2023-04-12 13:37:43 -07:00
Konrad `ktoso` Malawski
80b93863a9 [Concurrency] Rename Job to ExecutorJob, ease transition with typealias (#65006) 2023-04-11 14:52:10 +09:00
Kavon Farvardin
363448a0d7 bring back the noncopyable Job type in the _Concurrency lib
This reverts commit abe377ce68.

Co-authored-by: Konrad `ktoso` Malawski <konrad_malawski@apple.com>
2023-03-24 08:58:40 -07:00
Konrad `ktoso` Malawski
abe377ce68 [Workaround][Concurrency] Mark Job as NOT moveonly until we fix moveonly types (#64536) 2023-03-23 07:43:51 +09:00
Konrad `ktoso` Malawski
e0877594da [Concurrency] Custom executors with move-only Job (#63569) 2023-03-18 14:02:43 +09:00
Konrad `ktoso` Malawski
ac0c3b75c6 [Concurrency] Freeze JobPriority, comment that Flags location is assumed (#64267) 2023-03-10 16:49:37 +09:00
Konrad `ktoso` Malawski
c446f4cb12 review followup 2023-03-03 13:37:57 +09:00