diff options
| author | Matt Weber <30441572+mweber15@users.noreply.github.com> | 2022-11-23 00:02:00 -0500 |
|---|---|---|
| committer | Matt Weber <30441572+mweber15@users.noreply.github.com> | 2024-11-06 22:25:04 -0500 |
| commit | 27b1b01daa99cd3cb9338e120cc1a26ca31f8833 (patch) | |
| tree | 8c5f107538341b32887feeaf9926fbeda04ce5cc /compiler/rustc_codegen_llvm/src | |
| parent | aa485fc2a1924c71036fa465e7bac6918ab6b275 (diff) | |
| download | rust-27b1b01daa99cd3cb9338e120cc1a26ca31f8833.tar.gz rust-27b1b01daa99cd3cb9338e120cc1a26ca31f8833.zip | |
Refactor `type_stub` from `DefId` to tuple
Diffstat (limited to 'compiler/rustc_codegen_llvm/src')
5 files changed, 26 insertions, 22 deletions
diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs index e9865dee61f..6099b8ddd42 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs @@ -1058,7 +1058,7 @@ fn build_struct_type_di_node<'ll, 'tcx>( Stub::Struct, unique_type_id, &compute_debuginfo_type_name(cx.tcx, struct_type, false), - Some(adt_def.did()), + Some(file_metadata_from_def_id(cx, 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()), @@ -1212,7 +1212,7 @@ fn build_closure_env_di_node<'ll, 'tcx>( Stub::Struct, unique_type_id, &type_name, - Some(def_id), + Some(file_metadata_from_def_id(cx, Some(def_id))), cx.size_and_align_of(closure_env_type), Some(containing_scope), DIFlags::FlagZero, @@ -1244,7 +1244,7 @@ fn build_union_type_di_node<'ll, 'tcx>( Stub::Union, unique_type_id, &type_name, - Some(union_def_id), + Some(file_metadata_from_def_id(cx, Some(union_def_id))), size_and_align_of(union_ty_and_layout), Some(containing_scope), DIFlags::FlagZero, @@ -1622,10 +1622,12 @@ fn tuple_field_name(field_index: usize) -> Cow<'static, str> { .unwrap_or_else(|| Cow::from(format!("__{field_index}"))) } +pub(crate) type DefinitionLocation<'ll> = (&'ll DIFile, c_uint); + pub(crate) fn file_metadata_from_def_id<'ll>( cx: &CodegenCx<'ll, '_>, def_id: Option<DefId>, -) -> (&'ll DIFile, c_uint) { +) -> DefinitionLocation<'ll> { if let Some(def_id) = def_id && let span = hygiene::walk_chain_collapsed(cx.tcx.def_span(def_id), DUMMY_SP) && !span.is_dummy() 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 489530df3a1..62e0f9d92be 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 @@ -16,8 +16,8 @@ use crate::debuginfo::metadata::enums::DiscrResult; use crate::debuginfo::metadata::type_map::{self, Stub, UniqueTypeId}; use crate::debuginfo::metadata::{ DINodeCreationResult, NO_GENERICS, NO_SCOPE_METADATA, SmallVec, UNKNOWN_LINE_NUMBER, - build_field_di_node, file_metadata, size_and_align_of, type_di_node, unknown_file_metadata, - visibility_di_flags, + build_field_di_node, file_metadata, file_metadata_from_def_id, size_and_align_of, type_di_node, + unknown_file_metadata, visibility_di_flags, }; use crate::debuginfo::utils::DIB; use crate::llvm::debuginfo::{DIFile, DIFlags, DIType}; @@ -199,7 +199,7 @@ pub(super) fn build_enum_type_di_node<'ll, 'tcx>( type_map::Stub::Union, unique_type_id, &enum_type_name, - Some(enum_adt_def.did()), + Some(file_metadata_from_def_id(cx, 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()), @@ -278,7 +278,7 @@ pub(super) fn build_coroutine_di_node<'ll, 'tcx>( type_map::Stub::Union, unique_type_id, &coroutine_type_name, - Some(coroutine_def_id), + Some(file_metadata_from_def_id(cx, Some(coroutine_def_id))), size_and_align_of(coroutine_type_and_layout), NO_SCOPE_METADATA, DIFlags::FlagZero, @@ -338,7 +338,6 @@ fn build_single_variant_union_fields<'ll, 'tcx>( let variant_struct_type_wrapper_di_node = build_variant_struct_wrapper_type_di_node( cx, - enum_adt_def, enum_type_and_layout, enum_type_di_node, variant_index, @@ -348,6 +347,7 @@ fn build_single_variant_union_fields<'ll, 'tcx>( tag_base_type_di_node, tag_base_type, DiscrResult::NoDiscriminant, + None, ); smallvec![ @@ -471,7 +471,6 @@ fn build_variant_names_type_di_node<'ll, 'tcx>( fn build_variant_struct_wrapper_type_di_node<'ll, 'tcx>( cx: &CodegenCx<'ll, 'tcx>, - enum_adt_def: AdtDef<'tcx>, enum_or_coroutine_type_and_layout: TyAndLayout<'tcx>, enum_or_coroutine_type_di_node: &'ll DIType, variant_index: VariantIdx, @@ -481,6 +480,7 @@ fn build_variant_struct_wrapper_type_di_node<'ll, 'tcx>( tag_base_type_di_node: &'ll DIType, tag_base_type: Ty<'tcx>, discr: DiscrResult, + source_info: Option<(&'ll DIFile, c_uint)>, ) -> &'ll DIType { type_map::build_type_with_children( cx, @@ -493,7 +493,7 @@ fn build_variant_struct_wrapper_type_di_node<'ll, 'tcx>( variant_index, ), &variant_struct_wrapper_type_name(variant_index), - Some(enum_adt_def.variant(variant_index).def_id), + source_info, // 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), @@ -780,13 +780,8 @@ fn build_union_fields_for_direct_tag_enum_or_coroutine<'ll, 'tcx>( let field_name = variant_union_field_name(variant_member_info.variant_index); let (size, align) = size_and_align_of(enum_type_and_layout); - let ty::Adt(enum_adt_def, _) = enum_type_and_layout.ty.kind() else { - unreachable!(); - }; - let variant_struct_type_wrapper = build_variant_struct_wrapper_type_di_node( cx, - *enum_adt_def, enum_type_and_layout, enum_type_di_node, variant_member_info.variant_index, @@ -796,6 +791,7 @@ fn build_union_fields_for_direct_tag_enum_or_coroutine<'ll, 'tcx>( tag_base_type_di_node, tag_base_type, variant_member_info.discr, + variant_member_info.source_info, ); // We use LLVMRustDIBuilderCreateMemberType() member type directly because 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 9974dac5a1d..754395257ee 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/mod.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/mod.rs @@ -208,7 +208,7 @@ fn build_enum_variant_struct_type_di_node<'ll, 'tcx>( variant_index, ), variant_def.name.as_str(), - Some(variant_def.def_id), + Some(file_metadata_from_def_id(cx, Some(variant_def.def_id))), // 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), 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 4a7981ddc88..604e9bab077 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/native.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/native.rs @@ -63,7 +63,7 @@ pub(super) fn build_enum_type_di_node<'ll, 'tcx>( Stub::Struct, unique_type_id, &enum_type_name, - Some(enum_adt_def.did()), + Some(file_metadata_from_def_id(cx, Some(enum_adt_def.did()))), size_and_align_of(enum_type_and_layout), Some(containing_scope), visibility_flags, @@ -147,7 +147,7 @@ pub(super) fn build_coroutine_di_node<'ll, 'tcx>( Stub::Struct, unique_type_id, &coroutine_type_name, - Some(coroutine_def_id), + Some(file_metadata_from_def_id(cx, Some(coroutine_def_id))), 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 1cd86d732eb..a6b399d7669 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/type_map.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/type_map.rs @@ -8,7 +8,9 @@ use rustc_macros::HashStable; use rustc_middle::bug; use rustc_middle::ty::{ParamEnv, PolyExistentialTraitRef, Ty, TyCtxt}; -use super::{SmallVec, UNKNOWN_LINE_NUMBER, file_metadata, unknown_file_metadata}; +use super::{ + DefinitionLocation, 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::{DIFlags, DIScope, DIType}; @@ -174,7 +176,7 @@ pub(super) fn stub<'ll, 'tcx>( kind: Stub<'ll>, unique_type_id: UniqueTypeId<'tcx>, name: &str, - def_id: Option<rustc_span::def_id::DefId>, + def_location: Option<DefinitionLocation<'ll>>, (size, align): (Size, Align), containing_scope: Option<&'ll DIScope>, flags: DIFlags, @@ -182,7 +184,11 @@ 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) = super::file_metadata_from_def_id(cx, def_id); + let (file_metadata, line_number) = if let Some(def_location) = def_location { + (def_location.0, def_location.1) + } else { + (unknown_file_metadata(cx), UNKNOWN_LINE_NUMBER) + }; let metadata = match kind { Stub::Struct | Stub::VTableTy { .. } => { |
