Skip to content

x = yield; makes generators larger than they need to be #69672

Closed
@jonas-schievink

Description

@jonas-schievink

This generator has a size of 4 Bytes:

    let mut gen = |mut x| {
        loop {
            drop(x);
            yield;
            x = makeit();
            useit(&x);
        }
    };

This one is 16 Bytes in size, even though it also does not need to keep x alive across the yield:

    let mut gen = |mut x| {
        loop {
            drop(x);
            x = yield;
            useit(&x);
        }
    };

(where makeit is a fn returning a usize, and useit is a fn taking &usize)

This seems to be fallout from #69302. Either the layout calculation soundness fix exposed it, or the visitor changes in there caused it.

This means that #69033 will increase the size of futures created from async fns, unless this bug is fixed.

Metadata

Metadata

Assignees

Labels

A-async-awaitArea: Async & AwaitA-coroutinesArea: CoroutinesAsyncAwait-TriagedAsync-await issues that have been triaged during a working group meeting.C-bugCategory: This is a bug.F-coroutines`#![feature(coroutines)]`I-heavyIssue: Problems and improvements with respect to binary size of generated code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions