mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-26 16:54:01 +00:00
79611d90b6
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.
119 lines
3.6 KiB
Diff
119 lines
3.6 KiB
Diff
- // MIR for `fn_pointers` before GVN
|
|
+ // MIR for `fn_pointers` after GVN
|
|
|
|
fn fn_pointers() -> () {
|
|
let mut _0: ();
|
|
let _1: fn(u8) -> u8;
|
|
let _2: ();
|
|
let mut _3: fn(u8) -> u8;
|
|
let _5: ();
|
|
let mut _6: fn(u8) -> u8;
|
|
let mut _9: {closure@$DIR/gvn.rs:614:19: 614:21};
|
|
let _10: ();
|
|
let mut _11: fn();
|
|
let mut _13: {closure@$DIR/gvn.rs:614:19: 614:21};
|
|
let _14: ();
|
|
let mut _15: fn();
|
|
scope 1 {
|
|
debug f => _1;
|
|
let _4: fn(u8) -> u8;
|
|
scope 2 {
|
|
debug g => _4;
|
|
let _7: {closure@$DIR/gvn.rs:614:19: 614:21};
|
|
scope 3 {
|
|
debug closure => _7;
|
|
let _8: fn();
|
|
scope 4 {
|
|
debug cf => _8;
|
|
let _12: fn();
|
|
scope 5 {
|
|
debug cg => _12;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
bb0: {
|
|
- StorageLive(_1);
|
|
+ nop;
|
|
_1 = identity::<u8> as fn(u8) -> u8 (PointerCoercion(ReifyFnPointer));
|
|
StorageLive(_2);
|
|
StorageLive(_3);
|
|
_3 = copy _1;
|
|
- _2 = opaque::<fn(u8) -> u8>(move _3) -> [return: bb1, unwind continue];
|
|
+ _2 = opaque::<fn(u8) -> u8>(copy _1) -> [return: bb1, unwind continue];
|
|
}
|
|
|
|
bb1: {
|
|
StorageDead(_3);
|
|
StorageDead(_2);
|
|
- StorageLive(_4);
|
|
+ nop;
|
|
_4 = identity::<u8> as fn(u8) -> u8 (PointerCoercion(ReifyFnPointer));
|
|
StorageLive(_5);
|
|
StorageLive(_6);
|
|
_6 = copy _4;
|
|
- _5 = opaque::<fn(u8) -> u8>(move _6) -> [return: bb2, unwind continue];
|
|
+ _5 = opaque::<fn(u8) -> u8>(copy _4) -> [return: bb2, unwind continue];
|
|
}
|
|
|
|
bb2: {
|
|
StorageDead(_6);
|
|
StorageDead(_5);
|
|
- StorageLive(_7);
|
|
- _7 = {closure@$DIR/gvn.rs:614:19: 614:21};
|
|
- StorageLive(_8);
|
|
+ nop;
|
|
+ _7 = const ZeroSized: {closure@$DIR/gvn.rs:614:19: 614:21};
|
|
+ nop;
|
|
StorageLive(_9);
|
|
- _9 = copy _7;
|
|
- _8 = move _9 as fn() (PointerCoercion(ClosureFnPointer(Safe)));
|
|
+ _9 = const ZeroSized: {closure@$DIR/gvn.rs:614:19: 614:21};
|
|
+ _8 = const ZeroSized: {closure@$DIR/gvn.rs:614:19: 614:21} as fn() (PointerCoercion(ClosureFnPointer(Safe)));
|
|
StorageDead(_9);
|
|
StorageLive(_10);
|
|
StorageLive(_11);
|
|
_11 = copy _8;
|
|
- _10 = opaque::<fn()>(move _11) -> [return: bb3, unwind continue];
|
|
+ _10 = opaque::<fn()>(copy _8) -> [return: bb3, unwind continue];
|
|
}
|
|
|
|
bb3: {
|
|
StorageDead(_11);
|
|
StorageDead(_10);
|
|
- StorageLive(_12);
|
|
+ nop;
|
|
StorageLive(_13);
|
|
- _13 = copy _7;
|
|
- _12 = move _13 as fn() (PointerCoercion(ClosureFnPointer(Safe)));
|
|
+ _13 = const ZeroSized: {closure@$DIR/gvn.rs:614:19: 614:21};
|
|
+ _12 = const ZeroSized: {closure@$DIR/gvn.rs:614:19: 614:21} as fn() (PointerCoercion(ClosureFnPointer(Safe)));
|
|
StorageDead(_13);
|
|
StorageLive(_14);
|
|
StorageLive(_15);
|
|
_15 = copy _12;
|
|
- _14 = opaque::<fn()>(move _15) -> [return: bb4, unwind continue];
|
|
+ _14 = opaque::<fn()>(copy _12) -> [return: bb4, unwind continue];
|
|
}
|
|
|
|
bb4: {
|
|
StorageDead(_15);
|
|
StorageDead(_14);
|
|
_0 = const ();
|
|
- StorageDead(_12);
|
|
- StorageDead(_8);
|
|
- StorageDead(_7);
|
|
- StorageDead(_4);
|
|
- StorageDead(_1);
|
|
+ nop;
|
|
+ nop;
|
|
+ nop;
|
|
+ nop;
|
|
+ nop;
|
|
return;
|
|
}
|
|
}
|
|
|