Commit Graph

21492 Commits

Author SHA1 Message Date
Konrad `ktoso` Malawski
5baa624085 Merge pull request #81820 from ktoso/pick-abi-fix-startSynchronously
[6.2][Concurrent] Restored old symbol for obsoleted `Task.startSynchronously`
2025-05-29 16:19:38 +09:00
Mike Ash
b42c7fa172 [6.2][Concurrency] Fix races/overflows in TaskGroup implementation.
statusCompletePendingReadyWaiting(), offer(), and poll() did a one-off compare_exchange_strong which could fail if the group was concurrently cancelled. Put these into loops so that they are retried when needed.

DiscardingTaskGroup creation passed the group result type as the task result type. waitAll() would then use the group result type when collecting task results. Since the task result type is always Void in this case, this would overflow the result buffer if the group result type was larger. This often works as it writes into the free space of the task allocator, but can crash if it happens to be at the end of a page or the group result type is particularly large.

rdar://151663730
(cherry picked from commit 5be22fa7cc)
2025-05-28 20:59:17 -04:00
Konrad `ktoso` Malawski
c8a8183d26 [6.2][Concurrency][SE-review update] Task names update (#81132)
**Description**: This adds "task name" parameter to all task creating
functions.

This is done in a few ways, e.g. we can backdeploy this to 5.1 in APIs
which do not accept the `TaskExecutor` but it they do we provide a
version for 6.0+ etc. This was requested in the SE acceptable of this
proposal [Acceptance post
SE-0469](https://forums.swift.org/t/accepted-with-modifications-se-0469-task-naming/79438).

This moves all these declarations to gyb since going through them one by
one has become unmaintainable otherwise.

**Scope/Impact**: All task creation APIs now gain a new task name
parameter.
**Risk:** Medium, changes existing APIs rather than adding "even more
overloads" though this risk was discussed in the team and accepted. This
has a potential to be source breaking it someone used Task.init and
friends as function.
**Testing**: CI testing, source compatibility suite testing
**Reviewed by**: 

**Original PR:** 
- https://github.com/swiftlang/swift/pull/81107 build changes required
for this
- https://github.com/swiftlang/swift/pull/80984


**Radar:**

---------

Co-authored-by: Kuba Mracek <mracek@apple.com>
2025-05-29 07:52:33 +09:00
Pavel Yaskevich
f404274e6d [Concurrent] Restored old symbol for obsoleted Task.startSynchronously
https://github.com/swiftlang/swift/pull/80821 added `@isolated(any)`
which is an ABI breaking change but since we are not planning to keep
this API around, let's use `@_silgen_name` to bring the old name back
for now.

Resolves: rdar://152178221
2025-05-29 06:48:31 +09:00
Konrad 'ktoso' Malawski
fa817f951d [Concurrency] Correct the signing of priority escalation handler 2025-05-23 17:06:12 -07:00
Pavel Yaskevich
5997a4dec4 [stdlib] Adopt @_inheritActorContext(always) on Task.immediate
This change aligns implementation with the current SE-0472 proposal.

(cherry picked from commit c3c1b4fca0)
(cherry picked from commit 8c05636e28)
(cherry picked from commit 0598b8c9f4)
2025-05-22 11:32:37 -07:00
Mike Ash
b319e4eaf0 Merge pull request #81616 from mikeash/error-object-weak-reference-6.2
[6.2][Runtime] Allow weak references to ErrorObjects.
2025-05-20 20:49:06 -04:00
Mike Ash
736337dceb [6.2][Runtime] Allow weak references to ErrorObjects.
When ObjC interop is not available, Error values are represented in ErrorObject boxes. These are full HeapObjects, but unowned refcounting ops asserted that the metadata was class metadata. This assert would be hit when destroying an ErrorObject that was weakly referenced. Expand the asserts to accept ErrorObject metadata as well.

rdar://150214921
(cherry picked from commit aea9c0c65a)
2025-05-19 15:21:45 -04:00
Allan Shortlidge
2d96b24e57 Embedded: Suppress spurious unused result warnings.
The results of `swift_retain(object:)` and `swift_bridgeObjectRetain(object:)`
should be discardable since it's typcial to not need the pointer returned from
these calls. Suppresses unused result warnings that were generated previously.
2025-05-19 09:24:53 -07:00
Allan Shortlidge
98951af301 CompatbilitySpan: Add a missing @unsafe.
The missing attribute was causing "no unsafe expressions" warnings elsewhere
when building the CompatibilitySpan library.
2025-05-19 09:24:41 -07:00
Allan Shortlidge
63adabb7ef Concurrency: Address new -strict-memory-safety warnings. 2025-05-19 09:24:13 -07:00
Alastair Houghton
77a9aa2089 [Cxx] Build the C++ interop support library for the Static SDK for Linux.
We need the C++ interop support library to make the build work, as
the Runtime module uses C++ interop.

(Also, we should build it, because some user programs might want to
use C++ interop.)

rdar://147201087
2025-05-15 14:30:37 +01:00
Pavel Yaskevich
b2e962068d [stdlib] Temporarily bring back Task.startSynchronously as deprecated
(cherry picked from commit 99d810aa7d)
2025-05-13 20:11:28 -07:00
Pavel Yaskevich
2bf00077e4 [stdlib] SE-0472: Rename Task and*TaskGroup APIs to match the proposal
`Task.startSynchronously` -> `Task.immediate`
`*TaskGroup.startTaskSynchronously{UnlessCancelled}` -> `*TaskGroup.addImmediateTask{UnlessCancelled}`

(cherry picked from commit 001eab867d)
2025-05-13 20:11:28 -07:00
Konrad 'ktoso' Malawski
910bc1a1a3 [Concurrency] Improve in order synchronous enqueue of startSynchronously
Previously there was still a sneaky hop which caused ordering issues.
This introduced a specific test startSynchronously_order which checks
that the task enqueues indeed are "immediate" and cleans up how we
handle this.

This also prepares for the being discussed in SE review direction of
this API that it SHOULD be ALLOWED to actually hop and NOT be
synchronous at all IF the isolation is specified on the closure and is
DIFFERENT than the callers dynamic isolation.

This effectively implements "synchronously run right now if dynamically
on the exact isolation as requested by the closure; otherwise enqueue
the task as usual".

resolves rdar://149284186
cc @drexin

(cherry picked from commit a24a28c217)
2025-05-13 20:10:35 -07:00
Alastair Houghton
02c160cdac Merge pull request #81335 from al45tair/eng/PR-148899609-6.2
[Concurrency] Don't pass negative times to the Dispatch code.
2025-05-13 11:29:35 +01:00
Doug Gregor
1072dbebb5 Merge pull request #81410 from swiftlang/egorzhdan/6.2-do-not-install-swiftmodules
🍒[cxx-interop] Do not install binary `.swiftmodule` files for the overlays
2025-05-12 19:28:38 -07:00
Devin Coughlin
2e941ef2db Merge pull request #81388 from hnrklssn/swiftify-anonymous-params-qual
[Swiftify] Emit @availability when expansions contain Span (#81320)
2025-05-12 17:29:18 -07:00
Egor Zhdan
10ab242b64 [cxx-interop] Do not install binary .swiftmodule files for the overlays
This fixes a deserialization failure in the compiler that occurred while loading the CxxStdlib overlay module:
```
Cross-reference to module 'Swift'
... Optional
... some
... with type <τ_0_0 where τ_0_0 : ~Copyable, τ_0_0 : ~Escapable> (Optional<τ_0_0>.Type) -> (τ_0_0) -> Optional<τ_0_0>
```

This was happening because the overlays were built against a different version of the Swift stdlib than is being used. The compiler is able to rebuild the Cxx and CxxStdlib modules from their textual interfaces. Let's use that feature unconditionally in production toolchains to avoid this kind of binary incompatibilities.

rdar://150416863
(cherry picked from commit 16b280862a)
2025-05-12 19:30:15 +01:00
Alastair Houghton
d6ce27b0e6 Merge pull request #81326 from al45tair/eng/PR-150753884
[Concurrency] Make initial executor construction fully thread safe.
2025-05-12 11:56:45 +01:00
Slava Pestov
874449374e RemoteInspection: Support for parameter packs 2025-05-09 14:50:19 -04:00
Slava Pestov
e2f10ed7ca RemoteInspection: Remove 'DidSubstitute' form of TypeRef::subst() 2025-05-09 14:50:16 -04:00
Nate Cook
c8c035ec32 [6.2][stdlib] Allow a default for optional interpolations (#81360)
Cherry-pick of #80547 for the 6.2 release branch.

---

Explanation: This cherry picks the implementation of SE-0477 to add a
string interpolation method with a `default:` parameter for optional
interpolation values.
Main Branch PR: https://github.com/swiftlang/swift/pull/80547
Risk: Low.
Reviewed By: @stephentyrone 
Resolves: rdar://150865613
Testing: New tests for the string interpolations and fix-its.
2025-05-09 12:10:58 -05:00
Henrik G. Olsson
f70676a340 [Swiftify] Emit @availability when expansions contain Span (#81320)
This prevents errors when compiling for older targets using a newer
compiler.

rdar://150740330
(cherry picked from commit 59d7d3160f)
2025-05-08 16:40:20 -07:00
3405691582
7a87fa5cbc Add a platform executor module for OpenBSD.
This is basically the same as the one for Linux, but it would be
somewhat awkward to add the platform conditional on a file named for
Linux when OpenBSD is not Linux.

Important note: if Dispatch is disabled, then this will cause a
compilation error (probably not just for OpenBSD either), because
PlatformExecutorFactory is both defined in PlatformExecutorNone.swift
and PlatformExecutor<...>.swift in this case.

Because this only bites OpenBSD bootstrap builds, and since OpenBSD
support has been upstreamed to Dispatch, default to the Dispatch
implementation for now to get this in, and we'll refactor in a different
pr.
2025-05-08 17:46:30 -04:00
Eric Miotto
6f696a4a75 Merge pull request #81165 from edymtt/edymtt/add-builtin-float-dep-to-distributed-and-synchronization-6.2
6.2: CMake: add explicit dependency to `_Builtin_float` to targets...
2025-05-08 12:07:41 -07:00
Guillaume Lessard
8d860936b2 Merge pull request #81225 from glessard/override-lifetime-publicly-6.2
[6.2, stdlib] make _overrideLifetime() functions public
2025-05-08 08:59:21 -07:00
Henrik G. Olsson
6861f2f4e4 [Swiftify] Don't use count from Span inside withUnsafeBufferPointer c… (#81316)
[Swiftify] Don't use count from Span inside withUnsafeBufferPointer c… (#81316)

Given a call like: ptr.withUnsafeBufferPointer { _ptrPtr in ... } ptr.count and _ptrPtr.count both contain the same value, but when ptr is a MutableSpan we get an error when referring to ptr inside a call to withUnsafeMutableBufferPointer, so we should use _ptrPtr.count instead.

rdar://150551109

[Swiftify] add _swiftifyOverrideLifetime for return Spans

std::span imports already have _cxxOverrideLifetime for their return
values. __counted_by needs the same, but Cxx may not be available at the
macro site, so we introduce _swiftifyOverrideLifetime in SwiftifyImport.

rdar://150569220
2025-05-07 21:06:45 -07:00
Guillaume Lessard
2942637f4a [stdlib] remove TODOs
These TODOs aren’t particularly actionable. What we really want is a way to define `_overrideLifetime()` in a not-unsafe way, and that will probably be a `Builtin` operation.
2025-05-07 17:14:08 -07:00
Guillaume Lessard
cae45f1584 [stdlib] make _overrideLifetime functions public
These are discussed in the lifetime annotations pitch: https://github.com/swiftlang/swift-evolution/pull/2750

Addresses rdar://150400414
2025-05-07 17:13:50 -07:00
Michael Gottesman
322a376432 Merge pull request #81334 from gottesmm/release/6.2-rdar150695113
[6.2][swift-settings] Now that we aren't using it immediately, remove it from tree.
2025-05-06 22:41:46 -07:00
Alejandro Alonso
2cc9fc61f4 Merge pull request #80855 from Azoy/62-value-generic-namelookup
[6.2] [NameLookup] Allow value generics to show up as static members
2025-05-06 20:55:07 -07:00
Michael Gottesman
e04e15f125 [swift-settings] Now that we aren't using it immediately, remove it from tree.
We can always get it back from the git history.

rdar://150695113
(cherry picked from commit 9d59dbed17)

Conflicts:
	include/swift/AST/DiagnosticsSema.def
	include/swift/Basic/Features.def
	test/abi/macOS/arm64/concurrency.swift
	test/abi/macOS/x86_64/concurrency.swift
2025-05-06 14:12:23 -07:00
Doug Gregor
68c7c85132 Merge pull request #81288 from swiftlang/revert-81127-pick-wip-inlinable-for-hashable-asyncstream
Revert "[6.2][Concurrency] Hashable funcs should be inlinable for AsyncStream"
2025-05-06 10:31:30 -07:00
Alastair Houghton
315d67c0e8 [Concurrency] Don't pass negative times to the Dispatch code.
Dispatch uses unsigned times, and cannot cope with times before its
clock started.  As such, passing negative times from Swift through to
the C++ code results in large unsigned values, which then causes us to
wait forever.  This is undesirable.

rdar://148899609
2025-05-06 16:31:05 +01:00
Alastair Houghton
418ae45ce2 [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-05-06 11:50:07 +01:00
Evan Wilde
728e57c022 Merge pull request #81283 from etcwilde/ewilde/6.2-FreeBSDPlatformExecutor
[6.2 🍒]: Add platform executor module for FreeBSD
2025-05-05 20:51:20 -07:00
Alejandro Alonso
9204a94a62 Merge pull request #81169 from Azoy/wrap-in-feature
[stdlib] Wrap InlineArray inlinable code in new feature
2025-05-05 18:42:52 -07:00
Alejandro Alonso
12919a2300 Merge pull request #78248 from Azoy/value-generic-static-member
[NameLookup] Allow value generics to show up as static members
2025-05-05 18:42:15 -07:00
Eric Miotto
06a2001708 CMake: add explicit dependency to _Builtin_float to targets...
... that would import that as a result of importing Darwin from the SDK.

Amend my previous change to Differentiation and Distributed in this
sense.

Addresses rdar://150400049

(cherry picked from commit 8c7e8550aa)
2025-05-05 13:48:55 -07:00
Doug Gregor
4669daaebd Fix issue with older compilers not handling MutableSpan code
The use of SendableCompletionHandlers here is completely incidental,
because it happened to be introduced at roughly the same time as the
bits we needed for MutableSpan. Fixes rdar://148072153.
2025-05-05 10:22:03 -07:00
Karoy Lorentey
4cde33c4b0 Merge pull request #80867 from lorentey/is_same_metatype_condfail_6.2
[6.2][stdlib] Allow metatype comparisons to work with outdated compilers
2025-05-05 10:03:35 -07:00
Doug Gregor
36a93dc91e Revert "[6.2][Concurrency] Hashable funcs should be inlinable for AsyncStream…"
This reverts commit ec7ed9ac39.
2025-05-05 10:02:38 -07:00
Evan Wilde
62c353a7f9 [6.2]: Add platform executor module for FreeBSD
Swift concurrency defines a default platform executor. This was not
defined for FreeBSD resulting in build failures. Defining it to use the
Dispatch executor.

Scope: This only impacts FreeBSD.
Risk: Low. This change only affects FreeBSD.
Reviewers: @compnerd, @ktoso, @al45tair
Testing: Local testing to ensure Concurrency builds on FreeBSD.
Fixes: rdar://150643436

(cherry picked from commit 4a41e50730)
2025-05-04 14:05:06 -07:00
Alastair Houghton
e767e7f705 Merge pull request #81196 from al45tair/eng/PR-150290165-6.2
[Concurrency] Fix copy-paste error.
2025-05-04 18:32:01 +01:00
Alastair Houghton
55cda7dd85 Merge pull request #80795 from al45tair/eng/PR-149058236-6.2
[Concurrency] Remove -executor-factory option and replace with magic type.
2025-05-04 18:29:30 +01:00
Stephen Canon
88e29fafc9 [6.2] Add static .nanoseconds(_: Double) to Duration (#81210) (#81236)
SE-0329 defines the following static factory methods:
```
public static func seconds<T: BinaryInteger>(_ seconds: T) -> Duration
public static func seconds(_ seconds: Double) -> Duration
public static func milliseconds<T: BinaryInteger>(_ milliseconds: T) -> Duration
public static func milliseconds(_ milliseconds: Double) -> Duration
public static func microseconds<T: BinaryInteger>(_ microseconds: T) -> Duration
public static func microseconds(_ microseconds: Double) -> Duration
public static func nanoseconds<T: BinaryInteger>(_ value: T) -> Duration
```
For no good reason, the obvious additional method:
```
public static func nanoseconds(_ nanoseconds: Double) -> Duration
```
was omitted. After talking this through with the LSG, we have decided
that this is simply a bug, and we will add this method without formal
evolution review.
2025-05-02 15:17:45 -07:00
Konrad `ktoso` Malawski
f6a864a188 Merge pull request #81135 from ktoso/pick-22b20e731eaa70746d3c21bf8c44836aa49dfabb
[6.2][Concurrency] Change isIsolatingCurrent... to return Bool?
2025-05-02 07:53:12 +09:00
Konrad `ktoso` Malawski
413349a0e8 Merge pull request #81230 from ktoso/pick-wip-escalation-handler-priority-auth
[6.2][Concurrency] Fix ptr auth for task priority escalation handler
2025-05-02 05:51:49 +09:00
Mike Ash
23e21ff47d Merge pull request #81206 from mikeash/fix-statusRecordLock-6.2
[6.2][Concurrency] Fix alreadyLocked in withStatusRecordLock.
2025-05-01 11:21:46 -04:00