Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Better pretty printing for const raw pointers #65859
Better pretty printing for const raw pointers #65859
Changes from 7 commits
22586d7
6a6ed12
d322044
3364c46
f2cb4d7
6c26bd6
175c608
c2dbe44
27d89ec
1407cdd
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this is a "fallback" case now, right? We already have a big case for references above. Unfortunately it is not immediately clear what distinguishes these cases.
Could you add some comments both at the
if let ty::Ref
above and at the match arm here describing why we do the matches we do in the order they are, and which various cases of references each conditional covers?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know the history of that big
if let ty::Ref
statement or why it looks the way it does internally, so I don't feel comfortable documenting it. But I added a comment specifying that it needs to happen before the general case.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From what I can see, the point of that is to print the content of the slice/array when possible for types
&[u8]
,[u8; N]
and&str
. Do you agree? If yes, please write that. Right now you only mention&str
but that is not the only type handled here.The fallback then is that for all other references and raw pointers, we just print the pointer value, not the thing it points to.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, here you are using the
Debug
implementation ofConstValue
. That's likely not what we want, it is calledDebug
for a reason. ;)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is no different from the old fallback. I simply moved the block that tries to print slices and strings to happen before the big match statement, so that the new const ref arm we just added doesn't override strings and slices.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True. This was already bad before. I pointed this out because it might be related to your comment at #65859 (comment).
if you don't want to fix this in this PR, feel free to open an issue. We shouldn't use
Debug
for regular output such as error messages, IMO.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's what I thought as well, but this is not the code path that causes that particular line in the mir-opt output. It comes from somewhere else, perhaps within miri itself. I don't feel confident making a decision about the fallback case, since I don't know what it affects, so I'll open an issue instead.
And since it won't be user facing, should I just bless this output and be done with it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is it not user-facing? Isn't this here used for the type mismatch errors that the PR updates?
I think I am confused about which change you are worried about. If this PR makes mir-opt fail, then please either fix that or update the mir-opt tests so that we can see in the diff what the changes are.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I saw this in the actual output from
src/tests/mir-opt/const_prop/const_prop_fails_gracefully.rs
, and thought I had introduced a bug, because a*const i32
should be covered by my changes, and be represented as{pointer} : *const i32
.So I updated the expected output to be this:
And started trying to get that to happen. But if it's not critical that mir dumps are pretty, I will happily abandon that work. I've solved the merge conflicts and pushed a blessing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW, on current nightly this prints
So, yeah, the new output is much better. :D
It seems like right now the code is shared between printing this error and printing the mir-dump, and that is likely not what we want?