@@ -129,25 +129,6 @@ impl<'hir> Entry<'hir> {
129129 }
130130}
131131
132- /// Stores a crate and any number of inlined items from other crates.
133- pub struct Forest < ' hir > {
134- krate : Crate < ' hir > ,
135- pub dep_graph : DepGraph ,
136- }
137-
138- impl Forest < ' hir > {
139- pub fn new ( krate : Crate < ' hir > , dep_graph : & DepGraph ) -> Forest < ' hir > {
140- Forest { krate, dep_graph : dep_graph. clone ( ) }
141- }
142-
143- /// This is used internally in the dependency tracking system.
144- /// Use the `krate` method to ensure your dependency on the
145- /// crate is tracked.
146- pub fn untracked_krate ( & self ) -> & Crate < ' hir > {
147- & self . krate
148- }
149- }
150-
151132/// This type is effectively a `HashMap<HirId, Entry<'hir>>`,
152133/// but it is implemented as 2 layers of arrays.
153134/// - first we have `A = IndexVec<DefIndex, B>` mapping `DefIndex`s to an inner value
@@ -157,11 +138,8 @@ pub(super) type HirEntryMap<'hir> = IndexVec<DefIndex, IndexVec<ItemLocalId, Opt
157138/// Represents a mapping from `NodeId`s to AST elements and their parent `NodeId`s.
158139#[ derive( Clone ) ]
159140pub struct Map < ' hir > {
160- /// The backing storage for all the AST nodes.
161- pub forest : & ' hir Forest < ' hir > ,
141+ pub krate : & ' hir Crate < ' hir > ,
162142
163- /// Same as the dep_graph in forest, just available with one fewer
164- /// deref. This is a gratuitous micro-optimization.
165143 pub dep_graph : DepGraph ,
166144
167145 /// The SVH of the local crate.
@@ -212,6 +190,13 @@ impl<'hir> Iterator for ParentHirIterator<'_, 'hir> {
212190}
213191
214192impl < ' hir > Map < ' hir > {
193+ /// This is used internally in the dependency tracking system.
194+ /// Use the `krate` method to ensure your dependency on the
195+ /// crate is tracked.
196+ pub fn untracked_krate ( & self ) -> & Crate < ' hir > {
197+ & self . krate
198+ }
199+
215200 #[ inline]
216201 fn lookup ( & self , id : HirId ) -> Option < & Entry < ' hir > > {
217202 let local_map = self . map . get ( id. owner ) ?;
@@ -399,33 +384,33 @@ impl<'hir> Map<'hir> {
399384 pub fn item ( & self , id : HirId ) -> & ' hir Item < ' hir > {
400385 self . read ( id) ;
401386
402- // N.B., intentionally bypass `self.forest. krate()` so that we
387+ // N.B., intentionally bypass `self.krate()` so that we
403388 // do not trigger a read of the whole krate here
404- self . forest . krate . item ( id)
389+ self . krate . item ( id)
405390 }
406391
407392 pub fn trait_item ( & self , id : TraitItemId ) -> & ' hir TraitItem < ' hir > {
408393 self . read ( id. hir_id ) ;
409394
410- // N.B., intentionally bypass `self.forest. krate()` so that we
395+ // N.B., intentionally bypass `self.krate()` so that we
411396 // do not trigger a read of the whole krate here
412- self . forest . krate . trait_item ( id)
397+ self . krate . trait_item ( id)
413398 }
414399
415400 pub fn impl_item ( & self , id : ImplItemId ) -> & ' hir ImplItem < ' hir > {
416401 self . read ( id. hir_id ) ;
417402
418- // N.B., intentionally bypass `self.forest. krate()` so that we
403+ // N.B., intentionally bypass `self.krate()` so that we
419404 // do not trigger a read of the whole krate here
420- self . forest . krate . impl_item ( id)
405+ self . krate . impl_item ( id)
421406 }
422407
423408 pub fn body ( & self , id : BodyId ) -> & ' hir Body < ' hir > {
424409 self . read ( id. hir_id ) ;
425410
426- // N.B., intentionally bypass `self.forest. krate()` so that we
411+ // N.B., intentionally bypass `self.krate()` so that we
427412 // do not trigger a read of the whole krate here
428- self . forest . krate . body ( id)
413+ self . krate . body ( id)
429414 }
430415
431416 pub fn fn_decl_by_hir_id ( & self , hir_id : HirId ) -> Option < & ' hir FnDecl < ' hir > > {
@@ -521,9 +506,9 @@ impl<'hir> Map<'hir> {
521506 pub fn trait_impls ( & self , trait_did : DefId ) -> & ' hir [ HirId ] {
522507 self . dep_graph . read ( DepNode :: new_no_params ( DepKind :: AllLocalTraitImpls ) ) ;
523508
524- // N.B., intentionally bypass `self.forest. krate()` so that we
509+ // N.B., intentionally bypass `self.krate()` so that we
525510 // do not trigger a read of the whole krate here
526- self . forest . krate . trait_impls . get ( & trait_did) . map_or ( & [ ] , |xs| & xs[ ..] )
511+ self . krate . trait_impls . get ( & trait_did) . map_or ( & [ ] , |xs| & xs[ ..] )
527512 }
528513
529514 /// Gets the attributes on the crate. This is preferable to
@@ -533,15 +518,15 @@ impl<'hir> Map<'hir> {
533518 let def_path_hash = self . definitions . def_path_hash ( CRATE_DEF_INDEX ) ;
534519
535520 self . dep_graph . read ( def_path_hash. to_dep_node ( DepKind :: Hir ) ) ;
536- & self . forest . krate . attrs
521+ & self . krate . attrs
537522 }
538523
539524 pub fn get_module ( & self , module : DefId ) -> ( & ' hir Mod < ' hir > , Span , HirId ) {
540525 let hir_id = self . as_local_hir_id ( module) . unwrap ( ) ;
541526 self . read ( hir_id) ;
542527 match self . find_entry ( hir_id) . unwrap ( ) . node {
543528 Node :: Item ( & Item { span, kind : ItemKind :: Mod ( ref m) , .. } ) => ( m, span, hir_id) ,
544- Node :: Crate => ( & self . forest . krate . module , self . forest . krate . span , hir_id) ,
529+ Node :: Crate => ( & self . krate . module , self . krate . span , hir_id) ,
545530 node => panic ! ( "not a module: {:?}" , node) ,
546531 }
547532 }
@@ -558,7 +543,7 @@ impl<'hir> Map<'hir> {
558543 // in the expect_* calls the loops below
559544 self . read ( hir_id) ;
560545
561- let module = & self . forest . krate . modules [ & hir_id] ;
546+ let module = & self . krate . modules [ & hir_id] ;
562547
563548 for id in & module. items {
564549 visitor. visit_item ( self . expect_item ( * id) ) ;
@@ -975,7 +960,7 @@ impl<'hir> Map<'hir> {
975960 // Unit/tuple structs/variants take the attributes straight from
976961 // the struct/variant definition.
977962 Some ( Node :: Ctor ( ..) ) => return self . attrs ( self . get_parent_item ( id) ) ,
978- Some ( Node :: Crate ) => Some ( & self . forest . krate . attrs [ ..] ) ,
963+ Some ( Node :: Crate ) => Some ( & self . krate . attrs [ ..] ) ,
979964 _ => None ,
980965 } ;
981966 attrs. unwrap_or ( & [ ] )
@@ -1054,7 +1039,7 @@ impl<'hir> Map<'hir> {
10541039 Some ( Node :: Visibility ( v) ) => bug ! ( "unexpected Visibility {:?}" , v) ,
10551040 Some ( Node :: Local ( local) ) => local. span ,
10561041 Some ( Node :: MacroDef ( macro_def) ) => macro_def. span ,
1057- Some ( Node :: Crate ) => self . forest . krate . span ,
1042+ Some ( Node :: Crate ) => self . krate . span ,
10581043 None => bug ! ( "hir::map::Map::span: id not in map: {:?}" , hir_id) ,
10591044 }
10601045 }
@@ -1222,7 +1207,8 @@ impl Named for ImplItem<'_> {
12221207pub fn map_crate < ' hir > (
12231208 sess : & rustc_session:: Session ,
12241209 cstore : & CrateStoreDyn ,
1225- forest : & ' hir Forest < ' hir > ,
1210+ krate : & ' hir Crate < ' hir > ,
1211+ dep_graph : DepGraph ,
12261212 definitions : Definitions ,
12271213) -> Map < ' hir > {
12281214 let _prof_timer = sess. prof . generic_activity ( "build_hir_map" ) ;
@@ -1235,31 +1221,18 @@ pub fn map_crate<'hir>(
12351221 . collect ( ) ;
12361222
12371223 let ( map, crate_hash) = {
1238- let hcx = crate :: ich:: StableHashingContext :: new ( sess, & forest. krate , & definitions, cstore) ;
1239-
1240- let mut collector = NodeCollector :: root (
1241- sess,
1242- & forest. krate ,
1243- & forest. dep_graph ,
1244- & definitions,
1245- & hir_to_node_id,
1246- hcx,
1247- ) ;
1248- intravisit:: walk_crate ( & mut collector, & forest. krate ) ;
1224+ let hcx = crate :: ich:: StableHashingContext :: new ( sess, krate, & definitions, cstore) ;
1225+
1226+ let mut collector =
1227+ NodeCollector :: root ( sess, krate, & dep_graph, & definitions, & hir_to_node_id, hcx) ;
1228+ intravisit:: walk_crate ( & mut collector, krate) ;
12491229
12501230 let crate_disambiguator = sess. local_crate_disambiguator ( ) ;
12511231 let cmdline_args = sess. opts . dep_tracking_hash ( ) ;
12521232 collector. finalize_and_compute_crate_hash ( crate_disambiguator, cstore, cmdline_args)
12531233 } ;
12541234
1255- let map = Map {
1256- forest,
1257- dep_graph : forest. dep_graph . clone ( ) ,
1258- crate_hash,
1259- map,
1260- hir_to_node_id,
1261- definitions,
1262- } ;
1235+ let map = Map { krate, dep_graph, crate_hash, map, hir_to_node_id, definitions } ;
12631236
12641237 sess. time ( "validate_HIR_map" , || {
12651238 hir_id_validator:: check_crate ( & map) ;
0 commit comments