Convert SerializedDepGraph to be a struct-of-arrays

Fixes #47326
This commit is contained in:
Wesley Wiser 2018-03-15 18:56:20 -04:00
parent 5508b27145
commit c43b1a09e0
5 changed files with 20 additions and 10 deletions

View File

@ -476,10 +476,8 @@ impl DepGraph {
fingerprints.resize(current_dep_graph.nodes.len(), Fingerprint::ZERO); fingerprints.resize(current_dep_graph.nodes.len(), Fingerprint::ZERO);
} }
let nodes: IndexVec<_, (DepNode, Fingerprint)> = let fingerprints = fingerprints.clone().convert_index_type();
current_dep_graph.nodes.iter_enumerated().map(|(idx, &dep_node)| { let nodes = current_dep_graph.nodes.clone().convert_index_type();
(dep_node, fingerprints[idx])
}).collect();
let total_edge_count: usize = current_dep_graph.edges.iter() let total_edge_count: usize = current_dep_graph.edges.iter()
.map(|v| v.len()) .map(|v| v.len())
@ -503,6 +501,7 @@ impl DepGraph {
SerializedDepGraph { SerializedDepGraph {
nodes, nodes,
fingerprints,
edge_list_indices, edge_list_indices,
edge_list_data, edge_list_data,
} }

View File

@ -23,7 +23,7 @@ impl PreviousDepGraph {
pub fn new(data: SerializedDepGraph) -> PreviousDepGraph { pub fn new(data: SerializedDepGraph) -> PreviousDepGraph {
let index: FxHashMap<_, _> = data.nodes let index: FxHashMap<_, _> = data.nodes
.iter_enumerated() .iter_enumerated()
.map(|(idx, &(dep_node, _))| (dep_node, idx)) .map(|(idx, &dep_node)| (dep_node, idx))
.collect(); .collect();
PreviousDepGraph { data, index } PreviousDepGraph { data, index }
} }
@ -41,7 +41,7 @@ impl PreviousDepGraph {
#[inline] #[inline]
pub fn index_to_node(&self, dep_node_index: SerializedDepNodeIndex) -> DepNode { pub fn index_to_node(&self, dep_node_index: SerializedDepNodeIndex) -> DepNode {
self.data.nodes[dep_node_index].0 self.data.nodes[dep_node_index]
} }
#[inline] #[inline]
@ -58,14 +58,14 @@ impl PreviousDepGraph {
pub fn fingerprint_of(&self, dep_node: &DepNode) -> Option<Fingerprint> { pub fn fingerprint_of(&self, dep_node: &DepNode) -> Option<Fingerprint> {
self.index self.index
.get(dep_node) .get(dep_node)
.map(|&node_index| self.data.nodes[node_index].1) .map(|&node_index| self.data.fingerprints[node_index])
} }
#[inline] #[inline]
pub fn fingerprint_by_index(&self, pub fn fingerprint_by_index(&self,
dep_node_index: SerializedDepNodeIndex) dep_node_index: SerializedDepNodeIndex)
-> Fingerprint { -> Fingerprint {
self.data.nodes[dep_node_index].1 self.data.fingerprints[dep_node_index]
} }
pub fn node_count(&self) -> usize { pub fn node_count(&self) -> usize {

View File

@ -20,7 +20,10 @@ newtype_index!(SerializedDepNodeIndex);
#[derive(Debug, RustcEncodable, RustcDecodable)] #[derive(Debug, RustcEncodable, RustcDecodable)]
pub struct SerializedDepGraph { pub struct SerializedDepGraph {
/// The set of all DepNodes in the graph /// The set of all DepNodes in the graph
pub nodes: IndexVec<SerializedDepNodeIndex, (DepNode, Fingerprint)>, pub nodes: IndexVec<SerializedDepNodeIndex, DepNode>,
/// The set of all Fingerprints in the graph. Each Fingerprint corresponds to
/// the DepNode at the same index in the nodes vector.
pub fingerprints: IndexVec<SerializedDepNodeIndex, Fingerprint>,
/// For each DepNode, stores the list of edges originating from that /// For each DepNode, stores the list of edges originating from that
/// DepNode. Encoded as a [start, end) pair indexing into edge_list_data, /// DepNode. Encoded as a [start, end) pair indexing into edge_list_data,
/// which holds the actual DepNodeIndices of the target nodes. /// which holds the actual DepNodeIndices of the target nodes.
@ -35,6 +38,7 @@ impl SerializedDepGraph {
pub fn new() -> SerializedDepGraph { pub fn new() -> SerializedDepGraph {
SerializedDepGraph { SerializedDepGraph {
nodes: IndexVec::new(), nodes: IndexVec::new(),
fingerprints: IndexVec::new(),
edge_list_indices: IndexVec::new(), edge_list_indices: IndexVec::new(),
edge_list_data: Vec::new(), edge_list_data: Vec::new(),
} }

View File

@ -503,6 +503,13 @@ impl<I: Idx, T> IndexVec<I, T> {
(c1, c2) (c1, c2)
} }
} }
pub fn convert_index_type<Ix: Idx>(self) -> IndexVec<Ix, T> {
IndexVec {
raw: self.raw,
_marker: PhantomData,
}
}
} }
impl<I: Idx, T: Clone> IndexVec<I, T> { impl<I: Idx, T: Clone> IndexVec<I, T> {

View File

@ -162,7 +162,7 @@ fn encode_dep_graph(tcx: TyCtxt,
let mut counts: FxHashMap<_, Stat> = FxHashMap(); let mut counts: FxHashMap<_, Stat> = FxHashMap();
for (i, &(node, _)) in serialized_graph.nodes.iter_enumerated() { for (i, &node) in serialized_graph.nodes.iter_enumerated() {
let stat = counts.entry(node.kind).or_insert(Stat { let stat = counts.entry(node.kind).or_insert(Stat {
kind: node.kind, kind: node.kind,
node_counter: 0, node_counter: 0,