Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[do not merge] Revert "Convert SerializedDepGraph to be a struct-of-arrays" #57070

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/librustc/dep_graph/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -506,10 +506,18 @@ impl DepGraph {
}

pub fn serialize(&self) -> SerializedDepGraph {
let mut fingerprints = self.fingerprints.borrow_mut();
let current_dep_graph = self.data.as_ref().unwrap().current.borrow();

let fingerprints = self.fingerprints.borrow().clone().convert_index_type();
let nodes = current_dep_graph.nodes.clone().convert_index_type();
// Make sure we don't run out of bounds below.
if current_dep_graph.nodes.len() > fingerprints.len() {
fingerprints.resize(current_dep_graph.nodes.len(), Fingerprint::ZERO);
}

let nodes: IndexVec<_, (DepNode, Fingerprint)> =
current_dep_graph.nodes.iter_enumerated().map(|(idx, &dep_node)| {
(dep_node, fingerprints[idx])
}).collect();

let total_edge_count: usize = current_dep_graph.edges.iter()
.map(|v| v.len())
Expand All @@ -533,7 +541,6 @@ impl DepGraph {

SerializedDepGraph {
nodes,
fingerprints,
edge_list_indices,
edge_list_data,
}
Expand Down
8 changes: 4 additions & 4 deletions src/librustc/dep_graph/prev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ impl PreviousDepGraph {
pub fn new(data: SerializedDepGraph) -> PreviousDepGraph {
let index: FxHashMap<_, _> = data.nodes
.iter_enumerated()
.map(|(idx, &dep_node)| (dep_node, idx))
.map(|(idx, &(dep_node, _))| (dep_node, idx))
.collect();
PreviousDepGraph { data, index }
}
Expand All @@ -41,7 +41,7 @@ impl PreviousDepGraph {

#[inline]
pub fn index_to_node(&self, dep_node_index: SerializedDepNodeIndex) -> DepNode {
self.data.nodes[dep_node_index]
self.data.nodes[dep_node_index].0
}

#[inline]
Expand All @@ -58,14 +58,14 @@ impl PreviousDepGraph {
pub fn fingerprint_of(&self, dep_node: &DepNode) -> Option<Fingerprint> {
self.index
.get(dep_node)
.map(|&node_index| self.data.fingerprints[node_index])
.map(|&node_index| self.data.nodes[node_index].1)
}

#[inline]
pub fn fingerprint_by_index(&self,
dep_node_index: SerializedDepNodeIndex)
-> Fingerprint {
self.data.fingerprints[dep_node_index]
self.data.nodes[dep_node_index].1
}

pub fn node_count(&self) -> usize {
Expand Down
5 changes: 1 addition & 4 deletions src/librustc/dep_graph/serialized.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ newtype_index! {
#[derive(Debug, RustcEncodable, RustcDecodable, Default)]
pub struct SerializedDepGraph {
/// The set of all DepNodes in the graph
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>,
pub nodes: IndexVec<SerializedDepNodeIndex, (DepNode, Fingerprint)>,
/// For each DepNode, stores the list of edges originating from that
/// DepNode. Encoded as a [start, end) pair indexing into edge_list_data,
/// which holds the actual DepNodeIndices of the target nodes.
Expand Down
7 changes: 0 additions & 7 deletions src/librustc_data_structures/indexed_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -665,13 +665,6 @@ impl<I: Idx, T> IndexVec<I, T> {
(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> {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_incremental/persist/save.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ fn encode_dep_graph(tcx: TyCtxt,

let mut counts: FxHashMap<_, Stat> = FxHashMap::default();

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 {
kind: node.kind,
node_counter: 0,
Expand Down