Commit Graph

21665 Commits

Author SHA1 Message Date
Henrik G. Olsson
bd233ea26e [Swiftify] Don't use count from Span inside withUnsafeBufferPointer call (#81267) 2025-05-04 01:52:05 -07:00
Doug Gregor
c249357f16 Merge pull request #81249 from DougGregor/observation-nonisolated-conformances
[Observation] Create nonisolated conformances to Observable
2025-05-02 12:56:27 -07:00
Karoy Lorentey
74efc7d354 Merge pull request #80859 from lorentey/is_same_metatype_condfail
[stdlib] Allow metatype comparisons to work with outdated compilers
2025-05-02 00:06:18 -07:00
Doug Gregor
3a01fc18b4 Make the _Concurrency library depend on _Builtin_float 2025-05-01 22:01:38 -07:00
Philippe Hausler
3f157ab712 [Observation] Use independent locking since the runtime functions reference a symbol that is not emitted (#81185)
The runtime functions for locking end up referencing a symbol that is
not publicly emitted. This leads to broken linux builds.
Since that interface is not public and does not offer a stable mechanism
and Synchronization cannot be used (due to it being a higher deployment
target) instead it has to revert to implementing locking from scratch
for all platforms.

This is mostly replicated from the swift-async-algorithms package and
should be usable enough to accomplish the goals of this module.

Resolves rdar://150060874
2025-05-01 17:30:50 -07:00
Mike Ash
2838208c06 Merge pull request #81234 from mikeash/useless-comment-begone
[Concurrency] Remove useless comment about assert in AsyncTask::complete().
2025-05-01 16:02:45 -04:00
Stephen Canon
ab2b28cc4b Add static .nanoseconds(_: Double) to Duration (#81210)
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-01 15:50:17 -04:00
Mike Ash
a1dbdd59d1 [Concurrency] Remove useless comment about assert in AsyncTask::complete().
This comment is really about an assert that's no longer present, so it should just go away.
2025-05-01 11:22:39 -04:00
Meghana Gupta
3cad5c5924 Merge pull request #81043 from meg-gupta/fixcow
Insert end_cow_mutation_addr for lifetime dependent values dependent on mutable addresses
2025-05-01 07:26:28 -07:00
Alastair Houghton
23a181730f Merge pull request #81200 from al45tair/eng/PR-150310927
[Concurrency] Fix issue with using Dispatch queues as executors.
2025-05-01 11:56:43 +01:00
Konrad `ktoso` Malawski
62c6159027 Merge pull request #81229 from ktoso/wip-escalation-handler-priority-auth
[Concurrency] Fix ptr auth for task priority escalation handler
2025-05-01 19:53:54 +09:00
Konrad 'ktoso' Malawski
8fccafd2fa [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:07:35 +09:00
Mike Ash
158b1c56aa Merge pull request #81205 from mikeash/fix-statusRecordLock
[Concurrency] Fix alreadyLocked in withStatusRecordLock.
2025-04-30 21:20:16 -04:00
Evan Wilde
4a41e50730 Add platform executor module for FreeBSD
Effectively the same as Linux and OpenBSD. If Dispatch is disabled, this
will fail because the dispatch executor isn't defined.
2025-04-30 17:08:53 -07:00
Guillaume Lessard
e0cfb31fcd [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-04-30 15:54:41 -07:00
Meghana Gupta
ceb3264e40 Disable runtime cow verification for mutableSpan property 2025-04-30 13:38:51 -07:00
Mike Ash
325b66ab20 [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
2025-04-30 13:53:31 -04:00
Alejandro Alonso
aad8513040 Merge pull request #81169 from Azoy/wrap-in-feature
[stdlib] Wrap InlineArray inlinable code in new feature
2025-04-30 09:45:26 -07:00
Alastair Houghton
e843a24a99 [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:18:42 +01:00
Alastair Houghton
0a5fa056e7 [Concurrency] Fix copy-paste error.
The `__builtin_add_overflow` should have been adding to `leeway`, not to
`deadline`.

rdar://150290165
2025-04-30 10:14:22 +01:00
Konrad `ktoso` Malawski
0083f09cf4 Merge pull request #81134 from ktoso/wip-adjust-isIsolatingCurrentContext-impl 2025-04-30 06:43:20 +09:00
Eric Miotto
ea74546e15 Merge pull request #81141 from edymtt/edymtt/add-builtin-float-dep-to-distributed-and-synchronization
Add `_Builtin_float` dependency to `Distributed` and `Synchronization`
2025-04-29 12:32:23 -07:00
Alejandro Alonso
865aed0c38 Wrap InlineArray inlinable code in new feature 2025-04-29 10:02:15 -07:00
Konrad 'ktoso' Malawski
6872707574 [embedded][Concurrency] Further refine C-api boundary for isIsolating... 2025-04-29 22:29:26 +09:00
Konrad 'ktoso' Malawski
ea16df04ac [Concurrency] adjust how we fail creating an IsIsolatingCurrentContextDecision 2025-04-29 20:08:56 +09:00
Konrad 'ktoso' Malawski
e1dc854f8f [Concurrency] Change isIsolatingCurrent... to return Bool?
This changes the isIsolatingCurrentContext function to return `Bool?`
and removes all the witness table trickery we did previously to detect
if it was implemented or not. This comes at a cost of trying to invoke
it always, before `checkIsolated`, but it makes for an simpler
implementation and more checkable even by third party Swift code which
may want to ask this question.

Along with the `withSerialExecutor` function, this now enables us to
check the isolation at runtime when we have an `any Actor` e.g. from
`#isolation`.

Updates SE-0471 according to
https://forums.swift.org/t/se-0471-improved-custom-serialexecutor-isolation-checking-for-concurrency-runtime/78834/
review discussions
2025-04-29 20:08:55 +09:00
Mike Ash
22c34dd254 Merge pull request #81041 from mikeash/unowned-destroyed-error-message
[Runtime] Change the unowned reference fatal error to "was already destroyed."
2025-04-28 19:49:06 -04:00
Eric Miotto
231a9d989d Add _Builtin_float dependency to Distributed and Synchronization
This will avoid errors in CI when the latter ones are scheduled before
the former.

Addresses rdar://149558141
2025-04-28 09:37:07 -07:00
Konrad 'ktoso' Malawski
06bb7183f4 [Concurrency] Hashable funcs should be inlinable for AsyncStream 2025-04-28 16:17:10 +09:00
Evan Wilde
1bff8cda36 Merge pull request #80877 from 3405691582/platform_executor
Add a platform executor module for OpenBSD.
2025-04-27 17:44:10 -07:00
Kuba (Brecka) Mracek
642a6ca7e6 Merge pull request #81107 from kubamracek/embedded-conc-arch-cmake
[embedded] Make the CMake setup for Embedded Concurrency distinguish ARCH and SUBDIR for builds products
2025-04-26 15:51:42 -07:00
Konrad `ktoso` Malawski
ccecaccba5 Merge pull request #81123 from ktoso/wip-correct-metadata-handling-distributed
[Distributed] thread-safety also for parameter type metadata
2025-04-27 01:59:28 +09:00
Andrew Trick
c25d46320c Merge pull request #81105 from atrick/rdar146319009-borrow-constraint
Fix LifetimeDependenceDiagnostics: scoped dependence on a copy
2025-04-26 08:08:15 -07:00
Kuba Mracek
c5aa98a449 [embedded] Make the CMake setup for Embedded Concurrency distnguish ARCH and SUBDIR for builds products 2025-04-26 07:03:19 -07:00
Konrad 'ktoso' Malawski
284c060d0a [Distributed] thread-safety also for parameter type metadata
We had fixed this bug in https://github.com/swiftlang/swift/pull/79381
but missed to realize the same problem existed for parameters as well.

This corrects the swift_func_getParameterTypeInfo impl, and also removes
the entire "unsafe" method, we no longer use it anywhere.

Resolves rdar://146679254
2025-04-26 21:30:13 +09: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
Andrew Trick
e9d11283b9 Add _overrideLifetime to Span APIs
The implementation previously took advantage of a missing diagnostic. They
returned a borrowed Span with a dependency on a copied argument. This illegally
promotes the dependency. This is what the author intended to do (the
implementation was correct) but the compiler can't know that so the code needs
to be explicit about overriding the lifetime.
2025-04-25 17:58:24 -07:00
Gábor Horváth
301a752707 Merge pull request #81097 from swiftlang/gaborh/mutable-span-conversion 2025-04-25 11:55:44 -07:00
3405691582
db942def27 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-04-25 14:05:58 -04:00
Gabor Horvath
7d0d872bdb [cxx-interop] Proper conversions between MutableSpan and C++ span
One of the initializers were missing and the other was crashing at
runtime due to a faulty signature in the overlay.

rdar://149846666
2025-04-25 11:28:32 +01:00
Konrad 'ktoso' Malawski
7112f7ea56 [Concurrency] Support ~Copyable in withSerialExecutor 2025-04-25 18:40:24 +09:00
Konrad 'ktoso' Malawski
fcbd7dbc0d [Concurrency] Support ~Copyable return type in withSerialExeutor 2025-04-25 18:40:24 +09:00
Konrad 'ktoso' Malawski
84764de38c [Concurrency] Fix code completion test given new actor method 2025-04-25 18:40:24 +09:00
Konrad 'ktoso' Malawski
20fe3b0dea [Concurrency] Offer way to get SerialExecutor from Actor 2025-04-25 18:40:23 +09:00
Evan Wilde
9ff70cdb43 Merge pull request #81010 from etcwilde/ewilde/runtime-fix-clobbered-memories
[SwiftCore]: Don't always clobber memory
2025-04-24 10:06:40 -07:00
Mike Ash
66111530e1 [Runtime] Change the unowned reference fatal error to "was already destroyed."
The "was already deallocated" message is incorrect, since the target of an unowned reference stays allocated even after being deinitialized. We could say "was already deinitialized" but that's a bit of a niche term. "Was already destroyed" conveys what happened without the reader needing to worry about deinitialization versus deallocation.

rdar://149237704
2025-04-23 15:28:16 -04:00
Kuba (Brecka) Mracek
685572ed49 Merge pull request #80977 from kubamracek/embedded-concurrency-function-sections
[embedded][Concurrency] Build C++ runtime Concurrency code with -ffunction-sections and more embedded friendly flags
2025-04-23 07:11:17 -07:00
Kuba (Brecka) Mracek
84ba9dd1ad Merge pull request #81011 from kubamracek/embedded-conc-non-darwin2
[embedded][Concurrency] Also apply non-Darwin flags in Concurrency C++ runtime builds when targeting armv7m/armv7em
2025-04-22 23:06:11 -07:00
Kuba (Brecka) Mracek
3597454f71 Merge pull request #80973 from kubamracek/embedded-empty-box
[embedded] Add swift_allocEmptyBox to the embedded runtime
2025-04-22 22:31:21 -07:00
Evan Wilde
6f39a52afc [SwiftCore]: Don't always clobber memory
The new build system set `SWIFT_RUNTIME_CLOBBER_FREED_OBJECTS` to 0.
Unfortunately, the check in the Swift runtime used `#ifdef`, so even
though it was turned off, it was actually enabled in some cases.

Fixing the issue in the build system as well as switching the check to
verify that value of `SWIFT_RUNTIME_CLOBBER_FREED_OBJECTS` is taken into
account in the sources. C/C++ implicitly defines macro values to 1 when
set without a value and 0 when it is not set.

Also making the hex a bit more recognizable and grep'able by including
it as a comment.

Fixes: rdar://149210738
2025-04-22 16:51:28 -07:00