11use std:: assert_matches:: assert_matches;
2- use std:: collections:: hash_map:: Entry ;
32use std:: fmt:: Debug ;
43use std:: hash:: Hash ;
54use std:: marker:: PhantomData ;
@@ -10,7 +9,7 @@ use rustc_data_structures::fingerprint::Fingerprint;
109use rustc_data_structures:: fx:: { FxHashMap , FxHashSet } ;
1110use rustc_data_structures:: outline;
1211use rustc_data_structures:: profiling:: QueryInvocationId ;
13- use rustc_data_structures:: sharded:: { self , Sharded } ;
12+ use rustc_data_structures:: sharded:: { self , ShardedHashMap } ;
1413use rustc_data_structures:: stable_hasher:: { HashStable , StableHasher } ;
1514use rustc_data_structures:: sync:: { AtomicU64 , Lock } ;
1615use rustc_data_structures:: unord:: UnordMap ;
@@ -449,24 +448,9 @@ impl<D: Deps> DepGraphData<D> {
449448 // As anonymous nodes are a small quantity compared to the full dep-graph, the
450449 // memory impact of this `anon_node_to_index` map remains tolerable, and helps
451450 // 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+ } )
470454 }
471455 } ;
472456
@@ -1085,7 +1069,7 @@ rustc_index::newtype_index! {
10851069pub ( super ) struct CurrentDepGraph < D : Deps > {
10861070 encoder : GraphEncoder < D > ,
10871071 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 > ,
10891073
10901074 /// This is used to verify that fingerprints do not change between the creation of a node
10911075 /// and its recomputation.
@@ -1164,13 +1148,10 @@ impl<D: Deps> CurrentDepGraph<D> {
11641148 & session. prof ,
11651149 previous,
11661150 ) ,
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+ ) ,
11741155 prev_index_to_index : Lock :: new ( IndexVec :: from_elem_n ( None , prev_graph_node_count) ) ,
11751156 anon_id_seed,
11761157 #[ cfg( debug_assertions) ]
0 commit comments