Skip to content

Commit 9580a71

Browse files
debuginfo: Refactor debuginfo generation for types -- Address review comments.
1 parent 19707b0 commit 9580a71

File tree

5 files changed

+25
-19
lines changed

5 files changed

+25
-19
lines changed

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

+19-16
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,10 @@ fn build_dyn_type_di_node<'ll, 'tcx>(
359359
NO_GENERICS,
360360
)
361361
} else {
362-
bug!("Only ty::Dynamic is valid for dyn_type_metadata(). Found {:?} instead.", dyn_type)
362+
bug!(
363+
"Only ty::Dynamic is valid for build_dyn_type_di_node(). Found {:?} instead.",
364+
dyn_type
365+
)
363366
}
364367
}
365368

@@ -390,15 +393,15 @@ fn build_slice_type_di_node<'ll, 'tcx>(
390393
ty::Str => cx.tcx.types.u8,
391394
_ => {
392395
bug!(
393-
"Only ty::Slice is valid for slice_type_metadata(). Found {:?} instead.",
396+
"Only ty::Slice is valid for build_slice_type_di_node(). Found {:?} instead.",
394397
slice_type
395398
)
396399
}
397400
};
398401

399-
let element_type_metadata = type_di_node(cx, element_type);
402+
let element_type_di_node = type_di_node(cx, element_type);
400403
return_if_di_node_created_in_meantime!(cx, unique_type_id);
401-
DINodeCreationResult { di_node: element_type_metadata, already_stored_in_typemap: false }
404+
DINodeCreationResult { di_node: element_type_di_node, already_stored_in_typemap: false }
402405
}
403406

404407
/// Get the debuginfo node for the given type.
@@ -445,7 +448,7 @@ pub fn type_di_node<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>, t: Ty<'tcx>) -> &'ll D
445448
ty::Tuple(_) => build_tuple_type_di_node(cx, unique_type_id),
446449
// Type parameters from polymorphized functions.
447450
ty::Param(_) => build_param_type_di_node(cx, t),
448-
_ => bug!("debuginfo: unexpected type in type_metadata: {:?}", t),
451+
_ => bug!("debuginfo: unexpected type in type_di_node(): {:?}", t),
449452
};
450453

