@@ -22,7 +22,7 @@ use abi;
2222use  value:: Value ; 
2323
2424use  llvm; 
25- use  llvm:: debuginfo:: { DIType ,  DIFile ,  DIScope ,  DIDescriptor , 
25+ use  llvm:: debuginfo:: { DIArray ,   DIType ,  DIFile ,  DIScope ,  DIDescriptor , 
2626                      DICompositeType ,  DILexicalBlock ,  DIFlags } ; 
2727use  llvm_util; 
2828
@@ -35,12 +35,14 @@ use rustc_data_structures::fingerprint::Fingerprint;
3535use  rustc:: ty:: Instance ; 
3636use  common:: CodegenCx ; 
3737use  rustc:: ty:: { self ,  AdtKind ,  ParamEnv ,  Ty ,  TyCtxt } ; 
38- use  rustc:: ty:: layout:: { self ,  Align ,  HasDataLayout ,   Integer ,  IntegerExt ,  LayoutOf , 
38+ use  rustc:: ty:: layout:: { self ,  Align ,  Integer ,  IntegerExt ,  LayoutOf , 
3939                        PrimitiveExt ,  Size ,  TyLayout } ; 
40+ use  rustc:: ty:: subst:: UnpackedKind ; 
4041use  rustc:: session:: config; 
4142use  rustc:: util:: nodemap:: FxHashMap ; 
4243use  rustc_fs_util:: path2cstr; 
4344use  rustc_data_structures:: small_c_str:: SmallCStr ; 
45+ use  rustc_target:: abi:: HasDataLayout ; 
4446
4547use  libc:: { c_uint,  c_longlong} ; 
4648use  std:: ffi:: CString ; 
@@ -273,6 +275,7 @@ impl RecursiveTypeDescription<'ll, 'tcx> {
273275
274276                // ... and attach them to the stub to complete it. 
275277                set_members_of_composite_type ( cx, 
278+                                               unfinished_type, 
276279                                              member_holding_stub, 
277280                                              member_descriptions) ; 
278281                return  MetadataCreationResult :: new ( metadata_stub,  true ) ; 
@@ -1214,6 +1217,7 @@ impl EnumMemberDescriptionFactory<'ll, 'tcx> {
12141217                    member_description_factory. create_member_descriptions ( cx) ; 
12151218
12161219                set_members_of_composite_type ( cx, 
1220+                                               self . enum_type , 
12171221                                              variant_type_metadata, 
12181222                                              member_descriptions) ; 
12191223                vec ! [ 
@@ -1254,6 +1258,7 @@ impl EnumMemberDescriptionFactory<'ll, 'tcx> {
12541258                        . create_member_descriptions ( cx) ; 
12551259
12561260                    set_members_of_composite_type ( cx, 
1261+                                                   self . enum_type , 
12571262                                                  variant_type_metadata, 
12581263                                                  member_descriptions) ; 
12591264                    MemberDescription  { 
@@ -1295,6 +1300,7 @@ impl EnumMemberDescriptionFactory<'ll, 'tcx> {
12951300                        member_description_factory. create_member_descriptions ( cx) ; 
12961301
12971302                    set_members_of_composite_type ( cx, 
1303+                                                   self . enum_type , 
12981304                                                  variant_type_metadata, 
12991305                                                  variant_member_descriptions) ; 
13001306
@@ -1354,6 +1360,7 @@ impl EnumMemberDescriptionFactory<'ll, 'tcx> {
13541360                            . create_member_descriptions ( cx) ; 
13551361
13561362                        set_members_of_composite_type ( cx, 
1363+                                                       self . enum_type , 
13571364                                                      variant_type_metadata, 
13581365                                                      member_descriptions) ; 
13591366
@@ -1765,13 +1772,15 @@ fn composite_type_metadata(
17651772                                                     containing_scope) ; 
17661773    // ... and immediately create and add the member descriptions. 
17671774    set_members_of_composite_type ( cx, 
1775+                                   composite_type, 
17681776                                  composite_type_metadata, 
17691777                                  member_descriptions) ; 
17701778
17711779    composite_type_metadata
17721780} 
17731781
1774- fn  set_members_of_composite_type ( cx :  & CodegenCx < ' ll ,  ' _ > , 
1782+ fn  set_members_of_composite_type ( cx :  & CodegenCx < ' ll ,  ' tcx > , 
1783+                                  composite_type :  Ty < ' tcx > , 
17751784                                 composite_type_metadata :  & ' ll  DICompositeType , 
17761785                                 member_descriptions :  Vec < MemberDescription < ' ll > > )  { 
17771786    // In some rare cases LLVM metadata uniquing would lead to an existing type 
@@ -1815,10 +1824,57 @@ fn set_members_of_composite_type(cx: &CodegenCx<'ll, '_>,
18151824        } ) 
18161825        . collect ( ) ; 
18171826
1827+     let  type_params = compute_type_parameters ( cx,  composite_type) ; 
18181828    unsafe  { 
18191829        let  type_array = create_DIArray ( DIB ( cx) ,  & member_metadata[ ..] ) ; 
1820-         llvm:: LLVMRustDICompositeTypeSetTypeArray ( 
1821-             DIB ( cx) ,  composite_type_metadata,  type_array) ; 
1830+         llvm:: LLVMRustDICompositeTypeReplaceArrays ( 
1831+             DIB ( cx) ,  composite_type_metadata,  Some ( type_array) ,  type_params) ; 
1832+     } 
1833+ } 
1834+ 
1835+ // Compute the type parameters for a type, if any, for the given 
1836+ // metadata. 
1837+ fn  compute_type_parameters ( cx :  & CodegenCx < ' ll ,  ' tcx > ,  ty :  Ty < ' tcx > )  -> Option < & ' ll  DIArray >  { 
1838+     if  let  ty:: Adt ( def,  substs)  = ty. sty  { 
1839+         if  !substs. types ( ) . next ( ) . is_none ( )  { 
1840+             let  generics = cx. tcx . generics_of ( def. did ) ; 
1841+             let  names = get_parameter_names ( cx,  generics) ; 
1842+             let  template_params:  Vec < _ >  = substs. iter ( ) . zip ( names) . filter_map ( |( kind,  name) | { 
1843+                 if  let  UnpackedKind :: Type ( ty)  = kind. unpack ( )  { 
1844+                     let  actual_type = cx. tcx . normalize_erasing_regions ( ParamEnv :: reveal_all ( ) ,  ty) ; 
1845+                     let  actual_type_metadata =
1846+                         type_metadata ( cx,  actual_type,  syntax_pos:: DUMMY_SP ) ; 
1847+                     let  name = SmallCStr :: new ( & name. as_str ( ) ) ; 
1848+                     Some ( unsafe  { 
1849+ 
1850+                         Some ( llvm:: LLVMRustDIBuilderCreateTemplateTypeParameter ( 
1851+                             DIB ( cx) , 
1852+                             None , 
1853+                             name. as_ptr ( ) , 
1854+                             actual_type_metadata, 
1855+                             unknown_file_metadata ( cx) , 
1856+                             0 , 
1857+                             0 , 
1858+                         ) ) 
1859+                     } ) 
1860+                 }  else  { 
1861+                     None 
1862+                 } 
1863+             } ) . collect ( ) ; 
1864+ 
1865+             return  Some ( create_DIArray ( DIB ( cx) ,  & template_params[ ..] ) ) ; 
1866+         } 
1867+     } 
1868+     return  Some ( create_DIArray ( DIB ( cx) ,  & [ ] ) ) ; 
1869+ 
1870+     fn  get_parameter_names ( cx :  & CodegenCx , 
1871+                            generics :  & ty:: Generics ) 
1872+                            -> Vec < InternedString >  { 
1873+         let  mut  names = generics. parent . map_or ( vec ! [ ] ,  |def_id| { 
1874+             get_parameter_names ( cx,  cx. tcx . generics_of ( def_id) ) 
1875+         } ) ; 
1876+         names. extend ( generics. params . iter ( ) . map ( |param| param. name ) ) ; 
1877+         names
18221878    } 
18231879} 
18241880
0 commit comments