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;
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 ;
@@ -449,24 +448,9 @@ impl<D: Deps> DepGraphData<D> {
449
448
// As anonymous nodes are a small quantity compared to the full dep-graph, the
450
449
// memory impact of this `anon_node_to_index` map remains tolerable, and helps
451
450
// us avoid useless growth of the graph with almost-equivalent nodes.
452
- match self
453
- . current
454
- . anon_node_to_index
455
- . get_shard_by_value ( & target_dep_node)
456
- . lock ( )
457
- . entry ( target_dep_node)
458
- {
459
- Entry :: Occupied ( entry) => * entry. get ( ) ,
460
- Entry :: Vacant ( entry) => {
461
- let dep_node_index = self . current . intern_new_node (
462
- target_dep_node,
463
- task_deps,
464
- Fingerprint :: ZERO ,
465
- ) ;
466
- entry. insert ( dep_node_index) ;
467
- dep_node_index
468
- }
469
- }
451
+ self . current . anon_node_to_index . get_or_insert_with ( target_dep_node, || {
452
+ self . current . intern_new_node ( target_dep_node, task_deps, Fingerprint :: ZERO )
453
+ } )
470
454
}
471
455
} ;
472
456
@@ -1085,7 +1069,7 @@ rustc_index::newtype_index! {
1085
1069
pub ( super ) struct CurrentDepGraph < D : Deps > {
1086
1070
encoder : GraphEncoder < D > ,
1087
1071
prev_index_to_index : Lock < IndexVec < SerializedDepNodeIndex , Option < DepNodeIndex > > > ,
1088
- anon_node_to_index : Sharded < FxHashMap < DepNode , DepNodeIndex > > ,
1072
+ anon_node_to_index : ShardedHashMap < DepNode , DepNodeIndex > ,
1089
1073
1090
1074
/// This is used to verify that fingerprints do not change between the creation of a node
1091
1075
/// and its recomputation.
@@ -1164,13 +1148,10 @@ impl<D: Deps> CurrentDepGraph<D> {
1164
1148
& session. prof ,
1165
1149
previous,
1166
1150
) ,
1167
- anon_node_to_index : Sharded :: new ( || {
1168
- FxHashMap :: with_capacity_and_hasher (
1169
- // FIXME: The count estimate is off as anon nodes are only a portion of the nodes.
1170
- new_node_count_estimate / sharded:: shards ( ) ,
1171
- Default :: default ( ) ,
1172
- )
1173
- } ) ,
1151
+ anon_node_to_index : ShardedHashMap :: with_capacity (
1152
+ // FIXME: The count estimate is off as anon nodes are only a portion of the nodes.
1153
+ new_node_count_estimate / sharded:: shards ( ) ,
1154
+ ) ,
1174
1155
prev_index_to_index : Lock :: new ( IndexVec :: from_elem_n ( None , prev_graph_node_count) ) ,
1175
1156
anon_id_seed,
1176
1157
#[ cfg( debug_assertions) ]
0 commit comments