@@ -203,6 +203,7 @@ fn build_pointer_or_reference_di_node<'ll, 'tcx>(
203203 Stub :: Struct ,
204204 unique_type_id,
205205 & ptr_type_debuginfo_name,
206+ None ,
206207 cx. size_and_align_of ( ptr_type) ,
207208 NO_SCOPE_METADATA ,
208209 DIFlags :: FlagZero ,
@@ -259,6 +260,7 @@ fn build_pointer_or_reference_di_node<'ll, 'tcx>(
259260 layout. fields. offset( abi:: WIDE_PTR_ADDR ) ,
260261 DIFlags :: FlagZero ,
261262 data_ptr_type_di_node,
263+ None ,
262264 ) ,
263265 build_field_di_node(
264266 cx,
@@ -268,6 +270,7 @@ fn build_pointer_or_reference_di_node<'ll, 'tcx>(
268270 layout. fields. offset( abi:: WIDE_PTR_EXTRA ) ,
269271 DIFlags :: FlagZero ,
270272 type_di_node( cx, extra_field. ty) ,
273+ None ,
271274 ) ,
272275 ]
273276 } ,
@@ -369,6 +372,7 @@ fn build_dyn_type_di_node<'ll, 'tcx>(
369372 Stub :: Struct ,
370373 unique_type_id,
371374 & type_name,
375+ None ,
372376 cx. size_and_align_of ( dyn_type) ,
373377 NO_SCOPE_METADATA ,
374378 DIFlags :: FlagZero ,
@@ -722,19 +726,36 @@ fn build_cpp_f16_di_node<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>) -> DINodeCreation
722726 // `f16`'s value to be displayed using a Natvis visualiser in `intrinsic.natvis`.
723727 let float_ty = cx. tcx . types . f16 ;
724728 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+ } ;
725737 type_map:: build_type_with_children (
726738 cx,
727739 type_map:: stub (
728740 cx,
729741 Stub :: Struct ,
730742 UniqueTypeId :: for_ty ( cx. tcx , float_ty) ,
731743 "f16" ,
744+ def_location,
732745 cx. size_and_align_of ( float_ty) ,
733746 NO_SCOPE_METADATA ,
734747 DIFlags :: FlagZero ,
735748 ) ,
736749 // Fields:
737750 |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+ } ;
738759 smallvec ! [ build_field_di_node(
739760 cx,
740761 float_di_node,
@@ -743,6 +764,7 @@ fn build_cpp_f16_di_node<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>) -> DINodeCreation
743764 Size :: ZERO ,
744765 DIFlags :: FlagZero ,
745766 type_di_node( cx, bits_ty) ,
767+ def_id,
746768 ) ]
747769 } ,
748770 NO_GENERICS ,
@@ -839,6 +861,7 @@ fn build_foreign_type_di_node<'ll, 'tcx>(
839861 Stub :: Struct ,
840862 unique_type_id,
841863 & compute_debuginfo_type_name ( cx. tcx , t, false ) ,
864+ None ,
842865 cx. size_and_align_of ( t) ,
843866 Some ( get_namespace_for_item ( cx, def_id) ) ,
844867 DIFlags :: FlagZero ,
@@ -989,15 +1012,22 @@ fn build_field_di_node<'ll, 'tcx>(
9891012 offset : Size ,
9901013 flags : DIFlags ,
9911014 type_di_node : & ' ll DIType ,
1015+ def_id : Option < DefId > ,
9921016) -> & ' 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+ } ;
9931023 unsafe {
9941024 llvm:: LLVMRustDIBuilderCreateMemberType (
9951025 DIB ( cx) ,
9961026 owner,
9971027 name. as_c_char_ptr ( ) ,
9981028 name. len ( ) ,
999- unknown_file_metadata ( cx ) ,
1000- UNKNOWN_LINE_NUMBER ,
1029+ file_metadata ,
1030+ line_number ,
10011031 size_and_align. 0 . bits ( ) ,
10021032 size_and_align. 1 . bits ( ) as u32 ,
10031033 offset. bits ( ) ,
@@ -1041,6 +1071,11 @@ fn build_struct_type_di_node<'ll, 'tcx>(
10411071 let containing_scope = get_namespace_for_item ( cx, adt_def. did ( ) ) ;
10421072 let struct_type_and_layout = cx. layout_of ( struct_type) ;
10431073 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+ } ;
10441079
10451080 type_map:: build_type_with_children (
10461081 cx,
@@ -1049,6 +1084,7 @@ fn build_struct_type_di_node<'ll, 'tcx>(
10491084 Stub :: Struct ,
10501085 unique_type_id,
10511086 & compute_debuginfo_type_name ( cx. tcx , struct_type, false ) ,
1087+ def_location,
10521088 size_and_align_of ( struct_type_and_layout) ,
10531089 Some ( containing_scope) ,
10541090 visibility_di_flags ( cx, adt_def. did ( ) , adt_def. did ( ) ) ,
@@ -1068,6 +1104,11 @@ fn build_struct_type_di_node<'ll, 'tcx>(
10681104 Cow :: Borrowed ( f. name . as_str ( ) )
10691105 } ;
10701106 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+ } ;
10711112 build_field_di_node (
10721113 cx,
10731114 owner,
@@ -1076,6 +1117,7 @@ fn build_struct_type_di_node<'ll, 'tcx>(
10761117 struct_type_and_layout. fields . offset ( i) ,
10771118 visibility_di_flags ( cx, f. did , adt_def. did ( ) ) ,
10781119 type_di_node ( cx, field_layout. ty ) ,
1120+ def_id,
10791121 )
10801122 } )
10811123 . collect ( )
@@ -1125,6 +1167,7 @@ fn build_upvar_field_di_nodes<'ll, 'tcx>(
11251167 layout. fields . offset ( index) ,
11261168 DIFlags :: FlagZero ,
11271169 type_di_node ( cx, up_var_ty) ,
1170+ None ,
11281171 )
11291172 } )
11301173 . collect ( )
@@ -1150,6 +1193,7 @@ fn build_tuple_type_di_node<'ll, 'tcx>(
11501193 Stub :: Struct ,
11511194 unique_type_id,
11521195 & type_name,
1196+ None ,
11531197 size_and_align_of ( tuple_type_and_layout) ,
11541198 NO_SCOPE_METADATA ,
11551199 DIFlags :: FlagZero ,
@@ -1168,6 +1212,7 @@ fn build_tuple_type_di_node<'ll, 'tcx>(
11681212 tuple_type_and_layout. fields . offset ( index) ,
11691213 DIFlags :: FlagZero ,
11701214 type_di_node ( cx, component_type) ,
1215+ None ,
11711216 )
11721217 } )
11731218 . collect ( )
@@ -1189,13 +1234,20 @@ fn build_closure_env_di_node<'ll, 'tcx>(
11891234 let containing_scope = get_namespace_for_item ( cx, def_id) ;
11901235 let type_name = compute_debuginfo_type_name ( cx. tcx , closure_env_type, false ) ;
11911236
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+
11921243 type_map:: build_type_with_children (
11931244 cx,
11941245 type_map:: stub (
11951246 cx,
11961247 Stub :: Struct ,
11971248 unique_type_id,
11981249 & type_name,
1250+ def_location,
11991251 cx. size_and_align_of ( closure_env_type) ,
12001252 Some ( containing_scope) ,
12011253 DIFlags :: FlagZero ,
@@ -1219,6 +1271,11 @@ fn build_union_type_di_node<'ll, 'tcx>(
12191271 let containing_scope = get_namespace_for_item ( cx, union_def_id) ;
12201272 let union_ty_and_layout = cx. layout_of ( union_type) ;
12211273 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+ } ;
12221279
12231280 type_map:: build_type_with_children (
12241281 cx,
@@ -1227,6 +1284,7 @@ fn build_union_type_di_node<'ll, 'tcx>(
12271284 Stub :: Union ,
12281285 unique_type_id,
12291286 & type_name,
1287+ def_location,
12301288 size_and_align_of ( union_ty_and_layout) ,
12311289 Some ( containing_scope) ,
12321290 DIFlags :: FlagZero ,
@@ -1239,6 +1297,11 @@ fn build_union_type_di_node<'ll, 'tcx>(
12391297 . enumerate ( )
12401298 . map ( |( i, f) | {
12411299 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+ } ;
12421305 build_field_di_node (
12431306 cx,
12441307 owner,
@@ -1247,6 +1310,7 @@ fn build_union_type_di_node<'ll, 'tcx>(
12471310 Size :: ZERO ,
12481311 DIFlags :: FlagZero ,
12491312 type_di_node ( cx, field_layout. ty ) ,
1313+ def_id,
12501314 )
12511315 } )
12521316 . collect ( )
@@ -1321,14 +1385,7 @@ pub(crate) fn build_global_var_di_node<'ll>(
13211385 // We may want to remove the namespace scope if we're in an extern block (see
13221386 // https://github.com/rust-lang/rust/pull/46457#issuecomment-351750952).
13231387 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) ) ;
13321389
13331390 let is_local_to_unit = is_node_local_to_unit ( cx, def_id) ;
13341391
@@ -1418,6 +1475,7 @@ fn build_vtable_type_di_node<'ll, 'tcx>(
14181475 Stub :: VTableTy { vtable_holder } ,
14191476 unique_type_id,
14201477 & vtable_type_name,
1478+ None ,
14211479 ( size, pointer_align) ,
14221480 NO_SCOPE_METADATA ,
14231481 DIFlags :: FlagArtificial ,
@@ -1455,6 +1513,7 @@ fn build_vtable_type_di_node<'ll, 'tcx>(
14551513 field_offset,
14561514 DIFlags :: FlagZero ,
14571515 field_type_di_node,
1516+ None ,
14581517 ) )
14591518 } )
14601519 . collect ( )
@@ -1606,3 +1665,20 @@ fn tuple_field_name(field_index: usize) -> Cow<'static, str> {
16061665 . map ( |s| Cow :: from ( * s) )
16071666 . unwrap_or_else ( || Cow :: from ( format ! ( "__{field_index}" ) ) )
16081667}
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