@@ -38,7 +38,6 @@ use rustc_span::symbol::{sym, Symbol};
38
38
use rustc_span:: {
39
39
self , DebuggerVisualizerFile , ExternalSource , FileName , SourceFile , Span , SyntaxContext ,
40
40
} ;
41
- use rustc_target:: abi:: VariantIdx ;
42
41
use std:: borrow:: Borrow ;
43
42
use std:: collections:: hash_map:: Entry ;
44
43
use std:: hash:: Hash ;
@@ -1178,8 +1177,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
1178
1177
record ! ( self . tables. super_predicates_of[ def_id] <- self . tcx. super_predicates_of( def_id) ) ;
1179
1178
}
1180
1179
if let DefKind :: Enum | DefKind :: Struct | DefKind :: Union = def_kind {
1181
- let params_in_repr = self . tcx . params_in_repr ( def_id) ;
1182
- record ! ( self . tables. params_in_repr[ def_id] <- params_in_repr) ;
1180
+ self . encode_info_for_adt ( def_id) ;
1183
1181
}
1184
1182
if should_encode_trait_impl_trait_tys ( tcx, def_id)
1185
1183
&& let Ok ( table) = self . tcx . collect_return_position_impl_trait_in_trait_tys ( def_id)
@@ -1199,9 +1197,38 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
1199
1197
}
1200
1198
}
1201
1199
1202
- fn encode_enum_variant_info ( & mut self , def : ty:: AdtDef < ' tcx > , index : VariantIdx ) {
1200
+ #[ instrument( level = "trace" , skip( self ) ) ]
1201
+ fn encode_info_for_adt ( & mut self , def_id : DefId ) {
1202
+ let tcx = self . tcx ;
1203
+ let adt_def = tcx. adt_def ( def_id) ;
1204
+ record ! ( self . tables. repr_options[ def_id] <- adt_def. repr( ) ) ;
1205
+
1206
+ let params_in_repr = self . tcx . params_in_repr ( def_id) ;
1207
+ record ! ( self . tables. params_in_repr[ def_id] <- params_in_repr) ;
1208
+
1209
+ if adt_def. is_enum ( ) {
1210
+ record_array ! ( self . tables. children[ def_id] <- iter:: from_generator( ||
1211
+ for variant in tcx. adt_def( def_id) . variants( ) {
1212
+ yield variant. def_id. index;
1213
+ // Encode constructors which take a separate slot in value namespace.
1214
+ if let Some ( ctor_def_id) = variant. ctor_def_id( ) {
1215
+ yield ctor_def_id. index;
1216
+ }
1217
+ }
1218
+ ) ) ;
1219
+ }
1220
+
1221
+ // In some cases, along with the item itself, we also
1222
+ // encode some sub-items. Usually we want some info from the item
1223
+ // so it's easier to do that here then to wait until we would encounter
1224
+ // normally in the visitor walk.
1225
+ for variant in adt_def. variants ( ) . iter ( ) {
1226
+ self . encode_enum_variant_info ( variant) ;
1227
+ }
1228
+ }
1229
+
1230
+ fn encode_enum_variant_info ( & mut self , variant : & ty:: VariantDef ) {
1203
1231
let tcx = self . tcx ;
1204
- let variant = & def. variant ( index) ;
1205
1232
let def_id = variant. def_id ;
1206
1233
debug ! ( "EncodeContext::encode_enum_variant_info({:?})" , def_id) ;
1207
1234
@@ -1218,27 +1245,14 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
1218
1245
f. did. index
1219
1246
} ) ) ;
1220
1247
if let Some ( ( CtorKind :: Fn , ctor_def_id) ) = variant. ctor {
1221
- // FIXME(eddyb) encode signature only in `encode_enum_variant_ctor`.
1222
- record ! ( self . tables. fn_sig[ def_id] <- tcx. fn_sig( ctor_def_id) ) ;
1223
- }
1224
- }
1225
-
1226
- fn encode_enum_variant_ctor ( & mut self , def : ty:: AdtDef < ' tcx > , index : VariantIdx ) {
1227
- let variant = & def. variant ( index) ;
1228
- let Some ( ( ctor_kind, def_id) ) = variant. ctor else { return } ;
1229
- debug ! ( "EncodeContext::encode_enum_variant_ctor({:?})" , def_id) ;
1248
+ debug ! ( "EncodeContext::encode_enum_variant_ctor({:?})" , ctor_def_id) ;
1230
1249
1231
- // FIXME(eddyb) encode only the `CtorKind` for constructors.
1232
- let data = VariantData {
1233
- discr : variant. discr ,
1234
- ctor : Some ( ( ctor_kind, def_id. index ) ) ,
1235
- is_non_exhaustive : variant. is_field_list_non_exhaustive ( ) ,
1236
- } ;
1250
+ self . tables . constness . set ( ctor_def_id. index , hir:: Constness :: Const ) ;
1237
1251
1238
- record ! ( self . tables . variant_data [ def_id ] <- data ) ;
1239
- self . tables . constness . set ( def_id . index , hir :: Constness :: Const ) ;
1240
- if ctor_kind == CtorKind :: Fn {
1241
- record ! ( self . tables. fn_sig[ def_id] <- self . tcx . fn_sig( def_id ) ) ;
1252
+ let fn_sig = tcx . fn_sig ( ctor_def_id ) ;
1253
+ record ! ( self . tables. fn_sig [ ctor_def_id ] <- fn_sig ) ;
1254
+ // FIXME(eddyb) encode signature only for `ctor_def_id`.
1255
+ record ! ( self . tables. fn_sig[ def_id] <- fn_sig) ;
1242
1256
}
1243
1257
}
1244
1258
@@ -1291,25 +1305,6 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
1291
1305
}
1292
1306
}
1293
1307
1294
- fn encode_struct_ctor ( & mut self , adt_def : ty:: AdtDef < ' tcx > ) {
1295
- let variant = adt_def. non_enum_variant ( ) ;
1296
- let Some ( ( ctor_kind, def_id) ) = variant. ctor else { return } ;
1297
- debug ! ( "EncodeContext::encode_struct_ctor({:?})" , def_id) ;
1298
-
1299
- let data = VariantData {
1300
- discr : variant. discr ,
1301
- ctor : Some ( ( ctor_kind, def_id. index ) ) ,
1302
- is_non_exhaustive : variant. is_field_list_non_exhaustive ( ) ,
1303
- } ;
1304
-
1305
- record ! ( self . tables. repr_options[ def_id] <- adt_def. repr( ) ) ;
1306
- record ! ( self . tables. variant_data[ def_id] <- data) ;
1307
- self . tables . constness . set ( def_id. index , hir:: Constness :: Const ) ;
1308
- if ctor_kind == CtorKind :: Fn {
1309
- record ! ( self . tables. fn_sig[ def_id] <- self . tcx. fn_sig( def_id) ) ;
1310
- }
1311
- }
1312
-
1313
1308
fn encode_explicit_item_bounds ( & mut self , def_id : DefId ) {
1314
1309
debug ! ( "EncodeContext::encode_explicit_item_bounds({:?})" , def_id) ;
1315
1310
let bounds = self . tcx . explicit_item_bounds ( def_id) ;
@@ -1518,33 +1513,6 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
1518
1513
self . tables . is_type_alias_impl_trait . set ( def_id. index , ( ) ) ;
1519
1514
}
1520
1515
}
1521
- hir:: ItemKind :: Enum ( ..) => {
1522
- let adt_def = self . tcx . adt_def ( def_id) ;
1523
- record ! ( self . tables. repr_options[ def_id] <- adt_def. repr( ) ) ;
1524
- }
1525
- hir:: ItemKind :: Struct ( ..) => {
1526
- let adt_def = self . tcx . adt_def ( def_id) ;
1527
- record ! ( self . tables. repr_options[ def_id] <- adt_def. repr( ) ) ;
1528
- self . tables . constness . set ( def_id. index , hir:: Constness :: Const ) ;
1529
-
1530
- let variant = adt_def. non_enum_variant ( ) ;
1531
- record ! ( self . tables. variant_data[ def_id] <- VariantData {
1532
- discr: variant. discr,
1533
- ctor: variant. ctor. map( |( kind, def_id) | ( kind, def_id. index) ) ,
1534
- is_non_exhaustive: variant. is_field_list_non_exhaustive( ) ,
1535
- } ) ;
1536
- }
1537
- hir:: ItemKind :: Union ( ..) => {
1538
- let adt_def = self . tcx . adt_def ( def_id) ;
1539
- record ! ( self . tables. repr_options[ def_id] <- adt_def. repr( ) ) ;
1540
-
1541
- let variant = adt_def. non_enum_variant ( ) ;
1542
- record ! ( self . tables. variant_data[ def_id] <- VariantData {
1543
- discr: variant. discr,
1544
- ctor: variant. ctor. map( |( kind, def_id) | ( kind, def_id. index) ) ,
1545
- is_non_exhaustive: variant. is_field_list_non_exhaustive( ) ,
1546
- } ) ;
1547
- }
1548
1516
hir:: ItemKind :: Impl ( hir:: Impl { defaultness, constness, .. } ) => {
1549
1517
self . tables . impl_defaultness . set ( def_id. index , * defaultness) ;
1550
1518
self . tables . constness . set ( def_id. index , * constness) ;
@@ -1583,31 +1551,15 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
1583
1551
}
1584
1552
hir:: ItemKind :: Static ( ..)
1585
1553
| hir:: ItemKind :: Const ( ..)
1554
+ | hir:: ItemKind :: Enum ( ..)
1555
+ | hir:: ItemKind :: Struct ( ..)
1556
+ | hir:: ItemKind :: Union ( ..)
1586
1557
| hir:: ItemKind :: ForeignMod { .. }
1587
1558
| hir:: ItemKind :: GlobalAsm ( ..)
1588
1559
| hir:: ItemKind :: TyAlias ( ..) => { }
1589
1560
} ;
1590
1561
// FIXME(eddyb) there should be a nicer way to do this.
1591
1562
match item. kind {
1592
- hir:: ItemKind :: Enum ( ..) => {
1593
- record_array ! ( self . tables. children[ def_id] <- iter:: from_generator( ||
1594
- for variant in tcx. adt_def( def_id) . variants( ) {
1595
- yield variant. def_id. index;
1596
- // Encode constructors which take a separate slot in value namespace.
1597
- if let Some ( ctor_def_id) = variant. ctor_def_id( ) {
1598
- yield ctor_def_id. index;
1599
- }
1600
- }
1601
- ) )
1602
- }
1603
- hir:: ItemKind :: Struct ( ..) | hir:: ItemKind :: Union ( ..) => {
1604
- record_array ! ( self . tables. children[ def_id] <-
1605
- self . tcx. adt_def( def_id) . non_enum_variant( ) . fields. iter( ) . map( |f| {
1606
- assert!( f. did. is_local( ) ) ;
1607
- f. did. index
1608
- } )
1609
- )
1610
- }
1611
1563
hir:: ItemKind :: Impl { .. } | hir:: ItemKind :: Trait ( ..) => {
1612
1564
let associated_item_def_ids = self . tcx . associated_item_def_ids ( def_id) ;
1613
1565
record_array ! ( self . tables. children[ def_id] <-
@@ -1635,17 +1587,6 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
1635
1587
// so it's easier to do that here then to wait until we would encounter
1636
1588
// normally in the visitor walk.
1637
1589
match item. kind {
1638
- hir:: ItemKind :: Enum ( ..) => {
1639
- let def = self . tcx . adt_def ( item. owner_id . to_def_id ( ) ) ;
1640
- for ( i, _) in def. variants ( ) . iter_enumerated ( ) {
1641
- self . encode_enum_variant_info ( def, i) ;
1642
- self . encode_enum_variant_ctor ( def, i) ;
1643
- }
1644
- }
1645
- hir:: ItemKind :: Struct ( ..) => {
1646
- let def = self . tcx . adt_def ( item. owner_id . to_def_id ( ) ) ;
1647
- self . encode_struct_ctor ( def) ;
1648
- }
1649
1590
hir:: ItemKind :: Impl { .. } => {
1650
1591
for & trait_item_def_id in
1651
1592
self . tcx . associated_item_def_ids ( item. owner_id . to_def_id ( ) ) . iter ( )
0 commit comments