Skip to content

Commit 58c148a

Browse files
committed
Use ShardedHashMap for anon_node_to_index
1 parent 129f39c commit 58c148a

File tree

1 file changed

+9
-28
lines changed
  • compiler/rustc_query_system/src/dep_graph

1 file changed

+9
-28
lines changed

compiler/rustc_query_system/src/dep_graph/graph.rs

+9-28
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use std::assert_matches::assert_matches;
2-
use std::collections::hash_map::Entry;
32
use std::fmt::Debug;
43
use std::hash::Hash;
54
use std::marker::PhantomData;
@@ -10,7 +9,7 @@ use rustc_data_structures::fingerprint::{Fingerprint, PackedFingerprint};
109
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
1110
use rustc_data_structures::outline;
1211
use rustc_data_structures::profiling::QueryInvocationId;
13-
use rustc_data_structures::sharded::{self, Sharded};
12+
use rustc_data_structures::sharded::{self, ShardedHashMap};
1413
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
1514
use rustc_data_structures::sync::{AtomicU64, Lock};
1615
use rustc_data_structures::unord::UnordMap;
@@ -447,24 +446,9 @@ impl<D: Deps> DepGraphData<D> {
447446
// As anonymous nodes are a small quantity compared to the full dep-graph, the
448447
// memory impact of this `anon_node_to_index` map remains tolerable, and helps
449448
// 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+
})
468452
}
469453
};
470454

@@ -1123,7 +1107,7 @@ rustc_index::newtype_index! {
11231107
pub(super) struct CurrentDepGraph<D: Deps> {
11241108
encoder: GraphEncoder<D>,
11251109
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>,
11271111

11281112
/// This is used to verify that fingerprints do not change between the creation of a node
11291113
/// and its recomputation.
@@ -1202,13 +1186,10 @@ impl<D: Deps> CurrentDepGraph<D> {
12021186
&session.prof,
12031187
previous,
12041188
),
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+
),
12121193
prev_index_to_index: Lock::new(IndexVec::from_elem_n(None, prev_graph_node_count)),
12131194
anon_id_seed,
12141195
#[cfg(debug_assertions)]

0 commit comments

Comments
 (0)