Skip to content

Commit bb2059f

Browse files
debuginfo: Simplify TypeMap used during LLVM debuginfo generation -- address review comments.
1 parent e72e639 commit bb2059f

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

+23-8
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,20 @@ mod unique_type_id {
113113
/// A unique identifier for anything that we create a debuginfo node for.
114114
/// The types it contains are expected to already be normalized (which
115115
/// 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.
116120
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, HashStable)]
117121
pub(super) enum UniqueTypeId<'tcx> {
122+
/// The ID of a regular type as it shows up at the language level.
118123
Ty(Ty<'tcx>, HiddenZst),
124+
/// The ID for the artificial struct type describing a single enum variant.
119125
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.
120128
VariantPart(Ty<'tcx>, HiddenZst),
129+
/// The ID of the artificial type we create for VTables.
121130
VTableTy(Ty<'tcx>, Option<PolyExistentialTraitRef<'tcx>>, HiddenZst),
122131
}
123132

@@ -163,7 +172,11 @@ mod unique_type_id {
163172
UniqueTypeId::VTableTy(self_type, implemented_trait, HiddenZst { _inaccessible: () })
164173
}
165174

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 {
167180
let mut hasher = StableHasher::new();
168181
let mut hcx = tcx.create_stable_hashing_context();
169182
hcx.while_hashing_spans(false, |hcx| {
@@ -646,9 +659,8 @@ pub fn type_metadata<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>, t: Ty<'tcx>) -> &'ll
646659
"expected type metadata for unique \
647660
type ID '{:?}' to already be in \
648661
the `debuginfo::TypeMap` but it \
649-
was not. (Ty = {})",
662+
was not.",
650663
unique_type_id,
651-
t
652664
);
653665
}
654666
};
@@ -672,6 +684,9 @@ fn recursion_marker_type<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>) -> &'ll DIType {
672684
//
673685
// FIXME: the name `<recur_type>` does not fit the naming scheme
674686
// 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.
675690
let name = "<recur_type>";
676691
llvm::LLVMRustDIBuilderCreateBasicType(
677692
DIB(cx),
@@ -2030,7 +2045,7 @@ fn prepare_enum_metadata<'ll, 'tcx>(
20302045
};
20312046

20322047
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);
20342049

20352050
unsafe {
20362051
llvm::LLVMRustDIBuilderCreateUnionType(
@@ -2142,7 +2157,7 @@ fn prepare_enum_metadata<'ll, 'tcx>(
21422157
};
21432158

21442159
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);
21462161

21472162
let empty_array = create_DIArray(DIB(cx), &[]);
21482163
let name = "";
@@ -2171,7 +2186,7 @@ fn prepare_enum_metadata<'ll, 'tcx>(
21712186
// an equivalent layout but offers us much better integration with
21722187
// debuggers.
21732188
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);
21752190

21762191
unsafe {
21772192
llvm::LLVMRustDIBuilderCreateStructType(
@@ -2345,7 +2360,7 @@ fn create_struct_stub<'ll, 'tcx>(
23452360
flags: DIFlags,
23462361
vtable_holder: Option<&'ll DIType>,
23472362
) -> &'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);
23492364

23502365
let metadata_stub = unsafe {
23512366
// `LLVMRustDIBuilderCreateStructType()` wants an empty array. A null
@@ -2383,7 +2398,7 @@ fn create_union_stub<'ll, 'tcx>(
23832398
containing_scope: &'ll DIScope,
23842399
) -> &'ll DICompositeType {
23852400
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);
23872402

23882403
let metadata_stub = unsafe {
23892404
// `LLVMRustDIBuilderCreateUnionType()` wants an empty array. A null

0 commit comments

Comments
 (0)