Skip to content

Aggregate rvalue in optimized mir #52865

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
bjorn3 opened this issue Jul 30, 2018 · 1 comment
Closed

Aggregate rvalue in optimized mir #52865

bjorn3 opened this issue Jul 30, 2018 · 1 comment

Comments

@bjorn3
Copy link
Member

bjorn3 commented Jul 30, 2018

#![allow(warnings)]

fn needs_slice(s: &[u8]) {}

fn gives_array(a: u8) {
    needs_slice(&[a])
}

fn main() {}

(Playground)

Mir from tcx.optimized_mir:

fn gives_array(_1: u8) -> (){
    let mut _0: ();                      // return place
    let mut _2: &[u8];
    let mut _3: &[u8; 1];
    let mut _4: &[u8; 1];
    let mut _5: [u8; 1];
    let mut _6: u8;

    bb0: {                              
        StorageLive(_2);                 // bb0[0]: scope 0 at src/main.rs:6:17: 6:21
        StorageLive(_3);                 // bb0[1]: scope 0 at src/main.rs:6:17: 6:21
        StorageLive(_4);                 // bb0[2]: scope 0 at src/main.rs:6:17: 6:21
        StorageLive(_5);                 // bb0[3]: scope 0 at src/main.rs:6:18: 6:21
        StorageLive(_6);                 // bb0[4]: scope 0 at src/main.rs:6:19: 6:20
        _6 = _1;                         // bb0[5]: scope 0 at src/main.rs:6:19: 6:20
        _5 = [move _6];                  // bb0[6]: scope 0 at src/main.rs:6:18: 6:21
        StorageDead(_6);                 // bb0[7]: scope 0 at src/main.rs:6:20: 6:21
        _4 = &_5;                        // bb0[8]: scope 0 at src/main.rs:6:17: 6:21
        _3 = _4;                         // bb0[9]: scope 0 at src/main.rs:6:17: 6:21
        _2 = move _3 as &[u8] (Unsize);  // bb0[10]: scope 0 at src/main.rs:6:17: 6:21
        StorageDead(_3);                 // bb0[11]: scope 0 at src/main.rs:6:20: 6:21
        _0 = const needs_slice(move _2) -> bb1; // bb0[12]: scope 0 at src/main.rs:6:5: 6:22
                                         // ty::Const
                                         // + ty: for<'r> fn(&'r [u8]) {needs_slice}
                                         // + val: Value(ByVal(Undef))
                                         // mir::Constant
                                         // + span: src/main.rs:6:5: 6:16
                                         // + ty: for<'r> fn(&'r [u8]) {needs_slice}
                                         // + literal: const needs_slice
    }

    bb1: {                              
        StorageDead(_2);                 // bb1[0]: scope 0 at src/main.rs:6:21: 6:22
        StorageDead(_4);                 // bb1[1]: scope 0 at src/main.rs:7:1: 7:2
        StorageDead(_5);                 // bb1[2]: scope 0 at src/main.rs:7:1: 7:2
        return;                          // bb1[3]: scope 0 at src/main.rs:7:2: 7:2
    }
}

This contains an aggregate (_5 = [move _6];), while the docs of Rvalue::Aggregate seem to imply that it shouldn't exist after optimizations:

These rvalues can be optimized away after type-checking and before lowering.

@bjorn3
Copy link
Member Author

bjorn3 commented Aug 11, 2018

This is a dupe of #48193

@bjorn3 bjorn3 closed this as completed Aug 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant