Commit Graph

1608 Commits

Author SHA1 Message Date
Eric Miotto
28e2f079b5 CMake: on Darwin be explicit about inclusion in the dyld shared cache (#70856)
This entails passing a linker flags to Apple linkers when the standard
library is not meant for inclusion in such cache.

For this to have effect on every library, propagate link flags when
building _Concurrency and Observation.

This is needed for Apple internal configurations.

Addresses rdar://120653968
2024-01-29 09:42:38 -08:00
Zev Eisenberg
5a67adde2d Clarify wording. (#71191)
“And” is a continuation of a prior statement. “But” is a negation of a prior statement.
2024-01-28 15:56:13 +09:00
Rick van Voorden
f8ae46b3f3 [inclusive-language] changed sanity to soundness 2024-01-25 18:18:02 -08:00
Doug Gregor
4c990dc0b9 Introduce an egregious source-compatibility hack for AsyncSequence.flatMap
Allow `AsyncSequence.flatMap` to be defined with "incorrect" availability,
meaning that the function can refer to the `Failure` associated type
in its where clause even though the function is back-deployed to
before the `Failure` associated type was introduced.

We believe this is safe, and that this notion can be generalized to any
use of an associated type in a same-type constraint of a function
(yes, it sounds weird), but for now introduce a narrower hack to see
how things work in practice and whether it addresses all of the
source-compatibility concerns we've uncovered.
2024-01-25 16:04:58 -08:00
Doug Gregor
9bacd3ed07 Remove workaround for do..catch not handling concrete error types 2024-01-25 16:04:49 -08:00
Doug Gregor
6ebb0ff560 Replace AsyncIteratorProtocol.nextElement() with isolated next(_:)
Use an optional isolated parameter to this new `next(_:)` overload to
keep it on the same actor as the caller, and pass `#isolation` when
desugaring the async for..in loop. This keeps async iteration loops on
the same actor, allowing non-Sendable values to be used with many
async sequences.
2024-01-25 16:04:48 -08:00
Doug Gregor
ec945bf3d9 Implement AsyncThrowingStream.nextElement() with typed throws 2024-01-25 16:04:47 -08:00
Doug Gregor
3482ca02ad Add availability for the Failure associated type of async sequences 2024-01-25 16:04:46 -08:00
Doug Gregor
0baa5b978b Typed throws is enabled by default, we don't need to opt in 2024-01-25 16:04:45 -08:00
Doug Gregor
b0029b24f5 Add AsyncThrowingFlatMapSequence.nextElement() 2024-01-25 16:04:45 -08:00
Doug Gregor
1b6a18f52b Adopt nextElement() in AsyncFlatMapSequence
`AsyncFlatMapSequence` is somewhat troublesome for typed throws,
because it can produce errors from two different sources: the `Base`
async sequence and the `SegmentOfResult` async sequence. However, we
need to pick one `Failure` type for the `AsyncFlatMapSequence`, and
there is no surface-language equivalent to the `errorUnion` operation
described in SE-0413.

So, we do something a little bit sneaky. We effectively require that
`SegmentOfResult.Failure` either be equivalent to `Base.Failure` or be
`Never`, such so that when the async sequence retruned by the closure
throws, it throws the same thing as the base sequence. Therefore, the
`Failure` type is defined to be `Base.Failure`.

This property isn't enforced at the type level, but instead in the
`AsyncSequence.flatMap` signatures: we replace the one signature that
returned `AsyncFlatMapSequence` with three overloads that differ only
in their generic requirements, adding:
1. `where SegmentOfResult.Failure == Failure`
2. `where SegmentOfResult.Failure == Never`
3. `where SegmentOfResult.Failure == Never, Failure == Never` (a
tiebreaker between the two above)

For cases where `SegmentOfResult.Failure` is neither `Never` nor
`Failure`, overloading will choose the `flatMap` function that returns
an `AsyncThrowingFlatMapSequence`. This can mean that existing code
will choose a different overload and get a different type, but other
than the type identity changing, the resulting sequence will behave
the same way.
2024-01-25 16:04:45 -08:00
Doug Gregor
3e726ebc55 Add nextElement() and explicit Failure types for a number of asynchronous iterators 2024-01-25 16:04:44 -08:00
Doug Gregor
909257ecd0 Implement nextElement() on most async sequences that have rethrowing next()
Start implementing `nextElement()` for the various async sequences
provided by the concurrency library, starting with those that
currently depend on `rethrows` with conformances, an undocumented
feature we're trying to stage out of the language.

With the exception of `AsyncFlatMapSequence`, all of these async
sequences have obvious implementations of `nextElement()`. We'll save
that one for later.
2024-01-25 16:04:44 -08:00
Doug Gregor
239f8d8a78 Rename AsyncIteratorProtocol._nextElement -> nextElement 2024-01-25 16:04:43 -08:00
Doug Gregor
b2a5ebe1bd Always emit AsyncIteratorProtocol._nextElement into the client
... this allows us to use the entrypoint when back-deploying code that
uses the async for..in loop.
2024-01-25 16:04:43 -08:00
Doug Gregor
bb7a563e6c Switch async for-each loop over to _nextElement and drop @rethrows.
This couples together several changes to move entirely from
`@rethrows` over to typed throws:

* Use the `Failure` type to determine whether an async for-each loop
will throw, rather than depending on rethrows checking

* Introduce a special carve-out for `rethrows` functions that have a
generic requirement on an `AsyncSequence` or `AsyncIteratorProtocol`,
which uses that requirement's `Failure` type as potentially being part
of the thrown error type. This allows existing generic functions like
the following to continue to work:

    func f<S: AsyncSequence>(_: S) rethrows

* Switch SIL generation for the async for-each loop from the prior
`next()` over to the typed-throws version `_nextElement`.

* Remove `@rethrows` from `AsyncSequence` and `AsyncIteratorProtocol`
entirely. We are now fully dependent on typed throws.
2024-01-25 16:04:43 -08:00
Doug Gregor
a5bdb12b48 Adopt typed throws in AsyncIteratorProtocol and AsyncSequence
Introduce a new associated type `Failure` into the two protocols involved
in async sequences, which represents the type thrown when the sequence
fails. Introduce a defaulted `_nextElement()` operations that throws
`Failure` or produces the next element of the sequence. Provide a
default implementation of `_nextElement()` in terms of `next()` that
force-cases the thrown error to the `Failure` type.

Introduce special associated type inference logic for the `Failure`
type of an `AsyncIteratorProtocol` conformance when there is no
specific _nextElement()` witness. This inference logic looks at the
witness for `next()`:
* If `next()` throws nothing, `Failure` is inferred to `Never`.
* If `next()` throws, `Failure` is inferred to `any Error`.
* If `next()` rethrows, `Failure` is inferred to `T.Failure`, where
`T` is the first type parameter with a conformance to either
`AsyncSequence` or `AsyncIteratorProtocol`.

The default implementation and the inference rule, together, allow
existing async sequences to continue working as before, and set us up
for changing the contract of the `async for` loop to use
`_nextIterator()` rather than `next()`.

Give `AsyncSequence` and `AsyncIteratorProtocol` primary associated
types for the element and failure types, which will allow them to be
used more generally with existential and opaque types.
2024-01-25 16:04:42 -08:00
Allan Shortlidge
b5a36cfdba Merge pull request #71030 from tshortli/resolve-even-more-warnings
Resolve even more warnings
2024-01-19 21:03:03 -08:00
Konrad `ktoso` Malawski
1dec00a420 [TaskExecutors] Task initializer and withTaskExecutor parameter changes (#70783) 2024-01-20 11:03:26 +09:00
Allan Shortlidge
64d0f72d98 NFC: Address a warning in swift_task_asyncMainDrainQueueImpl().
The function is marked `noreturn` but the compiler was not able to reason
statically about whether this constraint is met. From code inspection it's
clear that the call to `swift_task_donateThreadToGlobalExecutorUntil()` does
not return, so `swift_unreachable()` can be used to suppress the warning.
2024-01-19 15:43:35 -08:00
Doug Gregor
8d67a37231 Only declare isolation macro when the compiler supports macros 2024-01-18 18:47:26 -08:00
Doug Gregor
24c2d1a49c Switch #isolation from AnyActor to Actor
We are currently lacking the ability to describe "normal or distributed
actor" with a single protocol in a manner that allows hopping to it,
because `AnyActor` is a marker protocol. Use `Actor` while we sort
this out.
2024-01-18 18:46:47 -08:00
Allan Shortlidge
92a0867f08 Merge pull request #70948 from tshortli/resolve-concurrency-runtime-warnings
Resolve warnings in the Concurrency runtime
2024-01-16 18:59:50 -08:00
Allan Shortlidge
05dbd059e1 Merge pull request #70943 from tshortli/resolve-more-warnings
Resolve more warnings
2024-01-16 17:19:51 -08:00
Allan Shortlidge
8343e7a292 NFC: Suppress -Wreturn-type-c-linkage warnings in GlobalExecutor.cpp. 2024-01-16 16:21:06 -08:00
Allan Shortlidge
f18b196ed8 NFC: Suppress a -Wunreachable-code warning in GlobalExecutor.cpp.
The `swift_unreachable()` is currently statically unreachable but we'd like to
leave it in place in case the control flow before it changes in the future.
2024-01-16 16:21:06 -08:00
Allan Shortlidge
00da82ddd7 NFC: Remove a superfluous if #available from Executor.swift.
Confirmed with Konrad that this was copypasta.
2024-01-16 16:21:06 -08:00
Doug Gregor
8b514ec029 Merge pull request #70902 from DougGregor/isolation-macro
Implement `#isolation` macro to produce the isolation of the current context
2024-01-16 14:27:00 -08:00
Doug Gregor
255009dddb Implement #isolation macro to produce the isolation of the current context
Introduce a new expression macro that produces an value of type
`(any AnyActor)?` that describes the current actor isolation. This
isolation will be `nil` in non-isolated code, and refer to either the
actor instance of shared global actor in other cases.

This is currently behind the experimental feature flag
OptionalIsolatedParameters.
2024-01-16 14:25:51 -08:00
Allan Shortlidge
79d0ecafaa NFC: Ignore deprecation of asl_log in the runtime and demangling library.
ASL is deprecated in macOS 10.12. It may be time to transition to os_log now
that deployment targets have been raised to 10.12, but until that project
starts these warnings are just pollution.

Filed rdar://121066531 to track adoption of `os_log()` if appropriate.
2024-01-16 13:27:55 -08:00
Konrad `ktoso` Malawski
9d3540fd75 [docs] TaskLocal APIs from non-Task code (#70622) 2024-01-15 11:38:01 +09:00
Allan Shortlidge
1680d5733d Concurrency: Remove superfluous trys in ExecutorAssertions.swift. 2024-01-13 16:23:55 -08:00
Allan Shortlidge
100e5ee797 [Concurrency] Fix more missing builtin guards for DiscardingTaskGroup.
Follow-up to https://github.com/apple/swift/pull/70837.
2024-01-11 10:22:55 -08:00
Konrad `ktoso` Malawski
70b1c0e43c [Concurrency] Major cleanup of assert/precondition/assume isolated docs (#70800)
Co-authored-by: Alex Martini <amartini@apple.com>
2024-01-10 23:48:32 -08:00
Konrad `ktoso` Malawski
ef80d778dc [Concurrency] Fix the missing builtin guards for DiscardingTaskGroup (#70837) 2024-01-10 22:55:38 -08:00
Yuta Saito
7cccbcc84f [DiscardingTG] Remove reabstraction thunk for () -> Void to () -> T (#70537)
Concurrency runtime expects discarding task operation entrypoint
function not to have result type, but the current SILGen
implementation generates reabstraction thunk to convert `() -> Void`
to `() -> T` for the operation function.

Since the `T` is always `Void` for DiscardingTG, the mismatch of result
type expectation does not cause any problem on most platforms, but the
signature mismatch causes a problem on WebAssembly.

This patch introduces new builtin operations for creating discarding
task, which always takes `() -> Void` as the operation function type.
2024-01-10 07:17:15 +09:00
AtariDreams
e2d2ca05d6 waitQueue.compare_exchange_strong in the true loop can be weak (#70636) 2024-01-09 16:49:43 +09:00
Rokhini Prabhu
61bec0d786 Always clear out the SchedulerPrivate fields before enqueueing the task
into the executor
2023-12-21 19:22:05 -08:00
Doug Gregor
0fbbc6ae65 [SE-0392] Back-deploy assertIsolation/assumeIsolation
The assertIsolation/assumeIsolation operations on actors are
back-deployable back to the introduction of concurrency. Do so.

Resolves rdar://111880539
2023-12-14 15:13:46 -08:00
Rokhini Prabhu
ed8ed32dba Clean up Concurrency build system so that all the logic around choice of
which executor for which type of setting, is consolidated and we have a
single knob we use to determine when to use dispatch as our global
executor.

Radar-Id: rdar://problem/119416196
2023-12-13 16:09:51 -08:00
Konrad `ktoso` Malawski
828f589be4 Initial Task Executor implementation Task(on:), addTask(on:) etc. (#68793)
Co-authored-by: John McCall <rjmccall@gmail.com>
2023-12-12 17:14:24 +09:00
Kuba (Brecka) Mracek
b8b68f0d2e Merge pull request #70352 from kubamracek/embedded-install-concurrency
[embedded] Make sure to install the embedded Concurrency .a libraries into the toolchain
2023-12-11 08:55:38 -08:00
Kuba Mracek
9581e92589 [embedded] Make sure to install the embedded Concurrency .a libraries into the toolchain 2023-12-08 21:38:33 -08:00
Rokhini Prabhu
ffd1ad2286 Convert use of std::mutex in task groups to use Mutex from threading package
Radar-Id: rdar://problem/119415891
2023-12-08 20:17:52 -08:00
Kuba (Brecka) Mracek
ea499a5bdb Merge pull request #70055 from kubamracek/embedded-darwin
[embedded] Port and start building Darwin.swiftmodule as embedded
2023-11-30 17:47:55 -08:00
Kuba Mracek
7c84cdb83f [embedded] Start installing embedded Concurrency and Darwin modules into the toolchain 2023-11-28 16:18:10 -08:00
Kuba Mracek
a0ec73ef42 [embedded] Start building embedded support on Linux/ELF, expand archs of the embedded stdlib to cover common embedded targets, take 2 2023-11-28 10:31:39 -08:00
Angela Laar
55b82e9de5 Merge pull request #70058 from apple/revert-69973-embedded-linux
Revert "[embedded] Start building embedded support on Linux/ELF, expand archs of the embedded stdlib to cover common embedded targets"
2023-11-28 09:30:06 -08:00
Konrad `ktoso` Malawski
c468479b86 docs: improve withTaskCancellationHandler docs (#70035)
* docs: improve withTaskCancellationHandler docs

* prefer using non-deprecated withCancHandler method

* Apply suggestions from code review

Co-authored-by: Alex Martini <amartini@apple.com>

---------

Co-authored-by: Alex Martini <amartini@apple.com>
2023-11-28 04:46:42 -08:00
Doug Gregor
130adac5c5 Revert "[embedded] Start building embedded support on Linux/ELF, expand archs of the embedded stdlib to cover common embedded targets" 2023-11-27 22:20:54 -08:00