@@ -3,16 +3,14 @@ pub use self::definitions::{
33 DefKey , DefPath , DefPathData , DefPathHash , Definitions , DisambiguatedDefPathData ,
44} ;
55
6- use crate :: arena:: Arena ;
76use crate :: hir:: { HirOwner , HirOwnerItems } ;
8- use crate :: middle:: cstore:: CrateStoreDyn ;
97use crate :: ty:: query:: Providers ;
108use crate :: ty:: TyCtxt ;
119use rustc_ast:: ast:: { self , Name , NodeId } ;
1210use rustc_data_structures:: fx:: FxHashMap ;
1311use rustc_data_structures:: svh:: Svh ;
1412use rustc_hir:: def:: { DefKind , Res } ;
15- use rustc_hir:: def_id:: { DefId , DefIndex , LocalDefId , LOCAL_CRATE } ;
13+ use rustc_hir:: def_id:: { CrateNum , DefId , DefIndex , LocalDefId , LOCAL_CRATE } ;
1614use rustc_hir:: intravisit;
1715use rustc_hir:: itemlikevisit:: ItemLikeVisitor ;
1816use rustc_hir:: print:: Nested ;
@@ -129,38 +127,20 @@ fn is_body_owner<'hir>(node: Node<'hir>, hir_id: HirId) -> bool {
129127 }
130128}
131129
132- /// Represents a mapping from `NodeId`s to AST elements and their parent `NodeId`s.
133- pub struct EarlyMap < ' hir > {
134- pub krate : & ' hir Crate < ' hir > ,
135-
130+ pub struct IndexedHir < ' hir > {
136131 /// The SVH of the local crate.
137132 pub crate_hash : Svh ,
138133
139134 pub ( super ) owner_map : FxHashMap < DefIndex , & ' hir HirOwner < ' hir > > ,
140135 pub ( super ) owner_items_map : FxHashMap < DefIndex , & ' hir HirOwnerItems < ' hir > > ,
141136
142- pub ( crate ) definitions : & ' hir Definitions ,
143-
144137 /// The reverse mapping of `node_to_hir_id`.
145138 pub ( super ) hir_to_node_id : FxHashMap < HirId , NodeId > ,
146139}
147140
148- /// Represents a mapping from `NodeId`s to AST elements and their parent `NodeId`s.
141+ # [ derive ( Copy , Clone ) ]
149142pub struct Map < ' hir > {
150143 pub ( super ) tcx : TyCtxt < ' hir > ,
151-
152- pub ( super ) krate : & ' hir Crate < ' hir > ,
153-
154- /// The SVH of the local crate.
155- pub crate_hash : Svh ,
156-
157- pub ( super ) owner_map : FxHashMap < DefIndex , & ' hir HirOwner < ' hir > > ,
158- pub ( super ) owner_items_map : FxHashMap < DefIndex , & ' hir HirOwnerItems < ' hir > > ,
159-
160- pub ( super ) definitions : & ' hir Definitions ,
161-
162- /// The reverse mapping of `node_to_hir_id`.
163- pub ( super ) hir_to_node_id : FxHashMap < HirId , NodeId > ,
164144}
165145
166146/// An iterator that walks up the ancestor tree of a given `HirId`.
@@ -196,21 +176,18 @@ impl<'hir> Iterator for ParentHirIterator<'_, 'hir> {
196176}
197177
198178impl < ' hir > Map < ' hir > {
199- /// This is used internally in the dependency tracking system.
200- /// Use the `krate` method to ensure your dependency on the
201- /// crate is tracked.
202- pub fn untracked_krate ( & self ) -> & Crate < ' hir > {
203- & self . krate
179+ pub fn krate ( & self ) -> & ' hir Crate < ' hir > {
180+ self . tcx . hir_crate ( LOCAL_CRATE )
204181 }
205182
206183 #[ inline]
207- pub fn definitions ( & self ) -> & Definitions {
208- & self . definitions
184+ pub fn definitions ( & self ) -> & ' hir Definitions {
185+ & self . tcx . definitions
209186 }
210187
211188 pub fn def_key ( & self , def_id : DefId ) -> DefKey {
212189 assert ! ( def_id. is_local( ) ) ;
213- self . definitions . def_key ( def_id. index )
190+ self . tcx . definitions . def_key ( def_id. index )
214191 }
215192
216193 pub fn def_path_from_hir_id ( & self , id : HirId ) -> Option < DefPath > {
@@ -219,7 +196,7 @@ impl<'hir> Map<'hir> {
219196
220197 pub fn def_path ( & self , def_id : DefId ) -> DefPath {
221198 assert ! ( def_id. is_local( ) ) ;
222- self . definitions . def_path ( def_id. index )
199+ self . tcx . definitions . def_path ( def_id. index )
223200 }
224201
225202 #[ inline]
@@ -248,42 +225,42 @@ impl<'hir> Map<'hir> {
248225 #[ inline]
249226 pub fn opt_local_def_id ( & self , hir_id : HirId ) -> Option < DefId > {
250227 let node_id = self . hir_to_node_id ( hir_id) ;
251- self . definitions . opt_local_def_id ( node_id)
228+ self . tcx . definitions . opt_local_def_id ( node_id)
252229 }
253230
254231 #[ inline]
255232 pub fn opt_local_def_id_from_node_id ( & self , node : NodeId ) -> Option < DefId > {
256- self . definitions . opt_local_def_id ( node)
233+ self . tcx . definitions . opt_local_def_id ( node)
257234 }
258235
259236 #[ inline]
260237 pub fn as_local_node_id ( & self , def_id : DefId ) -> Option < NodeId > {
261- self . definitions . as_local_node_id ( def_id)
238+ self . tcx . definitions . as_local_node_id ( def_id)
262239 }
263240
264241 #[ inline]
265242 pub fn as_local_hir_id ( & self , def_id : DefId ) -> Option < HirId > {
266- self . definitions . as_local_hir_id ( def_id)
243+ self . tcx . definitions . as_local_hir_id ( def_id)
267244 }
268245
269246 #[ inline]
270247 pub fn hir_to_node_id ( & self , hir_id : HirId ) -> NodeId {
271- self . hir_to_node_id [ & hir_id]
248+ self . tcx . index_hir ( LOCAL_CRATE ) . hir_to_node_id [ & hir_id]
272249 }
273250
274251 #[ inline]
275252 pub fn node_to_hir_id ( & self , node_id : NodeId ) -> HirId {
276- self . definitions . node_to_hir_id ( node_id)
253+ self . tcx . definitions . node_to_hir_id ( node_id)
277254 }
278255
279256 #[ inline]
280257 pub fn def_index_to_hir_id ( & self , def_index : DefIndex ) -> HirId {
281- self . definitions . def_index_to_hir_id ( def_index)
258+ self . tcx . definitions . def_index_to_hir_id ( def_index)
282259 }
283260
284261 #[ inline]
285262 pub fn local_def_id_to_hir_id ( & self , def_id : LocalDefId ) -> HirId {
286- self . definitions . def_index_to_hir_id ( def_id. to_def_id ( ) . index )
263+ self . tcx . definitions . def_index_to_hir_id ( def_id. to_def_id ( ) . index )
287264 }
288265
289266 pub fn def_kind ( & self , hir_id : HirId ) -> Option < DefKind > {
@@ -1045,45 +1022,42 @@ impl Named for ImplItem<'_> {
10451022 }
10461023}
10471024
1048- pub fn map_crate < ' hir > (
1049- sess : & rustc_session:: Session ,
1050- arena : & ' hir Arena < ' hir > ,
1051- cstore : & CrateStoreDyn ,
1052- krate : & ' hir Crate < ' hir > ,
1053- definitions : Definitions ,
1054- ) -> EarlyMap < ' hir > {
1055- let _prof_timer = sess. prof . generic_activity ( "build_hir_map" ) ;
1025+ pub ( super ) fn index_hir < ' tcx > ( tcx : TyCtxt < ' tcx > , cnum : CrateNum ) -> & ' tcx IndexedHir < ' tcx > {
1026+ assert_eq ! ( cnum, LOCAL_CRATE ) ;
1027+
1028+ let _prof_timer = tcx. sess . prof . generic_activity ( "build_hir_map" ) ;
10561029
10571030 // Build the reverse mapping of `node_to_hir_id`.
1058- let hir_to_node_id = definitions
1031+ let hir_to_node_id = tcx
1032+ . definitions
10591033 . node_to_hir_id
10601034 . iter_enumerated ( )
10611035 . map ( |( node_id, & hir_id) | ( hir_id, node_id) )
10621036 . collect ( ) ;
10631037
10641038 let ( owner_map, owner_items_map, crate_hash) = {
1065- let hcx = crate :: ich:: StableHashingContext :: new ( sess, krate, & definitions, cstore) ;
1066-
1067- let mut collector =
1068- NodeCollector :: root ( sess, arena, krate, & definitions, & hir_to_node_id, hcx) ;
1069- intravisit:: walk_crate ( & mut collector, krate) ;
1070-
1071- let crate_disambiguator = sess. local_crate_disambiguator ( ) ;
1072- let cmdline_args = sess. opts . dep_tracking_hash ( ) ;
1073- collector. finalize_and_compute_crate_hash ( crate_disambiguator, cstore, cmdline_args)
1039+ let hcx = tcx. create_stable_hashing_context ( ) ;
1040+
1041+ let mut collector = NodeCollector :: root (
1042+ tcx. sess ,
1043+ & * * tcx. arena ,
1044+ tcx. untracked_crate ,
1045+ & tcx. definitions ,
1046+ & hir_to_node_id,
1047+ hcx,
1048+ ) ;
1049+ intravisit:: walk_crate ( & mut collector, tcx. untracked_crate ) ;
1050+
1051+ let crate_disambiguator = tcx. sess . local_crate_disambiguator ( ) ;
1052+ let cmdline_args = tcx. sess . opts . dep_tracking_hash ( ) ;
1053+ collector. finalize_and_compute_crate_hash ( crate_disambiguator, & * tcx. cstore , cmdline_args)
10741054 } ;
10751055
1076- let map = EarlyMap {
1077- krate,
1056+ let map = tcx. arena . alloc ( IndexedHir {
10781057 crate_hash,
10791058 owner_map,
10801059 owner_items_map : owner_items_map. into_iter ( ) . map ( |( k, v) | ( k, & * v) ) . collect ( ) ,
10811060 hir_to_node_id,
1082- definitions : arena. alloc ( definitions) ,
1083- } ;
1084-
1085- sess. time ( "validate_HIR_map" , || {
1086- hir_id_validator:: check_crate ( & map, sess) ;
10871061 } ) ;
10881062
10891063 map
0 commit comments