-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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 support for gen fn
#118457
Add support for gen fn
#118457
Conversation
r? @b-naber (rustbot has picked a reviewer for you, use r? to override) |
@rustbot author |
r? compiler-errors I'll review this |
I would not worry too much about this, since I can add support for async gen fn on top of #118420 if this lands first (which it very likely will) You can make it a diagnostic tho I guess, or just leave it as a span-bug lol. I don't even think we parse |
This comment has been minimized.
This comment has been minimized.
I don't know, so that's the thing to check :) The main thing is I want to make sure if you write |
This comment has been minimized.
This comment has been minimized.
@@ -2536,6 +2547,8 @@ impl<'a> Parser<'a> { | |||
} | |||
} | |||
|
|||
// FIXME(eholk): add keyword recovery logic for genness |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm considering leaving this for a later PR that's focused on diagnostic improvements around gen fn
, so that this one can focus on the baseline functionality.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that's fine I guess
Please change the FIXME though to not reference a single person, since this is associated with feature work
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Some changes occurred in src/tools/clippy cc @rust-lang/clippy Some changes occurred in src/tools/rustfmt cc @rust-lang/rustfmt |
I'm ready to have this reviewed now. @rustbot ready |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More nits and reviews
Also raised the question whether this needs to be blocked on the RFC landing or if it is still okay to land this pre-RFC: https://rust-lang.zulipchat.com/#narrow/stream/213817-t-lang/topic/Generators.2C.20lang-team.20experiments.2C.20RFCs.2C.20oh.20my!/near/405406740 edit: seems ok
compiler/rustc_resolve/src/late.rs
Outdated
@@ -940,7 +942,8 @@ impl<'a: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast, | |||
this.visit_generics(generics); | |||
|
|||
let declaration = &sig.decl; | |||
let async_node_id = sig.header.asyncness.opt_return_id(); | |||
let async_node_id = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a test that makes sure that gen fn
captures lifetimes in its signature.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added gen_fn_lifetime_capture.rs
, but I'm not sure it completely exercises everything it should.
@@ -2536,6 +2547,8 @@ impl<'a> Parser<'a> { | |||
} | |||
} | |||
|
|||
// FIXME(eholk): add keyword recovery logic for genness |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that's fine I guess
Please change the FIXME though to not reference a single person, since this is associated with feature work
☔ The latest upstream changes (presumably #118507) made this pull request unmergeable. Please resolve the merge conflicts. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I've addressed all your comments. I'd appreciate a double check on the lifetime capture test though.
compiler/rustc_resolve/src/late.rs
Outdated
@@ -940,7 +942,8 @@ impl<'a: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast, | |||
this.visit_generics(generics); | |||
|
|||
let declaration = &sig.decl; | |||
let async_node_id = sig.header.asyncness.opt_return_id(); | |||
let async_node_id = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added gen_fn_lifetime_capture.rs
, but I'm not sure it completely exercises everything it should.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the future, do you mind cleaning up this PR history a bit? Commits like 09f0741 don't really seem necessary -- you could've probably just amended that commit into whatever bad merge you performed in the first place.
@bors r+ rollup=never |
Thanks for the r+! I'll clean things up better in the future. The various "Fix CI" commits could also be squashed into something else. |
☀️ Test successful - checks-actions |
Finished benchmarking commit (56278a6): comparison URL. Overall result: no relevant changes - no action needed@rustbot label: -perf-regression Instruction countThis benchmark run did not return any relevant results for this metric. Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesThis benchmark run did not return any relevant results for this metric. Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 675.106s -> 675.495s (0.06%) |
This builds on #116447 to add support for
gen fn
functions. For the most part we follow the same approach as desugaringasync fn
, but replacingFuture
withIterator
andasync {}
withgen {}
for the body.The version implemented here uses the return type of a
gen fn
as the yield type. For example:In the future, I think we should experiment with a syntax like
gen fn count_to_three() yield i32 { ... }
, but that can go in another PR.cc @oli-obk @compiler-errors