451454
{
@@ -456,7 +459,7 @@ pub fn type_di_node<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>, t: Ty<'tcx>) -> &'ll D
456459
Some(di_node) => di_node,
457460
None => {
458461
bug!(
459-
"expected type di_node for unique \
462+
"expected type debuginfo node for unique \
460463
type ID '{:?}' to already be in \
461464
the `debuginfo::TypeMap` but it \
462465
was not.",
@@ -754,7 +757,7 @@ pub fn build_compile_unit_di_node<'ll, 'tcx>(
754757
name_in_debuginfo.push("@");
755758
name_in_debuginfo.push(codegen_unit_name);
756759

757-
debug!("compile_unit_metadata: {:?}", name_in_debuginfo);
760+
debug!("build_compile_unit_di_node: {:?}", name_in_debuginfo);
758761
let rustc_producer =
759762
format!("rustc version {}", option_env!("CFG_VERSION").expect("CFG_VERSION"),);
760763
// FIXME(#41252) Remove "clang LLVM" if we can get GDB and LLVM to play nice.
@@ -1003,7 +1006,7 @@ fn closure_saved_names_of_captured_variables(tcx: TyCtxt<'_>, def_id: DefId) ->
10031006
fn build_upvar_field_di_nodes<'ll, 'tcx>(
10041007
cx: &CodegenCx<'ll, 'tcx>,
10051008
closure_or_generator_ty: Ty<'tcx>,
1006-
closure_or_generator_metadata: &'ll DIType,
1009+
closure_or_generator_di_node: &'ll DIType,
10071010
) -> SmallVec<&'ll DIType> {
10081011
let (&def_id, up_var_tys) = match closure_or_generator_ty.kind() {
10091012
ty::Generator(def_id, substs, _) => {
@@ -1016,7 +1019,7 @@ fn build_upvar_field_di_nodes<'ll, 'tcx>(
10161019
}
10171020
_ => {
10181021
bug!(
1019-
"new_upvar_member_descriptions() called with non-closure-or-generator-type: {:?}",
1022+
"build_upvar_field_di_nodes() called with non-closure-or-generator-type: {:?}",
10201023
closure_or_generator_ty
10211024
)
10221025
}
@@ -1038,7 +1041,7 @@ fn build_upvar_field_di_nodes<'ll, 'tcx>(
10381041
.map(|(index, (up_var_ty, capture_name))| {
10391042
build_field_di_node(
10401043
cx,
1041-
closure_or_generator_metadata,
1044+
closure_or_generator_di_node,
10421045
capture_name,
10431046
cx.size_and_align_of(up_var_ty),
10441047
layout.fields.offset(index),
@@ -1074,14 +1077,14 @@ fn build_tuple_type_di_node<'ll, 'tcx>(
10741077
DIFlags::FlagZero,
10751078
),
10761079
// Fields:
1077-
|cx, tuple_metadata| {
1080+
|cx, tuple_di_node| {
10781081
component_types
10791082
.into_iter()
10801083
.enumerate()
10811084
.map(|(index, component_type)| {
10821085
build_field_di_node(
10831086
cx,
1084-
tuple_metadata,
1087+
tuple_di_node,
10851088
&tuple_field_name(index),
10861089
cx.size_and_align_of(component_type),
10871090
tuple_type_and_layout.fields.offset(index),
@@ -1095,14 +1098,14 @@ fn build_tuple_type_di_node<'ll, 'tcx>(
10951098
)
10961099
}
10971100

1098-
/// Builds the debufinfo node for a closure environment.
1101+
/// Builds the debuginfo node for a closure environment.
10991102
fn build_closure_env_di_node<'ll, 'tcx>(
11001103
cx: &CodegenCx<'ll, 'tcx>,
11011104
unique_type_id: UniqueTypeId<'tcx>,
11021105
) -> DINodeCreationResult<'ll> {
11031106
let closure_env_type = unique_type_id.expect_ty();
11041107
let &ty::Closure(def_id, _substs) = closure_env_type.kind() else {
1105-
bug!("new_closure_env_metadata() called with non-closure-type: {:?}", closure_env_type)
1108+
bug!("build_closure_env_di_node() called with non-closure-type: {:?}", closure_env_type)
11061109
};
11071110
let containing_scope = get_namespace_for_item(cx, def_id);
11081111
let type_name = compute_debuginfo_type_name(cx.tcx, closure_env_type, false);
@@ -1225,15 +1228,15 @@ fn build_generic_type_param_di_nodes<'ll, 'tcx>(
12251228
if let GenericArgKind::Type(ty) = kind.unpack() {
12261229
let actual_type =
12271230
cx.tcx.normalize_erasing_regions(ParamEnv::reveal_all(), ty);
1228-
let actual_type_metadata = type_di_node(cx, actual_type);
1231+
let actual_type_di_node = type_di_node(cx, actual_type);
12291232
let name = name.as_str();
12301233
Some(unsafe {
12311234
llvm::LLVMRustDIBuilderCreateTemplateTypeParameter(
12321235
DIB(cx),
12331236
None,
12341237
name.as_ptr().cast(),
12351238
name.len(),
1236-
actual_type_metadata,
1239+
actual_type_di_node,
12371240
)
12381241
})
12391242
} else {

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

+2
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ fn tag_base_type<'ll, 'tcx>(
126126
// If the niche is the NULL value of a reference, then `discr_enum_ty` will be
127127
// a RawPtr. CodeView doesn't know what to do with enums whose base type is a
128128
// pointer so we fix this up to just be `usize`.
129+
// DWARF might be able to deal with this but with an integer type we are on
130+
// the safe side there too.
129131
cx.data_layout().ptr_sized_integer()
130132
}
131133
}

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@ impl<'ll> DINodeCreationResult<'ll> {
145145
}
146146
}
147147

148-
#[allow(dead_code)]
149148
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
150149
pub enum Stub<'ll> {
151150
Struct,
@@ -233,7 +232,7 @@ pub(super) fn stub<'ll, 'tcx>(
233232
/// This function enables creating debuginfo nodes that can recursively refer to themselves.
234233
/// It will first insert the given stub into the type map and only then execute the `members`
235234
/// and `generics` closures passed in. These closures have access to the stub so they can
236-
/// directly attach fields to them. If build the type of a field transitively refers back
235+
/// directly attach fields to them. If the type of a field transitively refers back
237236
/// to the type currently being built, the stub will already be found in the type map,
238237
/// which effectively breaks the recursion cycle.
239238
pub(super) fn build_type_with_children<'ll, 'tcx>(

Diff for: compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ fn push_debuginfo_type_name<'tcx>(
364364
// "{async_fn_env#0}<T1, T2, ...>", etc.
365365
// In the case of cpp-like debuginfo, the name additionally gets wrapped inside of
366366
// an artificial `enum$<>` type, as defined in msvc_enum_fallback().
367-
if cpp_like_debuginfo && matches!(t.kind(), ty::Generator(..)) {
367+
if cpp_like_debuginfo && t.is_generator() {
368368
let ty_and_layout = tcx.layout_of(ParamEnv::reveal_all().and(t)).unwrap();
369369
msvc_enum_fallback(
370370
tcx,

Diff for: src/tools/compiletest/src/runtest.rs

+2
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,8 @@ impl<'test> TestCx<'test> {
669669
// type is present in the PDB, which is very confusing.
670670
// Therefore we delete any existing PDB file before compiling the test
671671
// case.
672+
// FIXME: If can reliably detect that MSVC's link.exe is used, then
673+
// passing `/INCREMENTAL:NO` might be a cleaner way to do this.
672674
let pdb_file = exe_file.with_extension(".pdb");
673675
if pdb_file.exists() {
674676
std::fs::remove_file(pdb_file).unwrap();

0 commit comments

Comments
 (0)