Uh oh!
There was an error while loading. Please reload this page.
Disentangle Debug and Display for Ty. - #115661
Conversation
rustbot
commented
Sep 8, 2023
r? @oli-obk (rustbot has picked a reviewer for you, use r? to override) |
nnethercote
commented
Sep 8, 2023
This has a lot of overlap with #107084, but is a bit smaller. There are some follow-ups that could be done, but I think it's worth focusing on the minimal core to start with. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
compiler-errors
commented
Sep 8, 2023
r=me if you fix the layout tests, or else maybe we should further discuss the tradeoffs of using debug vs display for that... |
6d4a693 to
7d8c291Comparennethercote
commented
Sep 8, 2023
All comments addressed. Thanks for the fast review. @bors try |
bors
commented
Sep 8, 2023
…y, r=<try> Disentangle `Debug` and `Display` for `Ty`. The `Debug` impl for `Ty` just calls the `Display` impl for `Ty`. This is surprising and annoying. In particular, it means `Debug` doesn't show as much information as `Debug` for `TyKind` does. And `Debug` is used in some user-facing error messages, which seems bad. This commit changes the `Debug` impl for `Ty` to call the `Debug` impl for `TyKind`. It also does a number of follow-up changes to preserve existing output, many of which involve inserting `with_no_trimmed_paths!` calls. It also adds `Display` impls for `UserType` and `Canonical`. Some tests have changes to expected output: - Those that use the `rustc_abi(debug)` attribute. - Those that use the `rustc_layout(debug)` attribute. - Those that use the `EMIT_MIR` annotation. In each case the output is slightly uglier than before. This isn't ideal, but it's pretty weird (particularly for the attributes) that the output is using `Debug` in the first place. They're fairly obscure attributes (I hadn't heard of them) so I'm not worried by this. For `async-is-unwindsafe.stderr`, there is one line that now lacks a full path. This is a consistency improvement, because all the other mentions of `Context` in this test lack a path.
This comment has been minimized.
This comment has been minimized.
Uh oh!
There was an error while loading. Please reload this page.
bors
commented
Sep 8, 2023
☀️ Try build successful - checks-actions |
7d8c291 to
51d5e5dCompare
This comment has been minimized.
This comment has been minimized.
51d5e5d to
650ac03Compare
This comment has been minimized.
This comment has been minimized.
The `Debug` impl for `Ty` just calls the `Display` impl for `Ty`. This is surprising and annoying. In particular, it means `Debug` doesn't show as much information as `Debug` for `TyKind` does. And `Debug` is used in some user-facing error messages, which seems bad. This commit changes the `Debug` impl for `Ty` to call the `Debug` impl for `TyKind`. It also does a number of follow-up changes to preserve existing output, many of which involve inserting `with_no_trimmed_paths!` calls. It also adds `Display` impls for `UserType` and `Canonical`. Some tests have changes to expected output: - Those that use the `rustc_abi(debug)` attribute. - Those that use the `EMIT_MIR` annotation. In each case the output is slightly uglier than before. This isn't ideal, but it's pretty weird (particularly for the attribute) that the output is using `Debug` in the first place. They're fairly obscure attributes (I hadn't heard of them) so I'm not worried by this. For `async-is-unwindsafe.stderr`, there is one line that now lacks a full path. This is a consistency improvement, because all the other mentions of `Context` in this test lack a path.
650ac03 to
64ea8ebComparennethercote
commented
Sep 11, 2023
@bors r=compiler-errors |
bors
commented
Sep 11, 2023
bors
commented
Sep 11, 2023
bors
commented
Sep 11, 2023
☀️ Test successful - checks-actions |
rust-timer
commented
Sep 11, 2023
Finished benchmarking commit (7d1e416): comparison URL. Overall result: ✅ improvements - no action needed@rustbot label: -perf-regression Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)This benchmark run did not return any relevant results for this metric. CyclesThis benchmark run did not return any relevant results for this metric. Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 628.501s -> 630.224s (0.27%) |
It looks like this made the debug printing of TyAndLayout, MPlaceTy, mir::ConstantKind, ty::Const and a bunch of other types that don't have Having Can we find a solution to that? IMO the previous situation was actually pretty reasonable; if you wanted the full output you'd debug-print |
nnethercote
commented
Sep 15, 2023
Printing Here are some principles that I think are relevant here.
The old code violated several of these principles, which worked ok in some cases but caused problems in other cases.
Why is (This is a good illustration of the old code's shortcomings: in order to print out The nicest solution here would be an improved Alternatively, it is possible to implement A more hacky solution: #107084 introduced a hand-written |
That sounds like something that can be fixed by changing the debug-printing of
Yeah, and when I debug the compiler, I need output that fits on a screen. This PR breaks that. I've literally never wanted to see the debug printing this PR produces. So you cannot claim that your implementation is more suited for compiler debugging than the old one. It is just suited for debugging a different part of the compiler.
The new code has the same shortcoming. You just optimized printing types for a different part of the compiler. (And it's not just
It would be an improved, hand-written Debug impl for every single of these types that have a
That only helps for a subset of the types, namely those that embed |
oli-obk
commented
Sep 15, 2023
We could change TyKind::Debug to a manual impl that is less verbose, but still preserves all information recursively |
BoxyUwU
commented
Sep 15, 2023
TyKind: Debug does have a manual impl that's less verbose, and so does |
#115866 fixes the fallout for the interpreter and TyAndLayout. (I took the relevant commit from your #107084.) MIR printing does not seem to have completely exploded so a lot of it seems to already use the However,
Yeah, having ADTs not print out the raw AdtDef + GenericArgs would help a lot. Also, the sizes of array types are super verbose. |
nnethercote
commented
Sep 15, 2023
Thanks for doing #115866, I think that's a good follow-up.
👍 |
RalfJung
commented
Sep 16, 2023
#115884 should help with arrays. |
…er-errors make interpreter and TyAndLayout type Debug impl independent of Ty debug impl This fixes some (but not all) of the fallout from rust-lang#115661. Second commit is taken from rust-lang#107084 (and slightly adjusted); I preserved the original git author information.
Rollup merge of rust-lang#115866 - RalfJung:interpret-debug, r=compiler-errors make interpreter and TyAndLayout type Debug impl independent of Ty debug impl This fixes some (but not all) of the fallout from rust-lang#115661. Second commit is taken from rust-lang#107084 (and slightly adjusted); I preserved the original git author information.
jackh726
commented
Sep 18, 2023
Another pretty clear regression in type printing from this is placeholders:
as opposed to
(impl here) I think overall, printing of type info is quite difficult to get "right". While I can understand the sentiment of "Debug formatting shouldn't hide anything", I think there's more nuance to that. Reading through debug logs is difficult - it's made even more difficult when there is a ton of extra info around that's not strictly needed to understand the general idea of what's going on. (Asking because I haven't really read through the code) How does this interact with I don't think I'd go as far to say this should be reverted until an MCP resolves, but I do think it probably would have been reasonable to have opened one for it (though, I can imagine this sort of problem might not have been expected). It's clear I'm not the only one who's run into this. |
nnethercote
commented
Sep 18, 2023
Much of this is the printing of the If that extra stuff was gone it would become:
which would be a lot shorter. And it's not hard to imagine some more concise custom syntax for |
RalfJung
commented
Sep 18, 2023
via email
The DefId without the extra stuff seems completely useless? One has to know what "0:8” refers to, after all. It's like a reference, which prints what it points to, even for Debug. |
RalfJung
commented
Sep 18, 2023
via email
But yeah given the large impact of this change it is definitely MCP-worthy. |
nnethercote
commented
Sep 18, 2023
Sure, but is dereferencing it the right thing to do in |
RalfJung
commented
Sep 18, 2023
via email
I think if it prints a DefId it needs to print what it points to. A DefId without that is about as useful as a raw memory address. The only reasonable way to shorten that output is to omit the DefId entirely.
I don't work with placeholder types though so I cannot say what is most useful to debug them. |
nnethercote
commented
Sep 18, 2023
I think printing a raw memory address is potentially a reasonable thing to do. It's what you'd get with a derived |
RalfJung
commented
Sep 18, 2023
Sure, sometimes it's what you want, and then you manually cast to a raw ptr or use |
nnethercote
commented
Sep 18, 2023
The raw memory address is a distraction. A better example would be a type with an index. There are many examples. Printing the index by itself isn't that informative. But I think |
RalfJung
commented
Sep 21, 2023
Another problem caused by this PR is that the output of a failing @nnethercote could you file an MCP so we can collect these issues in a better place than a merged PR? |
nnethercote
commented
Sep 22, 2023
I'm travelling for the next week. I can file something when I get back, if someone else doesn't want to file something in the meantime. |
The
Debugimpl forTyjust calls theDisplayimpl forTy. This is surprising and annoying. In particular, it meansDebugdoesn't show as much information asDebugforTyKinddoes. AndDebugis used in some user-facing error messages, which seems bad.This commit changes the
Debugimpl forTyto call theDebugimpl forTyKind. It also does a number of follow-up changes to preserve existing output, many of which involve insertingwith_no_trimmed_paths!calls. It also addsDisplayimpls forUserTypeandCanonical.Some tests have changes to expected output:
rustc_abi(debug)attribute.rustc_layout(debug)attribute.EMIT_MIRannotation.In each case the output is slightly uglier than before. This isn't ideal, but it's pretty weird (particularly for the attributes) that the output is using
Debugin the first place. They're fairly obscure attributes (I hadn't heard of them) so I'm not worried by this.For
async-is-unwindsafe.stderr, there is one line that now lacks a full path. This is a consistency improvement, because all the other mentions ofContextin this test lack a path.