@@ -309,6 +309,7 @@ impl RecursiveTypeDescription<'ll, 'tcx> {
309309 unfinished_type,
310310 member_holding_stub,
311311 member_descriptions,
312+ None ,
312313 ) ;
313314 MetadataCreationResult :: new ( metadata_stub, true )
314315 }
@@ -1459,6 +1460,7 @@ struct EnumMemberDescriptionFactory<'ll, 'tcx> {
14591460 layout : TyAndLayout < ' tcx > ,
14601461 tag_type_metadata : Option < & ' ll DIType > ,
14611462 containing_scope : & ' ll DIScope ,
1463+ common_members : Vec < Option < & ' ll DIType > > ,
14621464 span : Span ,
14631465}
14641466
@@ -1493,10 +1495,6 @@ impl EnumMemberDescriptionFactory<'ll, 'tcx> {
14931495 } else {
14941496 type_metadata ( cx, self . enum_type , self . span )
14951497 } ;
1496- let flags = match self . enum_type . kind ( ) {
1497- ty:: Generator ( ..) => DIFlags :: FlagArtificial ,
1498- _ => DIFlags :: FlagZero ,
1499- } ;
15001498
15011499 match self . layout . variants {
15021500 Variants :: Single { index } => {
@@ -1523,14 +1521,15 @@ impl EnumMemberDescriptionFactory<'ll, 'tcx> {
15231521 self . enum_type ,
15241522 variant_type_metadata,
15251523 member_descriptions,
1524+ Some ( & self . common_members ) ,
15261525 ) ;
15271526 vec ! [ MemberDescription {
15281527 name: if fallback { String :: new( ) } else { variant_info. variant_name( ) } ,
15291528 type_metadata: variant_type_metadata,
15301529 offset: Size :: ZERO ,
15311530 size: self . layout. size,
15321531 align: self . layout. align. abi,
1533- flags,
1532+ flags: DIFlags :: FlagZero ,
15341533 discriminant: None ,
15351534 source_info: variant_info. source_info( cx) ,
15361535 } ]
@@ -1572,6 +1571,7 @@ impl EnumMemberDescriptionFactory<'ll, 'tcx> {
15721571 self . enum_type ,
15731572 variant_type_metadata,
15741573 member_descriptions,
1574+ Some ( & self . common_members ) ,
15751575 ) ;
15761576
15771577 MemberDescription {
@@ -1584,7 +1584,7 @@ impl EnumMemberDescriptionFactory<'ll, 'tcx> {
15841584 offset : Size :: ZERO ,
15851585 size : self . layout . size ,
15861586 align : self . layout . align . abi ,
1587- flags,
1587+ flags : DIFlags :: FlagZero ,
15881588 discriminant : Some (
15891589 self . layout . ty . discriminant_for_variant ( cx. tcx , i) . unwrap ( ) . val
15901590 as u64 ,
@@ -1621,6 +1621,7 @@ impl EnumMemberDescriptionFactory<'ll, 'tcx> {
16211621 self . enum_type ,
16221622 variant_type_metadata,
16231623 variant_member_descriptions,
1624+ Some ( & self . common_members ) ,
16241625 ) ;
16251626
16261627 // Encode the information about the null variant in the union
@@ -1667,7 +1668,7 @@ impl EnumMemberDescriptionFactory<'ll, 'tcx> {
16671668 offset: Size :: ZERO ,
16681669 size: variant. size,
16691670 align: variant. align. abi,
1670- flags,
1671+ flags: DIFlags :: FlagZero ,
16711672 discriminant: None ,
16721673 source_info: variant_info. source_info( cx) ,
16731674 } ]
@@ -1695,6 +1696,7 @@ impl EnumMemberDescriptionFactory<'ll, 'tcx> {
16951696 self . enum_type ,
16961697 variant_type_metadata,
16971698 member_descriptions,
1699+ Some ( & self . common_members ) ,
16981700 ) ;
16991701
17001702 let niche_value = if i == dataful_variant {
@@ -1717,7 +1719,7 @@ impl EnumMemberDescriptionFactory<'ll, 'tcx> {
17171719 offset : Size :: ZERO ,
17181720 size : self . layout . size ,
17191721 align : self . layout . align . abi ,
1720- flags,
1722+ flags : DIFlags :: FlagZero ,
17211723 discriminant : niche_value,
17221724 source_info : variant_info. source_info ( cx) ,
17231725 }
@@ -1849,13 +1851,6 @@ impl<'tcx> VariantInfo<'_, 'tcx> {
18491851 }
18501852 None
18511853 }
1852-
1853- fn is_artificial ( & self ) -> bool {
1854- match self {
1855- VariantInfo :: Generator { .. } => true ,
1856- VariantInfo :: Adt ( ..) => false ,
1857- }
1858- }
18591854}
18601855
18611856/// Returns a tuple of (1) `type_metadata_stub` of the variant, (2) a
@@ -1881,8 +1876,7 @@ fn describe_enum_variant(
18811876 & variant_name,
18821877 unique_type_id,
18831878 Some ( containing_scope) ,
1884- // FIXME(tmandry): This doesn't seem to have any effect.
1885- if variant. is_artificial ( ) { DIFlags :: FlagArtificial } else { DIFlags :: FlagZero } ,
1879+ DIFlags :: FlagZero ,
18861880 )
18871881 } ) ;
18881882
@@ -1945,11 +1939,6 @@ fn prepare_enum_metadata(
19451939) -> RecursiveTypeDescription < ' ll , ' tcx > {
19461940 let tcx = cx. tcx ;
19471941 let enum_name = compute_debuginfo_type_name ( tcx, enum_type, false ) ;
1948- // FIXME(tmandry): This doesn't seem to have any effect.
1949- let enum_flags = match enum_type. kind ( ) {
1950- ty:: Generator ( ..) => DIFlags :: FlagArtificial ,
1951- _ => DIFlags :: FlagZero ,
1952- } ;
19531942
19541943 let containing_scope = get_namespace_for_item ( cx, enum_def_id) ;
19551944 // FIXME: This should emit actual file metadata for the enum, but we
@@ -2082,7 +2071,7 @@ fn prepare_enum_metadata(
20822071 UNKNOWN_LINE_NUMBER ,
20832072 layout. size . bits ( ) ,
20842073 layout. align . abi . bits ( ) as u32 ,
2085- enum_flags ,
2074+ DIFlags :: FlagZero ,
20862075 None ,
20872076 0 , // RuntimeLang
20882077 unique_type_id_str. as_ptr ( ) . cast ( ) ,
@@ -2102,6 +2091,7 @@ fn prepare_enum_metadata(
21022091 layout,
21032092 tag_type_metadata : discriminant_type_metadata,
21042093 containing_scope,
2094+ common_members : vec ! [ ] ,
21052095 span,
21062096 } ) ,
21072097 ) ;
@@ -2171,7 +2161,7 @@ fn prepare_enum_metadata(
21712161 }
21722162 } ;
21732163
2174- let mut outer_fields = match layout. variants {
2164+ let outer_fields = match layout. variants {
21752165 Variants :: Single { .. } => vec ! [ ] ,
21762166 Variants :: Multiple { .. } => {
21772167 let tuple_mdf = TupleMemberDescriptionFactory {
@@ -2203,18 +2193,21 @@ fn prepare_enum_metadata(
22032193 UNKNOWN_LINE_NUMBER ,
22042194 layout. size . bits ( ) ,
22052195 layout. align . abi . bits ( ) as u32 ,
2206- enum_flags ,
2196+ DIFlags :: FlagZero ,
22072197 discriminator_metadata,
22082198 empty_array,
22092199 variant_part_unique_type_id_str. as_ptr ( ) . cast ( ) ,
22102200 variant_part_unique_type_id_str. len ( ) ,
22112201 )
22122202 } ;
2213- outer_fields. push ( Some ( variant_part) ) ;
22142203
22152204 let struct_wrapper = {
22162205 // The variant part must be wrapped in a struct according to DWARF.
2217- let type_array = create_DIArray ( DIB ( cx) , & outer_fields) ;
2206+ // All fields except the discriminant (including `outer_fields`)
2207+ // should be put into structures inside the variant part, which gives
2208+ // an equivalent layout but offers us much better integration with
2209+ // debuggers.
2210+ let type_array = create_DIArray ( DIB ( cx) , & [ Some ( variant_part) ] ) ;
22182211
22192212 let type_map = debug_context ( cx) . type_map . borrow ( ) ;
22202213 let unique_type_id_str = type_map. get_unique_type_id_as_string ( unique_type_id) ;
@@ -2229,7 +2222,7 @@ fn prepare_enum_metadata(
22292222 UNKNOWN_LINE_NUMBER ,
22302223 layout. size . bits ( ) ,
22312224 layout. align . abi . bits ( ) as u32 ,
2232- enum_flags ,
2225+ DIFlags :: FlagZero ,
22332226 None ,
22342227 type_array,
22352228 0 ,
@@ -2251,6 +2244,7 @@ fn prepare_enum_metadata(
22512244 layout,
22522245 tag_type_metadata : None ,
22532246 containing_scope,
2247+ common_members : outer_fields,
22542248 span,
22552249 } ) ,
22562250 )
@@ -2283,7 +2277,13 @@ fn composite_type_metadata(
22832277 DIFlags :: FlagZero ,
22842278 ) ;
22852279 // ... and immediately create and add the member descriptions.
2286- set_members_of_composite_type ( cx, composite_type, composite_type_metadata, member_descriptions) ;
2280+ set_members_of_composite_type (
2281+ cx,
2282+ composite_type,
2283+ composite_type_metadata,
2284+ member_descriptions,
2285+ None ,
2286+ ) ;
22872287
22882288 composite_type_metadata
22892289}
@@ -2293,6 +2293,7 @@ fn set_members_of_composite_type(
22932293 composite_type : Ty < ' tcx > ,
22942294 composite_type_metadata : & ' ll DICompositeType ,
22952295 member_descriptions : Vec < MemberDescription < ' ll > > ,
2296+ common_members : Option < & Vec < Option < & ' ll DIType > > > ,
22962297) {
22972298 // In some rare cases LLVM metadata uniquing would lead to an existing type
22982299 // description being used instead of a new one created in
@@ -2311,10 +2312,13 @@ fn set_members_of_composite_type(
23112312 }
23122313 }
23132314
2314- let member_metadata: Vec < _ > = member_descriptions
2315+ let mut member_metadata: Vec < _ > = member_descriptions
23152316 . into_iter ( )
23162317 . map ( |desc| Some ( desc. into_metadata ( cx, composite_type_metadata) ) )
23172318 . collect ( ) ;
2319+ if let Some ( other_members) = common_members {
2320+ member_metadata. extend ( other_members. iter ( ) ) ;
2321+ }
23182322
23192323 let type_params = compute_type_parameters ( cx, composite_type) ;
23202324 unsafe {
0 commit comments