- 
                Notifications
    You must be signed in to change notification settings 
- Fork 13.9k
          Disentangle Debug and Display for Ty.
          #115661
        
          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
Conversation
| r? @oli-obk (rustbot has picked a reviewer for you, use r? to override) | 
| 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. | 
| 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
    7d8c291      
    Compare
  
    | All comments addressed. Thanks for the fast review. @bors try | 
…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.
| ☀️ Try build successful - checks-actions | 
7d8c291    to
    51d5e5d      
    Compare
  
    
      
        
              This comment has been minimized.
        
        
      
    
  This comment has been minimized.
51d5e5d    to
    650ac03      
    Compare
  
    
      
        
              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
    64ea8eb      
    Compare
  
    | @bors r=compiler-errors | 
| ☀️ Test successful - checks-actions | 
| 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  | 
| 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  | 
| We could change TyKind::Debug to a manual impl that is less verbose, but still preserves all information recursively | 
| 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. | 
| Thanks for doing #115866, I think that's a good follow-up. 
 👍 | 
| #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.
| 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. | 
| 
 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  | 
| 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. | 
| But yeah given the large impact of this change it is definitely MCP-worthy. | 
| 
 Sure, but is dereferencing it the right thing to do in  | 
| 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. | 
| I think printing a raw memory address is potentially a reasonable thing to do. It's what you'd get with a derived  | 
| 
 Sure, sometimes it's what you want, and then you manually cast to a raw ptr or use  | 
| 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  | 
| 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? | 
| 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.