Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a proposal to generalize AsyncSequence and AsyncIteratorProtocol. #2264

Merged
merged 7 commits into from
Jan 26, 2024

Conversation

hborla
Copy link
Member

@hborla hborla commented Jan 5, 2024

No description provided.

## Introduction

This proposal generalizes `AsyncSequence` in two ways:
1. The bespoke `@rethrows` attribute is replaced with proper `throws` polymorphism via adoption of typed throws.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do wonder how much discussion of @rethrows is appropriate given that it's never been an official feature. Perhaps makes sense to mention as an aside below but I don't know if it warrants callout up-front?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed this to just say proper throws polymorphism is accomplished with typed throws adoption.

proposals/NNNN-generalize-async-sequence.md Outdated Show resolved Hide resolved

#### Error type inference from `for try await` loops

The `Failure` associated type is only accessible at runtime in the Swift 5.11 standard library; code running against older standard library versions does not include the `Failure` requirement in the witness tables for `AsyncSequence` and `AsyncIteratorProtocol` conformances. This impacts error type inference from `for try await` loops.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would potentially make more sense to move this below a couple paragraphs, once we've introduced what the inference behavior actually is (i.e., as a caveat to the MyAsyncIterator example, and just before "When the throw error type of an AsyncIteratorProtocol..."

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh hmm, I meant this as a general statement that doesn't just apply to error type inference in for try await loops. Maybe I should move this up into the previous section to describe why the Failure associated type has Swift 5.11 availability. Then this section can say that because Failure is only available in Swift 5.11, thrown error type inference depends on availability context. Thoughts?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that reorganization makes sense to me!

proposals/NNNN-generalize-async-sequence.md Outdated Show resolved Hide resolved
proposals/NNNN-generalize-async-sequence.md Outdated Show resolved Hide resolved
proposals/NNNN-generalize-async-sequence.md Outdated Show resolved Hide resolved
hborla and others added 6 commits January 22, 2024 21:32
Co-authored-by: Laszlo Teveli <tevelee@users.noreply.github.com>
Co-authored-by: Luca Bernardi <luka.bernardi@gmail.com>
* Move discussion of the experimental `@rethrows` out to "Source Compatibility"

* Rename `nextElement(_:)` to `next(isolation:)`
@Jumhyn Jumhyn merged commit 5e27164 into swiftlang:main Jan 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants