Closed
Description
Currently, generators won't ever reuse storage slots, causing them to take up more space than is necessary:
#![feature(generators)]
fn main() {
let a = || {
{
let x: i32 = 5;
yield;
println!("{:?}", x);
}
{
let x: i32 = 5;
yield;
println!("{:?}", x);
}
};
println!("{}", std::mem::size_of_val(&a)); // prints "12", could print "8" (4 for state, 4 for `x`)
}
Finding optimal solutions seems like a difficult packing problem, but it should be easy to do quite a bit better.
Also see the example case in #59087.
Metadata
Metadata
Assignees
Labels
Area: Async & AwaitArea: CoroutinesAsync-await issues that have been triaged during a working group meeting.Category: An issue proposing an enhancement or a PR with one.`#![feature(coroutines)]`Issue: Problems and improvements with respect to binary size of generated code.Medium priorityRelevant to the compiler team, which will review and decide on the PR/issue.