Skip to content

[MIR] Requiring TempRef to only be assigned to once may be too restrictive #31002

Closed
@nagisa

Description

@nagisa

In MIR we want tmp* values to be SSA, however ensuring that constraint in trans (i.e. in TempRef) is wrong, I think.

Namely, for code like this:

#![feature(rustc_attrs)]
struct A(f32);
#[rustc_mir(graphviz="mir.gv")]
fn mir(f: f32) -> bool { !(f.is_nan() || f.is_infinite()) }
fn main() { println!("{:?}", mir(0.0)); }

we will generate following MIR (graphviz version, because easier to visualise):

MIR

which will result in

test.rs:17:7: 17:36 error: internal compiler error: operand const false already assigned
test.rs:17     !(f.is_nan() || f.is_infinite())
                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Note how we assign tmp0 twice, but the two branches are fully disjoint, and thus, for the purposes of data-flow tmp0 is still SSA, but for the purposes of translator tmp0 is assigned multiple times.

If we want TempRefs to stay SSA across translation of the whole function, we will need something like a phi in the MIR.

cc @nikomatsakis

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-MIRArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions