Skip to content
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

[msvc] Consistently show active variant and fix visualization for single variant enums #86636

Merged
merged 8 commits into from
Jul 6, 2021

Conversation

wesleywiser
Copy link
Member

Prior to this change, there were a few cases where inspecting an enum in either WinDbg or Visual Studio would not show the active variant name. After these changes, we now consistently show the active variant name as [variant] in the debugger.

We also didn't handle single variant enums very well. That is now also resolved.

Before:
image

After:
image

r? @michaelwoerister

@wesleywiser wesleywiser added A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.) O-windows-msvc Toolchain: MSVC, Operating system: Windows labels Jun 25, 2021
@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 25, 2021
@@ -282,6 +282,17 @@ pub fn push_debuginfo_type_name<'tcx>(
output.push_str("enum$<");
push_item_name(tcx, def.did, true, output);
push_type_params(tcx, substs, output, visited);

if let Variants::Single { index: variant_idx } = &layout.variants {
// Uninhabited enums can't be constructed and should never need to be visualized so
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if these end up being behind a pointer? As in: &() as as *const _ as *const Void.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question! In that case, we just don't have any information to display.

image

Copy link
Member

@michaelwoerister michaelwoerister left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great 😃 I love how the code actually becomes simpler. Thanks, @wesleywiser!

r=me with the nits addressed.

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs Outdated Show resolved Hide resolved
// cdb-check: [+0x000] variant0 [Type: enum$<core::option::Option<u32>>::None]
// cdb-check: [+0x000] variant1 [Type: enum$<core::option::Option<u32>>::Some]
// cdb-check: [+0x004] __0 : 0xc [Type: unsigned int]
// cdb-check: [+0x000] discriminant : Some (0x1) [Type: core::option::Option]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the -r2 flag disable natvis? It would be great to give a minimal description of how the dx command is used here at the top of the file.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the -r2 flag means "expand recursively 2 levels". The ! format specifier is what disables the natvis for this expression.

@bors
Copy link
Contributor

bors commented Jul 2, 2021

☔ The latest upstream changes (presumably #85269) made this pull request unmergeable. Please resolve the merge conflicts.

Previously, directly tagged enums had a `variant$` field which would
show the name of the active variant. We now show the variant using a
`[variant]` synthetic item just like we do for niche-layout enums.
Prior to this, we only showed the `[variant]` synthetic property when
the dataful variant is active. With this change, we now always show it
so the behavior is consistent.
Previously, only the fields would be displayed with no indication of the
variant name. If you already knew the enum was univariant, this was ok
but if the enum was univariant because of layout, for example, a
`Result<T, !>` then it could be very confusing which variant was the
active one.
This isn't used anymore after rust-lang#85292
@rust-log-analyzer

This comment has been minimized.

@wesleywiser
Copy link
Member Author

@bors r=michaelwoerister

@bors
Copy link
Contributor

bors commented Jul 3, 2021

📌 Commit 9c31482 has been approved by michaelwoerister

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 3, 2021
@bors
Copy link
Contributor

bors commented Jul 3, 2021

⌛ Testing commit 9c31482 with merge 02f9811f757f35bee5720f23e9fef27ad7437711...

let discr_ty = enum_layout.field(cx, tag_field).ty;
let (size, align) = cx.size_and_align_of(discr_ty);
Some(MemberDescription {
name: "discriminant".into(),
Copy link
Member

@bjorn3 bjorn3 Jul 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe name this discriminant$? enum Foo { discriminant { bar: u8 } } is valid and would otherwise conflict with this I think.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Foo in your example is Variants::Single so it doesn't fall into this case. enum Foo2 { discriminant { bar: u8 }, baz { bat: u8 } } does fall into this case but is represented as

enum Foo2 {
  discriminant = 0,
  baz = 1,
}

union enum$<Foo2> {
  Foo2 discriminant;
  struct discriminant {
    byte bar;
  }  variant0;
  struct baz {
    byte bat;
  }  variant1;
} 

So the discriminant name used here can't conflict with an identifier used in Rust source.

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Jul 3, 2021

💔 Test failed - checks-actions

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jul 3, 2021
@wesleywiser
Copy link
Member Author

@bors r=michaelwoerister

@bors
Copy link
Contributor

bors commented Jul 5, 2021

📌 Commit 38b9061 has been approved by michaelwoerister

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 5, 2021
@bors
Copy link
Contributor

bors commented Jul 6, 2021

⌛ Testing commit 38b9061 with merge 7e92fb437a199962555fb4d120014a25ca804600...

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Jul 6, 2021

💔 Test failed - checks-actions

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jul 6, 2021
@wesleywiser
Copy link
Member Author

@bors r=michaelwoerister

@bors
Copy link
Contributor

bors commented Jul 6, 2021

📌 Commit 457165e has been approved by michaelwoerister

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 6, 2021
@bors
Copy link
Contributor

bors commented Jul 6, 2021

⌛ Testing commit 457165e with merge 8853999...

@bors
Copy link
Contributor

bors commented Jul 6, 2021

☀️ Test successful - checks-actions
Approved by: michaelwoerister
Pushing 8853999 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Jul 6, 2021
@bors bors merged commit 8853999 into rust-lang:master Jul 6, 2021
@rustbot rustbot added this to the 1.55.0 milestone Jul 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.) merged-by-bors This PR was explicitly merged by bors. O-windows-msvc Toolchain: MSVC, Operating system: Windows S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants