@@ -203,6 +203,7 @@ fn build_pointer_or_reference_di_node<'ll, 'tcx>(
203
203
Stub :: Struct ,
204
204
unique_type_id,
205
205
& ptr_type_debuginfo_name,
206
+ None ,
206
207
cx. size_and_align_of ( ptr_type) ,
207
208
NO_SCOPE_METADATA ,
208
209
DIFlags :: FlagZero ,
@@ -259,6 +260,7 @@ fn build_pointer_or_reference_di_node<'ll, 'tcx>(
259
260
layout. fields. offset( abi:: WIDE_PTR_ADDR ) ,
260
261
DIFlags :: FlagZero ,
261
262
data_ptr_type_di_node,
263
+ None ,
262
264
) ,
263
265
build_field_di_node(
264
266
cx,
@@ -268,6 +270,7 @@ fn build_pointer_or_reference_di_node<'ll, 'tcx>(
268
270
layout. fields. offset( abi:: WIDE_PTR_EXTRA ) ,
269
271
DIFlags :: FlagZero ,
270
272
type_di_node( cx, extra_field. ty) ,
273
+ None ,
271
274
) ,
272
275
]
273
276
} ,
@@ -369,6 +372,7 @@ fn build_dyn_type_di_node<'ll, 'tcx>(
369
372
Stub :: Struct ,
370
373
unique_type_id,
371
374
& type_name,
375
+ None ,
372
376
cx. size_and_align_of ( dyn_type) ,
373
377
NO_SCOPE_METADATA ,
374
378
DIFlags :: FlagZero ,
@@ -722,19 +726,36 @@ fn build_cpp_f16_di_node<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>) -> DINodeCreation
722
726
// `f16`'s value to be displayed using a Natvis visualiser in `intrinsic.natvis`.
723
727
let float_ty = cx. tcx . types . f16 ;
724
728
let bits_ty = cx. tcx . types . u16 ;
729
+ let def_location = if cx. sess ( ) . opts . unstable_opts . debug_info_type_line_numbers {
730
+ match float_ty. kind ( ) {
731
+ ty:: Adt ( def, _) => Some ( file_metadata_from_def_id ( cx, Some ( def. did ( ) ) ) ) ,
732
+ _ => None ,
733
+ }
734
+ } else {
735
+ None
736
+ } ;
725
737
type_map:: build_type_with_children (
726
738
cx,
727
739
type_map:: stub (
728
740
cx,
729
741
Stub :: Struct ,
730
742
UniqueTypeId :: for_ty ( cx. tcx , float_ty) ,
731
743
"f16" ,
744
+ def_location,
732
745
cx. size_and_align_of ( float_ty) ,
733
746
NO_SCOPE_METADATA ,
734
747
DIFlags :: FlagZero ,
735
748
) ,
736
749
// Fields:
737
750
|cx, float_di_node| {
751
+ let def_id = if cx. sess ( ) . opts . unstable_opts . debug_info_type_line_numbers {
752
+ match bits_ty. kind ( ) {
753
+ ty:: Adt ( def, _) => Some ( def. did ( ) ) ,
754
+ _ => None ,
755
+ }
756
+ } else {
757
+ None
758
+ } ;
738
759
smallvec ! [ build_field_di_node(
739
760
cx,
740
761
float_di_node,
@@ -743,6 +764,7 @@ fn build_cpp_f16_di_node<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>) -> DINodeCreation
743
764
Size :: ZERO ,
744
765
DIFlags :: FlagZero ,
745
766
type_di_node( cx, bits_ty) ,
767
+ def_id,
746
768
) ]
747
769
} ,
748
770
NO_GENERICS ,
@@ -839,6 +861,7 @@ fn build_foreign_type_di_node<'ll, 'tcx>(
839
861
Stub :: Struct ,
840
862
unique_type_id,
841
863
& compute_debuginfo_type_name ( cx. tcx , t, false ) ,
864
+ None ,
842
865
cx. size_and_align_of ( t) ,
843
866
Some ( get_namespace_for_item ( cx, def_id) ) ,
844
867
DIFlags :: FlagZero ,
@@ -989,15 +1012,22 @@ fn build_field_di_node<'ll, 'tcx>(
989
1012
offset : Size ,
990
1013
flags : DIFlags ,
991
1014
type_di_node : & ' ll DIType ,
1015
+ def_id : Option < DefId > ,
992
1016
) -> & ' ll DIType {
1017
+ let ( file_metadata, line_number) = if cx. sess ( ) . opts . unstable_opts . debug_info_type_line_numbers
1018
+ {
1019
+ file_metadata_from_def_id ( cx, def_id)
1020
+ } else {
1021
+ ( unknown_file_metadata ( cx) , UNKNOWN_LINE_NUMBER )
1022
+ } ;
993
1023
unsafe {
994
1024
llvm:: LLVMRustDIBuilderCreateMemberType (
995
1025
DIB ( cx) ,
996
1026
owner,
997
1027
name. as_c_char_ptr ( ) ,
998
1028
name. len ( ) ,
999
- unknown_file_metadata ( cx ) ,
1000
- UNKNOWN_LINE_NUMBER ,
1029
+ file_metadata ,
1030
+ line_number ,
1001
1031
size_and_align. 0 . bits ( ) ,
1002
1032
size_and_align. 1 . bits ( ) as u32 ,
1003
1033
offset. bits ( ) ,
@@ -1041,6 +1071,11 @@ fn build_struct_type_di_node<'ll, 'tcx>(
1041
1071
let containing_scope = get_namespace_for_item ( cx, adt_def. did ( ) ) ;
1042
1072
let struct_type_and_layout = cx. layout_of ( struct_type) ;
1043
1073
let variant_def = adt_def. non_enum_variant ( ) ;
1074
+ let def_location = if cx. sess ( ) . opts . unstable_opts . debug_info_type_line_numbers {
1075
+ Some ( file_metadata_from_def_id ( cx, Some ( adt_def. did ( ) ) ) )
1076
+ } else {
1077
+ None
1078
+ } ;
1044
1079
1045
1080
type_map:: build_type_with_children (
1046
1081
cx,
@@ -1049,6 +1084,7 @@ fn build_struct_type_di_node<'ll, 'tcx>(
1049
1084
Stub :: Struct ,
1050
1085
unique_type_id,
1051
1086
& compute_debuginfo_type_name ( cx. tcx , struct_type, false ) ,
1087
+ def_location,
1052
1088
size_and_align_of ( struct_type_and_layout) ,
1053
1089
Some ( containing_scope) ,
1054
1090
visibility_di_flags ( cx, adt_def. did ( ) , adt_def. did ( ) ) ,
@@ -1068,6 +1104,11 @@ fn build_struct_type_di_node<'ll, 'tcx>(
1068
1104
Cow :: Borrowed ( f. name . as_str ( ) )
1069
1105
} ;
1070
1106
let field_layout = struct_type_and_layout. field ( cx, i) ;
1107
+ let def_id = if cx. sess ( ) . opts . unstable_opts . debug_info_type_line_numbers {
1108
+ Some ( f. did )
1109
+ } else {
1110
+ None
1111
+ } ;
1071
1112
build_field_di_node (
1072
1113
cx,
1073
1114
owner,
@@ -1076,6 +1117,7 @@ fn build_struct_type_di_node<'ll, 'tcx>(
1076
1117
struct_type_and_layout. fields . offset ( i) ,
1077
1118
visibility_di_flags ( cx, f. did , adt_def. did ( ) ) ,
1078
1119
type_di_node ( cx, field_layout. ty ) ,
1120
+ def_id,
1079
1121
)
1080
1122
} )
1081
1123
. collect ( )
@@ -1125,6 +1167,7 @@ fn build_upvar_field_di_nodes<'ll, 'tcx>(
1125
1167
layout. fields . offset ( index) ,
1126
1168
DIFlags :: FlagZero ,
1127
1169
type_di_node ( cx, up_var_ty) ,
1170
+ None ,
1128
1171
)
1129
1172
} )
1130
1173
. collect ( )
@@ -1150,6 +1193,7 @@ fn build_tuple_type_di_node<'ll, 'tcx>(
1150
1193
Stub :: Struct ,
1151
1194
unique_type_id,
1152
1195
& type_name,
1196
+ None ,
1153
1197
size_and_align_of ( tuple_type_and_layout) ,
1154
1198
NO_SCOPE_METADATA ,
1155
1199
DIFlags :: FlagZero ,
@@ -1168,6 +1212,7 @@ fn build_tuple_type_di_node<'ll, 'tcx>(
1168
1212
tuple_type_and_layout. fields . offset ( index) ,
1169
1213
DIFlags :: FlagZero ,
1170
1214
type_di_node ( cx, component_type) ,
1215
+ None ,
1171
1216
)
1172
1217
} )
1173
1218
. collect ( )
@@ -1189,13 +1234,20 @@ fn build_closure_env_di_node<'ll, 'tcx>(
1189
1234
let containing_scope = get_namespace_for_item ( cx, def_id) ;
1190
1235
let type_name = compute_debuginfo_type_name ( cx. tcx , closure_env_type, false ) ;
1191
1236
1237
+ let def_location = if cx. sess ( ) . opts . unstable_opts . debug_info_type_line_numbers {
1238
+ Some ( file_metadata_from_def_id ( cx, Some ( def_id) ) )
1239
+ } else {
1240
+ None
1241
+ } ;
1242
+
1192
1243
type_map:: build_type_with_children (
1193
1244
cx,
1194
1245
type_map:: stub (
1195
1246
cx,
1196
1247
Stub :: Struct ,
1197
1248
unique_type_id,
1198
1249
& type_name,
1250
+ def_location,
1199
1251
cx. size_and_align_of ( closure_env_type) ,
1200
1252
Some ( containing_scope) ,
1201
1253
DIFlags :: FlagZero ,
@@ -1219,6 +1271,11 @@ fn build_union_type_di_node<'ll, 'tcx>(
1219
1271
let containing_scope = get_namespace_for_item ( cx, union_def_id) ;
1220
1272
let union_ty_and_layout = cx. layout_of ( union_type) ;
1221
1273
let type_name = compute_debuginfo_type_name ( cx. tcx , union_type, false ) ;
1274
+ let def_location = if cx. sess ( ) . opts . unstable_opts . debug_info_type_line_numbers {
1275
+ Some ( file_metadata_from_def_id ( cx, Some ( union_def_id) ) )
1276
+ } else {
1277
+ None
1278
+ } ;
1222
1279
1223
1280
type_map:: build_type_with_children (
1224
1281
cx,
@@ -1227,6 +1284,7 @@ fn build_union_type_di_node<'ll, 'tcx>(
1227
1284
Stub :: Union ,
1228
1285
unique_type_id,
1229
1286
& type_name,
1287
+ def_location,
1230
1288
size_and_align_of ( union_ty_and_layout) ,
1231
1289
Some ( containing_scope) ,
1232
1290
DIFlags :: FlagZero ,
@@ -1239,6 +1297,11 @@ fn build_union_type_di_node<'ll, 'tcx>(
1239
1297
. enumerate ( )
1240
1298
. map ( |( i, f) | {
1241
1299
let field_layout = union_ty_and_layout. field ( cx, i) ;
1300
+ let def_id = if cx. sess ( ) . opts . unstable_opts . debug_info_type_line_numbers {
1301
+ Some ( f. did )
1302
+ } else {
1303
+ None
1304
+ } ;
1242
1305
build_field_di_node (
1243
1306
cx,
1244
1307
owner,
@@ -1247,6 +1310,7 @@ fn build_union_type_di_node<'ll, 'tcx>(
1247
1310
Size :: ZERO ,
1248
1311
DIFlags :: FlagZero ,
1249
1312
type_di_node ( cx, field_layout. ty ) ,
1313
+ def_id,
1250
1314
)
1251
1315
} )
1252
1316
. collect ( )
@@ -1321,14 +1385,7 @@ pub(crate) fn build_global_var_di_node<'ll>(
1321
1385
// We may want to remove the namespace scope if we're in an extern block (see
1322
1386
// https://github.com/rust-lang/rust/pull/46457#issuecomment-351750952).
1323
1387
let var_scope = get_namespace_for_item ( cx, def_id) ;
1324
- let span = hygiene:: walk_chain_collapsed ( tcx. def_span ( def_id) , DUMMY_SP ) ;
1325
-
1326
- let ( file_metadata, line_number) = if !span. is_dummy ( ) {
1327
- let loc = cx. lookup_debug_loc ( span. lo ( ) ) ;
1328
- ( file_metadata ( cx, & loc. file ) , loc. line )
1329
- } else {
1330
- ( unknown_file_metadata ( cx) , UNKNOWN_LINE_NUMBER )
1331
- } ;
1388
+ let ( file_metadata, line_number) = file_metadata_from_def_id ( cx, Some ( def_id) ) ;
1332
1389
1333
1390
let is_local_to_unit = is_node_local_to_unit ( cx, def_id) ;
1334
1391
@@ -1418,6 +1475,7 @@ fn build_vtable_type_di_node<'ll, 'tcx>(
1418
1475
Stub :: VTableTy { vtable_holder } ,
1419
1476
unique_type_id,
1420
1477
& vtable_type_name,
1478
+ None ,
1421
1479
( size, pointer_align) ,
1422
1480
NO_SCOPE_METADATA ,
1423
1481
DIFlags :: FlagArtificial ,
@@ -1455,6 +1513,7 @@ fn build_vtable_type_di_node<'ll, 'tcx>(
1455
1513
field_offset,
1456
1514
DIFlags :: FlagZero ,
1457
1515
field_type_di_node,
1516
+ None ,
1458
1517
) )
1459
1518
} )
1460
1519
. collect ( )
@@ -1606,3 +1665,20 @@ fn tuple_field_name(field_index: usize) -> Cow<'static, str> {
1606
1665
. map ( |s| Cow :: from ( * s) )
1607
1666
. unwrap_or_else ( || Cow :: from ( format ! ( "__{field_index}" ) ) )
1608
1667
}
1668
+
1669
+ pub ( crate ) type DefinitionLocation < ' ll > = ( & ' ll DIFile , c_uint ) ;
1670
+
1671
+ pub ( crate ) fn file_metadata_from_def_id < ' ll > (
1672
+ cx : & CodegenCx < ' ll , ' _ > ,
1673
+ def_id : Option < DefId > ,
1674
+ ) -> DefinitionLocation < ' ll > {
1675
+ if let Some ( def_id) = def_id
1676
+ && let span = hygiene:: walk_chain_collapsed ( cx. tcx . def_span ( def_id) , DUMMY_SP )
1677
+ && !span. is_dummy ( )
1678
+ {
1679
+ let loc = cx. lookup_debug_loc ( span. lo ( ) ) ;
1680
+ ( file_metadata ( cx, & loc. file ) , loc. line )
1681
+ } else {
1682
+ ( unknown_file_metadata ( cx) , UNKNOWN_LINE_NUMBER )
1683
+ }
1684
+ }
0 commit comments