diff options
| author | bors <bors@rust-lang.org> | 2024-08-19 23:10:46 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-08-19 23:10:46 +0000 |
| commit | 79611d90b6b3fc6f17a0b07ba228b28e89de16e3 (patch) | |
| tree | c84e12cab4b353c1471ccde4880fc47656c0f7bc /tests/mir-opt/coverage/branch_match_arms.main.InstrumentCoverage.diff | |
| parent | 636d7ff91b9847d6d43c7bbe023568828f6e3246 (diff) | |
| parent | b9cffa7de071e8deae2b0c6b4780bba25f8ec875 (diff) | |
| download | rust-79611d90b6b3fc6f17a0b07ba228b28e89de16e3.tar.gz rust-79611d90b6b3fc6f17a0b07ba228b28e89de16e3.zip | |
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.
Diffstat (limited to 'tests/mir-opt/coverage/branch_match_arms.main.InstrumentCoverage.diff')
| -rw-r--r-- | tests/mir-opt/coverage/branch_match_arms.main.InstrumentCoverage.diff | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/tests/mir-opt/coverage/branch_match_arms.main.InstrumentCoverage.diff b/tests/mir-opt/coverage/branch_match_arms.main.InstrumentCoverage.diff index 3d791734f46..eeeac70b5b8 100644 --- a/tests/mir-opt/coverage/branch_match_arms.main.InstrumentCoverage.diff +++ b/tests/mir-opt/coverage/branch_match_arms.main.InstrumentCoverage.diff @@ -71,33 +71,33 @@ bb5: { + Coverage::ExpressionUsed(2); StorageLive(_9); - _9 = ((_1 as A).0: u32); + _9 = copy ((_1 as A).0: u32); StorageLive(_10); - _10 = _9; + _10 = copy _9; _0 = consume(move _10) -> [return: bb12, unwind: bb14]; } bb6: { StorageLive(_7); - _7 = ((_1 as B).0: u32); + _7 = copy ((_1 as B).0: u32); StorageLive(_8); - _8 = _7; + _8 = copy _7; _0 = consume(move _8) -> [return: bb11, unwind: bb14]; } bb7: { StorageLive(_5); - _5 = ((_1 as C).0: u32); + _5 = copy ((_1 as C).0: u32); StorageLive(_6); - _6 = _5; + _6 = copy _5; _0 = consume(move _6) -> [return: bb10, unwind: bb14]; } bb8: { StorageLive(_3); - _3 = ((_1 as D).0: u32); + _3 = copy ((_1 as D).0: u32); StorageLive(_4); - _4 = _3; + _4 = copy _3; _0 = consume(move _4) -> [return: bb9, unwind: bb14]; } |
