11use crate :: arena:: Arena ;
2- use crate :: dep_graph:: { DepGraph , DepKind , DepNode , DepNodeIndex } ;
32use crate :: hir:: map:: definitions:: { self , DefPathHash } ;
4- use crate :: hir:: map:: { Entry , HirEntryMap , Map } ;
3+ use crate :: hir:: map:: { Entry , Map } ;
54use crate :: hir:: { HirItem , HirOwner , HirOwnerItems } ;
65use crate :: ich:: StableHashingContext ;
76use crate :: middle:: cstore:: CrateStore ;
@@ -35,70 +34,38 @@ pub(super) struct NodeCollector<'a, 'hir> {
3534 owner_map : FxHashMap < DefIndex , & ' hir HirOwner < ' hir > > ,
3635 owner_items_map : FxHashMap < DefIndex , & ' hir mut HirOwnerItems < ' hir > > ,
3736
38- /// The node map
39- map : HirEntryMap < ' hir > ,
4037 /// The parent of this node
4138 parent_node : hir:: HirId ,
4239
43- // These fields keep track of the currently relevant DepNodes during
44- // the visitor's traversal.
4540 current_dep_node_owner : DefIndex ,
46- current_signature_dep_index : DepNodeIndex ,
47- current_full_dep_index : DepNodeIndex ,
48- currently_in_body : bool ,
4941
50- dep_graph : & ' a DepGraph ,
5142 definitions : & ' a definitions:: Definitions ,
5243 hir_to_node_id : & ' a FxHashMap < HirId , NodeId > ,
5344
5445 hcx : StableHashingContext < ' a > ,
5546
5647 // We are collecting `DepNode::HirBody` hashes here so we can compute the
57- // crate hash from then later on.
48+ // crate hash from them later on.
5849 hir_body_nodes : Vec < ( DefPathHash , Fingerprint ) > ,
5950}
6051
61- fn input_dep_node_and_hash (
62- dep_graph : & DepGraph ,
52+ fn hash (
6353 hcx : & mut StableHashingContext < ' _ > ,
64- dep_node : DepNode ,
6554 input : impl for < ' a > HashStable < StableHashingContext < ' a > > ,
66- ) -> ( DepNodeIndex , Fingerprint ) {
67- let dep_node_index = dep_graph. input_task ( dep_node, & mut * hcx, & input) . 1 ;
68-
69- let hash = if dep_graph. is_fully_enabled ( ) {
70- dep_graph. fingerprint_of ( dep_node_index)
71- } else {
72- let mut stable_hasher = StableHasher :: new ( ) ;
73- input. hash_stable ( hcx, & mut stable_hasher) ;
74- stable_hasher. finish ( )
75- } ;
76-
77- ( dep_node_index, hash)
55+ ) -> Fingerprint {
56+ let mut stable_hasher = StableHasher :: new ( ) ;
57+ input. hash_stable ( hcx, & mut stable_hasher) ;
58+ stable_hasher. finish ( )
7859}
7960
80- fn alloc_hir_dep_nodes (
81- dep_graph : & DepGraph ,
61+ fn hash_body (
8262 hcx : & mut StableHashingContext < ' _ > ,
8363 def_path_hash : DefPathHash ,
8464 item_like : impl for < ' a > HashStable < StableHashingContext < ' a > > ,
8565 hir_body_nodes : & mut Vec < ( DefPathHash , Fingerprint ) > ,
86- ) -> ( DepNodeIndex , DepNodeIndex ) {
87- let sig = dep_graph
88- . input_task (
89- DepNode :: from_def_path_hash ( def_path_hash, DepKind :: Hir ) ,
90- & mut * hcx,
91- HirItemLike { item_like : & item_like, hash_bodies : false } ,
92- )
93- . 1 ;
94- let ( full, hash) = input_dep_node_and_hash (
95- dep_graph,
96- hcx,
97- DepNode :: from_def_path_hash ( def_path_hash, DepKind :: HirBody ) ,
98- HirItemLike { item_like : & item_like, hash_bodies : true } ,
99- ) ;
66+ ) {
67+ let hash = hash ( hcx, HirItemLike { item_like : & item_like } ) ;
10068 hir_body_nodes. push ( ( def_path_hash, hash) ) ;
101- ( sig, full)
10269}
10370
10471fn upstream_crates ( cstore : & dyn CrateStore ) -> Vec < ( Symbol , Fingerprint , Svh ) > {
@@ -121,7 +88,6 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
12188 sess : & ' a Session ,
12289 arena : & ' hir Arena < ' hir > ,
12390 krate : & ' hir Crate < ' hir > ,
124- dep_graph : & ' a DepGraph ,
12591 definitions : & ' a definitions:: Definitions ,
12692 hir_to_node_id : & ' a FxHashMap < HirId , NodeId > ,
12793 mut hcx : StableHashingContext < ' a > ,
@@ -130,8 +96,7 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
13096
13197 let mut hir_body_nodes = Vec :: new ( ) ;
13298
133- // Allocate `DepNode`s for the root module.
134- let ( root_mod_sig_dep_index, root_mod_full_dep_index) = {
99+ {
135100 let Crate {
136101 ref item,
137102 // These fields are handled separately:
@@ -146,40 +111,31 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
146111 modules : _,
147112 } = * krate;
148113
149- alloc_hir_dep_nodes (
150- dep_graph,
151- & mut hcx,
152- root_mod_def_path_hash,
153- item,
154- & mut hir_body_nodes,
155- )
114+ hash_body ( & mut hcx, root_mod_def_path_hash, item, & mut hir_body_nodes)
156115 } ;
157116
158117 let mut collector = NodeCollector {
159118 arena,
160119 krate,
161120 source_map : sess. source_map ( ) ,
162- map : IndexVec :: from_elem_n ( IndexVec :: new ( ) , definitions. def_index_count ( ) ) ,
163121 parent_node : hir:: CRATE_HIR_ID ,
164- current_signature_dep_index : root_mod_sig_dep_index,
165- current_full_dep_index : root_mod_full_dep_index,
166122 current_dep_node_owner : CRATE_DEF_INDEX ,
167- currently_in_body : false ,
168- dep_graph,
169123 definitions,
170124 hir_to_node_id,
171125 hcx,
172126 hir_body_nodes,
173- owner_map : FxHashMap :: default ( ) ,
174- owner_items_map : FxHashMap :: default ( ) ,
127+ owner_map : FxHashMap :: with_capacity_and_hasher (
128+ definitions. def_index_count ( ) ,
129+ Default :: default ( ) ,
130+ ) ,
131+ owner_items_map : FxHashMap :: with_capacity_and_hasher (
132+ definitions. def_index_count ( ) ,
133+ Default :: default ( ) ,
134+ ) ,
175135 } ;
176136 collector. insert_entry (
177137 hir:: CRATE_HIR_ID ,
178- Entry {
179- parent : hir:: CRATE_HIR_ID ,
180- dep_node : root_mod_sig_dep_index,
181- node : Node :: Crate ( & krate. item ) ,
182- } ,
138+ Entry { parent : hir:: CRATE_HIR_ID , node : Node :: Crate ( & krate. item ) } ,
183139 ) ;
184140
185141 collector
@@ -191,7 +147,6 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
191147 cstore : & dyn CrateStore ,
192148 commandline_args_hash : u64 ,
193149 ) -> (
194- HirEntryMap < ' hir > ,
195150 FxHashMap < DefIndex , & ' hir HirOwner < ' hir > > ,
196151 FxHashMap < DefIndex , & ' hir mut HirOwnerItems < ' hir > > ,
197152 Svh ,
@@ -238,7 +193,7 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
238193 let crate_hash: Fingerprint = stable_hasher. finish ( ) ;
239194
240195 let svh = Svh :: new ( crate_hash. to_smaller_hash ( ) ) ;
241- ( self . map , self . owner_map , self . owner_items_map , svh)
196+ ( self . owner_map , self . owner_items_map , svh)
242197 }
243198
244199 fn insert_entry ( & mut self , id : HirId , entry : Entry < ' hir > ) {
@@ -265,26 +220,10 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
265220 items. items [ id. local_id ] =
266221 Some ( HirItem { parent : entry. parent . local_id , node : entry. node } ) ;
267222 }
268-
269- debug ! ( "hir_map: {:?} => {:?}" , id, entry) ;
270- let local_map = & mut self . map [ id. owner ] ;
271- let len = local_map. len ( ) ;
272- if i >= len {
273- local_map. extend ( repeat ( None ) . take ( i - len + 1 ) ) ;
274- }
275- local_map[ id. local_id ] = Some ( entry) ;
276223 }
277224
278225 fn insert ( & mut self , span : Span , hir_id : HirId , node : Node < ' hir > ) {
279- let entry = Entry {
280- parent : self . parent_node ,
281- dep_node : if self . currently_in_body {
282- self . current_full_dep_index
283- } else {
284- self . current_signature_dep_index
285- } ,
286- node,
287- } ;
226+ let entry = Entry { parent : self . parent_node , node } ;
288227
289228 // Make sure that the DepNode of some node coincides with the HirId
290229 // owner of that node.
@@ -339,29 +278,14 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
339278 f : F ,
340279 ) {
341280 let prev_owner = self . current_dep_node_owner ;
342- let prev_signature_dep_index = self . current_signature_dep_index ;
343- let prev_full_dep_index = self . current_full_dep_index ;
344- let prev_in_body = self . currently_in_body ;
345281
346282 let def_path_hash = self . definitions . def_path_hash ( dep_node_owner) ;
347283
348- let ( signature_dep_index, full_dep_index) = alloc_hir_dep_nodes (
349- self . dep_graph ,
350- & mut self . hcx ,
351- def_path_hash,
352- item_like,
353- & mut self . hir_body_nodes ,
354- ) ;
355- self . current_signature_dep_index = signature_dep_index;
356- self . current_full_dep_index = full_dep_index;
284+ hash_body ( & mut self . hcx , def_path_hash, item_like, & mut self . hir_body_nodes ) ;
357285
358286 self . current_dep_node_owner = dep_node_owner;
359- self . currently_in_body = false ;
360287 f ( self ) ;
361- self . currently_in_body = prev_in_body;
362288 self . current_dep_node_owner = prev_owner;
363- self . current_full_dep_index = prev_full_dep_index;
364- self . current_signature_dep_index = prev_signature_dep_index;
365289 }
366290}
367291
@@ -390,10 +314,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
390314 }
391315
392316 fn visit_nested_body ( & mut self , id : BodyId ) {
393- let prev_in_body = self . currently_in_body ;
394- self . currently_in_body = true ;
395317 self . visit_body ( self . krate . body ( id) ) ;
396- self . currently_in_body = prev_in_body;
397318 }
398319
399320 fn visit_param ( & mut self , param : & ' hir Param < ' hir > ) {
@@ -616,19 +537,16 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
616537 }
617538}
618539
619- // This is a wrapper structure that allows determining if span values within
620- // the wrapped item should be hashed or not.
621540struct HirItemLike < T > {
622541 item_like : T ,
623- hash_bodies : bool ,
624542}
625543
626544impl < ' hir , T > HashStable < StableHashingContext < ' hir > > for HirItemLike < T >
627545where
628546 T : HashStable < StableHashingContext < ' hir > > ,
629547{
630548 fn hash_stable ( & self , hcx : & mut StableHashingContext < ' hir > , hasher : & mut StableHasher ) {
631- hcx. while_hashing_hir_bodies ( self . hash_bodies , |hcx| {
549+ hcx. while_hashing_hir_bodies ( true , |hcx| {
632550 self . item_like . hash_stable ( hcx, hasher) ;
633551 } ) ;
634552 }
0 commit comments