Skip to content

Commit 27b1b01

Browse files
committed
Refactor type_stub from DefId to tuple
1 parent aa485fc commit 27b1b01

File tree

5 files changed

+26
-22
lines changed

5 files changed

+26
-22
lines changed

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,7 +1058,7 @@ fn build_struct_type_di_node<'ll, 'tcx>(
10581058
Stub::Struct,
10591059
unique_type_id,
10601060
&compute_debuginfo_type_name(cx.tcx, struct_type, false),
1061-
Some(adt_def.did()),
1061+
Some(file_metadata_from_def_id(cx, Some(adt_def.did()))),
10621062
size_and_align_of(struct_type_and_layout),
10631063
Some(containing_scope),
10641064
visibility_di_flags(cx, adt_def.did(), adt_def.did()),
@@ -1212,7 +1212,7 @@ fn build_closure_env_di_node<'ll, 'tcx>(
12121212
Stub::Struct,
12131213
unique_type_id,
12141214
&type_name,
1215-
Some(def_id),
1215+
Some(file_metadata_from_def_id(cx, Some(def_id))),
12161216
cx.size_and_align_of(closure_env_type),
12171217
Some(containing_scope),
12181218
DIFlags::FlagZero,
@@ -1244,7 +1244,7 @@ fn build_union_type_di_node<'ll, 'tcx>(
12441244
Stub::Union,
12451245
unique_type_id,
12461246
&type_name,
1247-
Some(union_def_id),
1247+
Some(file_metadata_from_def_id(cx, Some(union_def_id))),
12481248
size_and_align_of(union_ty_and_layout),
12491249
Some(containing_scope),
12501250
DIFlags::FlagZero,
@@ -1622,10 +1622,12 @@ fn tuple_field_name(field_index: usize) -> Cow<'static, str> {
16221622
.unwrap_or_else(|| Cow::from(format!("__{field_index}")))
16231623
}
16241624

1625+
pub(crate) type DefinitionLocation<'ll> = (&'ll DIFile, c_uint);
1626+
16251627
pub(crate) fn file_metadata_from_def_id<'ll>(
16261628
cx: &CodegenCx<'ll, '_>,
16271629
def_id: Option<DefId>,
1628-
) -> (&'ll DIFile, c_uint) {
1630+
) -> DefinitionLocation<'ll> {
16291631
if let Some(def_id) = def_id
16301632
&& let span = hygiene::walk_chain_collapsed(cx.tcx.def_span(def_id), DUMMY_SP)
16311633
&& !span.is_dummy()

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

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ use crate::debuginfo::metadata::enums::DiscrResult;
1616
use crate::debuginfo::metadata::type_map::{self, Stub, UniqueTypeId};
1717
use crate::debuginfo::metadata::{
1818
DINodeCreationResult, NO_GENERICS, NO_SCOPE_METADATA, SmallVec, UNKNOWN_LINE_NUMBER,
19-
build_field_di_node, file_metadata, size_and_align_of, type_di_node, unknown_file_metadata,
20-
visibility_di_flags,
19+
build_field_di_node, file_metadata, file_metadata_from_def_id, size_and_align_of, type_di_node,
20+
unknown_file_metadata, visibility_di_flags,
2121
};
2222
use crate::debuginfo::utils::DIB;
2323
use crate::llvm::debuginfo::{DIFile, DIFlags, DIType};
@@ -199,7 +199,7 @@ pub(super) fn build_enum_type_di_node<'ll, 'tcx>(
199199
type_map::Stub::Union,
200200
unique_type_id,
201201
&enum_type_name,
202-
Some(enum_adt_def.did()),
202+
Some(file_metadata_from_def_id(cx, Some(enum_adt_def.did()))),
203203
cx.size_and_align_of(enum_type),
204204
NO_SCOPE_METADATA,
205205
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>(
278278
type_map::Stub::Union,
279279
unique_type_id,
280280
&coroutine_type_name,
281-
Some(coroutine_def_id),
281+
Some(file_metadata_from_def_id(cx, Some(coroutine_def_id))),
282282
size_and_align_of(coroutine_type_and_layout),
283283
NO_SCOPE_METADATA,
284284
DIFlags::FlagZero,
@@ -338,7 +338,6 @@ fn build_single_variant_union_fields<'ll, 'tcx>(
338338

339339
let variant_struct_type_wrapper_di_node = build_variant_struct_wrapper_type_di_node(
340340
cx,
341-
enum_adt_def,
342341
enum_type_and_layout,
343342
enum_type_di_node,
344343
variant_index,
@@ -348,6 +347,7 @@ fn build_single_variant_union_fields<'ll, 'tcx>(
348347
tag_base_type_di_node,
349348
tag_base_type,
350349
DiscrResult::NoDiscriminant,
350+
None,
351351
);
352352

353353
smallvec![
@@ -471,7 +471,6 @@ fn build_variant_names_type_di_node<'ll, 'tcx>(
471471

472472
fn build_variant_struct_wrapper_type_di_node<'ll, 'tcx>(
473473
cx: &CodegenCx<'ll, 'tcx>,
474-
enum_adt_def: AdtDef<'tcx>,
475474
enum_or_coroutine_type_and_layout: TyAndLayout<'tcx>,
476475
enum_or_coroutine_type_di_node: &'ll DIType,
477476
variant_index: VariantIdx,
@@ -481,6 +480,7 @@ fn build_variant_struct_wrapper_type_di_node<'ll, 'tcx>(
481480
tag_base_type_di_node: &'ll DIType,
482481
tag_base_type: Ty<'tcx>,
483482
discr: DiscrResult,
483+
source_info: Option<(&'ll DIFile, c_uint)>,
484484
) -> &'ll DIType {
485485
type_map::build_type_with_children(
486486
cx,
@@ -493,7 +493,7 @@ fn build_variant_struct_wrapper_type_di_node<'ll, 'tcx>(
493493
variant_index,
494494
),
495495
&variant_struct_wrapper_type_name(variant_index),
496-
Some(enum_adt_def.variant(variant_index).def_id),
496+
source_info,
497497
// NOTE: We use size and align of enum_type, not from variant_layout:
498498
size_and_align_of(enum_or_coroutine_type_and_layout),
499499
Some(enum_or_coroutine_type_di_node),
@@ -780,13 +780,8 @@ fn build_union_fields_for_direct_tag_enum_or_coroutine<'ll, 'tcx>(
780780
let field_name = variant_union_field_name(variant_member_info.variant_index);
781781
let (size, align) = size_and_align_of(enum_type_and_layout);
782782

783-
let ty::Adt(enum_adt_def, _) = enum_type_and_layout.ty.kind() else {
784-
unreachable!();
785-
};
786-
787783
let variant_struct_type_wrapper = build_variant_struct_wrapper_type_di_node(
788784
cx,
789-
*enum_adt_def,
790785
enum_type_and_layout,
791786
enum_type_di_node,
792787
variant_member_info.variant_index,
@@ -796,6 +791,7 @@ fn build_union_fields_for_direct_tag_enum_or_coroutine<'ll, 'tcx>(
796791
tag_base_type_di_node,
797792
tag_base_type,
798793
variant_member_info.discr,
794+
variant_member_info.source_info,
799795
);
800796

801797
// 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
@@ -208,7 +208,7 @@ fn build_enum_variant_struct_type_di_node<'ll, 'tcx>(
208208
variant_index,
209209
),
210210
variant_def.name.as_str(),
211-
Some(variant_def.def_id),
211+
Some(file_metadata_from_def_id(cx, Some(variant_def.def_id))),
212212
// NOTE: We use size and align of enum_type, not from variant_layout:
213213
size_and_align_of(enum_type_and_layout),
214214
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
@@ -63,7 +63,7 @@ pub(super) fn build_enum_type_di_node<'ll, 'tcx>(
6363
Stub::Struct,
6464
unique_type_id,
6565
&enum_type_name,
66-
Some(enum_adt_def.did()),
66+
Some(file_metadata_from_def_id(cx, Some(enum_adt_def.did()))),
6767
size_and_align_of(enum_type_and_layout),
6868
Some(containing_scope),
6969
visibility_flags,
@@ -147,7 +147,7 @@ pub(super) fn build_coroutine_di_node<'ll, 'tcx>(
147147
Stub::Struct,
148148
unique_type_id,
149149
&coroutine_type_name,
150-
Some(coroutine_def_id),
150+
Some(file_metadata_from_def_id(cx, Some(coroutine_def_id))),
151151
size_and_align_of(coroutine_type_and_layout),
152152
Some(containing_scope),
153153
DIFlags::FlagZero,

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ use rustc_macros::HashStable;
88
use rustc_middle::bug;
99
use rustc_middle::ty::{ParamEnv, PolyExistentialTraitRef, Ty, TyCtxt};
1010

11-
use super::{SmallVec, UNKNOWN_LINE_NUMBER, file_metadata, unknown_file_metadata};
11+
use super::{
12+
DefinitionLocation, SmallVec, UNKNOWN_LINE_NUMBER, file_metadata, unknown_file_metadata,
13+
};
1214
use crate::common::{AsCCharPtr, CodegenCx};
1315
use crate::debuginfo::utils::{DIB, create_DIArray, debug_context};
1416
use crate::llvm::debuginfo::{DIFlags, DIScope, DIType};
@@ -174,15 +176,19 @@ pub(super) fn stub<'ll, 'tcx>(
174176
kind: Stub<'ll>,
175177
unique_type_id: UniqueTypeId<'tcx>,
176178
name: &str,
177-
def_id: Option<rustc_span::def_id::DefId>,
179+
def_location: Option<DefinitionLocation<'ll>>,
178180
(size, align): (Size, Align),
179181
containing_scope: Option<&'ll DIScope>,
180182
flags: DIFlags,
181183
) -> StubInfo<'ll, 'tcx> {
182184
let empty_array = create_DIArray(DIB(cx), &[]);
183185
let unique_type_id_str = unique_type_id.generate_unique_id_string(cx.tcx);
184186

185-
let (file_metadata, line_number) = super::file_metadata_from_def_id(cx, def_id);
187+
let (file_metadata, line_number) = if let Some(def_location) = def_location {
188+
(def_location.0, def_location.1)
189+
} else {
190+
(unknown_file_metadata(cx), UNKNOWN_LINE_NUMBER)
191+
};
186192

187193
let metadata = match kind {
188194
Stub::Struct | Stub::VTableTy { .. } => {

0 commit comments

Comments
 (0)