@@ -129,30 +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
- 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
-
156
132
/// This type is effectively a `HashMap<HirId, Entry<'hir>>`,
157
133
/// but it is implemented as 2 layers of arrays.
158
134
/// - 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
162
138
/// Represents a mapping from `NodeId`s to AST elements and their parent `NodeId`s.
163
139
#[ derive( Clone ) ]
164
140
pub struct Map < ' hir > {
165
- /// The backing storage for all the AST nodes.
166
- pub forest : & ' hir Forest < ' hir > ,
141
+ krate : & ' hir Crate < ' hir > ,
167
142
168
- /// Same as the dep_graph in forest, just available with one fewer
169
- /// deref. This is a gratuitous micro-optimization.
170
143
pub dep_graph : DepGraph ,
171
144
172
145
/// The SVH of the local crate.
@@ -217,6 +190,13 @@ impl<'hir> Iterator for ParentHirIterator<'_, 'hir> {
217
190
}
218
191
219
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
+
220
200
#[ inline]
221
201
fn lookup ( & self , id : HirId ) -> Option < & Entry < ' hir > > {
222
202
let local_map = self . map . get ( id. owner ) ?;
@@ -401,40 +381,36 @@ impl<'hir> Map<'hir> {
401
381
self . lookup ( id) . cloned ( )
402
382
}
403
383
404
- pub fn krate ( & self ) -> & ' hir Crate < ' hir > {
405
- self . forest . krate ( )
406
- }
407
-
408
384
pub fn item ( & self , id : HirId ) -> & ' hir Item < ' hir > {
409
385
self . read ( id) ;
410
386
411
- // N.B., intentionally bypass `self.forest. krate()` so that we
387
+ // N.B., intentionally bypass `self.krate()` so that we
412
388
// do not trigger a read of the whole krate here
413
- self . forest . krate . item ( id)
389
+ self . krate . item ( id)
414
390
}
415
391
416
392
pub fn trait_item ( & self , id : TraitItemId ) -> & ' hir TraitItem < ' hir > {
417
393
self . read ( id. hir_id ) ;
418
394
419
- // N.B., intentionally bypass `self.forest. krate()` so that we
395
+ // N.B., intentionally bypass `self.krate()` so that we
420
396
// do not trigger a read of the whole krate here
421
- self . forest . krate . trait_item ( id)
397
+ self . krate . trait_item ( id)
422
398
}
423
399
424
400
pub fn impl_item ( & self , id : ImplItemId ) -> & ' hir ImplItem < ' hir > {
425
401
self . read ( id. hir_id ) ;
426
402
427
- // N.B., intentionally bypass `self.forest. krate()` so that we
403
+ // N.B., intentionally bypass `self.krate()` so that we
428
404
// do not trigger a read of the whole krate here
429
- self . forest . krate . impl_item ( id)
405
+ self . krate . impl_item ( id)
430
406
}
431
407
432
408
pub fn body ( & self , id : BodyId ) -> & ' hir Body < ' hir > {
433
409
self . read ( id. hir_id ) ;
434
410
435
- // N.B., intentionally bypass `self.forest. krate()` so that we
411
+ // N.B., intentionally bypass `self.krate()` so that we
436
412
// do not trigger a read of the whole krate here
437
- self . forest . krate . body ( id)
413
+ self . krate . body ( id)
438
414
}
439
415
440
416
pub fn fn_decl_by_hir_id ( & self , hir_id : HirId ) -> Option < & ' hir FnDecl < ' hir > > {
@@ -530,9 +506,9 @@ impl<'hir> Map<'hir> {
530
506
pub fn trait_impls ( & self , trait_did : DefId ) -> & ' hir [ HirId ] {
531
507
self . dep_graph . read ( DepNode :: new_no_params ( DepKind :: AllLocalTraitImpls ) ) ;
532
508
533
- // N.B., intentionally bypass `self.forest. krate()` so that we
509
+ // N.B., intentionally bypass `self.krate()` so that we
534
510
// 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[ ..] )
536
512
}
537
513
538
514
/// Gets the attributes on the crate. This is preferable to
@@ -542,15 +518,15 @@ impl<'hir> Map<'hir> {
542
518
let def_path_hash = self . definitions . def_path_hash ( CRATE_DEF_INDEX ) ;
543
519
544
520
self . dep_graph . read ( def_path_hash. to_dep_node ( DepKind :: Hir ) ) ;
545
- & self . forest . krate . attrs
521
+ & self . krate . attrs
546
522
}
547
523
548
524
pub fn get_module ( & self , module : DefId ) -> ( & ' hir Mod < ' hir > , Span , HirId ) {
549
525
let hir_id = self . as_local_hir_id ( module) . unwrap ( ) ;
550
526
self . read ( hir_id) ;
551
527
match self . find_entry ( hir_id) . unwrap ( ) . node {
552
528
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) ,
554
530
node => panic ! ( "not a module: {:?}" , node) ,
555
531
}
556
532
}
@@ -567,7 +543,7 @@ impl<'hir> Map<'hir> {
567
543
// in the expect_* calls the loops below
568
544
self . read ( hir_id) ;
569
545
570
- let module = & self . forest . krate . modules [ & hir_id] ;
546
+ let module = & self . krate . modules [ & hir_id] ;
571
547
572
548
for id in & module. items {
573
549
visitor. visit_item ( self . expect_item ( * id) ) ;
@@ -984,7 +960,7 @@ impl<'hir> Map<'hir> {
984
960
// Unit/tuple structs/variants take the attributes straight from
985
961
// the struct/variant definition.
986
962
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 [ ..] ) ,
988
964
_ => None ,
989
965
} ;
990
966
attrs. unwrap_or ( & [ ] )
@@ -1063,7 +1039,7 @@ impl<'hir> Map<'hir> {
1063
1039
Some ( Node :: Visibility ( v) ) => bug ! ( "unexpected Visibility {:?}" , v) ,
1064
1040
Some ( Node :: Local ( local) ) => local. span ,
1065
1041
Some ( Node :: MacroDef ( macro_def) ) => macro_def. span ,
1066
- Some ( Node :: Crate ) => self . forest . krate . span ,
1042
+ Some ( Node :: Crate ) => self . krate . span ,
1067
1043
None => bug ! ( "hir::map::Map::span: id not in map: {:?}" , hir_id) ,
1068
1044
}
1069
1045
}
@@ -1231,7 +1207,8 @@ impl Named for ImplItem<'_> {
1231
1207
pub fn map_crate < ' hir > (
1232
1208
sess : & rustc_session:: Session ,
1233
1209
cstore : & CrateStoreDyn ,
1234
- forest : & ' hir Forest < ' hir > ,
1210
+ krate : & ' hir Crate < ' hir > ,
1211
+ dep_graph : DepGraph ,
1235
1212
definitions : Definitions ,
1236
1213
) -> Map < ' hir > {
1237
1214
let _prof_timer = sess. prof . generic_activity ( "build_hir_map" ) ;
@@ -1244,31 +1221,18 @@ pub fn map_crate<'hir>(
1244
1221
. collect ( ) ;
1245
1222
1246
1223
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) ;
1258
1229
1259
1230
let crate_disambiguator = sess. local_crate_disambiguator ( ) ;
1260
1231
let cmdline_args = sess. opts . dep_tracking_hash ( ) ;
1261
1232
collector. finalize_and_compute_crate_hash ( crate_disambiguator, cstore, cmdline_args)
1262
1233
} ;
1263
1234
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 } ;
1272
1236
1273
1237
sess. time ( "validate_HIR_map" , || {
1274
1238
hir_id_validator:: check_crate ( & map) ;
0 commit comments