mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-23 07:14:28 +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. |
||
---|---|---|
.. | ||
address_of_pair.fn0.GVN.diff | ||
address_of_pair.rs | ||
aggregate.foo.GVN.panic-abort.diff | ||
aggregate.foo.GVN.panic-unwind.diff | ||
aggregate.main.GVN.panic-abort.diff | ||
aggregate.main.GVN.panic-unwind.diff | ||
aggregate.rs | ||
array_index.main.GVN.32bit.panic-abort.diff | ||
array_index.main.GVN.32bit.panic-unwind.diff | ||
array_index.main.GVN.64bit.panic-abort.diff | ||
array_index.main.GVN.64bit.panic-unwind.diff | ||
array_index.rs | ||
bad_op_div_by_zero.main.GVN.panic-abort.diff | ||
bad_op_div_by_zero.main.GVN.panic-unwind.diff | ||
bad_op_div_by_zero.rs | ||
bad_op_mod_by_zero.main.GVN.panic-abort.diff | ||
bad_op_mod_by_zero.main.GVN.panic-unwind.diff | ||
bad_op_mod_by_zero.rs | ||
bad_op_unsafe_oob_for_slices.main.GVN.32bit.panic-abort.diff | ||
bad_op_unsafe_oob_for_slices.main.GVN.32bit.panic-unwind.diff | ||
bad_op_unsafe_oob_for_slices.main.GVN.64bit.panic-abort.diff | ||
bad_op_unsafe_oob_for_slices.main.GVN.64bit.panic-unwind.diff | ||
bad_op_unsafe_oob_for_slices.rs | ||
boolean_identities.rs | ||
boolean_identities.test.GVN.diff | ||
boxes.main.GVN.panic-abort.diff | ||
boxes.main.GVN.panic-unwind.diff | ||
boxes.rs | ||
cast.main.GVN.diff | ||
cast.rs | ||
checked_add.main.GVN.panic-abort.diff | ||
checked_add.main.GVN.panic-unwind.diff | ||
checked_add.rs | ||
control_flow_simplification.hello.GVN.panic-abort.diff | ||
control_flow_simplification.hello.GVN.panic-unwind.diff | ||
control_flow_simplification.hello.PreCodegen.before.panic-abort.mir | ||
control_flow_simplification.hello.PreCodegen.before.panic-unwind.mir | ||
control_flow_simplification.rs | ||
discriminant.main.GVN.32bit.diff | ||
discriminant.main.GVN.64bit.diff | ||
discriminant.rs | ||
indirect_mutation.bar.GVN.diff | ||
indirect_mutation.foo.GVN.diff | ||
indirect_mutation.rs | ||
indirect.main.GVN.panic-abort.diff | ||
indirect.main.GVN.panic-unwind.diff | ||
indirect.rs | ||
inherit_overflow.main.GVN.panic-abort.diff | ||
inherit_overflow.main.GVN.panic-unwind.diff | ||
inherit_overflow.rs | ||
invalid_constant.main.GVN.diff | ||
invalid_constant.main.RemoveZsts.diff | ||
invalid_constant.rs | ||
issue_66971.main.GVN.panic-abort.diff | ||
issue_66971.main.GVN.panic-unwind.diff | ||
issue_66971.rs | ||
issue_67019.main.GVN.panic-abort.diff | ||
issue_67019.main.GVN.panic-unwind.diff | ||
issue_67019.rs | ||
large_array_index.main.GVN.32bit.panic-abort.diff | ||
large_array_index.main.GVN.32bit.panic-unwind.diff | ||
large_array_index.main.GVN.64bit.panic-abort.diff | ||
large_array_index.main.GVN.64bit.panic-unwind.diff | ||
large_array_index.rs | ||
mult_by_zero.rs | ||
mult_by_zero.test.GVN.diff | ||
mutable_variable_aggregate_mut_ref.main.GVN.diff | ||
mutable_variable_aggregate_mut_ref.rs | ||
mutable_variable_aggregate_partial_read.main.GVN.panic-abort.diff | ||
mutable_variable_aggregate_partial_read.main.GVN.panic-unwind.diff | ||
mutable_variable_aggregate_partial_read.rs | ||
mutable_variable_aggregate.main.GVN.diff | ||
mutable_variable_aggregate.rs | ||
mutable_variable_no_prop.main.GVN.diff | ||
mutable_variable_no_prop.rs | ||
mutable_variable_unprop_assign.main.GVN.panic-abort.diff | ||
mutable_variable_unprop_assign.main.GVN.panic-unwind.diff | ||
mutable_variable_unprop_assign.rs | ||
mutable_variable.main.GVN.diff | ||
mutable_variable.rs | ||
offset_of.concrete.GVN.panic-abort.diff | ||
offset_of.concrete.GVN.panic-unwind.diff | ||
offset_of.generic.GVN.panic-abort.diff | ||
offset_of.generic.GVN.panic-unwind.diff | ||
offset_of.rs | ||
overwrite_with_const_with_params.rs | ||
overwrite_with_const_with_params.size_of.GVN.diff | ||
pointer_expose_provenance.main.GVN.panic-abort.diff | ||
pointer_expose_provenance.main.GVN.panic-unwind.diff | ||
pointer_expose_provenance.rs | ||
read_immutable_static.main.GVN.diff | ||
read_immutable_static.rs | ||
ref_deref_project.main.GVN.diff | ||
ref_deref_project.rs | ||
ref_deref.main.GVN.diff | ||
ref_deref.rs | ||
reify_fn_ptr.main.GVN.diff | ||
reify_fn_ptr.rs | ||
repeat.main.GVN.32bit.panic-abort.diff | ||
repeat.main.GVN.32bit.panic-unwind.diff | ||
repeat.main.GVN.64bit.panic-abort.diff | ||
repeat.main.GVN.64bit.panic-unwind.diff | ||
repeat.rs | ||
return_place.add.GVN.panic-abort.diff | ||
return_place.add.GVN.panic-unwind.diff | ||
return_place.add.PreCodegen.before.panic-abort.mir | ||
return_place.add.PreCodegen.before.panic-unwind.mir | ||
return_place.rs | ||
scalar_literal_propagation.main.GVN.panic-abort.diff | ||
scalar_literal_propagation.main.GVN.panic-unwind.diff | ||
scalar_literal_propagation.rs | ||
slice_len.main.GVN.32bit.panic-abort.diff | ||
slice_len.main.GVN.32bit.panic-unwind.diff | ||
slice_len.main.GVN.64bit.panic-abort.diff | ||
slice_len.main.GVN.64bit.panic-unwind.diff | ||
slice_len.rs | ||
switch_int.main.GVN.panic-abort.diff | ||
switch_int.main.GVN.panic-unwind.diff | ||
switch_int.main.SimplifyConstCondition-after-const-prop.panic-abort.diff | ||
switch_int.main.SimplifyConstCondition-after-const-prop.panic-unwind.diff | ||
switch_int.rs | ||
transmute.from_char.GVN.32bit.diff | ||
transmute.from_char.GVN.64bit.diff | ||
transmute.invalid_bool.GVN.32bit.diff | ||
transmute.invalid_bool.GVN.64bit.diff | ||
transmute.invalid_char.GVN.32bit.diff | ||
transmute.invalid_char.GVN.64bit.diff | ||
transmute.less_as_i8.GVN.32bit.diff | ||
transmute.less_as_i8.GVN.64bit.diff | ||
transmute.rs | ||
transmute.undef_union_as_integer.GVN.32bit.diff | ||
transmute.undef_union_as_integer.GVN.64bit.diff | ||
transmute.unreachable_box.GVN.32bit.diff | ||
transmute.unreachable_box.GVN.64bit.diff | ||
transmute.unreachable_direct.GVN.32bit.diff | ||
transmute.unreachable_direct.GVN.64bit.diff | ||
transmute.unreachable_mut.GVN.32bit.diff | ||
transmute.unreachable_mut.GVN.64bit.diff | ||
transmute.unreachable_ref.GVN.32bit.diff | ||
transmute.unreachable_ref.GVN.64bit.diff | ||
transmute.valid_char.GVN.32bit.diff | ||
transmute.valid_char.GVN.64bit.diff | ||
tuple_literal_propagation.main.GVN.panic-abort.diff | ||
tuple_literal_propagation.main.GVN.panic-unwind.diff | ||
tuple_literal_propagation.rs | ||
while_let_loops.change_loop_body.GVN.diff | ||
while_let_loops.rs |