Skip to content

Commit 8c5bc99

Browse files
committed
Store a index per dep node kind
1 parent 366dab1 commit 8c5bc99

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

compiler/rustc_query_system/src/dep_graph/serialized.rs

+14-7
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ use rustc_data_structures::sync::Lock;
4646
use rustc_index::{Idx, IndexVec};
4747
use rustc_serialize::opaque::{FileEncodeResult, FileEncoder, IntEncodedWithFixedSize, MemDecoder};
4848
use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
49+
use std::iter;
4950
use std::marker::PhantomData;
5051

5152
// The maximum value of `SerializedDepNodeIndex` leaves the upper two bits
@@ -81,8 +82,9 @@ pub struct SerializedDepGraph<K: DepKind> {
8182
/// A flattened list of all edge targets in the graph, stored in the same
8283
/// varint encoding that we use on disk. Edge sources are implicit in edge_list_indices.
8384
edge_list_data: Vec<u8>,
84-
/// Reciprocal map to `nodes`.
85-
index: FxHashMap<DepNode<K>, SerializedDepNodeIndex>,
85+
/// Stores a map from fingerprints to nodes per dep node kind.
86+
/// This is the reciprocal of `nodes`.
87+
index: Vec<FxHashMap<PackedFingerprint, SerializedDepNodeIndex>>,
8688
}
8789

8890
impl<K: DepKind> Default for SerializedDepGraph<K> {
@@ -137,7 +139,7 @@ impl<K: DepKind> SerializedDepGraph<K> {
137139

138140
#[inline]
139141
pub fn node_to_index_opt(&self, dep_node: &DepNode<K>) -> Option<SerializedDepNodeIndex> {
140-
self.index.get(dep_node).cloned()
142+
self.index.get(dep_node.kind.to_u16() as usize)?.get(&dep_node.hash).cloned()
141143
}
142144

143145
#[inline]
@@ -147,7 +149,7 @@ impl<K: DepKind> SerializedDepGraph<K> {
147149

148150
#[inline]
149151
pub fn node_count(&self) -> usize {
150-
self.index.len()
152+
self.nodes.len()
151153
}
152154
}
153155

@@ -220,7 +222,8 @@ impl<'a, K: DepKind + Decodable<MemDecoder<'a>>> Decodable<MemDecoder<'a>>
220222
for _index in 0..node_count {
221223
// Decode the header for this edge; the header packs together as many of the fixed-size
222224
// fields as possible to limit the number of times we update decoder state.
223-
let node_header = SerializedNodeHeader { bytes: d.read_array(), _marker: PhantomData };
225+
let node_header =
226+
SerializedNodeHeader::<K> { bytes: d.read_array(), _marker: PhantomData };
224227

225228
let _i: SerializedDepNodeIndex = nodes.push(node_header.node());
226229
debug_assert_eq!(_i.index(), _index);
@@ -251,8 +254,12 @@ impl<'a, K: DepKind + Decodable<MemDecoder<'a>>> Decodable<MemDecoder<'a>>
251254
// end of the array. This padding ensure it doesn't.
252255
edge_list_data.extend(&[0u8; DEP_NODE_PAD]);
253256

254-
let index: FxHashMap<_, _> =
255-
nodes.iter_enumerated().map(|(idx, &dep_node)| (dep_node, idx)).collect();
257+
let mut index: Vec<_> =
258+
iter::repeat(FxHashMap::default()).take(K::MAX as usize + 1).collect();
259+
260+
for (idx, node) in nodes.iter_enumerated() {
261+
index[node.kind.to_u16() as usize].insert(node.hash, idx);
262+
}
256263

257264
SerializedDepGraph { nodes, fingerprints, edge_list_indices, edge_list_data, index }
258265
}

0 commit comments

Comments
 (0)