rust/tests/mir-opt/copy-prop
bors 79611d90b6 Auto merge of #122551 - RayMuir:copy_fmt, r=saethlin
Added "copy" to Debug fmt for copy operands

In MIR's debug mode (--emit mir) the printing for Operands is slightly inconsistent.

The RValues - values on the right side of an Assign - are usually printed with their Operand when they are Places.

Example:
_2 = move _3

But for arguments, the operand is omitted.

_2 = _1

I propose a change be made, to display the place with the operand.

_2 = copy _1

Move and copy have different semantics, meaning this difference is important and helpful to the user. It also adds consistency to the pretty printing.

-- EDIT --

 Consider this example Rust program and its MIR output with the **updated pretty printer.**

This was generated with the arguments --emit mir --crate-type lib -Zmir-opt-level=0 (Otherwise, it's optimised away since it's a junk program).

```rust
fn main(foo: i32) {
    let v = 10;

    if v == 20 {
        foo;
    }
    else {
        v;
    }
}
```

```MIR
// WARNING: This output format is intended for human consumers only
// and is subject to change without notice. Knock yourself out.
fn main(_1: i32) -> () {
    debug foo => _1;
    let mut _0: ();
    let _2: i32;
    let mut _3: bool;
    let mut _4: i32;
    let _5: i32;
    let _6: i32;
    scope 1 {
        debug v => _2;
    }

    bb0: {
        StorageLive(_2);
        _2 = const 10_i32;
        StorageLive(_3);
        StorageLive(_4);
        _4 = copy _2;
        _3 = Eq(move _4, const 20_i32);
        switchInt(move _3) -> [0: bb2, otherwise: bb1];
    }

    bb1: {
        StorageDead(_4);
        StorageLive(_5);
        _5 = copy _1;
        StorageDead(_5);
        _0 = const ();
        goto -> bb3;
    }

    bb2: {
        StorageDead(_4);
        StorageLive(_6);
        _6 = copy _2;
        StorageDead(_6);
        _0 = const ();
        goto -> bb3;
    }

    bb3: {
        StorageDead(_3);
        StorageDead(_2);
        return;
    }
}
```

In this example program, we can see that when we move a place, it is preceded by "move". e.g. ``` _3 = Eq(move _4, const 20_i32);```. However, when we copy a place such as ```_5 = _1;```, it is not preceded by the operand in the original printout. I propose to change the print to include the copy ```_5 = copy _1``` as in this example.

