Skip to content

[MIR] match translation sometimes generates 3-armed boolean switches #33540

Closed
@arielb1

Description

@arielb1

STR

fn foo(x: bool, y: bool) -> u32{
    match (x, y) {
         (false, _) => 0,
         (_, false) => 1,
         (true, true) => 2,
    }
}```

## Generated MIR
bb0: {
    var0 = arg0; // Scope(1) at <anon>:1:8: 1:9
    var1 = arg1; // Scope(1) at <anon>:1:17: 1:18
    tmp1 = var0; // Scope(5) at <anon>:2:12: 2:13
    tmp2 = var1; // Scope(6) at <anon>:2:15: 2:16
    tmp0 = (tmp1, tmp2); // Scope(4) at <anon>:2:11: 2:17
    switchInt((tmp0.0: bool)) -> [false: bb5, otherwise: bb4]; // Scope(3) at <anon>:3:11: 3:16
}

bb1: {
    return = const 0u32; // Scope(10) at <anon>:3:25: 3:26
    goto -> bb8; // Scope(3) at <anon>:2:5: 6:6
}

bb2: {
    return = const 1u32; // Scope(11) at <anon>:4:24: 4:25
    goto -> bb8; // Scope(3) at <anon>:2:5: 6:6
}

bb3: {
    return = const 2u32; // Scope(12) at <anon>:5:26: 5:27
    goto -> bb8; // Scope(3) at <anon>:2:5: 6:6
}

bb4: {
    // THREE-ARMED SWITCH HERE:
    switchInt((tmp0.1: bool)) -> [false: bb2, true: bb6, otherwise: bb7]; // Scope(3) at <anon>:4:14: 4:19
}

bb5: {
    var2 = (tmp0.1: bool); // Scope(3) at <anon>:3:18: 3:20
    goto -> bb1; // Scope(3) at <anon>:3:10: 3:21
}

bb6: {
    switchInt((tmp0.0: bool)) -> [true: bb3, otherwise: bb7]; // Scope(3) at <anon>:5:11: 5:15
}

bb7: {
    tmp4 = promoted0; // Scope(3) at <anon>:2:5: 6:6
    core::panicking::panic(tmp4); // Scope(3) at <anon>:2:5: 6:6
}

bb8: {
    return; // Scope(0) at <anon>:1:1: 7:2
}

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