Commit Graph

17564 Commits

Author SHA1 Message Date
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
Konrad 'ktoso' Malawski
75a3cacaec [Concurrency] Hide the _withSerialExecutor, we will introduce executor 2025-05-01 22:08:18 +09:00
Konrad 'ktoso' Malawski
fe0889b285 [Concurrency] Offer way to get SerialExecutor from Actor 2025-05-01 22:07:13 +09:00
Alastair Houghton
c072992fe4 Merge pull request #81201 from al45tair/eng/PR-150310927-6.2
[Concurrency] Fix issue with using Dispatch queues as executors.
2025-05-01 11:57:24 +01:00
Meghana Gupta
7b0ac8b5b6 Merge pull request #81216 from meg-gupta/fixcowcp
[6.2] Insert end_cow_mutation_addr for lifetime dependent values dependent on mutable addresses
2025-05-01 00:44:41 -07:00
Konrad 'ktoso' Malawski
3615dbf398 [Concurrency] Fix ptr auth for task priority escalation handler
We missed to sign the handler. Along the way the signature of it
changed, so adjust for that.

How to get the number:

```
func PROPER(bar: (TaskPriority, TaskPriority) -> Void) {
    let p = TaskPriority.default
    bar(p, p)
}
```

```
-> % swiftc -target arm64e-apple-macos13 example.swift -S -o - | swift demangle | grep -a3 autda
	stur	x8, [x29, #-64]
	mov	x17, x8
	movk	x17, #11839, lsl #48 <<<<<<<<<
	autda	x16, x17
	ldr	x8, [x16, #64]
	lsr	x8, x8, #0
	add	x8, x8, #15
```

Resolves rdar://150378890
2025-05-01 12:13:29 +09:00
Doug Gregor
fcedb0b2a4 Merge pull request #81125 from DougGregor/unsafe-call-effects-6.2
[6.2] [Strict memory safety] Provide argument-specific diagnostics for calls
2025-04-30 15:09:50 -07:00
Meghana Gupta
67b5290ac2 Disable runtime cow verification for mutableSpan property 2025-04-30 14:38:02 -07:00
Mike Ash
a44dadd0e0 [6.2][Concurrency] Fix alreadyLocked in withStatusRecordLock.
If the preloaded status is locked, then we need to reload it in order to distinguish between the current thread holding the lock and another thread holding the lock. Without this, if another thread holds the lock, then we won't set the is-locked bit. We'll still actually hold the lock, but other threads may perform operations locklessly if the bit is not set, which can cause a crash. By reloading status in that case, we ensure that the bit is always set correctly.

This manifested as crashes in task cancellation but could cause other task-related issues as well.

Also remove an assert of !isStatusRecordLocked() in AsyncTask::complete(). We allow other threads to access tasks and take the lock for things like cancellation, so the lock may legitimately be held at that point.

rdar://150327908
(cherry picked from commit 325b66ab20)
2025-04-30 13:56:29 -04:00
Guillaume Lessard
c5acba54fa Merge pull request #80777 from glessard/rdar138440979-MutableSpan-mutableBytes
[6.2, SE-0467] add mutableBytes to MutableSpan
2025-04-30 09:46:44 -07:00
Alastair Houghton
7f5f45ced2 [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:29:14 +01:00
Alastair Houghton
ae47fd7140 [Concurrency] Fix copy-paste error.
The `__builtin_add_overflow` should have been adding to `leeway`, not to
`deadline`.

rdar://150290165
2025-04-30 10:19:04 +01:00
Konrad `ktoso` Malawski
ec7ed9ac39 [6.2][Concurrency] Hashable funcs should be inlinable for AsyncStream (#81127)
Small review followup for https://github.com/swiftlang/swift/pull/81064/

The impls should be @inlinable.

Original PR: https://github.com/swiftlang/swift/pull/81126
Radar: rdar://149914179
2025-04-30 00:58:01 -07:00