@@ -43,7 +43,6 @@ use std::borrow::Borrow;
43
43
use std:: collections:: hash_map:: Entry ;
44
44
use std:: hash:: Hash ;
45
45
use std:: io:: { Read , Seek , Write } ;
46
- use std:: iter;
47
46
use std:: num:: NonZeroUsize ;
48
47
use std:: path:: { Path , PathBuf } ;
49
48
@@ -456,7 +455,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
456
455
}
457
456
458
457
fn encode_info_for_items ( & mut self ) {
459
- self . encode_info_for_mod ( CRATE_DEF_ID , self . tcx . hir ( ) . root_module ( ) ) ;
458
+ self . encode_info_for_mod ( CRATE_DEF_ID ) ;
460
459
461
460
// Proc-macro crates only export proc-macro items, which are looked
462
461
// up using `proc_macro_data`
@@ -1324,7 +1323,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
1324
1323
record ! ( self . tables. implied_predicates_of[ def_id] <- self . tcx. implied_predicates_of( def_id) ) ;
1325
1324
}
1326
1325
if let DefKind :: Enum | DefKind :: Struct | DefKind :: Union = def_kind {
1327
- self . encode_info_for_adt ( def_id ) ;
1326
+ self . encode_info_for_adt ( local_id ) ;
1328
1327
}
1329
1328
if tcx. impl_method_has_trait_impl_trait_tys ( def_id)
1330
1329
&& let Ok ( table) = self . tcx . collect_return_position_impl_trait_in_trait_tys ( def_id)
@@ -1357,7 +1356,8 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
1357
1356
}
1358
1357
1359
1358
#[ instrument( level = "trace" , skip( self ) ) ]
1360
- fn encode_info_for_adt ( & mut self , def_id : DefId ) {
1359
+ fn encode_info_for_adt ( & mut self , local_def_id : LocalDefId ) {
1360
+ let def_id = local_def_id. to_def_id ( ) ;
1361
1361
let tcx = self . tcx ;
1362
1362
let adt_def = tcx. adt_def ( def_id) ;
1363
1363
record ! ( self . tables. repr_options[ def_id] <- adt_def. repr( ) ) ;
@@ -1366,15 +1366,9 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
1366
1366
record ! ( self . tables. params_in_repr[ def_id] <- params_in_repr) ;
1367
1367
1368
1368
if adt_def. is_enum ( ) {
1369
- record_array ! ( self . tables. children[ def_id] <- iter:: from_generator( ||
1370
- for variant in tcx. adt_def( def_id) . variants( ) {
1371
- yield variant. def_id. index;
1372
- // Encode constructors which take a separate slot in value namespace.
1373
- if let Some ( ctor_def_id) = variant. ctor_def_id( ) {
1374
- yield ctor_def_id. index;
1375
- }
1376
- }
1377
- ) ) ;
1369
+ let module_children = tcx. module_children_non_reexports ( local_def_id) ;
1370
+ record_array ! ( self . tables. children[ def_id] <-
1371
+ module_children. iter( ) . map( |def_id| def_id. local_def_index) ) ;
1378
1372
} else {
1379
1373
// For non-enum, there is only one variant, and its def_id is the adt's.
1380
1374
debug_assert_eq ! ( adt_def. variants( ) . len( ) , 1 ) ;
@@ -1406,7 +1400,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
1406
1400
}
1407
1401
}
1408
1402
1409
- fn encode_info_for_mod ( & mut self , local_def_id : LocalDefId , md : & hir :: Mod < ' _ > ) {
1403
+ fn encode_info_for_mod ( & mut self , local_def_id : LocalDefId ) {
1410
1404
let tcx = self . tcx ;
1411
1405
let def_id = local_def_id. to_def_id ( ) ;
1412
1406
debug ! ( "EncodeContext::encode_info_for_mod({:?})" , def_id) ;
@@ -1420,38 +1414,12 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
1420
1414
// Encode this here because we don't do it in encode_def_ids.
1421
1415
record ! ( self . tables. expn_that_defined[ def_id] <- tcx. expn_that_defined( local_def_id) ) ;
1422
1416
} else {
1423
- record_array ! ( self . tables. children[ def_id] <- iter:: from_generator( || {
1424
- for item_id in md. item_ids {
1425
- match tcx. hir( ) . item( * item_id) . kind {
1426
- // Foreign items are planted into their parent modules
1427
- // from name resolution point of view.
1428
- hir:: ItemKind :: ForeignMod { items, .. } => {
1429
- for foreign_item in items {
1430
- yield foreign_item. id. owner_id. def_id. local_def_index;
1431
- }
1432
- }
1433
- // Only encode named non-reexport children, reexports are encoded
1434
- // separately and unnamed items are not used by name resolution.
1435
- hir:: ItemKind :: ExternCrate ( ..) => continue ,
1436
- hir:: ItemKind :: Struct ( ref vdata, _) => {
1437
- yield item_id. owner_id. def_id. local_def_index;
1438
- // Encode constructors which take a separate slot in value namespace.
1439
- if let Some ( ctor_def_id) = vdata. ctor_def_id( ) {
1440
- yield ctor_def_id. local_def_index;
1441
- }
1442
- }
1443
- _ if tcx. def_key( item_id. owner_id. to_def_id( ) ) . get_opt_name( ) . is_some( ) => {
1444
- yield item_id. owner_id. def_id. local_def_index;
1445
- }
1446
- _ => continue ,
1447
- }
1448
- }
1449
- } ) ) ;
1417
+ let non_reexports = tcx. module_children_non_reexports ( local_def_id) ;
1418
+ record_array ! ( self . tables. children[ def_id] <-
1419
+ non_reexports. iter( ) . map( |def_id| def_id. local_def_index) ) ;
1450
1420
1451
- let reexports = tcx. module_reexports ( local_def_id) ;
1452
- if !reexports. is_empty ( ) {
1453
- record_array ! ( self . tables. module_reexports[ def_id] <- reexports) ;
1454
- }
1421
+ record_defaulted_array ! ( self . tables. module_children_reexports[ def_id] <-
1422
+ tcx. module_children_reexports( local_def_id) ) ;
1455
1423
}
1456
1424
}
1457
1425
@@ -1668,8 +1636,8 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
1668
1636
self . tables . is_macro_rules . set ( def_id. index , macro_def. macro_rules ) ;
1669
1637
record ! ( self . tables. macro_definition[ def_id] <- & * macro_def. body) ;
1670
1638
}
1671
- hir:: ItemKind :: Mod ( ref m ) => {
1672
- self . encode_info_for_mod ( item. owner_id . def_id , m ) ;
1639
+ hir:: ItemKind :: Mod ( .. ) => {
1640
+ self . encode_info_for_mod ( item. owner_id . def_id ) ;
1673
1641
}
1674
1642
hir:: ItemKind :: OpaqueTy ( ref opaque) => {
1675
1643
self . encode_explicit_item_bounds ( def_id) ;
0 commit comments