Skip to content

Broken MIR: generator contains type ... after copy & destination propagation #76375

Description

x.rs:

#![crate_type = "lib"]

#[inline(always)]
pub fn f(s: bool) -> String {
    let a = "Hello world!".to_string();
    let b = a;
    let c = b;
    if s {
        c
    } else {
        String::new()
    }
}

y.rs

#![crate_type = "lib"]

pub async fn g() {
    x::f(true);
    h().await;
}

pub async fn h() {}
$ rustc --edition=2018 -Zmir-opt-level=2 x.rs -Zunsound-mir-opts x.rs
$ rustc --edition=2018 -Zmir-opt-level=2 y.rs --extern x -L.
error: internal compiler error: src/librustc_mir/transform/generator.rs:752:13: Broken MIR: generator contains type std::string::String in MIR, but typeck only knows about {std::future::ResumeTy, impl std::future::Future, ()}

The copy propagation removes storage markers during optimization. Afterwards state transforms considers them to be always live across yield. Due to pass ordering, requires inliner to expose the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    A-coroutinesArea: CoroutinesA-mir-optArea: MIR optimizationsC-bugCategory: This is a bug.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.glacierICE tracked in rust-lang/glacier.requires-nightlyThis issue requires a nightly compiler in some way.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions