Skip to content

Commit aabddca

Browse files
committed
Refactor type_stub from DefId to tuple
1 parent a616535 commit aabddca

File tree

5 files changed

+24
-21
lines changed

5 files changed

+24
-21
lines changed

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -992,7 +992,7 @@ fn build_struct_type_di_node<'ll, 'tcx>(
992992
Stub::Struct,
993993
unique_type_id,
994994
&compute_debuginfo_type_name(cx.tcx, struct_type, false),
995-
Some(adt_def.did()),
995+
Some(file_metadata_from_def_id(cx, Some(adt_def.did()))),
996996
size_and_align_of(struct_type_and_layout),
997997
Some(containing_scope),
998998
DIFlags::FlagZero,
@@ -1152,7 +1152,7 @@ fn build_closure_env_di_node<'ll, 'tcx>(
11521152
Stub::Struct,
11531153
unique_type_id,
11541154
&type_name,
1155-
Some(def_id),
1155+
Some(file_metadata_from_def_id(cx, Some(def_id))),
11561156
cx.size_and_align_of(closure_env_type),
11571157
Some(containing_scope),
11581158
DIFlags::FlagZero,
@@ -1184,7 +1184,7 @@ fn build_union_type_di_node<'ll, 'tcx>(
11841184
Stub::Union,
11851185
unique_type_id,
11861186
&type_name,
1187-
Some(union_def_id),
1187+
Some(file_metadata_from_def_id(cx, Some(union_def_id))),
11881188
size_and_align_of(union_ty_and_layout),
11891189
Some(containing_scope),
11901190
DIFlags::FlagZero,
@@ -1554,10 +1554,12 @@ pub fn tuple_field_name(field_index: usize) -> Cow<'static, str> {
15541554
.unwrap_or_else(|| Cow::from(format!("__{}", field_index)))
15551555
}
15561556

1557+
pub type DefinitionLocation<'ll> = (&'ll DIFile, c_uint);
1558+
15571559
pub fn file_metadata_from_def_id<'ll>(
15581560
cx: &CodegenCx<'ll, '_>,
15591561
def_id: Option<DefId>,
1560-
) -> (&'ll DIFile, c_uint) {
1562+
) -> DefinitionLocation<'ll> {
15611563
if let Some(def_id) = def_id && let span = cx.tcx.def_span(def_id) && !span.is_dummy() {
15621564
let loc = cx.lookup_debug_loc(span.lo());
15631565
(file_metadata(cx, &loc.file), loc.line)

compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/cpp_like.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use crate::{
2424
metadata::{
2525
build_field_di_node,
2626
enums::{tag_base_type, DiscrResult},
27-
file_metadata, size_and_align_of, type_di_node,
27+
file_metadata, file_metadata_from_def_id, size_and_align_of, type_di_node,
2828
type_map::{self, Stub, UniqueTypeId},
2929
unknown_file_metadata, DINodeCreationResult, SmallVec, NO_GENERICS, NO_SCOPE_METADATA,
3030
UNKNOWN_LINE_NUMBER,
@@ -213,7 +213,7 @@ pub(super) fn build_enum_type_di_node<'ll, 'tcx>(
213213
type_map::Stub::Union,
214214
unique_type_id,
215215
&enum_type_name,
216-
Some(enum_adt_def.did()),
216+
Some(file_metadata_from_def_id(cx, Some(enum_adt_def.did()))),
217217
cx.size_and_align_of(enum_type),
218218
NO_SCOPE_METADATA,
219219
DIFlags::FlagZero,
@@ -292,7 +292,7 @@ pub(super) fn build_generator_di_node<'ll, 'tcx>(
292292
type_map::Stub::Union,
293293
unique_type_id,
294294
&generator_type_name,
295-
Some(generator_def_id),
295+
Some(file_metadata_from_def_id(cx, Some(generator_def_id))),
296296
size_and_align_of(generator_type_and_layout),
297297
NO_SCOPE_METADATA,
298298
DIFlags::FlagZero,
@@ -350,7 +350,6 @@ fn build_single_variant_union_fields<'ll, 'tcx>(
350350

351351
let variant_struct_type_wrapper_di_node = build_variant_struct_wrapper_type_di_node(
352352
cx,
353-
enum_adt_def,
354353
enum_type_and_layout,
355354
enum_type_di_node,
356355
variant_index,
@@ -360,6 +359,7 @@ fn build_single_variant_union_fields<'ll, 'tcx>(
360359
tag_base_type_di_node,
361360
tag_base_type,
362361
DiscrResult::NoDiscriminant,
362+
None,
363363
);
364364

365365
smallvec![
@@ -480,7 +480,6 @@ fn build_variant_names_type_di_node<'ll, 'tcx>(
480480

481481
fn build_variant_struct_wrapper_type_di_node<'ll, 'tcx>(
482482
cx: &CodegenCx<'ll, 'tcx>,
483-
enum_adt_def: AdtDef<'tcx>,
484483
enum_or_generator_type_and_layout: TyAndLayout<'tcx>,
485484
enum_or_generator_type_di_node: &'ll DIType,
486485
variant_index: VariantIdx,
@@ -490,6 +489,7 @@ fn build_variant_struct_wrapper_type_di_node<'ll, 'tcx>(
490489
tag_base_type_di_node: &'ll DIType,
491490
tag_base_type: Ty<'tcx>,
492491
discr: DiscrResult,
492+
source_info: Option<(&'ll DIFile, c_uint)>,
493493
) -> &'ll DIType {
494494
type_map::build_type_with_children(
495495
cx,
@@ -502,7 +502,7 @@ fn build_variant_struct_wrapper_type_di_node<'ll, 'tcx>(
502502
variant_index,
503503
),
504504
&variant_struct_wrapper_type_name(variant_index),
505-
Some(enum_adt_def.variant(variant_index).def_id),
505+
source_info,
506506
// NOTE: We use size and align of enum_type, not from variant_layout:
507507
size_and_align_of(enum_or_generator_type_and_layout),
508508
Some(enum_or_generator_type_di_node),
@@ -786,13 +786,8 @@ fn build_union_fields_for_direct_tag_enum_or_generator<'ll, 'tcx>(
786786
let field_name = variant_union_field_name(variant_member_info.variant_index);
787787
let (size, align) = size_and_align_of(enum_type_and_layout);
788788

789-
let ty::Adt(enum_adt_def, _) = enum_type_and_layout.ty.kind() else {
790-
unreachable!();
791-
};
792-
793789
let variant_struct_type_wrapper = build_variant_struct_wrapper_type_di_node(
794790
cx,
795-
*enum_adt_def,
796791
enum_type_and_layout,
797792
enum_type_di_node,
798793
variant_member_info.variant_index,
@@ -802,6 +797,7 @@ fn build_union_fields_for_direct_tag_enum_or_generator<'ll, 'tcx>(
802797
tag_base_type_di_node,
803798
tag_base_type,
804799
variant_member_info.discr,
800+
variant_member_info.source_info,
805801
);
806802

807803
// We use LLVMRustDIBuilderCreateMemberType() member type directly because

compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ fn build_enum_variant_struct_type_di_node<'ll, 'tcx>(
265265
variant_index,
266266
),
267267
variant_def.name.as_str(),
268-
Some(variant_def.def_id),
268+
Some(file_metadata_from_def_id(cx, Some(variant_def.def_id))),
269269
// NOTE: We use size and align of enum_type, not from variant_layout:
270270
size_and_align_of(enum_type_and_layout),
271271
Some(enum_type_di_node),

compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/native.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ pub(super) fn build_enum_type_di_node<'ll, 'tcx>(
7272
Stub::Struct,
7373
unique_type_id,
7474
&enum_type_name,
75-
Some(enum_adt_def.did()),
75+
Some(file_metadata_from_def_id(cx, Some(enum_adt_def.did()))),
7676
size_and_align_of(enum_type_and_layout),
7777
Some(containing_scope),
7878
DIFlags::FlagZero,
@@ -155,7 +155,7 @@ pub(super) fn build_generator_di_node<'ll, 'tcx>(
155155
Stub::Struct,
156156
unique_type_id,
157157
&generator_type_name,
158-
Some(generator_def_id),
158+
Some(file_metadata_from_def_id(cx, Some(generator_def_id))),
159159
size_and_align_of(generator_type_and_layout),
160160
Some(containing_scope),
161161
DIFlags::FlagZero,

compiler/rustc_codegen_llvm/src/debuginfo/metadata/type_map.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,14 @@ use rustc_target::abi::{Align, Size, VariantIdx};
1414
use crate::{
1515
common::CodegenCx,
1616
debuginfo::utils::{create_DIArray, debug_context, DIB},
17+
debuginfo::{metadata::unknown_file_metadata, UNKNOWN_LINE_NUMBER},
1718
llvm::{
1819
self,
1920
debuginfo::{DIFlags, DIScope, DIType},
2021
},
2122
};
2223

23-
use super::SmallVec;
24+
use super::{DefinitionLocation, SmallVec};
2425

2526
mod private {
2627
// This type cannot be constructed outside of this module because
@@ -183,15 +184,19 @@ pub(super) fn stub<'ll, 'tcx>(
183184
kind: Stub<'ll>,
184185
unique_type_id: UniqueTypeId<'tcx>,
185186
name: &str,
186-
def_id: Option<rustc_span::def_id::DefId>,
187+
def_location: Option<DefinitionLocation<'ll>>,
187188
(size, align): (Size, Align),
188189
containing_scope: Option<&'ll DIScope>,
189190
flags: DIFlags,
190191
) -> StubInfo<'ll, 'tcx> {
191192
let empty_array = create_DIArray(DIB(cx), &[]);
192193
let unique_type_id_str = unique_type_id.generate_unique_id_string(cx.tcx);
193194

194-
let (file_metadata, line_number) = super::file_metadata_from_def_id(cx, def_id);
195+
let (file_metadata, line_number) = if let Some(def_location) = def_location {
196+
(def_location.0, def_location.1)
197+
} else {
198+
(unknown_file_metadata(cx), UNKNOWN_LINE_NUMBER)
199+
};
195200

196201
let metadata = match kind {
197202
Stub::Struct | Stub::VTableTy { .. } => {

0 commit comments

Comments
 (0)