forked from rust-lang/rust
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#69716 - jonas-schievink:generator-size, r=tma…
…ndry Don't store locals in generators that are immediately overwritten with the resume argument This fixes rust-lang#69672 and makes rust-lang#69033 pass the async fn size tests again (in other words, there will be no size regression of async fn if both this and rust-lang#69033 land). ~~This is a small botch and I'd rather have a more precise analysis, but that seems much harder to pull off, so this special-cases `Yield` terminators that store the resume argument into a simple local (ie. without any field projections) and explicitly marks that local as "not live" in the suspend point of that yield. We know that this local does not need to be stored in the generator for this suspend point because the next resume would immediately overwrite it with the passed-in resume argument anyways. The local might still end up in the state if it is used across another yield.~~ (this now properly updates the dataflow framework to handle this case)
- Loading branch information
Showing
11 changed files
with
120 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#![feature(generators)] | ||
|
||
// run-pass | ||
|
||
use std::mem::size_of_val; | ||
|
||
fn main() { | ||
// Generator taking a `Copy`able resume arg. | ||
let gen_copy = |mut x: usize| { | ||
loop { | ||
drop(x); | ||
x = yield; | ||
} | ||
}; | ||
|
||
// Generator taking a non-`Copy` resume arg. | ||
let gen_move = |mut x: Box<usize>| { | ||
loop { | ||
drop(x); | ||
x = yield; | ||
} | ||
}; | ||
|
||
// Neither of these generators have the resume arg live across the `yield`, so they should be | ||
// 4 Bytes in size (only storing the discriminant) | ||
assert_eq!(size_of_val(&gen_copy), 4); | ||
assert_eq!(size_of_val(&gen_move), 4); | ||
} |