Commit Graph

21434 Commits

Author SHA1 Message Date
Saleem Abdulrasool
90d9ce76ba Concurrency: handle android similar to Linux
Android should use the dispatch based, Linux platform executor. However,
Android reports as `os(Android)` rather than `os(Linux)`. This adjusts
the condition to ensure that we have a platform executor factory for
Android.
2025-03-21 11:00:08 -07:00
Fabrice de Gans
d5ea19405d Put float and stddef back inside the ucrt module
These were split out in #79751. However, this split is not needed for
these. Furthermore, modulemaps have bugs when it comes to re-exporting
some modules, resulting in missing exports.
2025-03-21 10:01:01 -07:00
Holly Borla
bac0a10ae2 [Macros] Update the name and argument list for the function body macro
that wraps a function or closure body in a new top-level task.
2025-03-21 06:21:45 -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
Dario Rexin
35a44e5168 [Concurrency] Fix templated code in Task+startSynchronously.swift (#80100)
* [Concurrency] Fix templated code in Task+startSynchronously.swift

rdar://147348183

The gyb code always dropped the `throws` modifier, no matter which case was being processed.

* Update Task+startSynchronously.swift.gyb

* Fix abi tests
2025-03-20 18:29:31 -07:00
Dave Lee
6ca8e0d502 [Concurrency] Change signposts to use decimal format for task ids (#80154)
Change task ids to be formatted using decimal instead of hex.

An example of previous signposts:

```
task=e resumefn=0x2807722bc jobPriority=0 isChildTask=0, isFuture=1 isGroupChildTask=0 isAsyncLetTask=0 parent=0 group=0x0 asyncLet=0x0
```

this will now show `task=14` instead of `task=e`
2025-03-20 13:23:37 -07:00
Gabor Horvath
3d6c714cd6 [cxx-interop] Add span property to std::vector
rdar://146944876
2025-03-20 16:15:06 +00:00
Mike Ash
1e265c24d7 Merge pull request #80096 from mikeash/task-group-cancellation-lock-fix
[Concurrency] Fix a race when using cancelAll on a task group concurrently with child tasks being removed.
2025-03-20 11:53:31 -04:00
Saleem Abdulrasool
43ec13a65b Merge pull request #80151 from Steelskin/fabrice/restore-ucrt-legacy-stdio-def
Restore legacy_stdio_definitions in ucrt.modulemap
2025-03-19 21:57:15 -07:00
Fabrice de Gans
7a965cee00 Restore legacy_stdio_definitions in ucrt.modulemap
This was removed in #79751 but is required in some cases.
2025-03-19 16:51:38 -07:00
Andrew Trick
955d089a90 CxxSpanReturnThunkBuilder: use _cxxOverrideLifetime(_:copying:)
Do not rely on the @_unsafeNonescapableResult attribute. That attribute is only
for temporarily working around bugs! And it only affects lifetime diagnostics within
the function. It has no affect on the caller's diagnostics, so it won't solve
this problem:

func macroGeneratedThunk() -> CxxSpan<Int> {
  return _unsafeRemoveLifetime(Span...)
}

We cannot simply add @_unsafeRemoveLifetime to the thunk, because SwiftSyntax
does not natively support the attribute. We don't want to add SwiftSyntax
support because this attribute will never be supported syntax!

Instead, use `_overrideLifetime` copying the `Void` type to remove a dependency:

func macroGeneratedThunk() -> CxxSpan<Int> {
  return _cxxOverrideLifetime(Span..., copying: ())
}
2025-03-19 11:59:05 -07:00
Andrew Trick
e91981266b Update CXXSpan for strict @lifetime 2025-03-19 11:59:04 -07:00
Andrew Trick
c6116be7b5 Update stdlib source with explicit @lifetime(copy self) 2025-03-19 11:59:04 -07:00
Andrew Trick
411a65be2e Add @lifetime annotation to RawSpan.init() and Span.init()
These empty initializers have @lifetime(immortal).
2025-03-19 11:59:04 -07:00
Egor Zhdan
02dfe26f8f Merge pull request #80090 from swiftlang/egorzhdan/std-string-interpolation
[cxx-interop] Conform `std::string` to `ExpressibleByStringInterpolation`
2025-03-19 18:28:56 +00:00
Mike Ash
953a7a5b74 [Runtime] Include size/alignment in allocation failure fatal error message.
It's hard to tell why a crash occurred with just "Could not allocate memory." Modify the message to include the size/alignment, which will help distinguish between an actual lack of memory and a request for an excessively large allocation.

While we're in there, add \n to a bunch of other fatal error helper functions that didn't have it.
2025-03-19 11:18:43 -04: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
Mike Ash
38c4fce1a8 [Concurrency] Fix a race when using cancelAll on a task group concurrently with child tasks being removed.
_swift_taskGroup_cancelAllChildren relies on there being no concurrent modification when called from the owning task, but this is not guaranteed.

Rearrange things to always take the owning task's status record lock when walking the group's children. Split _swift_taskGroup_cancelAllChildren into two functions, one which assumes/requires the lock is already held, and one which acquires the lock. We don't have the owning task in this case, but we can either get it from the current task, or by looking at the parent of the child task we're working on.

rdar://147172991
2025-03-18 14:52:07 -04:00
Alastair Houghton
0da95eb20d [Concurrency] Fix some warnings, use typed throws.
Fix a couple of `unsafe` warnings.

Also update `withUnsafeExecutorPrivateData` to use typed throws instead of
`rethrow`.

rdar://141348916
2025-03-18 18:37:31 +00:00
Alastair Houghton
fb0396c509 [Concurrency] Fall back to allocating from the heap, fix a test.
`CooperativeExecutor` should fall back to heap allocations if the task
allocator isn't available when it's enqueuing delayed jobs.

Also, remove the reference to `DispatchGlobalExecutor` from the
custom executor test.

rdar://141348916
2025-03-18 17:59:57 +00:00
Alejandro Alonso
25b10ebf76 Merge pull request #78092 from Azoy/enumerated-collection
[stdlib] Conditionally conform EnumeratedSequence to Collection(s)
2025-03-18 09:24:08 -07:00
Fabrice de Gans
5e3bd9f90b Merge pull request #79751 from Steelskin/fabrice/update-ucrt-modulemap
Update ucrt.modulemap for Windows SDK 10.0.26100
2025-03-18 09:04:24 -07:00
Egor Zhdan
e32e64353f [cxx-interop] Conform std::string to ExpressibleByStringInterpolation
This adds conformances for C++ string types (`std::string`, `std::u16string`, `std::u32string`) to `Swift.ExpressibleByStringInterpolation`.

These conformances currently implicitly use `DefaultStringInterpolation`. In the future we can provide more performant interpolation mechanisms for C++ strings specifically that avoid the extra conversion between Swift String and C++ string types.

rdar://147249169
2025-03-18 15:54:56 +00:00
Alastair Houghton
60fb31cf01 [Concurrency][32-bit] Store timestamp out-of-line on 32-bit.
CooperativeExecutor needs to store its timestamp out-of-line for
32-bit architectures (like WASI).

rdar://141348916
2025-03-18 15:46:51 +00:00
Alastair Houghton
167449f3db [Concurrency] Fix a typo and use var not let.
Fix a typo that caused us to not include the correct code for platforms
that use "singlethreaded" concurrency.

Also use `var` not `let` for the computed property in `PlatformExecutorFactory`.

rdar://141348916
2025-03-18 10:39:41 +00:00
Ben Rimmington
bbe26880a5 [stdlib] Update InlineArray (2) (#79866)
* Amend doc comments.
* Add `guard` for empty array.
* Add tests for initialization errors.
* Use `Self.` to call static method.
* Use `_checkIndex` in `swapAt` method.
* Wrap overlong lines.
2025-03-18 05:59:15 +00:00
Konrad `ktoso` Malawski
85fcd69833 [Concurrency] Implement detecting isIsolatingCurrentContext user impls (#79946)
* [Concurrency] Detect non-default impls of isIsolatingCurrentContext

* [Concurrency] No need for trailing info about isIsolating... in conformance

* Apply changes from review
2025-03-18 09:39:11 +09:00
Doug Gregor
9c2c4ea07f Merge pull request #79707 from DougGregor/transparent-integer-conversions
[Stdlib performance] Make integer conversion operations transparent
2025-03-17 16:37:16 -07: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
ad5b76a663 [Concurrency] Another missing availability annotation.
We need to annotate the `timestamp()` function for watchOS (apparently
not for macOS for some reason).

rdar://141348916
2025-03-17 18:48:17 +00: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
Mike Ash
13ef626044 Merge pull request #80021 from mikeash/metadata-allocator-memory-order-tsan
[Runtime] Fix memory ordering and TSan compatibility in MetadataAllocator.
2025-03-17 12:05:29 -04:00
Max Desiatov
5be82d18cb Fix variable never mutated warning in swift-backtrace (#80055)
```
stdlib/public/libexec/swift-backtrace/main.swift:590:15: warning: variable 'now' was never mutated; consider changing to 'let' constant
 588 |           let name = target!.name
 589 |           let pid = target!.pid
 590 |           var now = timespec(tv_sec: 0, tv_nsec: 0)
     |               `- warning: variable 'now' was never mutated; consider changing to 'let' constant
 591 |
 592 |           let ext: String
```
2025-03-17 08:30:16 -07: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
Erik Eckstein
5030c829ea stdlib: annotate the compiler intrinsic function _arrayConditionalCast with a semantic attribute
This is need for the optimizer to remove redundant array casts
2025-03-15 08:32:57 +01: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
Mike Ash
7a50a8fe67 [Runtime] Fix memory ordering and TSan compatibility in MetadataAllocator.
We need a store-release when putting a new page onto the metadata allocator so that other threads see the initialization. We also need to tell TSan about our memory barriers here, to avoid false positives in __swift_instantiateConcreteTypeFromMangledName when it reads from memory allocated here.

rdar://145778813
2025-03-14 12:46:34 -04:00
Mike Ash
f1070f7f1e Merge pull request #80000 from swiftlang/jgrynspan/145945680-mangledtypename-nonescapable
[Runtime] Allow ~Escapable types in _getMangledTypeName.
2025-03-14 11:53:12 -04:00
Alastair Houghton
a4f79f367a [Concurrency][Linux] Fix WASI build.
This doesn't actually add proper WASI support - it just fixes the
build so that we're no worse off than we were.

rdar://141348916
2025-03-14 14:57:15 +00:00
Konrad `ktoso` Malawski
57288d13c9 [Concurrency] task names dont need default nil arg (#80011) 2025-03-14 21:15:01 +09:00
Konrad `ktoso` Malawski
a92f37998e [freestanding] prefer strncpy with known length (#80005) 2025-03-14 04:44:09 -07:00
Alastair Houghton
8caa5c5c0d [Concurrency] Add a missing public.
The default implementation of `traits` on `Clock` needs to be `public`.

rdar://141348916
2025-03-14 10:01:37 +00:00
Doug Gregor
1fafebccdf Merge pull request #80006 from DougGregor/concurrency-if-task-to-thread
[Concurrency] Remove unnecessary #ifs that break task-to-thread model
2025-03-13 21:39:04 -07:00
Guillaume Lessard
39ca3dee4d Merge pull request #80003 from glessard/span-gardening
[stdlib] fix `Span`'s `Sendable` conformance
2025-03-13 18:54:42 -07: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
Guillaume Lessard
e81a2ee3a1 [stdlib] correctly express Span sendability 2025-03-13 13:54:18 -07:00
Alejandro Alonso
5d745fe5d5 Update MinimalCollections.swift 2025-03-13 10:50:06 -07:00
Alejandro Alonso
0646c61cf5 Fix bidirectional test to account for RandomAccess 2025-03-13 10:11:51 -07:00
Alejandro Alonso
b0d98549cb Update to match api acceptance 2025-03-13 09:58:44 -07:00
Alejandro Alonso
9894440454 Conditionally conform EnumeratedSequence to Collections 2025-03-13 09:58:09 -07:00