@@ -43,7 +43,6 @@ use std::borrow::Borrow;
4343use std:: collections:: hash_map:: Entry ;
4444use std:: hash:: Hash ;
4545use std:: io:: { Read , Seek , Write } ;
46- use std:: iter;
4746use std:: num:: NonZeroUsize ;
4847use std:: path:: { Path , PathBuf } ;
4948
@@ -456,7 +455,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
456455 }
457456
458457 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 ) ;
460459
461460 // Proc-macro crates only export proc-macro items, which are looked
462461 // up using `proc_macro_data`
@@ -1324,7 +1323,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
13241323 record ! ( self . tables. implied_predicates_of[ def_id] <- self . tcx. implied_predicates_of( def_id) ) ;
13251324 }
13261325 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 ) ;
13281327 }
13291328 if tcx. impl_method_has_trait_impl_trait_tys ( def_id)
13301329 && 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> {
13571356 }
13581357
13591358 #[ 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 ( ) ;
13611361 let tcx = self . tcx ;
13621362 let adt_def = tcx. adt_def ( def_id) ;
13631363 record ! ( self . tables. repr_options[ def_id] <- adt_def. repr( ) ) ;
@@ -1366,15 +1366,9 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
13661366 record ! ( self . tables. params_in_repr[ def_id] <- params_in_repr) ;
13671367
13681368 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) ) ;
13781372 } else {
13791373 // For non-enum, there is only one variant, and its def_id is the adt's.
13801374 debug_assert_eq ! ( adt_def. variants( ) . len( ) , 1 ) ;
@@ -1406,7 +1400,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
14061400 }
14071401 }
14081402
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 ) {
14101404 let tcx = self . tcx ;
14111405 let def_id = local_def_id. to_def_id ( ) ;
14121406 debug ! ( "EncodeContext::encode_info_for_mod({:?})" , def_id) ;
@@ -1420,38 +1414,12 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
14201414 // Encode this here because we don't do it in encode_def_ids.
14211415 record ! ( self . tables. expn_that_defined[ def_id] <- tcx. expn_that_defined( local_def_id) ) ;
14221416 } 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) ) ;
14501420
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) ) ;
14551423 }
14561424 }
14571425
@@ -1668,8 +1636,8 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
16681636 self . tables . is_macro_rules . set ( def_id. index , macro_def. macro_rules ) ;
16691637 record ! ( self . tables. macro_definition[ def_id] <- & * macro_def. body) ;
16701638 }
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 ) ;
16731641 }
16741642 hir:: ItemKind :: OpaqueTy ( ref opaque) => {
16751643 self . encode_explicit_item_bounds ( def_id) ;
0 commit comments