-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Added "copy" to Debug fmt for copy operands #122551
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @pnkfelix (or someone else) some time within the next two weeks. Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (
|
This comment has been minimized.
This comment has been minimized.
I'm not sure this adds any actual value; the people who are reading the MIR output probably are already well aware of the semantics here? But maybe making the pretty-printing line up has value. I certainly have valued assembly languages that chose the same number of letters in their opcodes (or at least a small upper bound to their lengh) for this exact reason. Who are the people who would care most about whether or not to make this change? The people in @rust-lang/wg-mir-opt ? |
I think this adds value. MIR is read by both MIR experts and non-expert users, and unless a non-experts reads the rustc pretty-printing code, or they reason by elimination, or someone teaches them that non-marked operands are always If anything, not marking the |
I'm moderately in favor of this. I think even tho it's obvious to me I'dve benefited from it when the difference was especially important. let's leave this open for a week to let other @rust-lang/wg-mir-opt folk chime in. If there are no explanations of why we should keep the status quo or do something else entirely in that week, let's bless everything and land it. |
LGTM. But do we also need to update |
I'm a fan of this. Emphasizing the place-vs-operand distinction always would be nice (there's no way to see in the MIR that (Maybe do the test updates in a separate commit, though, so we can ignore it in the blame history?) |
That may need looking into as I don't know off the top of my head. Is there anything more I'm required to do before this is accepted (this is my first pull request). |
I am confused by the PR description.
What "arguments"? Do you mean function arguments? But then the rest of the text seems to apply to all uses of So not sure what is actually being proposed here. It seems to just be about making |
It would be good if you could run |
For me, just bless all the test cases. We don't often use |
Apologies, hopefully this makes the PR a little clearer. 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). fn main(foo: i32) {
let v = 10;
if v == 20 {
foo;
}
else {
v;
}
} // 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. 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 Hope this clears the PR up. |
I ran the test and have attached it as the output was quite long. |
The interesting part of a |
That helps, thanks. :) Please update the PR description so that it reflects your current understanding and the current status of the PR. |
r? mir-opt |
I approve of the contents of the commits, though I'd expect some conversation with the first-time contributor before taking over their PR. |
Thanks for the detailed explanation of the process above, it was very helpful. It's certainly a bit more advanced than I'm used to, but I have some colleagues who are a bit more experienced with Git and its processes, which is lucky. I think from the PR's history that someone has done what was asked? If so, then great. Otherwise, let me know and I'll do the bit that was originally asked. Thanks for the patience! |
So shall it be! @bors r+ rollup=never p=1 |
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.
The job Click to see the possible cause of the failure (guessed by this bot)
|
💔 Test failed - checks-actions |
@bors retry |
☀️ Test successful - checks-actions |
Finished benchmarking commit (79611d9): comparison URL. Overall result: no relevant changes - no action needed@rustbot label: -perf-regression Instruction countThis benchmark run did not return any relevant results for this metric. Max RSS (memory usage)This benchmark run did not return any relevant results for this metric. CyclesResults (secondary 2.1%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 751.143s -> 749.461s (-0.22%) |
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).
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.