Skip to content

Commit 07ebc13

Browse files
debuginfo: Refactor debuginfo generation for types
This commit - changes names to use di_node instead of metadata - uniformly names all functions that build new debuginfo nodes build_xyz_di_node - renames CrateDebugContext to CodegenUnitDebugContext (which is more accurate) - moves TypeMap and functions that work directly work with it to a new type_map module - moves and reimplements enum related builder functions to a new enums module - splits enum debuginfo building for the native and cpp-like cases, since they are mostly separate - uses SmallVec instead of Vec in many places - removes the old infrastructure for dealing with recursion cycles (create_and_register_recursive_type_forward_declaration(), RecursiveTypeDescription, set_members_of_composite_type(), MemberDescription, MemberDescriptionFactory, prepare_xyz_metadata(), etc) - adds type_map::build_type_with_children() as a replacement for dealing with recursion cycles - adds many (doc-)comments explaining what's going on - changes cpp-like naming for C-Style enums so they don't get a enum$<...> name (because the NatVis visualizer does not apply to them) - fixes detection of what is a C-style enum because some enums where classified as C-style even though they have fields - changes the position of discriminant debuginfo node so it is consistently nested inside the top-level union instead of, sometimes, next to it
1 parent 0ac4658 commit 07ebc13

File tree

18 files changed

+2293
-1764
lines changed

18 files changed

+2293
-1764
lines changed

compiler/rustc_codegen_llvm/src/allocator.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ pub(crate) unsafe fn codegen(
140140
llvm::LLVMDisposeBuilder(llbuilder);
141141

142142
if tcx.sess.opts.debuginfo != DebugInfo::None {
143-
let dbg_cx = debuginfo::CrateDebugContext::new(llmod);
144-
debuginfo::metadata::compile_unit_metadata(tcx, module_name, &dbg_cx);
143+
let dbg_cx = debuginfo::CodegenUnitDebugContext::new(llmod);
144+
debuginfo::metadata::build_compile_unit_di_node(tcx, module_name, &dbg_cx);
145145
dbg_cx.finalize(tcx.sess);
146146
}
147147
}

compiler/rustc_codegen_llvm/src/consts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ impl<'ll> StaticMethods for CodegenCx<'ll, '_> {
428428
llvm::LLVMSetGlobalConstant(g, llvm::True);
429429
}
430430

431-
debuginfo::create_global_var_metadata(self, def_id, g);
431+
debuginfo::build_global_var_di_node(self, def_id, g);
432432

433433
if attrs.flags.contains(CodegenFnAttrFlags::THREAD_LOCAL) {
434434
llvm::set_thread_local_mode(g, self.tls_model);

compiler/rustc_codegen_llvm/src/context.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ pub struct CodegenCx<'ll, 'tcx> {
9595
pub isize_ty: &'ll Type,
9696

9797
pub coverage_cx: Option<coverageinfo::CrateCoverageContext<'ll, 'tcx>>,
98-
pub dbg_cx: Option<debuginfo::CrateDebugContext<'ll, 'tcx>>,
98+
pub dbg_cx: Option<debuginfo::CodegenUnitDebugContext<'ll, 'tcx>>,
9999

100100
eh_personality: Cell<Option<&'ll Value>>,
101101
eh_catch_typeinfo: Cell<Option<&'ll Value>>,
@@ -396,8 +396,12 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
396396
};
397397

398398
let dbg_cx = if tcx.sess.opts.debuginfo != DebugInfo::None {
399-
let dctx = debuginfo::CrateDebugContext::new(llmod);
400-
debuginfo::metadata::compile_unit_metadata(tcx, codegen_unit.name().as_str(), &dctx);
399+
let dctx = debuginfo::CodegenUnitDebugContext::new(llmod);
400+
debuginfo::metadata::build_compile_unit_di_node(
401+
tcx,
402+
codegen_unit.name().as_str(),
403+
&dctx,
404+
);
401405
Some(dctx)
402406
} else {
403407
None

0 commit comments

Comments
 (0)