Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upGenerator Resume Arguments #68524
Generator Resume Arguments #68524
Conversation
This comment has been minimized.
This comment has been minimized.
|
(rust_highfive has picked a reviewer for you, use r? to override) |
This comment was marked as resolved.
This comment was marked as resolved.
|
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 |
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 was marked as outdated.
This comment was marked as outdated.
|
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 |
This comment was marked as outdated.
This comment was marked as outdated.
|
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 |
4fa2c0e
to
a86373f
This comment was marked as resolved.
This comment was marked as resolved.
|
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 |
a86373f
to
7620e7e
This comment was marked as resolved.
This comment was marked as resolved.
|
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 |
7620e7e
to
239e313
This comment was marked as resolved.
This comment was marked as resolved.
|
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 |
239e313
to
6795f59
This comment was marked as outdated.
This comment was marked as outdated.
|
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 |
6795f59
to
b1944ab
| 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); |
This comment has been minimized.
This comment has been minimized.
Zoxc
Jan 25, 2020
Contributor
I noticed that the order of gather_init and gather_operand is swapped compared to DropAndReplace, but I'm not sure if it matters.
This comment has been minimized.
This comment has been minimized.
|
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 |
This comment has been minimized.
This comment has been minimized.
|
I think an assocated type makes more sense, as it is very unlikely to ever be overloaded for different resume types. |
This comment has been minimized.
This comment has been minimized.
|
Async generators (should) implement |
Instead of "closure is expected to take 0 arguments" we now get the expected type mismatch error.
This makes some error messages ungreat, but those seem to be preexisting bugs that also apply to closures / return position `impl Trait` in general.
This changes `Yield` from `as_rvalue` to `into` lowering, which could have a possible performance impact. I could imagine special-casing some resume types here to use a simpler lowering for them, but it's unclear if that makes sense at this stage.
The resume arg is passed as argument `_2` and needs to be moved to the `Yield`s target `Place`
f348be8
to
9fa46fe
This comment has been minimized.
This comment has been minimized.
|
@bors try @rust-timer queue One more run after #68672 has landed |
This comment has been minimized.
This comment has been minimized.
rust-timer
commented
Feb 2, 2020
|
Awaiting bors try build completion |
This comment has been minimized.
This comment has been minimized.
…<try> Generator Resume Arguments cc #43122 and #56974 Blockers: * [ ] Fix miscompilation when resume argument is live across a yield point (#68524 (comment)) * [x] Fix 10% compile time regression in `await-call-tree` benchmarks (#68524 (comment)) * [ ] Fix remaining 1-3% regression (#68524 (comment)) * [x] Make dropck rules account for resume arguments (#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 comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
rust-timer
commented
Feb 2, 2020
|
Queued e1322c9 with parent 0cbcb17, future comparison URL. |
This comment has been minimized.
This comment has been minimized.
|
Aaaand it's gone |
This comment was marked as resolved.
This comment was marked as resolved.
|
I've pushed an attempt at fixing the miscompilation I found above, but it's still there (although the generated MIR does look better now). I don't immediately see what's wrong with this MIR though: `generator_resume` MIR// MIR for `main::{{closure}}#0`
// source = MirSource { instance: Item(DefId(0:14 ~ resume_live_across_yield[317d]::main[0]::{{closure}}[0])), promoted: None }
// pass_name = generator_resume
// disambiguator = 0
// generator_layout = GeneratorLayout { field_tys: [Dropper], variant_fields: [[], [], [], [_0]], storage_conflicts: BitMatrix { num_rows: 1, num_columns: 1, words: [1], marker: PhantomData } }
fn main::{{closure}}#0(_1: std::pin::Pin<&mut [generator@/home/jonas/dev/rust/src/test/ui/generator/resume-live-across-yield.rs:21:17: 24:6 {Dropper, ()}]>, _2: Dropper) -> std::ops::GeneratorState<(), Dropper> {
debug _d => (((*(_1.0: &mut [generator@/home/jonas/dev/rust/src/test/ui/generator/resume-live-across-yield.rs:21:17: 24:6 {Dropper, ()}])) as variant#3).0: Dropper); // in scope 0 at /home/jonas/dev/rust/src/test/ui/generator/resume-live-across-yield.rs:21:18: 21:24
let mut _0: std::ops::GeneratorState<(), Dropper>; // return place in scope 0 at /home/jonas/dev/rust/src/test/ui/generator/resume-live-across-yield.rs:21:17: 24:6
let mut _3: Dropper; // in scope 0 at /home/jonas/dev/rust/src/test/ui/generator/resume-live-across-yield.rs:22:14: 22:19
let mut _4: (); // in scope 0 at /home/jonas/dev/rust/src/test/ui/generator/resume-live-across-yield.rs:22:14: 22:19
let mut _5: Dropper; // in scope 0 at /home/jonas/dev/rust/src/test/ui/generator/resume-live-across-yield.rs:21:26: 21:26
let mut _6: Dropper; // in scope 0 at /home/jonas/dev/rust/src/test/ui/generator/resume-live-across-yield.rs:21:18: 21:24
let mut _7: isize; // in scope 0 at /home/jonas/dev/rust/src/test/ui/generator/resume-live-across-yield.rs:21:17: 24:6
bb0: {
_7 = discriminant((*(_1.0: &mut [generator@/home/jonas/dev/rust/src/test/ui/generator/resume-live-across-yield.rs:21:17: 24:6 {Dropper, ()}]))); // bb0[0]: scope 0 at /home/jonas/dev/rust/src/test/ui/generator/resume-live-across-yield.rs:21:17: 24:6
switchInt(move _7) -> [0u32: bb1, 1u32: bb11, 2u32: bb12, 3u32: bb10, otherwise: bb13]; // bb0[1]: scope 0 at /home/jonas/dev/rust/src/test/ui/generator/resume-live-across-yield.rs:21:17: 24:6
}
bb1: {
(((*(_1.0: &mut [generator@/home/jonas/dev/rust/src/test/ui/generator/resume-live-across-yield.rs:21:17: 24:6 {Dropper, ()}])) as variant#3).0: Dropper) = move _2; // bb1[0]: scope 0 at /home/jonas/dev/rust/src/test/ui/generator/resume-live-across-yield.rs:21:17: 24:6
StorageLive(_3); // bb1[1]: scope 0 at /home/jonas/dev/rust/src/test/ui/generator/resume-live-across-yield.rs:22:14: 22:19
StorageLive(_4); // bb1[2]: scope 0 at /home/jonas/dev/rust/src/test/ui/generator/resume-live-across-yield.rs:22:14: 22:19
_4 = (); // bb1[3]: scope 0 at /home/jonas/dev/rust/src/test/ui/generator/resume-live-across-yield.rs:22:14: 22:19
_0 = std::ops::GeneratorState::<(), Dropper>::Yielded(move _4,); // bb1[4]: scope 0 at /home/jonas/dev/rust/src/test/ui/generator/resume-live-across-yield.rs:22:14: 22:19
discriminant((*(_1.0: &mut [generator@/home/jonas/dev/rust/src/test/ui/generator/resume-live-across-yield.rs:21:17: 24:6 {Dropper, ()}]))) = 3; // bb1[5]: scope 0 at /home/jonas/dev/rust/src/test/ui/generator/resume-live-across-yield.rs:22:14: 22:19
return; // bb1[6]: scope 0 at /home/jonas/dev/rust/src/test/ui/generator/resume-live-across-yield.rs:22:14: 22:19
}
bb2 (cleanup): {
discriminant((*(_1.0: &mut [generator@/home/jonas/dev/rust/src/test/ui/generator/resume-live-across-yield.rs:21:17: 24:6 {Dropper, ()}]))) = 2; // bb2[0]: scope 0 at /home/jonas/dev/rust/src/test/ui/generator/resume-live-across-yield.rs:21:17: 24:6
resume; // bb2[1]: scope 0 at /home/jonas/dev/rust/src/test/ui/generator/resume-live-across-yield.rs:21:17: 24:6
}
bb3: {
StorageDead(_4); // bb3[0]: scope 0 at /home/jonas/dev/rust/src/test/ui/generator/resume-live-across-yield.rs:22:18: 22:19
drop((((*(_1.0: &mut [generator@/home/jonas/dev/rust/src/test/ui/generator/resume-live-across-yield.rs:21:17: 24:6 {Dropper, ()}])) as variant#3).0: Dropper)) -> [return: bb7, unwind: bb6]; // bb3[1]: scope 0 at /home/jonas/dev/rust/src/test/ui/generator/resume-live-across-yield.rs:22:9: 22:11
}
bb4 (cleanup): {
goto -> bb8; // bb4[0]: scope 0 at /home/jonas/dev/rust/src/test/ui/generator/resume-live-across-yield.rs:24:5: 24:6
}
bb5: {
_0 = std::ops::GeneratorState::<(), Dropper>::Complete(move _5,); // bb5[0]: scope 0 at /home/jonas/dev/rust/src/test/ui/generator/resume-live-across-yield.rs:24:6: 24:6
discriminant((*(_1.0: &mut [generator@/home/jonas/dev/rust/src/test/ui/generator/resume-live-across-yield.rs:21:17: 24:6 {Dropper, ()}]))) = 1; // bb5[1]: scope 0 at /home/jonas/dev/rust/src/test/ui/generator/resume-live-across-yield.rs:24:6: 24:6
return; // bb5[2]: scope 0 at /home/jonas/dev/rust/src/test/ui/generator/resume-live-across-yield.rs:24:6: 24:6
}
bb6 (cleanup): {
(((*(_1.0: &mut [generator@/home/jonas/dev/rust/src/test/ui/generator/resume-live-across-yield.rs:21:17: 24:6 {Dropper, ()}])) as variant#3).0: Dropper) = move _3; // bb6[0]: scope 0 at /home/jonas/dev/rust/src/test/ui/generator/resume-live-across-yield.rs:22:9: 22:11
StorageDead(_3); // bb6[1]: scope 0 at /home/jonas/dev/rust/src/test/ui/generator/resume-live-across-yield.rs:22:18: 22:19
drop((((*(_1.0: &mut [generator@/home/jonas/dev/rust/src/test/ui/generator/resume-live-across-yield.rs:21:17: 24:6 {Dropper, ()}])) as variant#3).0: Dropper)) -> bb4; // bb6[2]: scope 0 at /home/jonas/dev/rust/src/test/ui/generator/resume-live-across-yield.rs:24:5: 24:6
}
bb7: {
(((*(_1.0: &mut [generator@/home/jonas/dev/rust/src/test/ui/generator/resume-live-across-yield.rs:21:17: 24:6 {Dropper, ()}])) as variant#3).0: Dropper) = move _3; // bb7[0]: scope 0 at /home/jonas/dev/rust/src/test/ui/generator/resume-live-across-yield.rs:22:9: 22:11
StorageDead(_3); // bb7[1]: scope 0 at /home/jonas/dev/rust/src/test/ui/generator/resume-live-across-yield.rs:22:18: 22:19
_5 = move (((*(_1.0: &mut [generator@/home/jonas/dev/rust/src/test/ui/generator/resume-live-across-yield.rs:21:17: 24:6 {Dropper, ()}])) as variant#3).0: Dropper); // bb7[2]: scope 0 at /home/jonas/dev/rust/src/test/ui/generator/resume-live-across-yield.rs:23:9: 23:11
goto -> bb9; // bb7[3]: scope 0 at /home/jonas/dev/rust/src/test/ui/generator/resume-live-across-yield.rs:24:5: 24:6
}
bb8 (cleanup): {
goto -> bb2; // bb8[0]: scope 0 at /home/jonas/dev/rust/src/test/ui/generator/resume-live-across-yield.rs:24:5: 24:6
}
bb9: {
goto -> bb5; // bb9[0]: scope 0 at /home/jonas/dev/rust/src/test/ui/generator/resume-live-across-yield.rs:24:5: 24:6
}
bb10: {
StorageLive(_2); // bb10[0]: scope 0 at /home/jonas/dev/rust/src/test/ui/generator/resume-live-across-yield.rs:21:17: 24:6
StorageLive(_3); // bb10[1]: scope 0 at /home/jonas/dev/rust/src/test/ui/generator/resume-live-across-yield.rs:21:17: 24:6
StorageLive(_4); // bb10[2]: scope 0 at /home/jonas/dev/rust/src/test/ui/generator/resume-live-across-yield.rs:21:17: 24:6
_3 = move _2; // bb10[3]: scope 0 at /home/jonas/dev/rust/src/test/ui/generator/resume-live-across-yield.rs:21:17: 24:6
goto -> bb3; // bb10[4]: scope 0 at /home/jonas/dev/rust/src/test/ui/generator/resume-live-across-yield.rs:21:17: 24:6
}
bb11: {
assert(const false, "generator resumed after completion") -> bb11; // bb11[0]: scope 0 at /home/jonas/dev/rust/src/test/ui/generator/resume-live-across-yield.rs:21:17: 24:6
// ty::Const
// + ty: bool
// + val: Value(Scalar(0x00))
// mir::Constant
// + span: /home/jonas/dev/rust/src/test/ui/generator/resume-live-across-yield.rs:21:17: 24:6
// + literal: Const { ty: bool, val: Value(Scalar(0x00)) }
}
bb12: {
assert(const false, "generator resumed after panicking") -> bb12; // bb12[0]: scope 0 at /home/jonas/dev/rust/src/test/ui/generator/resume-live-across-yield.rs:21:17: 24:6
// ty::Const
// + ty: bool
// + val: Value(Scalar(0x00))
// mir::Constant
// + span: /home/jonas/dev/rust/src/test/ui/generator/resume-live-across-yield.rs:21:17: 24:6
// + literal: Const { ty: bool, val: Value(Scalar(0x00)) }
}
bb13: {
unreachable; // bb13[0]: scope 0 at /home/jonas/dev/rust/src/test/ui/generator/resume-live-across-yield.rs:21:17: 24:6
}
} |
This comment was marked as resolved.
This comment was marked as resolved.
|
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 |
0c8395b
to
c1c9980
This comment was marked as resolved.
This comment was marked as resolved.
|
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 |
c1c9980
to
392e595
jonas-schievink commentedJan 24, 2020
•
edited
cc #43122 and #56974
Blockers:
await-call-treebenchmarks (#68524 (comment))Follow-up work:
box_region.rsto use resume arguments