diff options
| author | Matt Weber <30441572+mweber15@users.noreply.github.com> | 2022-11-16 21:31:30 -0500 |
|---|---|---|
| committer | Matt Weber <30441572+mweber15@users.noreply.github.com> | 2024-11-06 22:12:03 -0500 |
| commit | f3da8281853bce792a6a4220ccb432500b6b1da5 (patch) | |
| tree | f007dc0b02ba0df7c61b12c874f7e71a2d6dc332 /compiler/rustc_codegen_llvm/src/debuginfo | |
| parent | 94669d9d47e3a594f4179a2aca9997fa1aeea7ad (diff) | |
| download | rust-f3da8281853bce792a6a4220ccb432500b6b1da5.tar.gz rust-f3da8281853bce792a6a4220ccb432500b6b1da5.zip | |
Refactor `type_map::stub` parameters
Push span lookup into `type_map::stub` and pass the `DefId` instead of doing the lookup outside and passing in the location metadata.
Diffstat (limited to 'compiler/rustc_codegen_llvm/src/debuginfo')
5 files changed, 44 insertions, 60 deletions
diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs index ebc452286b6..b8fbedb9d67 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs @@ -204,8 +204,7 @@ fn build_pointer_or_reference_di_node<'ll, 'tcx>( Stub::Struct, unique_type_id, &ptr_type_debuginfo_name, - unknown_file_metadata(cx), - UNKNOWN_LINE_NUMBER, + None, cx.size_and_align_of(ptr_type), NO_SCOPE_METADATA, DIFlags::FlagZero, @@ -373,8 +372,7 @@ fn build_dyn_type_di_node<'ll, 'tcx>( Stub::Struct, unique_type_id, &type_name, - unknown_file_metadata(cx), - UNKNOWN_LINE_NUMBER, + None, cx.size_and_align_of(dyn_type), NO_SCOPE_METADATA, DIFlags::FlagZero, @@ -845,8 +843,7 @@ fn build_foreign_type_di_node<'ll, 'tcx>( Stub::Struct, unique_type_id, &compute_debuginfo_type_name(cx.tcx, t, false), - unknown_file_metadata(cx), - UNKNOWN_LINE_NUMBER, + None, cx.size_and_align_of(t), Some(get_namespace_for_item(cx, def_id)), DIFlags::FlagZero, @@ -1050,15 +1047,6 @@ fn build_struct_type_di_node<'ll, 'tcx>( let struct_type_and_layout = cx.layout_of(struct_type); let variant_def = adt_def.non_enum_variant(); - let tcx = cx.tcx; - let struct_span = tcx.def_span(adt_def.did()); - let (file_metadata, line_number) = if !struct_span.is_dummy() { - let loc = cx.lookup_debug_loc(struct_span.lo()); - (file_metadata(cx, &loc.file), loc.line) - } else { - (unknown_file_metadata(cx), UNKNOWN_LINE_NUMBER) - }; - type_map::build_type_with_children( cx, type_map::stub( @@ -1066,8 +1054,7 @@ fn build_struct_type_di_node<'ll, 'tcx>( Stub::Struct, unique_type_id, &compute_debuginfo_type_name(cx.tcx, struct_type, false), - file_metadata, - line_number, + Some(adt_def.did()), size_and_align_of(struct_type_and_layout), Some(containing_scope), visibility_di_flags(cx, adt_def.did(), adt_def.did()), @@ -1171,8 +1158,7 @@ fn build_tuple_type_di_node<'ll, 'tcx>( Stub::Struct, unique_type_id, &type_name, - unknown_file_metadata(cx), - UNKNOWN_LINE_NUMBER, + None, size_and_align_of(tuple_type_and_layout), NO_SCOPE_METADATA, DIFlags::FlagZero, @@ -1212,14 +1198,6 @@ fn build_closure_env_di_node<'ll, 'tcx>( let containing_scope = get_namespace_for_item(cx, def_id); let type_name = compute_debuginfo_type_name(cx.tcx, closure_env_type, false); - let closure_span = cx.tcx.def_span(def_id); - let (file_metadata, line_number) = if !closure_span.is_dummy() { - let loc = cx.lookup_debug_loc(closure_span.lo()); - (file_metadata(cx, &loc.file), loc.line) - } else { - (unknown_file_metadata(cx), UNKNOWN_LINE_NUMBER) - }; - type_map::build_type_with_children( cx, type_map::stub( @@ -1227,8 +1205,7 @@ fn build_closure_env_di_node<'ll, 'tcx>( Stub::Struct, unique_type_id, &type_name, - file_metadata, - line_number, + Some(def_id), cx.size_and_align_of(closure_env_type), Some(containing_scope), DIFlags::FlagZero, @@ -1260,8 +1237,7 @@ fn build_union_type_di_node<'ll, 'tcx>( Stub::Union, unique_type_id, &type_name, - unknown_file_metadata(cx), - UNKNOWN_LINE_NUMBER, + Some(union_def_id), size_and_align_of(union_ty_and_layout), Some(containing_scope), DIFlags::FlagZero, @@ -1454,8 +1430,7 @@ fn build_vtable_type_di_node<'ll, 'tcx>( Stub::VTableTy { vtable_holder }, unique_type_id, &vtable_type_name, - unknown_file_metadata(cx), - UNKNOWN_LINE_NUMBER, + None, (size, pointer_align), NO_SCOPE_METADATA, DIFlags::FlagArtificial, diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/cpp_like.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/cpp_like.rs index a33347aa283..751880b0cb7 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/cpp_like.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/cpp_like.rs @@ -199,8 +199,7 @@ pub(super) fn build_enum_type_di_node<'ll, 'tcx>( type_map::Stub::Union, unique_type_id, &enum_type_name, - unknown_file_metadata(cx), - UNKNOWN_LINE_NUMBER, + Some(enum_adt_def.did()), cx.size_and_align_of(enum_type), NO_SCOPE_METADATA, visibility_di_flags(cx, enum_adt_def.did(), enum_adt_def.did()), @@ -276,8 +275,7 @@ pub(super) fn build_coroutine_di_node<'ll, 'tcx>( type_map::Stub::Union, unique_type_id, &coroutine_type_name, - unknown_file_metadata(cx), - UNKNOWN_LINE_NUMBER, + None, size_and_align_of(coroutine_type_and_layout), NO_SCOPE_METADATA, DIFlags::FlagZero, @@ -332,6 +330,7 @@ fn build_single_variant_union_fields<'ll, 'tcx>( variant_index, Cow::from(enum_adt_def.variant(variant_index).name.as_str()), )), + enum_adt_def.did(), ); let variant_struct_type_wrapper_di_node = build_variant_struct_wrapper_type_di_node( @@ -394,6 +393,7 @@ fn build_union_fields_for_enum<'ll, 'tcx>( let variant_name = Cow::from(enum_adt_def.variant(variant_index).name.as_str()); (variant_index, variant_name) }), + enum_adt_def.did(), ); let visibility_flags = visibility_di_flags(cx, enum_adt_def.did(), enum_adt_def.did()); @@ -451,6 +451,7 @@ fn build_variant_names_type_di_node<'ll, 'tcx>( cx: &CodegenCx<'ll, 'tcx>, containing_scope: &'ll DIType, variants: impl Iterator<Item = (VariantIdx, Cow<'tcx, str>)>, + enum_def_id: rustc_span::def_id::DefId, ) -> &'ll DIType { // Create an enumerator for each variant. super::build_enumeration_type_di_node( @@ -458,6 +459,7 @@ fn build_variant_names_type_di_node<'ll, 'tcx>( "VariantNames", variant_names_enum_base_type(cx), variants.map(|(variant_index, variant_name)| (variant_name, variant_index.as_u32().into())), + enum_def_id, containing_scope, ) } @@ -485,8 +487,7 @@ fn build_variant_struct_wrapper_type_di_node<'ll, 'tcx>( variant_index, ), &variant_struct_wrapper_type_name(variant_index), - unknown_file_metadata(cx), - UNKNOWN_LINE_NUMBER, + None, // NOTE: We use size and align of enum_type, not from variant_layout: size_and_align_of(enum_or_coroutine_type_and_layout), Some(enum_or_coroutine_type_di_node), @@ -690,6 +691,7 @@ fn build_union_fields_for_direct_tag_coroutine<'ll, 'tcx>( variant_range .clone() .map(|variant_index| (variant_index, CoroutineArgs::variant_name(variant_index))), + coroutine_def_id, ); let discriminants: IndexVec<VariantIdx, DiscrResult> = { diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/mod.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/mod.rs index 4402f289454..2a6a21061a3 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/mod.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/mod.rs @@ -16,8 +16,8 @@ use super::{SmallVec, size_and_align_of}; use crate::common::{AsCCharPtr, CodegenCx}; use crate::debuginfo::metadata::type_map::{self, Stub}; use crate::debuginfo::metadata::{ - UNKNOWN_LINE_NUMBER, build_field_di_node, build_generic_type_param_di_nodes, type_di_node, - unknown_file_metadata, + UNKNOWN_LINE_NUMBER, build_field_di_node, build_generic_type_param_di_nodes, + file_metadata_from_def_id, type_di_node, unknown_file_metadata, }; use crate::debuginfo::utils::{DIB, create_DIArray, get_namespace_for_item}; use crate::llvm::debuginfo::{DIFlags, DIType}; @@ -77,6 +77,7 @@ fn build_c_style_enum_di_node<'ll, 'tcx>( let name = Cow::from(enum_adt_def.variant(variant_index).name.as_str()); (name, discr.val) }), + enum_adt_def.did(), containing_scope, ), already_stored_in_typemap: false, @@ -92,6 +93,7 @@ fn build_enumeration_type_di_node<'ll, 'tcx>( type_name: &str, base_type: Ty<'tcx>, enumerators: impl Iterator<Item = (Cow<'tcx, str>, u128)>, + def_id: rustc_span::def_id::DefId, containing_scope: &'ll DIType, ) -> &'ll DIType { let is_unsigned = match base_type.kind() { @@ -115,14 +117,16 @@ fn build_enumeration_type_di_node<'ll, 'tcx>( }) .collect(); + let (file_metadata, line_number) = file_metadata_from_def_id(cx, Some(def_id)); + unsafe { llvm::LLVMRustDIBuilderCreateEnumerationType( DIB(cx), containing_scope, type_name.as_c_char_ptr(), type_name.len(), - unknown_file_metadata(cx), - UNKNOWN_LINE_NUMBER, + file_metadata, + line_number, size.bits(), align.bits() as u32, create_DIArray(DIB(cx), &enumerator_di_nodes[..]), @@ -204,8 +208,7 @@ fn build_enum_variant_struct_type_di_node<'ll, 'tcx>( variant_index, ), variant_def.name.as_str(), - unknown_file_metadata(cx), - UNKNOWN_LINE_NUMBER, + None, // NOTE: We use size and align of enum_type, not from variant_layout: size_and_align_of(enum_type_and_layout), Some(enum_type_di_node), @@ -288,8 +291,7 @@ fn build_coroutine_variant_struct_type_di_node<'ll, 'tcx>( Stub::Struct, unique_type_id, &variant_name, - unknown_file_metadata(cx), - UNKNOWN_LINE_NUMBER, + None, size_and_align_of(coroutine_type_and_layout), Some(coroutine_type_di_node), DIFlags::FlagZero, @@ -355,11 +357,7 @@ enum DiscrResult { impl DiscrResult { fn opt_single_val(&self) -> Option<u128> { - if let Self::Value(d) = *self { - Some(d) - } else { - None - } + if let Self::Value(d) = *self { Some(d) } else { None } } } diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/native.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/native.rs index 07c3784efe7..7e7de7101cf 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/native.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/native.rs @@ -62,8 +62,7 @@ pub(super) fn build_enum_type_di_node<'ll, 'tcx>( Stub::Struct, unique_type_id, &enum_type_name, - unknown_file_metadata(cx), - UNKNOWN_LINE_NUMBER, + Some(enum_adt_def.did()), size_and_align_of(enum_type_and_layout), Some(containing_scope), visibility_flags, @@ -143,8 +142,7 @@ pub(super) fn build_coroutine_di_node<'ll, 'tcx>( Stub::Struct, unique_type_id, &coroutine_type_name, - unknown_file_metadata(cx), - UNKNOWN_LINE_NUMBER, + None, size_and_align_of(coroutine_type_and_layout), Some(containing_scope), DIFlags::FlagZero, diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/type_map.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/type_map.rs index f8f8cf914ba..70cc476c93e 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/type_map.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/type_map.rs @@ -8,10 +8,10 @@ use rustc_macros::HashStable; use rustc_middle::bug; use rustc_middle::ty::{ParamEnv, PolyExistentialTraitRef, Ty, TyCtxt}; -use super::{SmallVec, UNKNOWN_LINE_NUMBER, unknown_file_metadata}; +use super::{SmallVec, UNKNOWN_LINE_NUMBER, file_metadata, unknown_file_metadata}; use crate::common::{AsCCharPtr, CodegenCx}; use crate::debuginfo::utils::{DIB, create_DIArray, debug_context}; -use crate::llvm::debuginfo::{DIFile, DIFlags, DIScope, DIType}; +use crate::llvm::debuginfo::{DIFlags, DIScope, DIType}; use crate::llvm::{self}; mod private { @@ -174,8 +174,7 @@ pub(super) fn stub<'ll, 'tcx>( kind: Stub<'ll>, unique_type_id: UniqueTypeId<'tcx>, name: &str, - file_metadata: &'ll DIFile, - line_number: u32, + def_id: Option<rustc_span::def_id::DefId>, (size, align): (Size, Align), containing_scope: Option<&'ll DIScope>, flags: DIFlags, @@ -183,6 +182,18 @@ pub(super) fn stub<'ll, 'tcx>( let empty_array = create_DIArray(DIB(cx), &[]); let unique_type_id_str = unique_type_id.generate_unique_id_string(cx.tcx); + let (file_metadata, line_number) = if let Some(def_id) = def_id { + let span = cx.tcx.def_span(def_id); + if !span.is_dummy() { + let loc = cx.lookup_debug_loc(span.lo()); + (file_metadata(cx, &loc.file), loc.line) + } else { + (unknown_file_metadata(cx), UNKNOWN_LINE_NUMBER) + } + } else { + (unknown_file_metadata(cx), UNKNOWN_LINE_NUMBER) + }; + let metadata = match kind { Stub::Struct | Stub::VTableTy { .. } => { let vtable_holder = match kind { |
