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 gen blocks and reserve keyword in Rust 2024 #3513

Merged
merged 45 commits into from
Apr 7, 2024
Merged
Changes from 1 commit
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
1cbbe3c
WIP
oli-obk Oct 11, 2023
6b3726e
iter -> gen
oli-obk Oct 11, 2023
585afb9
`?` desugaring
oli-obk Oct 11, 2023
c905ce0
Use correct desugaring to support all `Try` types
oli-obk Oct 11, 2023
e10c2a6
Unresolved questions and future ideas
oli-obk Oct 12, 2023
625826d
replace-all failure
oli-obk Oct 12, 2023
3f3799a
Motivation and generators
oli-obk Oct 12, 2023
4146a83
Add implementation section
oli-obk Oct 12, 2023
ca7bb01
Some details about interactions with other features
oli-obk Oct 12, 2023
e07b766
Explain lack of fusing
oli-obk Oct 12, 2023
1bb969f
Actually, the `async gen` troubles aren't anything beyond the `self-r…
oli-obk Oct 12, 2023
7d06af4
feedback (#2)
shepmaster Oct 12, 2023
08c07d2
Address concerns around my phrasing of `async gen` blocks
oli-obk Oct 13, 2023
d89eb26
Address some concerns
oli-obk Oct 13, 2023
e06745e
No syntax, only semantics
oli-obk Oct 13, 2023
09c3ff1
`Iterator::size_hint`
oli-obk Oct 13, 2023
45ce4db
Update RFC PR id
oli-obk Oct 13, 2023
e9bbc6e
Fix and improve capitalization and punctuation
traviscross Oct 13, 2023
118b777
Fix links to the unresolved questions section
traviscross Oct 13, 2023
00335a2
Add section noting C# prior art
traviscross Oct 13, 2023
94096d5
Add example and mention of `std::iter::from_fn`
traviscross Oct 13, 2023
a8295c8
Clarify rules on the valid return type of a `gen` block
traviscross Oct 13, 2023
e5c803c
Clarify section on error handling
traviscross Oct 13, 2023
b949fec
Add more full history of generators in prior art
traviscross Oct 16, 2023
c982935
Switch back to using `gen` keyword throughout RFC
traviscross Oct 18, 2023
ffcf881
Remove language about an experiment
traviscross Oct 18, 2023
b524348
Address T-lang feedback
oli-obk Feb 29, 2024
349c517
Give some examples of self-referential generators and why they don't …
oli-obk Feb 29, 2024
b836635
Make self-referential `gen` blocks an open question
traviscross Mar 13, 2024
6478947
Adjust for `Generator -> Coroutine` rename
traviscross Mar 14, 2024
a2bf473
Add unresolved question about implemented traits
traviscross Mar 14, 2024
caf93ba
Fix `k#gen`
traviscross Mar 15, 2024
8846955
Fix where we fixed `k#gen`
traviscross Mar 15, 2024
32ffb27
Add tracking issue for RFC 3513
traviscross Mar 27, 2024
3f0159d
Rename file for RFC 3513
traviscross Mar 27, 2024
787e0e9
Update feature name to `gen_blocks`
traviscross Mar 27, 2024
ad74905
Unwrap lines
traviscross Mar 27, 2024
f6cd712
Add future possibility of implementing `FusedIterator`
traviscross Mar 27, 2024
4bf6106
Remove incorrect statement about pinning
traviscross Mar 27, 2024
59be7f9
Add open question about Rust 2015 and Rust 2018
traviscross Mar 28, 2024
31c7b28
Do a round of copyediting
traviscross Mar 27, 2024
7eacd06
Add Koka example to prior art
traviscross Mar 28, 2024
a021905
Add Rust example to prior art
traviscross Mar 28, 2024
354abf6
Add note about `return yield EXPR`
traviscross Mar 29, 2024
22f7267
Use RLE as a stronger motivating example
traviscross Mar 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Remove language about an experiment
Some of the language in this RFC implied that this is an experiment
and that another RFC would be required.  This isn't how we want to
frame things.  Another RFC could always be required, but it's also
possible that stabilization could occur on the basis of this RFC.

This is a normal RFC.  Let's remove all language about this being an
experiment.
  • Loading branch information
traviscross committed Oct 18, 2023
commit ffcf8811e5fd88280c23bd8225cbbce36d92542c
21 changes: 9 additions & 12 deletions text/0000-gen-fn.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
# Summary
[summary]: #summary

Reserve the `gen` keyword in the 2024 edition and start experimenting on
implementing generator functions and blocks that allow implementing `Iterator`s
without writing `Iterator::next` impls under placeholder syntax.
Reserve the `gen` keyword in the 2024 edition.

Add `gen {}` blocks to the language. These implement `Iterator` by `yield`ing
elements. This is simpler and more intuitive than creating a custom type and
Expand All @@ -23,11 +21,12 @@ Furthermore, add `gen fn` to the language. `gen fn foo(arg: X) -> Y` desugars to
# Motivation
[motivation]: #motivation

The main motivation of this RFC is to reserve a new keyword in the 2024 edition.
The feature used by the keyword described here should be treated as an e-RFC for
experimentation on nightly. I would like to avoid discussion of the semantics
provided here, deferring that discussion until during the experimental
implementation work.
The main motivation of this RFC is to reserve a new keyword in the 2024
edition. We will discuss the semantic questions of generators in this
document, but we do not have to settle them with this RFC. We'll describe
current thinking on the semantics, but some questions will be left open to be
answered at a later time after we gain more experience with the
implementation.

Writing iterators manually can be very painful. Many iterators can be written by
chaining `Iterator` methods, but some need to be written as a `struct` and have
Expand Down Expand Up @@ -280,10 +279,8 @@ gen fn foo() {}

## Different syntax for `gen fn`:

This RFC explicitly picks an attribute, as that has no conflicts with any other syntax, even within macros, and
does not pick any option that may influence how experimental users think about syntax.
There are many options to choose from, and we'll have to decide on one before stabilization.
Some options are:
This RFC selects `gen` as the keyword. But there are other options we might
pick. Here are some alternatives:

```rust
fn foo(args) yield item
Expand Down