Commit Graph

250 Commits

Author SHA1 Message Date
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
8443b5f76c Merge pull request #79789 from al45tair/custom-executors
[Concurrency] Provide a Swift interface for custom main and global executors.
2025-03-21 09:05:03 +00: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
Konrad `ktoso` Malawski
85e4685f90 [Concurrency] Adjust task escalation APIs to SE accepted shapes (#79988)
* [Concurrency] Adjust task escalation APIs to SE accepted shapes

* adjust test a little bit

* Fix closure lifetime in withTaskPriorityEscalationHandler

* avoid bringing workaround func into abi by marking AEIC
2025-03-18 07:05:11 +09:00
Alastair Houghton
ed08858998 [Concurrency] Fix availability.
Fix up availability after the non-Darwin changes.  Also update the
ABI baseline.

Fix a Win32 typo.

rdar://141348916
2025-03-17 16:24:06 +00:00
Alastair Houghton
f0defd83bd [Concurrency] Add CooperativeExecutor, use it.
Also tweak the sleep implementations to let the hooks run if there
isn't a `SchedulableExecutor` (for hooked mode).

rdar://141348916
2025-03-17 13:10:35 +00:00
Michael Gottesman
70bb344db3 [concurrency] Make extension have the same availability as its only containing declaration.
Otherwise in certain cases, we will run into:

1588 | extension GlobalActor {
     | |         `- error: 'GlobalActor' is only available in macOS 10.15 or newer
     | `- note: add @available attribute to enclosing extension
1589 |   @available(SwiftStdlib 6.2, *)
1590 |   @_silgen_name("_swift_task_isCurrentGlobalActor")

rdar://146848568
2025-03-14 13:18:56 -07:00
Konrad `ktoso` Malawski
57288d13c9 [Concurrency] task names dont need default nil arg (#80011) 2025-03-14 21:15:01 +09:00
Doug Gregor
a1132ca169 [Concurrency] Remove unnecessary #ifs that break task-to-thread model
Fixes rdar://146968199
2025-03-13 16:43:19 -07: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
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
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
8c4dea9802 Revert "[concurrency] Add support for HopToMainActorIfNeededThunk." (#79938)
* Revert "[concurrency] Add support for HopToMainActorIfNeededThunk."

This reverts commit 0e0665bfbd.

* remove some last bits of 0e0665b
2025-03-13 06:48:03 +09:00
Doug Gregor
2efa05d615 Merge pull request #79905 from DougGregor/DougGregor/concurrency-lib-6-2-fix
[Concurrency lib] Stdlib 9999 -> 6.2, where this code would land
2025-03-11 10:56:38 -07:00
Doug Gregor
0de53547e5 [Concurrency lib] Stdlib 9999 -> 6.2, where this code would land 2025-03-10 23:07:06 -07:00
Doug Gregor
170845b864 Strict memory safety cleanups for the concurrency library 2025-03-10 15:42:11 -07:00
Doug Gregor
6dd141ad54 Replace dlsym of swift_task_isCurrentGlobalActor with a constructor hook
Following the approach taken with the concurrency-specific type
descriptors, register a hook function for the "is current global actor"
check used for isolated conformances.
2025-03-07 23:51:43 -08:00
Doug Gregor
951b535608 Metadata and runtime support for checking isolated conformances at runtime
Extend the metadata representation of protocol conformance descriptors
to include information about the global actor to which the conformance is
isolated (when there is one), as well as the conformance of that type to
the GlobalActor protocol. Emit this metadata whenever a conformance is
isolated.

When performing a conforms-to-protocol check at runtime, check whether
the conformance that was found is isolated. If so, extract the serial
executor for the global actor and check whether we are running on that
executor. If not, the conformance fails.
2025-03-07 23:51:25 -08:00
Konrad `ktoso` Malawski
fda7f539fb Reapply "Task names" (#79562) (#79600) 2025-03-08 10:58:49 +09:00
Yuta Saito
f06d2f04f9 stdlib: Fix the signature of _taskEscalate to return a priority
The `swift_task_escalate` is defined to return the new priority of the
task after the escalation but the silgen_name'd function did not have
the return type specified.

Follow up to 18c25845d6
2025-03-04 11:44:13 +00: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
Konrad `ktoso` Malawski
09003d6f11 Revert "Merge pull request #77609 from ktoso/wip-task-names" (#79562)
This reverts commit 4ab5d2604f.
2025-02-23 22:59:21 -08:00
Allan Shortlidge
73b301d369 Concurrency: Fix variable was never mutated warnings and indentation.
NFC.
2025-02-22 12:09:23 -08:00
Konrad `ktoso` Malawski
4ab5d2604f Merge pull request #77609 from ktoso/wip-task-names
[Concurrency] Task names
2025-02-21 22:28:33 +09:00
Alex Martini
06bdfa96b2 Remove double word 2025-02-14 17:23:50 -08:00
Guillaume Lessard
e10e476fe4 [concurrency] fix availabilities
These two functions are called from a context that has SwiftStdlib 6.2 availability. Theyshould have that same availability.
2025-02-10 19:14:25 -08:00
Konrad `ktoso` Malawski
26c521d317 [Concurrency] Add new APIs to ABI check & add more tests 2025-02-10 17:55:42 +09:00
Konrad `ktoso` Malawski
29d95cef85 [Concurrency] Fix ptrauth value for __ptrauth_swift_escalation_notification_function
Previously these records were not used at all, so changing this has no
impact on existing runtimes. Note that we changedd the FunctionType
because the previous one was slightly incorrect -- the context comes
LAST in the type, not first.
2025-02-08 17:18:59 +09:00
Konrad `ktoso` Malawski
67e6373c23 [Concurrency] minor renames of new API for adding escalation handlers 2025-02-08 17:18:58 +09:00
Konrad `ktoso` Malawski
655bd67f67 [Concurrency] Task priority escalation handler API 2025-02-08 17:18:58 +09:00
Konrad `ktoso` Malawski
18c25845d6 [Concurrency] Task.escalatePriority 2025-02-08 17:18:57 +09:00
Michael Gottesman
b1750bad1a [concurrency] Implement swift_task_runOnMainActor.
This routine takes a synchronous non-throwing main actor isolated closure
without a result. If we are dynamically on the main actor, we just run the
closure synchronously. Otherwise, we run a new task on the main actor and call
the closure on that.

This builds on top of the previous commit by using
swift_task_isCurrentExecutorWithFlags in the implementation of this function.

To backwards deploy this function on Darwin, I used some tricks from libdispatch
to validate that we are on the main queue.
2024-10-17 11:17:38 -07:00
Kuba Mracek
9b56ea03d2 [Concurrency] Drop the cloned code for Embedded around 'any actor' 2024-09-30 10:30:09 -07:00
Alex Martini
44ecc6325f Revise for documentation style
- Use the spelling "canceled" per Apple Style Guide
- Use code voice for symbol name
- Use contractions
- Avoid parenthesis for asides
- Change "it" to "that function" to reduce ambiguity
2024-09-18 15:42:14 -07:00
Konrad `ktoso` Malawski
57bf319577 Update Task.swift 2024-09-18 09:38:02 +09:00
Konrad `ktoso` Malawski
6c8d0c9e1b Apply suggestions from code review
Co-authored-by: Alex Martini <amartini@apple.com>
2024-09-18 09:29:04 +09:00
Konrad `ktoso` Malawski
5e29d51674 Apply suggestions from code review
Co-authored-by: Alex Martini <amartini@apple.com>
2024-09-18 09:13:18 +09:00
Konrad `ktoso` Malawski
6d37240ef2 Update Task.cancel() with more details
Add more details into cancel() docs, some developers were worried if they are allowed to call it concurrently and multiple times etc.
2024-09-17 09:38:43 +09: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
Harlan Haskins
a721ef63f6 Un-deprecate Task.startOnMainActor (#75544) 2024-08-16 06:36:18 +09:00
Allan Shortlidge
fb6ab05746 Concurrency: Restore -enable-experimental-feature IsolatedAny.
Supported older compilers don't enable this feature by default, so it can't be
omitted from the `_Concurrency` module's flags (regression from
https://github.com/swiftlang/swift/pull/74543).

Additionally, remove `@_allowFeatureSuppression(IsolatedAny)` from all
declarations. We no longer need to support compilers that don't have the
`IsolatedAny` feature, so the suppression is superfluous and the alternative
branches didn't actually build anyways. _Additionally_, the suppressible
feature logic could not handle suppressing `IsolatedAny` simultaneously with
`SendingArgsAndResults`, resulting in a broken interface because `sending` was
used outside `#if $SendingArgsAndResults` guards.
2024-07-03 10:36:47 -07:00
Allan Shortlidge
346bbcaa05 Concurrency: Remove superfluous $BuiltinCreateAsyncTaskInGroup guards. 2024-07-02 22:26:55 -07:00
Allan Shortlidge
ee8a1152b2 Concurrency: Promote BuiltinCreateTask feature to baseline. 2024-07-02 22:26:55 -07:00
Michael Gottesman
d28eef2d62 [sending] Convert the TaskGroup APIs 2024-06-21 06:11:17 -07:00
Michael Gottesman
b541e0299e [concurrency] Deprecate some source compatibility APIs in swift 5 and obsolete in swift 6.
These APIs remained to preserve source compatibility during bringup. We do not
want them used in swift 6 mode... so deprecate in swift 5 and obsolete in swift
6.
2024-06-21 02:24:03 -07:00
Michael Gottesman
4697546e09 [sending] Mark Task.init,detached, and friends as sending methods instead of __owned @Sendable so we can capture non-isolated values. 2024-06-21 02:24:03 -07:00
Konrad `ktoso` Malawski
0135623d9a [docs] fix typo in type name in code snippet 2024-06-10 17:21:47 +09:00
Konrad `ktoso` Malawski
d8cba034b3 [docs] remove swift style code highlighting on non-swift snippet 2024-06-10 17:20:57 +09:00