1
1
use std:: assert_matches:: assert_matches;
2
- use std:: collections:: hash_map:: Entry ;
3
2
use std:: fmt:: Debug ;
4
3
use std:: hash:: Hash ;
5
4
use std:: marker:: PhantomData ;
@@ -10,7 +9,7 @@ use rustc_data_structures::fingerprint::{Fingerprint, PackedFingerprint};
10
9
use rustc_data_structures:: fx:: { FxHashMap , FxHashSet } ;
11
10
use rustc_data_structures:: outline;
12
11
use rustc_data_structures:: profiling:: QueryInvocationId ;
13
- use rustc_data_structures:: sharded:: { self , Sharded } ;
12
+ use rustc_data_structures:: sharded:: { self , ShardedHashMap } ;
14
13
use rustc_data_structures:: stable_hasher:: { HashStable , StableHasher } ;
15
14
use rustc_data_structures:: sync:: { AtomicU64 , Lock } ;
16
15
use rustc_data_structures:: unord:: UnordMap ;
@@ -447,24 +446,9 @@ impl<D: Deps> DepGraphData<D> {
447
446
// As anonymous nodes are a small quantity compared to the full dep-graph, the
448
447
// memory impact of this `anon_node_to_index` map remains tolerable, and helps
449
448
// us avoid useless growth of the graph with almost-equivalent nodes.
450
- match self
451
- . current
452
- . anon_node_to_index
453
- . get_shard_by_value ( & target_dep_node)
454
- . lock ( )
455
- . entry ( target_dep_node)
456
- {
457
- Entry :: Occupied ( entry) => * entry. get ( ) ,
458
- Entry :: Vacant ( entry) => {
459
- let dep_node_index = self . current . intern_new_node (
460
- target_dep_node,
461
- task_deps,
462
- Fingerprint :: ZERO ,
463
- ) ;
464
- entry. insert ( dep_node_index) ;
465
- dep_node_index
466
- }
467
- }
449
+ self . current . anon_node_to_index . get_or_insert_with ( target_dep_node, || {
450
+ self . current . intern_new_node ( target_dep_node, task_deps, Fingerprint :: ZERO )
451
+ } )
468
452
}
469
453
} ;
470
454
@@ -1123,7 +1107,7 @@ rustc_index::newtype_index! {
1123
1107
pub ( super ) struct CurrentDepGraph < D : Deps > {
1124
1108
encoder : GraphEncoder < D > ,
1125
1109
prev_index_to_index : Lock < IndexVec < SerializedDepNodeIndex , Option < DepNodeIndex > > > ,
1126
- anon_node_to_index : Sharded < FxHashMap < DepNode , DepNodeIndex > > ,
1110
+ anon_node_to_index : ShardedHashMap < DepNode , DepNodeIndex > ,
1127
1111
1128
1112
/// This is used to verify that fingerprints do not change between the creation of a node
1129
1113
/// and its recomputation.
@@ -1202,13 +1186,10 @@ impl<D: Deps> CurrentDepGraph<D> {
1202
1186
& session. prof ,
1203
1187
previous,
1204
1188
) ,
1205
- anon_node_to_index : Sharded :: new ( || {
1206
- FxHashMap :: with_capacity_and_hasher (
1207
- // FIXME: The count estimate is off as anon nodes are only a portion of the nodes.
1208
- new_node_count_estimate / sharded:: shards ( ) ,
1209
- Default :: default ( ) ,
1210
- )
1211
- } ) ,
1189
+ anon_node_to_index : ShardedHashMap :: with_capacity (
1190
+ // FIXME: The count estimate is off as anon nodes are only a portion of the nodes.
1191
+ new_node_count_estimate / sharded:: shards ( ) ,
1192
+ ) ,
1212
1193
prev_index_to_index : Lock :: new ( IndexVec :: from_elem_n ( None , prev_graph_node_count) ) ,
1213
1194
anon_id_seed,
1214
1195
#[ cfg( debug_assertions) ]
0 commit comments