Regarding the arguments part. When I originally submitted this PR, I was under the impression this only affected the print for arguments to a function, but actually, it affects anything that uses a copy. This is preferable anyway with regard to consistency. The PR is about making ```copy``` explicit.
2024-08-19 23:10:46 +00:00
..
borrowed_local.borrowed.CopyProp.panic-abort.diff Bless *all* the mir-opt tests 2024-08-18 16:07:33 -07:00
borrowed_local.borrowed.CopyProp.panic-unwind.diff Bless *all* the mir-opt tests 2024-08-18 16:07:33 -07:00
borrowed_local.compare_address.CopyProp.panic-abort.diff Bless *all* the mir-opt tests 2024-08-18 16:07:33 -07:00
borrowed_local.compare_address.CopyProp.panic-unwind.diff Bless *all* the mir-opt tests 2024-08-18 16:07:33 -07:00
borrowed_local.non_freeze.CopyProp.panic-abort.diff Bless *all* the mir-opt tests 2024-08-18 16:07:33 -07:00
borrowed_local.non_freeze.CopyProp.panic-unwind.diff Bless *all* the mir-opt tests 2024-08-18 16:07:33 -07:00
borrowed_local.rs Update mir-opt filechecks 2024-08-18 15:52:23 -07:00
branch.foo.CopyProp.panic-abort.diff Bless *all* the mir-opt tests 2024-08-18 16:07:33 -07:00
branch.foo.CopyProp.panic-unwind.diff Bless *all* the mir-opt tests 2024-08-18 16:07:33 -07:00
branch.rs mir-opt tests: rename unit-test -> test-mir-pass 2024-04-20 13:19:34 +02:00
calls.multiple_edges.CopyProp.diff Bless *all* the mir-opt tests 2024-08-18 16:07:33 -07:00
calls.nrvo.CopyProp.diff Bless *all* the mir-opt tests 2024-08-18 16:07:33 -07:00
calls.rs mir-opt tests: rename unit-test -> test-mir-pass 2024-04-20 13:19:34 +02:00
copy_propagation_arg.arg_src.CopyProp.panic-abort.diff Bless *all* the mir-opt tests 2024-08-18 16:07:33 -07:00
copy_propagation_arg.arg_src.CopyProp.panic-unwind.diff Bless *all* the mir-opt tests 2024-08-18 16:07:33 -07:00
copy_propagation_arg.bar.CopyProp.panic-abort.diff Bless *all* the mir-opt tests 2024-08-18 16:07:33 -07:00
copy_propagation_arg.bar.CopyProp.panic-unwind.diff Bless *all* the mir-opt tests 2024-08-18 16:07:33 -07:00
copy_propagation_arg.baz.CopyProp.panic-abort.diff Bless *all* the mir-opt tests 2024-08-18 16:07:33 -07:00
copy_propagation_arg.baz.CopyProp.panic-unwind.diff Bless *all* the mir-opt tests 2024-08-18 16:07:33 -07:00
copy_propagation_arg.foo.CopyProp.panic-abort.diff Bless *all* the mir-opt tests 2024-08-18 16:07:33 -07:00
copy_propagation_arg.foo.CopyProp.panic-unwind.diff Bless *all* the mir-opt tests 2024-08-18 16:07:33 -07:00
copy_propagation_arg.rs mir-opt tests: rename unit-test -> test-mir-pass 2024-04-20 13:19:34 +02:00
custom_move_arg.f.CopyProp.panic-abort.diff Bless *all* the mir-opt tests 2024-08-18 16:07:33 -07:00
custom_move_arg.f.CopyProp.panic-unwind.diff Bless *all* the mir-opt tests 2024-08-18 16:07:33 -07:00
custom_move_arg.rs Reformat `mir!` macro invocations to use braces. 2024-06-03 13:24:44 +10:00
cycle.main.CopyProp.panic-abort.diff Bless *all* the mir-opt tests 2024-08-18 16:07:33 -07:00
cycle.main.CopyProp.panic-unwind.diff Bless *all* the mir-opt tests 2024-08-18 16:07:33 -07:00
cycle.rs mir-opt tests: rename unit-test -> test-mir-pass 2024-04-20 13:19:34 +02:00
dead_stores_79191.f.CopyProp.after.panic-abort.mir Bless *all* the mir-opt tests 2024-08-18 16:07:33 -07:00
dead_stores_79191.f.CopyProp.after.panic-unwind.mir Bless *all* the mir-opt tests 2024-08-18 16:07:33 -07:00
dead_stores_79191.rs mir-opt tests: rename unit-test -> test-mir-pass 2024-04-20 13:19:34 +02:00
dead_stores_better.f.CopyProp.after.panic-abort.mir Bless *all* the mir-opt tests 2024-08-18 16:07:33 -07:00
dead_stores_better.f.CopyProp.after.panic-unwind.mir Bless *all* the mir-opt tests 2024-08-18 16:07:33 -07:00
dead_stores_better.rs mir-opt tests: rename unit-test -> test-mir-pass 2024-04-20 13:19:34 +02:00
issue_107511.main.CopyProp.panic-abort.diff Bless *all* the mir-opt tests 2024-08-18 16:07:33 -07:00
issue_107511.main.CopyProp.panic-unwind.diff Bless *all* the mir-opt tests 2024-08-18 16:07:33 -07:00
issue_107511.rs mir-opt tests: rename unit-test -> test-mir-pass 2024-04-20 13:19:34 +02:00
move_arg.f.CopyProp.panic-abort.diff Bless *all* the mir-opt tests 2024-08-18 16:07:33 -07:00
move_arg.f.CopyProp.panic-unwind.diff Bless *all* the mir-opt tests 2024-08-18 16:07:33 -07:00
move_arg.rs mir-opt tests: rename unit-test -> test-mir-pass 2024-04-20 13:19:34 +02:00
move_projection.f.CopyProp.panic-abort.diff Bless *all* the mir-opt tests 2024-08-18 16:07:33 -07:00
move_projection.f.CopyProp.panic-unwind.diff Bless *all* the mir-opt tests 2024-08-18 16:07:33 -07:00
move_projection.rs rustfmt `tests/mir-opt`. 2024-06-03 14:17:16 +10:00
mutate_through_pointer.f.CopyProp.diff Bless *all* the mir-opt tests 2024-08-18 16:07:33 -07:00
mutate_through_pointer.rs Reformat `mir!` macro invocations to use braces. 2024-06-03 13:24:44 +10:00
non_dominate.f.CopyProp.diff Bless *all* the mir-opt tests 2024-08-18 16:07:33 -07:00
non_dominate.rs Reformat `mir!` macro invocations to use braces. 2024-06-03 13:24:44 +10:00
partial_init.main.CopyProp.diff Remove comments from mir-opt MIR dumps 2023-06-15 15:19:11 -04:00
partial_init.rs mir-opt tests: rename unit-test -> test-mir-pass 2024-04-20 13:19:34 +02:00
reborrow.demiraw.CopyProp.panic-abort.diff Bless *all* the mir-opt tests 2024-08-18 16:07:33 -07:00
reborrow.demiraw.CopyProp.panic-unwind.diff Bless *all* the mir-opt tests 2024-08-18 16:07:33 -07:00
reborrow.miraw.CopyProp.panic-abort.diff Bless *all* the mir-opt tests 2024-08-18 16:07:33 -07:00
reborrow.miraw.CopyProp.panic-unwind.diff Bless *all* the mir-opt tests 2024-08-18 16:07:33 -07:00
reborrow.remut.CopyProp.panic-abort.diff Remove comments from mir-opt MIR dumps 2023-06-15 15:19:11 -04:00
reborrow.remut.CopyProp.panic-unwind.diff Bless tests 2023-06-23 18:36:25 +01:00
reborrow.reraw.CopyProp.panic-abort.diff Remove comments from mir-opt MIR dumps 2023-06-15 15:19:11 -04:00
reborrow.reraw.CopyProp.panic-unwind.diff Bless tests 2023-06-23 18:36:25 +01:00
reborrow.rs stabilize raw_ref_op 2024-08-18 19:46:53 +02:00