Skip to content

Commit 19707b0

Browse files
debuginfo: Refactor debuginfo generation for types -- Address outstanding FIXMEs.
1 parent 07a1194 commit 19707b0

File tree

3 files changed

+19
-20
lines changed

3 files changed

+19
-20
lines changed

Diff for: compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

+1-9
Original file line numberDiff line numberDiff line change
@@ -1120,11 +1120,7 @@ fn build_closure_env_di_node<'ll, 'tcx>(
11201120
),
11211121
// Fields:
11221122
|cx, owner| build_upvar_field_di_nodes(cx, closure_env_type, owner),
1123-
// Generics:
1124-
|_| {
1125-
// FIXME(mw): Should we specify generic parameters for closures?
1126-
smallvec![]
1127-
},
1123+
NO_GENERICS,
11281124
)
11291125
}
11301126

@@ -1178,10 +1174,6 @@ fn build_union_type_di_node<'ll, 'tcx>(
11781174
)
11791175
}
11801176

1181-
//=-----------------------------------------------------------------------------
1182-
// Enums
1183-
//=-----------------------------------------------------------------------------
1184-
11851177
// FIXME(eddyb) maybe precompute this? Right now it's computed once
11861178
// per generator monomorphization, but it doesn't depend on substs.
11871179
fn generator_layout_and_saved_local_names<'tcx>(

Diff for: compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/mod.rs

+15-8
Original file line numberDiff line numberDiff line change
@@ -110,15 +110,14 @@ fn tag_base_type<'ll, 'tcx>(
110110
_ => false,
111111
});
112112

113-
// FIXME(mw): Why are niche and regular tags treated differently? Because we want to preserve
114-
// the sign?
115113
match enum_type_and_layout.layout.variants() {
116114
// A single-variant enum has no discriminant.
117115
Variants::Single { .. } => {
118116
bug!("tag_base_type() called for enum without tag: {:?}", enum_type_and_layout)
119117
}
120118

121119
Variants::Multiple { tag_encoding: TagEncoding::Niche { .. }, tag, .. } => {
120+
// Niche tags are always normalized to unsized integers of the correct size.
122121
match tag.value {
123122
Primitive::Int(t, _) => t,
124123
Primitive::F32 => Integer::I32,
@@ -134,26 +133,34 @@ fn tag_base_type<'ll, 'tcx>(
134133
}
135134

136135
Variants::Multiple { tag_encoding: TagEncoding::Direct, tag, .. } => {
136+
// Direct tags preserve the sign.
137137
tag.value.to_ty(cx.tcx)
138138
}
139139
}
140140
}
141141

142-
/// This is a helper function. FIXME: elaborate docs.
142+
/// Build a DW_TAG_enumeration_type debuginfo node, with the given base type and variants.
143+
/// This is a helper function and does not register anything in the type map by itself.
144+
///
145+
/// `variants` is an iterator of (discr-value, variant-name).
146+
///
147+
// NOTE: Handling of discriminant values is somewhat inconsistent. They can appear as u128,
148+
// u64, and i64. Here everything gets mapped to i64 because that's what LLVM's API expects.
143149
fn build_enumeration_type_di_node<'ll, 'tcx>(
144150
cx: &CodegenCx<'ll, 'tcx>,
145151
type_name: &str,
146152
base_type: Ty<'tcx>,
147153
variants: &mut dyn Iterator<Item = (Discr<'tcx>, Cow<'tcx, str>)>,
148154
containing_scope: &'ll DIType,
149155
) -> &'ll DIType {
156+
let is_unsigned = match base_type.kind() {
157+
ty::Int(_) => false,
158+
ty::Uint(_) => true,
159+
_ => bug!("build_enumeration_type_di_node() called with non-integer tag type."),
160+
};
161+
150162
let enumerator_di_nodes: SmallVec<Option<&'ll DIType>> = variants
151163
.map(|(discr, variant_name)| {
152-
let is_unsigned = match discr.ty.kind() {
153-
ty::Int(_) => false,
154-
ty::Uint(_) => true,
155-
_ => bug!("build_enumeration_type_di_node() called with non-integer tag type."),
156-
};
157164
unsafe {
158165
Some(llvm::LLVMRustDIBuilderCreateEnumerator(
159166
DIB(cx),

Diff for: compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/native.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -410,9 +410,9 @@ fn build_enum_variant_member_di_node<'ll, 'tcx>(
410410
variant_member_info.variant_name.len(),
411411
file_di_node,
412412
line_number,
413-
enum_type_and_layout.size.bits(), // FIXME: Unused?
414-
enum_type_and_layout.align.abi.bits() as u32, // FIXME: Unused?
415-
Size::ZERO.bits(), // FIXME: Unused?
413+
enum_type_and_layout.size.bits(),
414+
enum_type_and_layout.align.abi.bits() as u32,
415+
Size::ZERO.bits(),
416416
discr_value.map(|v| cx.const_u64(v)),
417417
DIFlags::FlagZero,
418418
variant_member_info.variant_struct_type_di_node,

0 commit comments

Comments
 (0)