Skip to content

Const Prop does not finish propagation into user defined variables #66638

Closed
@wesleywiser

Description

@wesleywiser

The const prop pass handles propagation into temporaries correctly but doesn't propagate temporaries into user defined variables.

example

fn main() {
  let x = 2 + 2;
}

currently compiles to the following MIR:

fn  main() -> () {
    let mut _0: ();
    let _1: i32;
    let mut _2: (i32, bool);
    scope 1 {
    }

    bb0: {
        StorageLive(_1);
        (_2.0: i32) = const 4i32;
        (_2.1: bool) = const false;
        _1 = move (_2.0: i32);
        StorageDead(_1);
        return;
    }
}

but should ideally compile to:

fn  main() -> () {
    let mut _0: ();
    let _1: i32;
    scope 1 {
    }

    bb0: {
        StorageLive(_1);
        _1 = const 4i32;
        StorageDead(_1);
        return;
    }
}

Metadata

Metadata

Assignees

Labels

A-MIRArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.htmlC-enhancementCategory: An issue proposing an enhancement or a PR with one.I-compiletimeIssue: Problems and improvements with respect to compile times.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions