@@ -129,25 +129,6 @@ impl<'hir> Entry<'hir> {
129
129
}
130
130
}
131
131
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
-
151
132
/// This type is effectively a `HashMap<HirId, Entry<'hir>>`,
152
133
/// but it is implemented as 2 layers of arrays.
153
134
/// - 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
157
138
/// Represents a mapping from `NodeId`s to AST elements and their parent `NodeId`s.
158
139
#[ derive( Clone ) ]
159
140
pub struct Map < ' hir > {
160
- /// The backing storage for all the AST nodes.
161
- pub forest : & ' hir Forest < ' hir > ,
141
+ pub krate : & ' hir Crate < ' hir > ,
162
142
163
- /// Same as the dep_graph in forest, just available with one fewer
164
- /// deref. This is a gratuitous micro-optimization.
165
143
pub dep_graph : DepGraph ,
166
144
167
145
/// The SVH of the local crate.
@@ -212,6 +190,13 @@ impl<'hir> Iterator for ParentHirIterator<'_, 'hir> {
212
190
}
213
191
214
192
impl < ' 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
+
215
200
#[ inline]
216
201
fn lookup ( & self , id : HirId ) -> Option < & Entry < ' hir > > {
217
202
let local_map = self . map . get ( id. owner ) ?;
@@ -399,33 +384,33 @@ impl<'hir> Map<'hir> {
399
384
pub fn item ( & self , id : HirId ) -> & ' hir Item < ' hir > {
400
385
self . read ( id) ;
401
386
402
- // N.B., intentionally bypass `self.forest. krate()` so that we
387
+ // N.B., intentionally bypass `self.krate()` so that we
403
388
// do not trigger a read of the whole krate here
404
- self . forest . krate . item ( id)
389
+ self . krate . item ( id)
405
390
}
406
391
407
392
pub fn trait_item ( & self , id : TraitItemId ) -> & ' hir TraitItem < ' hir > {
408
393
self . read ( id. hir_id ) ;
409
394
410
- // N.B., intentionally bypass `self.forest. krate()` so that we
395
+ // N.B., intentionally bypass `self.krate()` so that we
411
396
// do not trigger a read of the whole krate here
412
- self . forest . krate . trait_item ( id)
397
+ self . krate . trait_item ( id)
413
398
}
414
399
415
400
pub fn impl_item ( & self , id : ImplItemId ) -> & ' hir ImplItem < ' hir > {
416
401
self . read ( id. hir_id ) ;
417
402
418
- // N.B., intentionally bypass `self.forest. krate()` so that we
403
+ // N.B., intentionally bypass `self.krate()` so that we
419
404
// do not trigger a read of the whole krate here
420
- self . forest . krate . impl_item ( id)
405
+ self . krate . impl_item ( id)
421
406
}
422
407
423
408
pub fn body ( & self , id : BodyId ) -> & ' hir Body < ' hir > {
424
409
self . read ( id. hir_id ) ;
425
410
426
- // N.B., intentionally bypass `self.forest. krate()` so that we
411
+ // N.B., intentionally bypass `self.krate()` so that we
427
412
// do not trigger a read of the whole krate here
428
- self . forest . krate . body ( id)
413
+ self . krate . body ( id)
429
414
}
430
415
431
416
pub fn fn_decl_by_hir_id ( & self , hir_id : HirId ) -> Option < & ' hir FnDecl < ' hir > > {
@@ -521,9 +506,9 @@ impl<'hir> Map<'hir> {
521
506
pub fn trait_impls ( & self , trait_did : DefId ) -> & ' hir [ HirId ] {
522
507
self . dep_graph . read ( DepNode :: new_no_params ( DepKind :: AllLocalTraitImpls ) ) ;
523
508
524
- // N.B., intentionally bypass `self.forest. krate()` so that we
509
+ // N.B., intentionally bypass `self.krate()` so that we
525
510
// 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[ ..] )
527
512
}
528
513
529
514
/// Gets the attributes on the crate. This is preferable to
@@ -533,15 +518,15 @@ impl<'hir> Map<'hir> {
533
518
let def_path_hash = self . definitions . def_path_hash ( CRATE_DEF_INDEX ) ;
534
519
535
520
self . dep_graph . read ( def_path_hash. to_dep_node ( DepKind :: Hir ) ) ;
536
- & self . forest . krate . attrs
521
+ & self . krate . attrs
537
522
}
538
523
539
524
pub fn get_module ( & self , module : DefId ) -> ( & ' hir Mod < ' hir > , Span , HirId ) {
540
525
let hir_id = self . as_local_hir_id ( module) . unwrap ( ) ;
541
526
self . read ( hir_id) ;
542
527
match self . find_entry ( hir_id) . unwrap ( ) . node {
543
528
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) ,
545
530
node => panic ! ( "not a module: {:?}" , node) ,
546
531
}
547
532
}
@@ -558,7 +543,7 @@ impl<'hir> Map<'hir> {
558
543
// in the expect_* calls the loops below
559
544
self . read ( hir_id) ;
560
545
561
- let module = & self . forest . krate . modules [ & hir_id] ;
546
+ let module = & self . krate . modules [ & hir_id] ;
562
547
563
548
for id in & module. items {
564
549
visitor. visit_item ( self . expect_item ( * id) ) ;
@@ -975,7 +960,7 @@ impl<'hir> Map<'hir> {
975
960
// Unit/tuple structs/variants take the attributes straight from
976
961
// the struct/variant definition.
977
962
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 [ ..] ) ,
979
964
_ => None ,
980
965
} ;
981
966
attrs. unwrap_or ( & [ ] )
@@ -1054,7 +1039,7 @@ impl<'hir> Map<'hir> {
1054
1039
Some ( Node :: Visibility ( v) ) => bug ! ( "unexpected Visibility {:?}" , v) ,
1055
1040
Some ( Node :: Local ( local) ) => local. span ,
1056
1041
Some ( Node :: MacroDef ( macro_def) ) => macro_def. span ,
1057
- Some ( Node :: Crate ) => self . forest . krate . span ,
1042
+ Some ( Node :: Crate ) => self . krate . span ,
1058
1043
None => bug ! ( "hir::map::Map::span: id not in map: {:?}" , hir_id) ,
1059
1044
}
1060
1045
}
@@ -1222,7 +1207,8 @@ impl Named for ImplItem<'_> {
1222
1207
pub fn map_crate < ' hir > (
1223
1208
sess : & rustc_session:: Session ,
1224
1209
cstore : & CrateStoreDyn ,
1225
- forest : & ' hir Forest < ' hir > ,
1210
+ krate : & ' hir Crate < ' hir > ,
1211
+ dep_graph : DepGraph ,
1226
1212
definitions : Definitions ,
1227
1213
) -> Map < ' hir > {
1228
1214
let _prof_timer = sess. prof . generic_activity ( "build_hir_map" ) ;
@@ -1235,31 +1221,18 @@ pub fn map_crate<'hir>(
1235
1221
. collect ( ) ;
1236
1222
1237
1223
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) ;
1249
1229
1250
1230
let crate_disambiguator = sess. local_crate_disambiguator ( ) ;
1251
1231
let cmdline_args = sess. opts . dep_tracking_hash ( ) ;
1252
1232
collector. finalize_and_compute_crate_hash ( crate_disambiguator, cstore, cmdline_args)
1253
1233
} ;
1254
1234
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 } ;
1263
1236
1264
1237
sess. time ( "validate_HIR_map" , || {
1265
1238
hir_id_validator:: check_crate ( & map) ;
0 commit comments