Commit Graph

1440 Commits

Author SHA1 Message Date
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
733dd86c92 Merge pull request #79896 from DougGregor/strict-memory-safety-cleanups
Strict memory safety cleanups
2025-03-11 01:26:30 -07:00
Doug Gregor
0de53547e5 [Concurrency lib] Stdlib 9999 -> 6.2, where this code would land 2025-03-10 23:07:06 -07:00
Michael Gottesman
04bb69f426 Merge pull request #79727 from gottesmm/pr-025c1133954b74e7b4eda77e1a6f3bcafd4eb6cf
[concurrency] Add initial support for SwiftSettings to control defaultIsolation at the file level.
2025-03-10 22:35:00 -07:00
Konrad `ktoso` Malawski
e056c63c89 [Concurrency] Implement isIsolatingCurrentContext requirement and mode (#79788) 2025-03-11 09:48:38 +09:00
Michael Gottesman
f64dd5a8d5 [concurrency] Add initial support for SwiftSettings to control defaultIsolation at the file level.
We introduce a new macro called #SwiftSettings that can be used in conjunction
with a new stdlib type called SwiftSetting to control the default isolation at
the file level. It overrides the current default isolation whether it is the
current nonisolated state or main actor (when -enable-experimental-feature
UnspecifiedMeansMainActorIsolated is set).
2025-03-10 17:33:45 -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
4aeaab4921 Merge pull request #79762 from kateinoigakukun/yt/fix-task-escalate-sig
stdlib: Fix the signature of `_taskEscalate` to return a priority
2025-03-05 12:29:35 +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
Holly Borla
8be41edf6f [Concurrency] Add a macro for wrapping a function body in a new task. 2025-03-03 20:51:14 -08: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
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
Konrad `ktoso` Malawski
e8668684a1 Merge pull request #79411 from amartini51/typo_144059094
Remove double word ("a a" and "the the")
2025-02-20 13:05:06 +09:00
Mike Ash
44ff7e59c6 Merge pull request #78817 from mikeash/fix-supersleep
[Concurrency] Fix Task.sleep on values greater than Int64.max.
2025-02-18 21:07:05 -05:00
Alex Martini
06bdfa96b2 Remove double word 2025-02-14 17:23:50 -08:00
Allan Shortlidge
6e3eb96d91 Concurrency: Fix an unused variable warning. 2025-02-13 07:40:53 -08:00
Guillaume Lessard
6b90664f54 [concurrency] fix availabilities some more
Extensions cannot be more available than their type for swiftinterface files.
2025-02-11 13:14:49 -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
Saleem Abdulrasool
6028fde00a Merge pull request #79116 from compnerd/silence
Concurrency: silence some unused variable warnings
2025-02-04 10:28:30 -08:00
Saleem Abdulrasool
0174528f81 stdlib: fix the problem swept under the rug in 58a97f1603
The `-Winvalid-offsetof` warning is valid in this case. `offsetof` is
being applied to types with a non-standard layout. The layout of this
type is undefined by the specification. There is no guarantee that the
type layout is uniform across all ABIs. It is not possible to portably
compute the offset statically, especially efficiently.

Sink this check into a unit test to avoid performing this test at
runtime. In order to do this in the standard library, we would need to
do this check through a global constructor.
2025-02-03 09:25:06 -08:00
Saleem Abdulrasool
8040430bc7 Concurrency: silence some unused variable warnings
This cleans up some warnings from the unused variables. The variables
were referenced by `assert` cases only.
2025-02-03 09:22:50 -08:00
Allan Shortlidge
4799f1e295 Concurrency: Suppress some warnings. 2025-02-01 13:52:43 -08:00
Kuba Mracek
aea2bb563c [embedded] Prepare the Embedded Concurrency library for building on armv7m/armv7em 2025-01-30 10:48:09 -08:00
Saleem Abdulrasool
f1b859c9a5 Concurrency: centralise the definition for std::bit_cast
Remove the multiple definitions of `std::bit_cast` into a header. While
this is still not great, it does reduce the duplication. This also
silently works towards reducing a bit of the UB introduced here by
adding an inline namespace for `std` which you are not technically
allowed to use. However, by doing this, we have a clear migration path
away from this once we adopt C++20.
2025-01-28 11:14:15 -08:00
Saleem Abdulrasool
c9df7c57a9 Concurrency: silence some -Wcast-function-type-mismatch warnings
The C++ standard does not guarantee that the code and data pointers are
interchangeable. Recent enhancements to clang now properly identify the
improper `reinterpret_cast` between function types. Silence the warning
by switching to `std::bit_cast`. Unfortunately, this is a C++20 feature
and we are still on C++17. In the case that the compiler doesn't have a
`bit_cast` implementation, fallback with some UB to a local definition.
2025-01-25 10:37:01 -08:00
Mike Ash
29efab6ccc [Concurrency] Fix Task.sleep on values greater than Int64.max.
In the Dispatch implementation, clamp the delay to INT64_MAX. Swift's nanoseconds value is unsigned, but we ultimately use it with dispatch_time, which takes a signed int64_t. Extremely large values get interpreted as negative, which results in not sleeping.

INT64_MAX nanoseconds is about 292 years, so it should be difficult to notice a practical effect from sleeping for less time than requested due to the clamping.

rdar://143278824
2025-01-22 12:28:18 -05:00
Tony Allevato
3bd71c9d62 [NFC] Include <cstdlib> and <cstdint> where necessary.
Our Bazel builds have become more strict about libc++
dependencies recently, so these are required to pick up
declarations of `malloc` and `uint32_t`, respectively.
2025-01-22 07:47:16 -05: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
Alex Lorenz
b3ec0ff245 [stdlib] fix android build
ptrauth isn't available when stdlib is built with NDK's clang
2024-12-15 21:33:33 -08:00
Konrad `ktoso` Malawski
55603ec2d4 Use __ptrauth_swift_deinit_work_function in IsolatedDeinitJob 2024-12-12 16:41:04 +09:00
Konrad `ktoso` Malawski
9317f12bd0 Add pointer auth for isolated deinit work function 2024-12-12 16:41:03 +09:00
Mykola Pokhylets
5ac1cba8d1 Handle versioning of the IsolatedDeinit feature 2024-12-12 16:41:02 +09:00
Mike Ash
e727252733 [Concurrency] Fix start of version ranges in install name magic symbols.
The magic symbols specify a version range where clients should reference a @rpath relative path to libswift_Concurrency.dylib instead of the standard absolute path. This version range started at macOS 10.15 and aligned versions, which is the oldest target supported by Concurrency. However, clients that use Concurrency can target earlier OSes as long as they availability-check their use of Concurrency. When targeting something earlier than 10.15, they'd reference the absolute path, then fail to find the back-deployment Concurrency runtime on OS versions that need it.

Fix this by setting the start of the range to macOS 10.9 and aligned, which is the oldest target supported by Swift.

rdar://140476764
2024-12-09 15:57:46 -05:00
Kyle
7c6cc140ad Fix TaskLocal macro link issue 2024-12-04 15:17:10 +08:00
Kyle
a3e8d1068f Fix missing curly brace in TaskLocal documentation 2024-12-04 15:16:42 +08:00
John McCall
d8d70d9aac Add support for creating a task with a self-consuming task function.
Not used yet.
2024-11-15 22:51:57 -05:00