@@ -113,11 +113,20 @@ mod unique_type_id {
113
113
/// A unique identifier for anything that we create a debuginfo node for.
114
114
/// The types it contains are expected to already be normalized (which
115
115
/// is debug_asserted in the constructors).
116
+ ///
117
+ /// Note that there are some things that only show up in debuginfo, like
118
+ /// the separate type descriptions for each enum variant. These get an ID
119
+ /// too because they have their own debuginfo node in LLVM IR.
116
120
#[ derive( Debug , Clone , Copy , PartialEq , Eq , Hash , HashStable ) ]
117
121
pub ( super ) enum UniqueTypeId < ' tcx > {
122
+ /// The ID of a regular type as it shows up at the language level.
118
123
Ty ( Ty < ' tcx > , HiddenZst ) ,
124
+ /// The ID for the artificial struct type describing a single enum variant.
119
125
Variant ( Ty < ' tcx > , VariantIdx , HiddenZst ) ,
126
+ /// The ID for the single DW_TAG_variant_part nested inside the top-level
127
+ /// DW_TAG_structure_type that describes enums and generators.
120
128
VariantPart ( Ty < ' tcx > , HiddenZst ) ,
129
+ /// The ID of the artificial type we create for VTables.
121
130
VTableTy ( Ty < ' tcx > , Option < PolyExistentialTraitRef < ' tcx > > , HiddenZst ) ,
122
131
}
123
132
@@ -163,7 +172,11 @@ mod unique_type_id {
163
172
UniqueTypeId :: VTableTy ( self_type, implemented_trait, HiddenZst { _inaccessible : ( ) } )
164
173
}
165
174
166
- pub fn to_string ( & self , tcx : TyCtxt < ' tcx > ) -> String {
175
+ /// Generates a string version of this [UniqueTypeId], which can be used as the `UniqueId`
176
+ /// argument of the various `LLVMRustDIBuilderCreate*Type()` methods.
177
+ ///
178
+ /// Right now this takes the form of a hex-encoded opaque hash value.
179
+ pub fn generate_unique_id_string ( & self , tcx : TyCtxt < ' tcx > ) -> String {
167
180
let mut hasher = StableHasher :: new ( ) ;
168
181
let mut hcx = tcx. create_stable_hashing_context ( ) ;
169
182
hcx. while_hashing_spans ( false , |hcx| {
@@ -646,9 +659,8 @@ pub fn type_metadata<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>, t: Ty<'tcx>) -> &'ll
646
659
"expected type metadata for unique \
647
660
type ID '{:?}' to already be in \
648
661
the `debuginfo::TypeMap` but it \
649
- was not. (Ty = {}) ",
662
+ was not.",
650
663
unique_type_id,
651
- t
652
664
) ;
653
665
}
654
666
} ;
@@ -672,6 +684,9 @@ fn recursion_marker_type<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>) -> &'ll DIType {
672
684
//
673
685
// FIXME: the name `<recur_type>` does not fit the naming scheme
674
686
// of other types.
687
+ //
688
+ // FIXME: it might make sense to use an actual pointer type here
689
+ // so that debuggers can show the address.
675
690
let name = "<recur_type>" ;
676
691
llvm:: LLVMRustDIBuilderCreateBasicType (
677
692
DIB ( cx) ,
@@ -2030,7 +2045,7 @@ fn prepare_enum_metadata<'ll, 'tcx>(
2030
2045
} ;
2031
2046
2032
2047
let enum_metadata = {
2033
- let unique_type_id_str = unique_type_id. to_string ( tcx) ;
2048
+ let unique_type_id_str = unique_type_id. generate_unique_id_string ( tcx) ;
2034
2049
2035
2050
unsafe {
2036
2051
llvm:: LLVMRustDIBuilderCreateUnionType (
@@ -2142,7 +2157,7 @@ fn prepare_enum_metadata<'ll, 'tcx>(
2142
2157
} ;
2143
2158
2144
2159
let variant_part_unique_type_id_str =
2145
- UniqueTypeId :: for_enum_variant_part ( tcx, enum_type) . to_string ( tcx) ;
2160
+ UniqueTypeId :: for_enum_variant_part ( tcx, enum_type) . generate_unique_id_string ( tcx) ;
2146
2161
2147
2162
let empty_array = create_DIArray ( DIB ( cx) , & [ ] ) ;
2148
2163
let name = "" ;
@@ -2171,7 +2186,7 @@ fn prepare_enum_metadata<'ll, 'tcx>(
2171
2186
// an equivalent layout but offers us much better integration with
2172
2187
// debuggers.
2173
2188
let type_array = create_DIArray ( DIB ( cx) , & [ Some ( variant_part) ] ) ;
2174
- let unique_type_id_str = unique_type_id. to_string ( tcx) ;
2189
+ let unique_type_id_str = unique_type_id. generate_unique_id_string ( tcx) ;
2175
2190
2176
2191
unsafe {
2177
2192
llvm:: LLVMRustDIBuilderCreateStructType (
@@ -2345,7 +2360,7 @@ fn create_struct_stub<'ll, 'tcx>(
2345
2360
flags : DIFlags ,
2346
2361
vtable_holder : Option < & ' ll DIType > ,
2347
2362
) -> & ' ll DICompositeType {
2348
- let unique_type_id = unique_type_id. to_string ( cx. tcx ) ;
2363
+ let unique_type_id = unique_type_id. generate_unique_id_string ( cx. tcx ) ;
2349
2364
2350
2365
let metadata_stub = unsafe {
2351
2366
// `LLVMRustDIBuilderCreateStructType()` wants an empty array. A null
@@ -2383,7 +2398,7 @@ fn create_union_stub<'ll, 'tcx>(
2383
2398
containing_scope : & ' ll DIScope ,
2384
2399
) -> & ' ll DICompositeType {
2385
2400
let ( union_size, union_align) = cx. size_and_align_of ( union_type) ;
2386
- let unique_type_id = unique_type_id. to_string ( cx. tcx ) ;
2401
+ let unique_type_id = unique_type_id. generate_unique_id_string ( cx. tcx ) ;
2387
2402
2388
2403
let metadata_stub = unsafe {
2389
2404
// `LLVMRustDIBuilderCreateUnionType()` wants an empty array. A null
0 commit comments