1
1
use crate :: arena:: Arena ;
2
- use crate :: dep_graph:: { DepGraph , DepKind , DepNode , DepNodeIndex } ;
3
2
use crate :: hir:: map:: definitions:: { self , DefPathHash } ;
4
- use crate :: hir:: map:: { Entry , HirEntryMap , Map } ;
3
+ use crate :: hir:: map:: { Entry , Map } ;
5
4
use crate :: hir:: { HirItem , HirOwner , HirOwnerItems } ;
6
5
use crate :: ich:: StableHashingContext ;
7
6
use crate :: middle:: cstore:: CrateStore ;
@@ -35,70 +34,38 @@ pub(super) struct NodeCollector<'a, 'hir> {
35
34
owner_map : FxHashMap < DefIndex , & ' hir HirOwner < ' hir > > ,
36
35
owner_items_map : FxHashMap < DefIndex , & ' hir mut HirOwnerItems < ' hir > > ,
37
36
38
- /// The node map
39
- map : HirEntryMap < ' hir > ,
40
37
/// The parent of this node
41
38
parent_node : hir:: HirId ,
42
39
43
- // These fields keep track of the currently relevant DepNodes during
44
- // the visitor's traversal.
45
40
current_dep_node_owner : DefIndex ,
46
- current_signature_dep_index : DepNodeIndex ,
47
- current_full_dep_index : DepNodeIndex ,
48
- currently_in_body : bool ,
49
41
50
- dep_graph : & ' a DepGraph ,
51
42
definitions : & ' a definitions:: Definitions ,
52
43
hir_to_node_id : & ' a FxHashMap < HirId , NodeId > ,
53
44
54
45
hcx : StableHashingContext < ' a > ,
55
46
56
47
// 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.
58
49
hir_body_nodes : Vec < ( DefPathHash , Fingerprint ) > ,
59
50
}
60
51
61
- fn input_dep_node_and_hash (
62
- dep_graph : & DepGraph ,
52
+ fn hash (
63
53
hcx : & mut StableHashingContext < ' _ > ,
64
- dep_node : DepNode ,
65
54
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 ( )
78
59
}
79
60
80
- fn alloc_hir_dep_nodes (
81
- dep_graph : & DepGraph ,
61
+ fn hash_body (
82
62
hcx : & mut StableHashingContext < ' _ > ,
83
63
def_path_hash : DefPathHash ,
84
64
item_like : impl for < ' a > HashStable < StableHashingContext < ' a > > ,
85
65
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 } ) ;
100
68
hir_body_nodes. push ( ( def_path_hash, hash) ) ;
101
- ( sig, full)
102
69
}
103
70
104
71
fn upstream_crates ( cstore : & dyn CrateStore ) -> Vec < ( Symbol , Fingerprint , Svh ) > {
@@ -121,7 +88,6 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
121
88
sess : & ' a Session ,
122
89
arena : & ' hir Arena < ' hir > ,
123
90
krate : & ' hir Crate < ' hir > ,
124
- dep_graph : & ' a DepGraph ,
125
91
definitions : & ' a definitions:: Definitions ,
126
92
hir_to_node_id : & ' a FxHashMap < HirId , NodeId > ,
127
93
mut hcx : StableHashingContext < ' a > ,
@@ -130,8 +96,7 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
130
96
131
97
let mut hir_body_nodes = Vec :: new ( ) ;
132
98
133
- // Allocate `DepNode`s for the root module.
134
- let ( root_mod_sig_dep_index, root_mod_full_dep_index) = {
99
+ {
135
100
let Crate {
136
101
ref item,
137
102
// These fields are handled separately:
@@ -147,40 +112,31 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
147
112
proc_macros : _,
148
113
} = * krate;
149
114
150
- alloc_hir_dep_nodes (
151
- dep_graph,
152
- & mut hcx,
153
- root_mod_def_path_hash,
154
- item,
155
- & mut hir_body_nodes,
156
- )
115
+ hash_body ( & mut hcx, root_mod_def_path_hash, item, & mut hir_body_nodes)
157
116
} ;
158
117
159
118
let mut collector = NodeCollector {
160
119
arena,
161
120
krate,
162
121
source_map : sess. source_map ( ) ,
163
- map : IndexVec :: from_elem_n ( IndexVec :: new ( ) , definitions. def_index_count ( ) ) ,
164
122
parent_node : hir:: CRATE_HIR_ID ,
165
- current_signature_dep_index : root_mod_sig_dep_index,
166
- current_full_dep_index : root_mod_full_dep_index,
167
123
current_dep_node_owner : CRATE_DEF_INDEX ,
168
- currently_in_body : false ,
169
- dep_graph,
170
124
definitions,
171
125
hir_to_node_id,
172
126
hcx,
173
127
hir_body_nodes,
174
- owner_map : FxHashMap :: default ( ) ,
175
- owner_items_map : FxHashMap :: default ( ) ,
128
+ owner_map : FxHashMap :: with_capacity_and_hasher (
129
+ definitions. def_index_count ( ) ,
130
+ Default :: default ( ) ,
131
+ ) ,
132
+ owner_items_map : FxHashMap :: with_capacity_and_hasher (
133
+ definitions. def_index_count ( ) ,
134
+ Default :: default ( ) ,
135
+ ) ,
176
136
} ;
177
137
collector. insert_entry (
178
138
hir:: CRATE_HIR_ID ,
179
- Entry {
180
- parent : hir:: CRATE_HIR_ID ,
181
- dep_node : root_mod_sig_dep_index,
182
- node : Node :: Crate ( & krate. item ) ,
183
- } ,
139
+ Entry { parent : hir:: CRATE_HIR_ID , node : Node :: Crate ( & krate. item ) } ,
184
140
) ;
185
141
186
142
collector
@@ -192,7 +148,6 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
192
148
cstore : & dyn CrateStore ,
193
149
commandline_args_hash : u64 ,
194
150
) -> (
195
- HirEntryMap < ' hir > ,
196
151
FxHashMap < DefIndex , & ' hir HirOwner < ' hir > > ,
197
152
FxHashMap < DefIndex , & ' hir mut HirOwnerItems < ' hir > > ,
198
153
Svh ,
@@ -239,7 +194,7 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
239
194
let crate_hash: Fingerprint = stable_hasher. finish ( ) ;
240
195
241
196
let svh = Svh :: new ( crate_hash. to_smaller_hash ( ) ) ;
242
- ( self . map , self . owner_map , self . owner_items_map , svh)
197
+ ( self . owner_map , self . owner_items_map , svh)
243
198
}
244
199
245
200
fn insert_entry ( & mut self , id : HirId , entry : Entry < ' hir > ) {
@@ -266,26 +221,10 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
266
221
items. items [ id. local_id ] =
267
222
Some ( HirItem { parent : entry. parent . local_id , node : entry. node } ) ;
268
223
}
269
-
270
- debug ! ( "hir_map: {:?} => {:?}" , id, entry) ;
271
- let local_map = & mut self . map [ id. owner ] ;
272
- let len = local_map. len ( ) ;
273
- if i >= len {
274
- local_map. extend ( repeat ( None ) . take ( i - len + 1 ) ) ;
275
- }
276
- local_map[ id. local_id ] = Some ( entry) ;
277
224
}
278
225
279
226
fn insert ( & mut self , span : Span , hir_id : HirId , node : Node < ' hir > ) {
280
- let entry = Entry {
281
- parent : self . parent_node ,
282
- dep_node : if self . currently_in_body {
283
- self . current_full_dep_index
284
- } else {
285
- self . current_signature_dep_index
286
- } ,
287
- node,
288
- } ;
227
+ let entry = Entry { parent : self . parent_node , node } ;
289
228
290
229
// Make sure that the DepNode of some node coincides with the HirId
291
230
// owner of that node.
@@ -340,29 +279,14 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
340
279
f : F ,
341
280
) {
342
281
let prev_owner = self . current_dep_node_owner ;
343
- let prev_signature_dep_index = self . current_signature_dep_index ;
344
- let prev_full_dep_index = self . current_full_dep_index ;
345
- let prev_in_body = self . currently_in_body ;
346
282
347
283
let def_path_hash = self . definitions . def_path_hash ( dep_node_owner) ;
348
284
349
- let ( signature_dep_index, full_dep_index) = alloc_hir_dep_nodes (
350
- self . dep_graph ,
351
- & mut self . hcx ,
352
- def_path_hash,
353
- item_like,
354
- & mut self . hir_body_nodes ,
355
- ) ;
356
- self . current_signature_dep_index = signature_dep_index;
357
- self . current_full_dep_index = full_dep_index;
285
+ hash_body ( & mut self . hcx , def_path_hash, item_like, & mut self . hir_body_nodes ) ;
358
286
359
287
self . current_dep_node_owner = dep_node_owner;
360
- self . currently_in_body = false ;
361
288
f ( self ) ;
362
- self . currently_in_body = prev_in_body;
363
289
self . current_dep_node_owner = prev_owner;
364
- self . current_full_dep_index = prev_full_dep_index;
365
- self . current_signature_dep_index = prev_signature_dep_index;
366
290
}
367
291
}
368
292
@@ -391,10 +315,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
391
315
}
392
316
393
317
fn visit_nested_body ( & mut self , id : BodyId ) {
394
- let prev_in_body = self . currently_in_body ;
395
- self . currently_in_body = true ;
396
318
self . visit_body ( self . krate . body ( id) ) ;
397
- self . currently_in_body = prev_in_body;
398
319
}
399
320
400
321
fn visit_param ( & mut self , param : & ' hir Param < ' hir > ) {
@@ -617,19 +538,16 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
617
538
}
618
539
}
619
540
620
- // This is a wrapper structure that allows determining if span values within
621
- // the wrapped item should be hashed or not.
622
541
struct HirItemLike < T > {
623
542
item_like : T ,
624
- hash_bodies : bool ,
625
543
}
626
544
627
545
impl < ' hir , T > HashStable < StableHashingContext < ' hir > > for HirItemLike < T >
628
546
where
629
547
T : HashStable < StableHashingContext < ' hir > > ,
630
548
{
631
549
fn hash_stable ( & self , hcx : & mut StableHashingContext < ' hir > , hasher : & mut StableHasher ) {
632
- hcx. while_hashing_hir_bodies ( self . hash_bodies , |hcx| {
550
+ hcx. while_hashing_hir_bodies ( true , |hcx| {
633
551
self . item_like . hash_stable ( hcx, hasher) ;
634
552
} ) ;
635
553
}
0 commit comments