-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Generator Resume Arguments #68524
Generator Resume Arguments #68524
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
Glad to see this implemented, but it is not my area of expertise. r? @Zoxc for review or further reassignment. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
TerminatorKind::Yield { ref value, .. } => { | ||
TerminatorKind::Yield { ref value, resume_arg: ref place, .. } => { | ||
self.create_move_path(place); | ||
self.gather_init(place.as_ref(), InitKind::Deep); |
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 noticed that the order of gather_init
and gather_operand
is swapped compared to DropAndReplace
, but I'm not sure if it matters.
I think I'd prefer to make this PR make the argument be a type parameter instead of a associated type before landing to avoid some unnecessary churn in the compiler and for users of generators. I also don't know how correct this is with regards to drops and references, but those concerns could be delayed by just adding a |
I think an assocated type makes more sense, as it is very unlikely to ever be overloaded for different resume types. |
Async generators (should) implement |
This comment has been minimized.
This comment has been minimized.
Done!
True, but I'd prefer to not limit this feature to what async/await needs (that always leaves a sour taste in my mouth). I'm willing to add more tests, if you (or anyone else) have any suggestions for what needs to be tested here. The current tests are fairly minimal, but I did add some drop tests. |
There's still a lingering miscompilation somewhere: let mut g = |mut d| {
d = yield;
}; This ends up dropping Could this be because the transform assumes there will be at least one |
Let's see if the @bors try @rust-timer queue |
Awaiting bors try build completion |
@bors r+ |
📌 Commit 732913a has been approved by |
⌛ Testing commit 732913a with merge 003534dfa96de6c33f99b0ce3fc2c16456878039... |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
💔 Test failed - checks-azure |
It does not have unwinding support
@bors r=Zoxc |
📌 Commit 9d7b214 has been approved by |
…guments, r=Zoxc Generator Resume Arguments cc rust-lang#43122 and rust-lang#56974 Blockers: * [x] Fix miscompilation when resume argument is live across a yield point (rust-lang#68524 (comment)) * [x] Fix 10% compile time regression in `await-call-tree` benchmarks (rust-lang#68524 (comment)) * [x] Fix remaining 1-3% regression (rust-lang#68524 (comment)) - resolved (rust-lang#68524 (comment)) * [x] Make dropck rules account for resume arguments (rust-lang#68524 (comment)) Follow-up work: * Change async/await desugaring to make use of this feature * Rewrite [`box_region.rs`](https://github.com/rust-lang/rust/blob/3d8778d767f0dde6fe2bc9459f21ead8e124d8cb/src/librustc_data_structures/box_region.rs) to use resume arguments (this shows up in profiles too)
Rollup of 6 pull requests Successful merges: - #67359 (Rename -Zexternal-macro-backtrace to -Zmacro-backtrace and clean up implementation.) - #68524 (Generator Resume Arguments) - #68791 (implement proper linkchecker hardening) - #68886 (Mark fn map_or() as eagerly evaluated.) - #68888 (error code examples: replace some more ignore with compile_fail) - #68894 (Update E0565 examples) Failed merges: r? @ghost
@jonas-schievink Thanks for the change, I'd be interested about how it relates to the discussion in rust-lang/rfcs#2781 , I'd love to have your input :) |
@semtexzv I don't really have the energy to partake in RFC discussions, but I seem to have implemented the second option described in rust-lang/rfcs#2781 (comment) in this PR |
@jonas-schievink as far as I can tell, this PR doesn't introduce any generator syntax for defining the types of resume arguments and yield values. It still relies on type inference to get those types, right? What would a maximally qualified generator look like now? Something like this?:
|
@pitaj The resume argument works like a closure argument, you can give it an explicit type like |
cc #43122 and #56974
Blockers:
await-call-tree
benchmarks (Generator Resume Arguments #68524 (comment))Follow-up work:
box_region.rs
to use resume arguments (this shows up in profiles too)