@@ -579,6 +579,7 @@ pub struct ModuleItems {
579579 pub items : BTreeSet < HirId > ,
580580 pub trait_items : BTreeSet < TraitItemId > ,
581581 pub impl_items : BTreeSet < ImplItemId > ,
582+ pub foreign_items : BTreeSet < ForeignItemId > ,
582583}
583584
584585/// A type representing only the top-level module.
@@ -612,6 +613,7 @@ pub struct Crate<'hir> {
612613
613614 pub trait_items : BTreeMap < TraitItemId , TraitItem < ' hir > > ,
614615 pub impl_items : BTreeMap < ImplItemId , ImplItem < ' hir > > ,
616+ pub foreign_items : BTreeMap < ForeignItemId , ForeignItem < ' hir > > ,
615617 pub bodies : BTreeMap < BodyId , Body < ' hir > > ,
616618 pub trait_impls : BTreeMap < DefId , Vec < HirId > > ,
617619
@@ -644,6 +646,10 @@ impl Crate<'hir> {
644646 & self . impl_items [ & id]
645647 }
646648
649+ pub fn foreign_item ( & self , id : ForeignItemId ) -> & ForeignItem < ' hir > {
650+ & self . foreign_items [ & id]
651+ }
652+
647653 pub fn body ( & self , id : BodyId ) -> & Body < ' hir > {
648654 & self . bodies [ & id]
649655 }
@@ -673,6 +679,10 @@ impl Crate<'_> {
673679 for impl_item in self . impl_items . values ( ) {
674680 visitor. visit_impl_item ( impl_item) ;
675681 }
682+
683+ for foreign_item in self . foreign_items . values ( ) {
684+ visitor. visit_foreign_item ( foreign_item) ;
685+ }
676686 }
677687
678688 /// A parallel version of `visit_all_item_likes`.
@@ -695,6 +705,11 @@ impl Crate<'_> {
695705 par_for_each_in( & self . impl_items, |( _, impl_item) | {
696706 visitor. visit_impl_item( impl_item) ;
697707 } ) ;
708+ } ,
709+ {
710+ par_for_each_in( & self . foreign_items, |( _, foreign_item) | {
711+ visitor. visit_foreign_item( foreign_item) ;
712+ } ) ;
698713 }
699714 ) ;
700715 }
@@ -1840,7 +1855,7 @@ pub struct FnSig<'hir> {
18401855}
18411856
18421857// The bodies for items are stored "out of line", in a separate
1843- // hashmap in the `Crate`. Here we just record the node -id of the item
1858+ // hashmap in the `Crate`. Here we just record the hir -id of the item
18441859// so it can fetched later.
18451860#[ derive( Copy , Clone , PartialEq , Eq , PartialOrd , Ord , Encodable , Debug ) ]
18461861pub struct TraitItemId {
@@ -1884,7 +1899,7 @@ pub enum TraitItemKind<'hir> {
18841899}
18851900
18861901// The bodies for items are stored "out of line", in a separate
1887- // hashmap in the `Crate`. Here we just record the node -id of the item
1902+ // hashmap in the `Crate`. Here we just record the hir -id of the item
18881903// so it can fetched later.
18891904#[ derive( Copy , Clone , PartialEq , Eq , PartialOrd , Ord , Encodable , Debug ) ]
18901905pub struct ImplItemId {
@@ -2269,12 +2284,6 @@ pub struct Mod<'hir> {
22692284 pub item_ids : & ' hir [ ItemId ] ,
22702285}
22712286
2272- #[ derive( Debug , HashStable_Generic ) ]
2273- pub struct ForeignMod < ' hir > {
2274- pub abi : Abi ,
2275- pub items : & ' hir [ ForeignItem < ' hir > ] ,
2276- }
2277-
22782287#[ derive( Encodable , Debug , HashStable_Generic ) ]
22792288pub struct GlobalAsm {
22802289 pub asm : Symbol ,
@@ -2432,7 +2441,7 @@ impl VariantData<'hir> {
24322441}
24332442
24342443// The bodies for items are stored "out of line", in a separate
2435- // hashmap in the `Crate`. Here we just record the node -id of the item
2444+ // hashmap in the `Crate`. Here we just record the hir -id of the item
24362445// so it can fetched later.
24372446#[ derive( Copy , Clone , Encodable , Debug ) ]
24382447pub struct ItemId {
@@ -2521,7 +2530,7 @@ pub enum ItemKind<'hir> {
25212530 /// A module.
25222531 Mod ( Mod < ' hir > ) ,
25232532 /// An external module, e.g. `extern { .. }`.
2524- ForeignMod ( ForeignMod < ' hir > ) ,
2533+ ForeignMod { abi : Abi , items : & ' hir [ ForeignItemRef < ' hir > ] } ,
25252534 /// Module-level inline assembly (from `global_asm!`).
25262535 GlobalAsm ( & ' hir GlobalAsm ) ,
25272536 /// A type alias, e.g., `type Foo = Bar<u8>`.
@@ -2614,6 +2623,29 @@ pub enum AssocItemKind {
26142623 Type ,
26152624}
26162625
2626+ // The bodies for items are stored "out of line", in a separate
2627+ // hashmap in the `Crate`. Here we just record the hir-id of the item
2628+ // so it can fetched later.
2629+ #[ derive( Copy , Clone , PartialEq , Eq , PartialOrd , Ord , Encodable , Debug ) ]
2630+ pub struct ForeignItemId {
2631+ pub hir_id : HirId ,
2632+ }
2633+
2634+ /// A reference from a foreign block to one of its items. This
2635+ /// contains the item's ID, naturally, but also the item's name and
2636+ /// some other high-level details (like whether it is an associated
2637+ /// type or method, and whether it is public). This allows other
2638+ /// passes to find the impl they want without loading the ID (which
2639+ /// means fewer edges in the incremental compilation graph).
2640+ #[ derive( Debug , HashStable_Generic ) ]
2641+ pub struct ForeignItemRef < ' hir > {
2642+ pub id : ForeignItemId ,
2643+ #[ stable_hasher( project( name) ) ]
2644+ pub ident : Ident ,
2645+ pub span : Span ,
2646+ pub vis : Visibility < ' hir > ,
2647+ }
2648+
26172649#[ derive( Debug , HashStable_Generic ) ]
26182650pub struct ForeignItem < ' hir > {
26192651 #[ stable_hasher( project( name) ) ]
0 commit comments