@@ -129,30 +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- pub fn krate ( & self ) -> & Crate < ' hir > {
144- self . dep_graph . read ( DepNode :: new_no_params ( DepKind :: Krate ) ) ;
145- & self . krate
146- }
147-
148- /// This is used internally in the dependency tracking system.
149- /// Use the `krate` method to ensure your dependency on the
150- /// crate is tracked.
151- pub fn untracked_krate ( & self ) -> & Crate < ' hir > {
152- & self . krate
153- }
154- }
155-
156132/// This type is effectively a `HashMap<HirId, Entry<'hir>>`,
157133/// but it is implemented as 2 layers of arrays.
158134/// - first we have `A = IndexVec<DefIndex, B>` mapping `DefIndex`s to an inner value
@@ -162,11 +138,8 @@ pub(super) type HirEntryMap<'hir> = IndexVec<DefIndex, IndexVec<ItemLocalId, Opt
162138/// Represents a mapping from `NodeId`s to AST elements and their parent `NodeId`s.
163139#[ derive( Clone ) ]
164140pub struct Map < ' hir > {
165- /// The backing storage for all the AST nodes.
166- pub forest : & ' hir Forest < ' hir > ,
141+ krate : & ' hir Crate < ' hir > ,
167142
168- /// Same as the dep_graph in forest, just available with one fewer
169- /// deref. This is a gratuitous micro-optimization.
170143 pub dep_graph : DepGraph ,
171144
172145 /// The SVH of the local crate.
@@ -217,6 +190,13 @@ impl<'hir> Iterator for ParentHirIterator<'_, 'hir> {
217190}
218191
219192impl < ' 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+
220200 #[ inline]
221201 fn lookup ( & self , id : HirId ) -> Option < & Entry < ' hir > > {
222202 let local_map = self . map . get ( id. owner ) ?;
@@ -401,40 +381,36 @@ impl<'hir> Map<'hir> {
401381 self . lookup ( id) . cloned ( )
402382 }
403383
404- pub fn krate ( & self ) -> & ' hir Crate < ' hir > {
405- self . forest . krate ( )
406- }
407-
408384 pub fn item ( & self , id : HirId ) -> & ' hir Item < ' hir > {
409385 self . read ( id) ;
410386
411- // N.B., intentionally bypass `self.forest. krate()` so that we
387+ // N.B., intentionally bypass `self.krate()` so that we
412388 // do not trigger a read of the whole krate here
413- self . forest . krate . item ( id)
389+ self . krate . item ( id)
414390 }
415391
416392 pub fn trait_item ( & self , id : TraitItemId ) -> & ' hir TraitItem < ' hir > {
417393 self . read ( id. hir_id ) ;
418394
419- // N.B., intentionally bypass `self.forest. krate()` so that we
395+ // N.B., intentionally bypass `self.krate()` so that we
420396 // do not trigger a read of the whole krate here
421- self . forest . krate . trait_item ( id)
397+ self . krate . trait_item ( id)
422398 }
423399
424400 pub fn impl_item ( & self , id : ImplItemId ) -> & ' hir ImplItem < ' hir > {
425401 self . read ( id. hir_id ) ;
426402
427- // N.B., intentionally bypass `self.forest. krate()` so that we
403+ // N.B., intentionally bypass `self.krate()` so that we
428404 // do not trigger a read of the whole krate here
429- self . forest . krate . impl_item ( id)
405+ self . krate . impl_item ( id)
430406 }
431407
432408 pub fn body ( & self , id : BodyId ) -> & ' hir Body < ' hir > {
433409 self . read ( id. hir_id ) ;
434410
435- // N.B., intentionally bypass `self.forest. krate()` so that we
411+ // N.B., intentionally bypass `self.krate()` so that we
436412 // do not trigger a read of the whole krate here
437- self . forest . krate . body ( id)
413+ self . krate . body ( id)
438414 }
439415
440416 pub fn fn_decl_by_hir_id ( & self , hir_id : HirId ) -> Option < & ' hir FnDecl < ' hir > > {
@@ -530,9 +506,9 @@ impl<'hir> Map<'hir> {
530506 pub fn trait_impls ( & self , trait_did : DefId ) -> & ' hir [ HirId ] {
531507 self . dep_graph . read ( DepNode :: new_no_params ( DepKind :: AllLocalTraitImpls ) ) ;
532508
533- // N.B., intentionally bypass `self.forest. krate()` so that we
509+ // N.B., intentionally bypass `self.krate()` so that we
534510 // do not trigger a read of the whole krate here
535- self . forest . krate . trait_impls . get ( & trait_did) . map_or ( & [ ] , |xs| & xs[ ..] )
511+ self . krate . trait_impls . get ( & trait_did) . map_or ( & [ ] , |xs| & xs[ ..] )
536512 }
537513
538514 /// Gets the attributes on the crate. This is preferable to
@@ -542,15 +518,15 @@ impl<'hir> Map<'hir> {
542518 let def_path_hash = self . definitions . def_path_hash ( CRATE_DEF_INDEX ) ;
543519
544520 self . dep_graph . read ( def_path_hash. to_dep_node ( DepKind :: Hir ) ) ;
545- & self . forest . krate . attrs
521+ & self . krate . attrs
546522 }
547523
548524 pub fn get_module ( & self , module : DefId ) -> ( & ' hir Mod < ' hir > , Span , HirId ) {
549525 let hir_id = self . as_local_hir_id ( module) . unwrap ( ) ;
550526 self . read ( hir_id) ;
551527 match self . find_entry ( hir_id) . unwrap ( ) . node {
552528 Node :: Item ( & Item { span, kind : ItemKind :: Mod ( ref m) , .. } ) => ( m, span, hir_id) ,
553- Node :: Crate => ( & self . forest . krate . module , self . forest . krate . span , hir_id) ,
529+ Node :: Crate => ( & self . krate . module , self . krate . span , hir_id) ,
554530 node => panic ! ( "not a module: {:?}" , node) ,
555531 }
556532 }
@@ -567,7 +543,7 @@ impl<'hir> Map<'hir> {
567543 // in the expect_* calls the loops below
568544 self . read ( hir_id) ;
569545
570- let module = & self . forest . krate . modules [ & hir_id] ;
546+ let module = & self . krate . modules [ & hir_id] ;
571547
572548 for id in & module. items {
573549 visitor. visit_item ( self . expect_item ( * id) ) ;
@@ -984,7 +960,7 @@ impl<'hir> Map<'hir> {
984960 // Unit/tuple structs/variants take the attributes straight from
985961 // the struct/variant definition.
986962 Some ( Node :: Ctor ( ..) ) => return self . attrs ( self . get_parent_item ( id) ) ,
987- Some ( Node :: Crate ) => Some ( & self . forest . krate . attrs [ ..] ) ,
963+ Some ( Node :: Crate ) => Some ( & self . krate . attrs [ ..] ) ,
988964 _ => None ,
989965 } ;
990966 attrs. unwrap_or ( & [ ] )
@@ -1063,7 +1039,7 @@ impl<'hir> Map<'hir> {
10631039 Some ( Node :: Visibility ( v) ) => bug ! ( "unexpected Visibility {:?}" , v) ,
10641040 Some ( Node :: Local ( local) ) => local. span ,
10651041 Some ( Node :: MacroDef ( macro_def) ) => macro_def. span ,
1066- Some ( Node :: Crate ) => self . forest . krate . span ,
1042+ Some ( Node :: Crate ) => self . krate . span ,
10671043 None => bug ! ( "hir::map::Map::span: id not in map: {:?}" , hir_id) ,
10681044 }
10691045 }
@@ -1231,7 +1207,8 @@ impl Named for ImplItem<'_> {
12311207pub fn map_crate < ' hir > (
12321208 sess : & rustc_session:: Session ,
12331209 cstore : & CrateStoreDyn ,
1234- forest : & ' hir Forest < ' hir > ,
1210+ krate : & ' hir Crate < ' hir > ,
1211+ dep_graph : DepGraph ,
12351212 definitions : Definitions ,
12361213) -> Map < ' hir > {
12371214 let _prof_timer = sess. prof . generic_activity ( "build_hir_map" ) ;
@@ -1244,31 +1221,18 @@ pub fn map_crate<'hir>(
12441221 . collect ( ) ;
12451222
12461223 let ( map, crate_hash) = {
1247- let hcx = crate :: ich:: StableHashingContext :: new ( sess, & forest. krate , & definitions, cstore) ;
1248-
1249- let mut collector = NodeCollector :: root (
1250- sess,
1251- & forest. krate ,
1252- & forest. dep_graph ,
1253- & definitions,
1254- & hir_to_node_id,
1255- hcx,
1256- ) ;
1257- 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) ;
12581229
12591230 let crate_disambiguator = sess. local_crate_disambiguator ( ) ;
12601231 let cmdline_args = sess. opts . dep_tracking_hash ( ) ;
12611232 collector. finalize_and_compute_crate_hash ( crate_disambiguator, cstore, cmdline_args)
12621233 } ;
12631234
1264- let map = Map {
1265- forest,
1266- dep_graph : forest. dep_graph . clone ( ) ,
1267- crate_hash,
1268- map,
1269- hir_to_node_id,
1270- definitions,
1271- } ;
1235+ let map = Map { krate, dep_graph, crate_hash, map, hir_to_node_id, definitions } ;
12721236
12731237 sess. time ( "validate_HIR_map" , || {
12741238 hir_id_validator:: check_crate ( & map) ;
0 commit comments