Commit Graph

21 Commits

Author SHA1 Message Date
Allan Shortlidge
45f3e94b46 AST: Promote AssociatedTypeImplements feature to baseline. 2024-07-09 14:28:30 -07:00
Allan Shortlidge
9e875f9839 Concurrency: Declare explicit Failure typealiases on AsyncSequence iterators.
Associated type inference ought to take care of providing the `Failure`
typealias for these `AsyncIteratorProtocol` types. However, the inferred
typealias is printed with `@_implements` in the `.swiftinterface`, guarded with
the `$AssociatedTypeImplements` language feature guard, which means older
compilers cannot see the typealias and therefore think the conformance is
incomplete. To make sure the `_Concurrency` module's interface is backward
compatible, we must manually define these typealiases temporarily.

Part of rdar://125138945
2024-03-27 18:09:53 -07:00
Doug Gregor
8c452b5cf5 Fix accidental ABI break with AsyncSequence.flatMap
At the type that I introduced type throws into AsyncSequence and its
algorithms, I accidentally dropped a `@preconcurrency` on the ABI
entrypoint, leading to a mangled name change.

Fixes rdar://123639030.
2024-02-26 12:38:56 -08:00
Mishal Shah
af112c1591 Update the Swift version to 6.0 from 5.11 2024-02-19 17:47:16 -08:00
Doug Gregor
a4f0709c2f Rename AsyncIteratorProtocol.next(_:) to next(isolation:)
Match the name of the method as specified in SE-0421
2024-02-09 14:18:37 -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
3482ca02ad Add availability for the Failure associated type of async sequences 2024-01-25 16:04:46 -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
Jager-yoo
9b2b8b3a49 [stdlib] Correct actual print outputs in Concurrency files 2022-12-19 23:40:03 +09:00
Jager-yoo
b9bbe62006 [Concurrency] Revise Async- related files doc
- Revise '// Prints' comments style like the other stdlib files
- Remove verbose string interpolations and extra spaces
- Remove some unneeded parentheses
- Replace the majority of ' : ' with ': '
- Fix wrong indentation
- Keep files with a single empty line at the end
2022-05-16 14:55:27 +09:00
Josh Soref
7a57e7ce99 Spelling stdlib/public/concurrency (#42443)
* spelling: already

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: appropriate

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: asynchronous

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: cancel

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: divisible

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: execution

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: initialized

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: normally

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: preprocessed

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: priority

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: some

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: success

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: suspending

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: the

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: throws

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

Co-authored-by: Josh Soref <jsoref@users.noreply.github.com>
2022-04-21 11:12:57 -07:00
Philippe Hausler
b0f0cb257d Audit and correct AsyncSequence Sendability (#41253)
* Audit and correct AsyncSequence Sendability

* Annotate availability on Sendable conformances for AsyncSequences

* Fix typo of Sendable.Iterator

* Correct tests to use sendable builders

* Add @preconcurrency annotations and fixup one remaining missing @Sendable case

* Move preconcurrency to correct syntactical position

* Use unchecked Sendable conditional conformance instead of marking all internals as preconcurrency and sendable

* Use unchecked Sendable conditional conformance instead of marking all internals as preconcurrency and sendable for dropWhile

* claim ABI changes for marking of @preconcurrency as expected
2022-03-04 21:21:32 -08:00
Karoy Lorentey
47956908b7 [Concurrency] SwiftStdlib 5.5 ⟹ SwiftStdlib 5.1 (usages)
The concurrency runtime now deploys back to macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, which corresponds to the 5.1 release of the stdlib.

Adjust macro usages accordingly.
2021-10-28 14:36:36 -07:00
Doug Gregor
ed06fdebd0 Revert "Allow AsyncSequence operators to be inlined in their construction (#38310)"
This reverts commit 6a80196da3.
2021-10-12 11:31:49 -07:00
Philippe Hausler
6a80196da3 Allow AsyncSequence operators to be inlined in their construction (#38310) 2021-07-09 09:23:39 -07:00
Chris Adamson
af4ebb4c46 Provide doc comments for AsyncSequence and related types (#37383)
* First draft docs for iterator, sequence type.

Also drop(while:), to get a feel for the AsyncSequence->AsyncSequence cases.

* Source docs for contains and reduce.

* Docs for methods in AsyncSequence.

This covers all the methods that return a single value. Still working on the extension methods that return new sequences.

* Early source docs for dropFirst(_:) and its type

* Correct doc format for dropFirst(_:).

* Prefix, plus some fixes.

* Docs for prefix(while:).

* Apply Philippe's snippet fixes.

* First draft docs on the map sequences.

Plus miscellaneous fixes throughout.

* Show result of flatMap example.

* More explicit cancellation guidance.

* Convert snippets to trailing closures.

* Correct misplaced doc comments.

* Apply suggestions from code review

Co-authored-by: Philippe Hausler <phausler@apple.com>

* Apply editorial feedback.

* Apply additional editorial feedback.

* Apply suggestions from code review

Co-authored-by: bjlanier <blanier@apple.com>

* Apply further editorial feedback.

Co-authored-by: Chris Adamson <cadamson@apple.com>
Co-authored-by: Philippe Hausler <phausler@apple.com>
Co-authored-by: bjlanier <blanier@apple.com>
2021-05-14 10:16:36 -04:00
Alexis Laferrière
10d115bd5c [Concurrency] Use the SwiftStdlib 5.5 macro instead of 9999 versions 2021-05-04 09:30:58 -07:00
Mike Ash
1173b737aa [Concurrency] Add availability to Concurrency APIs.
This allows programs to target older OSes while using Concurrency behind an availability check. When targeting older OSes, the symbols are weak-linked and the compiler will require the use of Concurrency features to be guarded by an availability check.

rdar://75850003
2021-04-01 10:42:08 -04:00
Philippe Hausler
8578584f61 Implementations for operators and async functions on AsyncSequence per SE-0298 (#35740)
* Implementations for operators and async functions on AsyncSequence per SE-0298

* Add trailing new lines to AsyncSequence adopter files

* Remove extra // from preambles

* Transition sequence properties and sequence initializers to internal

* Rename Upstream to Base

* Rename "Failable" asynchronous sequences to "Throwing"

* Make iteration consistent with closure lifetimes and track failure via state

* Use for await syntax for async function extensions on AsyncSequence

* Work-around rethrows calculations being incorrect for conformance + closure rethrowing

* Update testing names to reflect Throwing versus Failable

* Incorperate runAsyncAndBlock into the test function for suite calls

* Remove @frozen from AsyncSequence operators

* Back out reduce family functions for now due to IRGen bug

* Additional corrections for throwing cases and fix up potential linux crasher

* Add a upstream and throwing tests and correct flatMap's throwing behavior

* Unify parameter names to count

* Add a more helpful precondition on prefix

* Add tests for throwing cases of non closure async functions on AsyncSequence

* Correct missing count transition in dropFirst

* Correct missing , in assertion

* [NFC] add commentary on optimization in dropFirst on dropFirst

* Disable collect tests for non macOS platforms for now

* Disable all async sequence tests for non macOS platforms for now
2021-02-12 14:43:59 -08:00