Skip to content

Commit 063ebfa

Browse files
Use enum2<_> instead of enum<_> for Cpp-like debuginfo enum type names.
And add more comments about niche tag enum encoding.
1 parent 622da5d commit 063ebfa

File tree

10 files changed

+87
-73
lines changed

10 files changed

+87
-73
lines changed

compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/cpp_like.rs

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ const SINGLE_VARIANT_VIRTUAL_DISR: u64 = 0;
6868
/// It's roughly equivalent to the following C/C++ code:
6969
///
7070
/// ```c
71-
/// union enum$<{fully-qualified-name}> {
71+
/// union enum2$<{fully-qualified-name}> {
7272
/// struct Variant0 {
7373
/// struct {name-of-variant-0} {
7474
/// <variant 0 fields>
@@ -91,12 +91,27 @@ const SINGLE_VARIANT_VIRTUAL_DISR: u64 = 0;
9191
/// }
9292
/// ```
9393
///
94-
/// As you can see, the type name is wrapped `enum$`. This way we can have a
95-
/// single NatVis rule for handling all enums.
94+
/// As you can see, the type name is wrapped in `enum2$<_>`. This way we can
95+
/// have a single NatVis rule for handling all enums. The `2` in `enum2$<_>`
96+
/// is an encoding version tag, so that debuggers can decide to decode this
97+
/// differently than the previous `enum$<_>` encoding emitted by earlier
98+
/// compiler versions.
9699
///
97-
/// For niche-tag enums, a variant might correspond to a range of tag values.
98-
/// In that case the variant struct has a `DISCR_BEGIN` and `DISCR_END` field
99-
/// instead of DISCR_EXACT.
100+
/// Niche-tag enums have one special variant, usually called the
101+
/// "dataful variant". This variant has a field that
102+
/// doubles as the tag of the enum. The variant is active when the value of
103+
/// that field is within a pre-defined range. Therefore the variant struct
104+
/// has a `DISCR_BEGIN` and `DISCR_END` field instead of `DISCR_EXACT` in
105+
/// that case. Both `DISCR_BEGIN` and `DISCR_END` are inclusive bounds.
106+
/// Note that these ranges can wrap around, so that `DISCR_END < DISCR_BEGIN`.
107+
///
108+
/// The field in the top-level union that corresponds to the dataful variant
109+
/// is called `variant_fallback` instead of `variant<index>`. This is mainly
110+
/// an optimization that enables a shorter NatVis definition. That way we
111+
/// only need to specify a `tag == variantX.DISCR_EXACT` entry for the indexed
112+
/// variants. Otherwise we'd need to have that and then an additional entry
113+
/// checking `in_range(variantX.DISCR_BEGIN, variantX.DISCR_END)` for each
114+
/// index.
100115
///
101116
/// Single-variant enums don't actually have a tag field. In this case we
102117
/// emit a static tag field (that always has the value 0) so we can use the

compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ fn push_debuginfo_type_name<'tcx>(
389389
// Name will be "{closure_env#0}<T1, T2, ...>", "{generator_env#0}<T1, T2, ...>", or
390390
// "{async_fn_env#0}<T1, T2, ...>", etc.
391391
// In the case of cpp-like debuginfo, the name additionally gets wrapped inside of
392-
// an artificial `enum$<>` type, as defined in msvc_enum_fallback().
392+
// an artificial `enum2$<>` type, as defined in msvc_enum_fallback().
393393
if cpp_like_debuginfo && t.is_generator() {
394394
let ty_and_layout = tcx.layout_of(ParamEnv::reveal_all().and(t)).unwrap();
395395
msvc_enum_fallback(
@@ -434,7 +434,7 @@ fn push_debuginfo_type_name<'tcx>(
434434
visited: &mut FxHashSet<Ty<'tcx>>,
435435
) {
436436
debug_assert!(!wants_c_like_enum_debuginfo(ty_and_layout));
437-
output.push_str("enum$<");
437+
output.push_str("enum2$<");
438438
push_inner(output, visited);
439439
push_close_angle_bracket(true, output);
440440
}

src/etc/natvis/intrinsic.natvis

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
33
<Type Name="str">
44
<DisplayString>{(char*)data_ptr,[length]s8}</DisplayString>
@@ -154,7 +154,7 @@
154154
This is the visualizer for all enums. It takes care of selecting the active variant.
155155
See `compiler\rustc_codegen_llvm\src\debuginfo\metadata\enums\cpp_like.rs` for more information.
156156
-->
157-
<Type Name="enum$&lt;*&gt;">
157+
<Type Name="enum2$&lt;*&gt;">
158158
<Intrinsic Name="in_range" Expression="(start &lt;= end) ? ((tag &gt;= start) &amp;&amp; (tag &lt;= end)) : ((tag &gt;= start) || (tag &lt;= end))">
159159
<Parameter Name="start" Type="unsigned __int64" />
160160
<Parameter Name="end" Type="unsigned __int64" />

src/test/debuginfo/generator-objects.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,26 +41,26 @@
4141

4242
// cdb-command: g
4343
// cdb-command: dx b
44-
// cdb-check: b : Unresumed [Type: enum$<generator_objects::main::generator_env$0>]
44+
// cdb-check: b : Unresumed [Type: enum2$<generator_objects::main::generator_env$0>]
4545
// cdb-check: [+0x[...]] _ref__a : 0x[...] : 5 [Type: int *]
4646

4747
// cdb-command: g
4848
// cdb-command: dx b
49-
// cdb-check: b : Suspend0 [Type: enum$<generator_objects::main::generator_env$0>]
49+
// cdb-check: b : Suspend0 [Type: enum2$<generator_objects::main::generator_env$0>]
5050
// cdb-check: [+0x[...]] c : 6 [Type: int]
5151
// cdb-check: [+0x[...]] d : 7 [Type: int]
5252
// cdb-check: [+0x[...]] _ref__a : 0x[...] : 5 [Type: int *]
5353

5454
// cdb-command: g
5555
// cdb-command: dx b
56-
// cdb-check: b : Suspend1 [Type: enum$<generator_objects::main::generator_env$0>]
56+
// cdb-check: b : Suspend1 [Type: enum2$<generator_objects::main::generator_env$0>]
5757
// cdb-check: [+0x[...]] c : 7 [Type: int]
5858
// cdb-check: [+0x[...]] d : 8 [Type: int]
5959
// cdb-check: [+0x[...]] _ref__a : 0x[...] : 6 [Type: int *]
6060

6161
// cdb-command: g
6262
// cdb-command: dx b
63-
// cdb-check: b : Returned [Type: enum$<generator_objects::main::generator_env$0>]
63+
// cdb-check: b : Returned [Type: enum2$<generator_objects::main::generator_env$0>]
6464
// cdb-check: [+0x[...]] _ref__a : 0x[...] : 6 [Type: int *]
6565

6666
#![feature(omit_gdb_pretty_printer_section, generators, generator_trait)]

src/test/debuginfo/msvc-pretty-enums.rs

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,106 +4,105 @@
44
// cdb-command: g
55

66
// cdb-command: dx a
7-
// cdb-check:a : Some [Type: enum$<core::option::Option<msvc_pretty_enums::CStyleEnum> >]
7+
// cdb-check:a : Some [Type: enum2$<core::option::Option<msvc_pretty_enums::CStyleEnum> >]
88
// cdb-check: [+0x000] __0 : Low (0x2) [Type: msvc_pretty_enums::CStyleEnum]
99

1010
// cdb-command: dx b
11-
// cdb-check:b : None [Type: enum$<core::option::Option<msvc_pretty_enums::CStyleEnum> >]
11+
// cdb-check:b : None [Type: enum2$<core::option::Option<msvc_pretty_enums::CStyleEnum> >]
1212

1313
// cdb-command: dx c
14-
// cdb-check:c : Tag1 [Type: enum$<msvc_pretty_enums::NicheLayoutEnum>]
14+
// cdb-check:c : Tag1 [Type: enum2$<msvc_pretty_enums::NicheLayoutEnum>]
1515

1616
// cdb-command: dx d
17-
// cdb-check:d : Data [Type: enum$<msvc_pretty_enums::NicheLayoutEnum>]
17+
// cdb-check:d : Data [Type: enum2$<msvc_pretty_enums::NicheLayoutEnum>]
1818
// cdb-check: [+0x000] my_data : High (0x10) [Type: msvc_pretty_enums::CStyleEnum]
1919

2020
// cdb-command: dx e
21-
// cdb-check:e : Tag2 [Type: enum$<msvc_pretty_enums::NicheLayoutEnum>]
21+
// cdb-check:e : Tag2 [Type: enum2$<msvc_pretty_enums::NicheLayoutEnum>]
2222

2323
// cdb-command: dx f
24-
// cdb-check:f : Some [Type: enum$<core::option::Option<ref$<u32> > >]
24+
// cdb-check:f : Some [Type: enum2$<core::option::Option<ref$<u32> > >]
2525
// cdb-check: [+0x000] __0 : 0x[...] : 0x1 [Type: unsigned int *]
2626

2727
// cdb-command: dx g
28-
// cdb-check:g : None [Type: enum$<core::option::Option<ref$<u32> > >]
28+
// cdb-check:g : None [Type: enum2$<core::option::Option<ref$<u32> > >]
2929

3030
// cdb-command: dx h
31-
// cdb-check:h : Some [Type: enum$<core::option::Option<u32> >]
31+
// cdb-check:h : Some [Type: enum2$<core::option::Option<u32> >]
3232
// cdb-check: [+0x004] __0 : 0xc [Type: unsigned int]
3333

3434
// cdb-command: dx i
35-
// cdb-check:i : None [Type: enum$<core::option::Option<u32> >]
35+
// cdb-check:i : None [Type: enum2$<core::option::Option<u32> >]
3636

3737
// cdb-command: dx j
3838
// cdb-check:j : High (0x10) [Type: msvc_pretty_enums::CStyleEnum]
3939

4040
// cdb-command: dx k
41-
// cdb-check:k : Some [Type: enum$<core::option::Option<alloc::string::String> >]
41+
// cdb-check:k : Some [Type: enum2$<core::option::Option<alloc::string::String> >]
4242
// cdb-check: [+0x000] __0 : "IAMA optional string!" [Type: alloc::string::String]
4343

4444
// cdb-command: dx l
45-
// cdb-check:l : Ok [Type: enum$<core::result::Result<u32,enum$<msvc_pretty_enums::Empty> > >]
45+
// cdb-check:l : Ok [Type: enum2$<core::result::Result<u32,enum2$<msvc_pretty_enums::Empty> > >]
4646
// cdb-check: [+0x000] __0 : 0x2a [Type: unsigned int]
4747

4848
// cdb-command: dx niche128_some
49-
// cdb-check:niche128_some : Some [Type: enum$<core::option::Option<core::num::nonzero::NonZeroI128> >]
49+
// cdb-check: niche128_some : Some [Type: enum2$<core::option::Option<core::num::nonzero::NonZeroI128> >]
5050
// Note: we can't actually read the value of the field because CDB cannot handle 128 bit integers.
5151
// cdb-check: [+0x000] __0 [...] [Type: core::num::nonzero::NonZeroI128]
5252

5353
// cdb-command: dx niche128_none
54-
// cdb-check: niche128_none : None [Type: enum$<core::option::Option<core::num::nonzero::NonZeroI128> >]
54+
// cdb-check: niche128_none : None [Type: enum2$<core::option::Option<core::num::nonzero::NonZeroI128> >]
5555

5656
// cdb-command: dx niche_w_fields_1_some,d
57-
// cdb-check: niche_w_fields_1_some,d : A [Type: enum$<msvc_pretty_enums::NicheLayoutWithFields1>]
57+
// cdb-check: niche_w_fields_1_some,d : A [Type: enum2$<msvc_pretty_enums::NicheLayoutWithFields1>]
5858
// cdb-check: [+0x[...]] __0 : 0x[...] : 77 [Type: unsigned char *]
5959
// cdb-check: [+0x[...]] __1 : 7 [Type: unsigned int]
6060

6161
// cdb-command: dx niche_w_fields_1_none,d
62-
// cdb-check: niche_w_fields_1_none,d : B [Type: enum$<msvc_pretty_enums::NicheLayoutWithFields1>]
62+
// cdb-check: niche_w_fields_1_none,d : B [Type: enum2$<msvc_pretty_enums::NicheLayoutWithFields1>]
6363
// cdb-check: [+0x[...]] __0 : 99 [Type: unsigned int]
6464

6565
// cdb-command: dx niche_w_fields_2_some,d
66-
// cdb-check: niche_w_fields_2_some,d : A [Type: enum$<msvc_pretty_enums::NicheLayoutWithFields2>]
67-
// cdb-check: [<Raw View>] [Type: enum$<msvc_pretty_enums::NicheLayoutWithFields2>]
66+
// cdb-check: niche_w_fields_2_some,d : A [Type: enum2$<msvc_pretty_enums::NicheLayoutWithFields2>]
6867
// cdb-check: [+0x[...]] __0 : 800 [Type: core::num::nonzero::NonZeroU32]
6968
// cdb-check: [+0x[...]] __1 : 900 [Type: unsigned __int64]
7069

7170
// cdb-command: dx niche_w_fields_2_none,d
72-
// cdb-check: niche_w_fields_2_none,d : B [Type: enum$<msvc_pretty_enums::NicheLayoutWithFields2>]
71+
// cdb-check: niche_w_fields_2_none,d : B [Type: enum2$<msvc_pretty_enums::NicheLayoutWithFields2>]
7372
// cdb-check: [+0x[...]] __0 : 1000 [Type: unsigned __int64]
7473

7574
// cdb-command: dx niche_w_fields_3_some,d
76-
// cdb-check: niche_w_fields_3_some,d : A [Type: enum$<msvc_pretty_enums::NicheLayoutWithFields3>]
75+
// cdb-check: niche_w_fields_3_some,d : A [Type: enum2$<msvc_pretty_enums::NicheLayoutWithFields3>]
7776
// cdb-check: [+0x[...]] __0 : 137 [Type: unsigned char]
7877
// cdb-check: [+0x[...]] __1 : true [Type: bool]
7978

8079
// cdb-command: dx niche_w_fields_3_niche1,d
81-
// cdb-check: niche_w_fields_3_niche1,d : B [Type: enum$<msvc_pretty_enums::NicheLayoutWithFields3>]
80+
// cdb-check: niche_w_fields_3_niche1,d : B [Type: enum2$<msvc_pretty_enums::NicheLayoutWithFields3>]
8281
// cdb-check: [+0x[...]] __0 : 12 [Type: unsigned char]
8382

8483
// cdb-command: dx niche_w_fields_3_niche2,d
85-
// cdb-check: niche_w_fields_3_niche2,d : C [Type: enum$<msvc_pretty_enums::NicheLayoutWithFields3>]
84+
// cdb-check: niche_w_fields_3_niche2,d : C [Type: enum2$<msvc_pretty_enums::NicheLayoutWithFields3>]
8685
// cdb-check: [+0x[...]] __0 : false [Type: bool]
8786

8887
// cdb-command: dx niche_w_fields_3_niche3,d
89-
// cdb-check: niche_w_fields_3_niche3,d : D [Type: enum$<msvc_pretty_enums::NicheLayoutWithFields3>]
88+
// cdb-check: niche_w_fields_3_niche3,d : D [Type: enum2$<msvc_pretty_enums::NicheLayoutWithFields3>]
9089
// cdb-check: [+0x[...]] __0 : 34 [Type: unsigned char]
9190

9291
// cdb-command: dx niche_w_fields_3_niche4,d
93-
// cdb-check: niche_w_fields_3_niche4,d : E [Type: enum$<msvc_pretty_enums::NicheLayoutWithFields3>]
92+
// cdb-check: niche_w_fields_3_niche4,d : E [Type: enum2$<msvc_pretty_enums::NicheLayoutWithFields3>]
9493
// cdb-check: [+0x[...]] __0 : 56 [Type: unsigned char]
9594

9695
// cdb-command: dx niche_w_fields_3_niche5,d
97-
// cdb-check: niche_w_fields_3_niche5,d : F [Type: enum$<msvc_pretty_enums::NicheLayoutWithFields3>]
96+
// cdb-check: niche_w_fields_3_niche5,d : F [Type: enum2$<msvc_pretty_enums::NicheLayoutWithFields3>]
9897

9998
// cdb-command: dx -r3 niche_w_fields_std_result_ok,d
100-
// cdb-check: niche_w_fields_std_result_ok,d : Ok [Type: enum$<core::result::Result<alloc::boxed::Box<slice$<u8>,alloc::alloc::Global>,u64> >]
99+
// cdb-check: niche_w_fields_std_result_ok,d : Ok [Type: enum2$<core::result::Result<alloc::boxed::Box<slice$<u8>,alloc::alloc::Global>,u64> >]
101100
// cdb-check: [+0x[...]] __0 [Type: alloc::boxed::Box<slice$<u8>,alloc::alloc::Global>]
102101
// cdb-check: [+0x[...]] data_ptr : [...]
103102
// cdb-check: [+0x[...]] length : 3 [...]
104103

105104
// cdb-command: dx -r3 niche_w_fields_std_result_err,d
106-
// cdb-check: niche_w_fields_std_result_err,d : Err [Type: enum$<core::result::Result<alloc::boxed::Box<slice$<u8>,alloc::alloc::Global>,u64> >]
105+
// cdb-check: niche_w_fields_std_result_err,d : Err [Type: enum2$<core::result::Result<alloc::boxed::Box<slice$<u8>,alloc::alloc::Global>,u64> >]
107106
// cdb-check: [+0x[...]] __0 : 789 [Type: unsigned __int64]
108107

109108
use std::num::{NonZeroI128, NonZeroU32};

src/test/debuginfo/msvc-scalarpair-params.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
// cdb-command: g
1919

2020
// cdb-command: dx o1
21-
// cdb-check:o1 : Some [Type: enum$<core::option::Option<u32> >]
21+
// cdb-check:o1 : Some [Type: enum2$<core::option::Option<u32> >]
2222
// cdb-check: [+0x004] __0 : 0x4d2 [Type: [...]]
2323
// cdb-command: dx o2
24-
// cdb-check:o2 : Some [Type: enum$<core::option::Option<u64> >]
24+
// cdb-check:o2 : Some [Type: enum2$<core::option::Option<u64> >]
2525
// cdb-check: [+0x008] __0 : 0x162e [Type: unsigned __int64]
2626

2727
// cdb-command: g

src/test/debuginfo/mutex.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,14 @@
2121

2222
//
2323
// cdb-command:dx lock,d
24-
// cdb-check:lock,d : Ok [Type: enum$<core::result::Result<std::sync::mutex::MutexGuard<i32>,enum$<std::sync::poison::TryLockError<std::sync::mutex::MutexGuard<i32> >, 0, 1, Poisoned> > >]
24+
// cdb-check:lock,d : Ok [Type: enum2$<core::result::Result<std::sync::mutex::MutexGuard<i32>,enum2$<std::sync::poison::TryLockError<std::sync::mutex::MutexGuard<i32> >, 0, 1, Poisoned> > >]
2525
// cdb-check: [variant] : Ok
2626
// cdb-check: [...] __0 [Type: std::sync::mutex::MutexGuard<i32>]
2727

2828
use std::sync::Mutex;
2929

3030
#[allow(unused_variables)]
31-
fn main()
32-
{
31+
fn main() {
3332
let m = Mutex::new(0);
3433
let lock = m.try_lock();
3534
zzz(); // #break

src/test/debuginfo/pretty-std.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,17 +116,17 @@
116116
// cdb-check: [chars] : "IAMA OS string [...]"
117117

118118
// cdb-command: dx some
119-
// cdb-check:some : Some [Type: enum$<core::option::Option<i16> >]
120-
// cdb-check: [<Raw View>] [Type: enum$<core::option::Option<i16> >]
119+
// cdb-check:some : Some [Type: enum2$<core::option::Option<i16> >]
120+
// cdb-check: [<Raw View>] [Type: enum2$<core::option::Option<i16> >]
121121
// cdb-check: [+0x002] __0 : 8 [Type: short]
122122

123123
// cdb-command: dx none
124-
// cdb-check:none : None [Type: enum$<core::option::Option<i64> >]
125-
// cdb-check: [<Raw View>] [Type: enum$<core::option::Option<i64> >]
124+
// cdb-check:none : None [Type: enum2$<core::option::Option<i64> >]
125+
// cdb-check: [<Raw View>] [Type: enum2$<core::option::Option<i64> >]
126126

127127
// cdb-command: dx some_string
128-
// cdb-check:some_string : Some [Type: enum$<core::option::Option<alloc::string::String> >]
129-
// cdb-check: [<Raw View>] [Type: enum$<core::option::Option<alloc::string::String> >]
128+
// cdb-check:some_string : Some [Type: enum2$<core::option::Option<alloc::string::String> >]
129+
// cdb-check: [<Raw View>] [Type: enum2$<core::option::Option<alloc::string::String> >]
130130
// cdb-check: [+0x000] __0 : "IAMA optional string!" [Type: alloc::string::String]
131131

132132
// cdb-command: dx linkedlist

src/test/debuginfo/result-types.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,14 @@
77
// cdb-command: g
88

99
// cdb-command: dx x,d
10-
// cdb-check:x,d : Ok [Type: enum$<core::result::Result<i32,str> >]
10+
// cdb-check:x,d : Ok [Type: enum2$<core::result::Result<i32,str> >]
1111
// cdb-check: [...] __0 : -3 [Type: int]
1212

1313
// cdb-command: dx y
14-
// cdb-check:y : Err [Type: enum$<core::result::Result<i32,str> >]
14+
// cdb-check:y : Err [Type: enum2$<core::result::Result<i32,str> >]
1515
// cdb-check: [...] __0 : "Some error message" [Type: str]
1616

17-
fn main()
18-
{
17+
fn main() {
1918
let x: Result<i32, &str> = Ok(-3);
2019
assert_eq!(x.is_ok(), true);
2120

@@ -25,4 +24,6 @@ fn main()
2524
zzz(); // #break.
2625
}
2726

28-
fn zzz() { () }
27+
fn zzz() {
28+
()
29+
}

0 commit comments

Comments
 (0)