Skip to content

Commit

Permalink
Get rid of PreviousDepGraph.
Browse files Browse the repository at this point in the history
  • Loading branch information
cjgillot committed May 22, 2021
1 parent fa72878 commit a50f1e9
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 79 deletions.
10 changes: 5 additions & 5 deletions compiler/rustc_incremental/src/persist/load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use rustc_data_structures::fx::FxHashMap;
use rustc_hir::definitions::DefPathTable;
use rustc_middle::dep_graph::{PreviousDepGraph, SerializedDepGraph, WorkProduct, WorkProductId};
use rustc_middle::dep_graph::{SerializedDepGraph, WorkProduct, WorkProductId};
use rustc_middle::ty::query::OnDiskCache;
use rustc_serialize::opaque::Decoder;
use rustc_serialize::Decodable;
Expand All @@ -22,8 +22,8 @@ pub enum LoadResult<T> {
Error { message: String },
}

impl LoadResult<(PreviousDepGraph, WorkProductMap)> {
pub fn open(self, sess: &Session) -> (PreviousDepGraph, WorkProductMap) {
impl LoadResult<(SerializedDepGraph, WorkProductMap)> {
pub fn open(self, sess: &Session) -> (SerializedDepGraph, WorkProductMap) {
match self {
LoadResult::Error { message } => {
sess.warn(&message);
Expand Down Expand Up @@ -84,7 +84,7 @@ impl<T> MaybeAsync<T> {
}
}

pub type DepGraphFuture = MaybeAsync<LoadResult<(PreviousDepGraph, WorkProductMap)>>;
pub type DepGraphFuture = MaybeAsync<LoadResult<(SerializedDepGraph, WorkProductMap)>>;

/// Launch a thread and load the dependency graph in the background.
pub fn load_dep_graph(sess: &Session) -> DepGraphFuture {
Expand Down Expand Up @@ -185,7 +185,7 @@ pub fn load_dep_graph(sess: &Session) -> DepGraphFuture {
let dep_graph = SerializedDepGraph::decode(&mut decoder)
.expect("Error reading cached dep-graph");

LoadResult::Ok { data: (PreviousDepGraph::new(dep_graph), prev_work_products) }
LoadResult::Ok { data: (dep_graph, prev_work_products) }
}
}
}))
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_incremental/src/persist/save.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::sync::join;
use rustc_middle::dep_graph::{DepGraph, PreviousDepGraph, WorkProduct, WorkProductId};
use rustc_middle::dep_graph::{DepGraph, SerializedDepGraph, WorkProduct, WorkProductId};
use rustc_middle::ty::TyCtxt;
use rustc_serialize::opaque::{FileEncodeResult, FileEncoder};
use rustc_serialize::Encodable as RustcEncodable;
Expand Down Expand Up @@ -186,7 +186,7 @@ fn encode_query_cache(tcx: TyCtxt<'_>, encoder: &mut FileEncoder) -> FileEncodeR

pub fn build_dep_graph(
sess: &Session,
prev_graph: PreviousDepGraph,
prev_graph: SerializedDepGraph,
prev_work_products: FxHashMap<WorkProductId, WorkProduct>,
) -> Option<DepGraph> {
if sess.opts.incremental.is_none() {
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_middle/src/dep_graph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ crate use dep_node::{make_compile_codegen_unit, make_compile_mono_item};
pub type DepGraph = rustc_query_system::dep_graph::DepGraph<DepKind>;
pub type TaskDeps = rustc_query_system::dep_graph::TaskDeps<DepKind>;
pub type DepGraphQuery = rustc_query_system::dep_graph::DepGraphQuery<DepKind>;
pub type PreviousDepGraph = rustc_query_system::dep_graph::PreviousDepGraph<DepKind>;
pub type SerializedDepGraph = rustc_query_system::dep_graph::SerializedDepGraph<DepKind>;
pub type EdgeFilter = rustc_query_system::dep_graph::debug::EdgeFilter<DepKind>;

Expand Down
15 changes: 7 additions & 8 deletions compiler/rustc_query_system/src/dep_graph/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ use std::marker::PhantomData;
use std::mem;
use std::sync::atomic::Ordering::Relaxed;

use super::prev::PreviousDepGraph;
use super::query::DepGraphQuery;
use super::serialized::{GraphEncoder, SerializedDepNodeIndex};
use super::serialized::{GraphEncoder, SerializedDepGraph, SerializedDepNodeIndex};
use super::{DepContext, DepKind, DepNode, HasDepContext, WorkProductId};
use crate::query::QueryContext;

Expand Down Expand Up @@ -78,7 +77,7 @@ struct DepGraphData<K: DepKind> {

/// The dep-graph from the previous compilation session. It contains all
/// nodes and edges as well as all fingerprints of nodes that have them.
previous: PreviousDepGraph<K>,
previous: SerializedDepGraph<K>,

colors: DepNodeColorMap,

Expand Down Expand Up @@ -109,7 +108,7 @@ where

impl<K: DepKind> DepGraph<K> {
pub fn new(
prev_graph: PreviousDepGraph<K>,
prev_graph: SerializedDepGraph<K>,
prev_work_products: FxHashMap<WorkProductId, WorkProduct>,
encoder: FileEncoder,
record_graph: bool,
Expand Down Expand Up @@ -857,7 +856,7 @@ rustc_index::newtype_index! {
/// For this reason, we avoid storing `DepNode`s more than once as map
/// keys. The `new_node_to_index` map only contains nodes not in the previous
/// graph, and we map nodes in the previous graph to indices via a two-step
/// mapping. `PreviousDepGraph` maps from `DepNode` to `SerializedDepNodeIndex`,
/// mapping. `SerializedDepGraph` maps from `DepNode` to `SerializedDepNodeIndex`,
/// and the `prev_index_to_index` vector (which is more compact and faster than
/// using a map) maps from `SerializedDepNodeIndex` to `DepNodeIndex`.
///
Expand Down Expand Up @@ -982,7 +981,7 @@ impl<K: DepKind> CurrentDepGraph<K> {
fn intern_node(
&self,
profiler: &SelfProfilerRef,
prev_graph: &PreviousDepGraph<K>,
prev_graph: &SerializedDepGraph<K>,
key: DepNode<K>,
edges: EdgesVec,
fingerprint: Option<Fingerprint>,
Expand Down Expand Up @@ -1080,7 +1079,7 @@ impl<K: DepKind> CurrentDepGraph<K> {
fn promote_node_and_deps_to_current(
&self,
profiler: &SelfProfilerRef,
prev_graph: &PreviousDepGraph<K>,
prev_graph: &SerializedDepGraph<K>,
prev_index: SerializedDepNodeIndex,
) -> DepNodeIndex {
self.debug_assert_not_in_new_nodes(prev_graph, prev_index);
Expand Down Expand Up @@ -1112,7 +1111,7 @@ impl<K: DepKind> CurrentDepGraph<K> {
#[inline]
fn debug_assert_not_in_new_nodes(
&self,
prev_graph: &PreviousDepGraph<K>,
prev_graph: &SerializedDepGraph<K>,
prev_index: SerializedDepNodeIndex,
) {
let node = &prev_graph.index_to_node(prev_index);
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_query_system/src/dep_graph/mod.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
pub mod debug;
mod dep_node;
mod graph;
mod prev;
mod query;
mod serialized;

pub use dep_node::{DepNode, DepNodeParams, WorkProductId};
pub use graph::{hash_result, DepGraph, DepNodeColor, DepNodeIndex, TaskDeps, WorkProduct};
pub use prev::PreviousDepGraph;
pub use query::DepGraphQuery;
pub use serialized::{SerializedDepGraph, SerializedDepNodeIndex};

Expand Down
56 changes: 0 additions & 56 deletions compiler/rustc_query_system/src/dep_graph/prev.rs

This file was deleted.

40 changes: 35 additions & 5 deletions compiler/rustc_query_system/src/dep_graph/serialized.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,19 @@ rustc_index::newtype_index! {
#[derive(Debug)]
pub struct SerializedDepGraph<K: DepKind> {
/// The set of all DepNodes in the graph
pub nodes: IndexVec<SerializedDepNodeIndex, DepNode<K>>,
nodes: IndexVec<SerializedDepNodeIndex, DepNode<K>>,
/// 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>,
fingerprints: IndexVec<SerializedDepNodeIndex, 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.
pub edge_list_indices: IndexVec<SerializedDepNodeIndex, (u32, u32)>,
edge_list_indices: IndexVec<SerializedDepNodeIndex, (u32, u32)>,
/// A flattened list of all edge targets in the graph. Edge sources are
/// implicit in edge_list_indices.
pub edge_list_data: Vec<SerializedDepNodeIndex>,
edge_list_data: Vec<SerializedDepNodeIndex>,
/// Reciprocal map to `nodes`.
index: FxHashMap<DepNode<K>, SerializedDepNodeIndex>,
}

impl<K: DepKind> Default for SerializedDepGraph<K> {
Expand All @@ -57,6 +59,7 @@ impl<K: DepKind> Default for SerializedDepGraph<K> {
fingerprints: Default::default(),
edge_list_indices: Default::default(),
edge_list_data: Default::default(),
index: Default::default(),
}
}
}
Expand All @@ -67,6 +70,30 @@ impl<K: DepKind> SerializedDepGraph<K> {
let targets = self.edge_list_indices[source];
&self.edge_list_data[targets.0 as usize..targets.1 as usize]
}

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

#[inline]
pub fn node_to_index_opt(&self, dep_node: &DepNode<K>) -> Option<SerializedDepNodeIndex> {
self.index.get(dep_node).cloned()
}

#[inline]
pub fn fingerprint_of(&self, dep_node: &DepNode<K>) -> Option<Fingerprint> {
self.index.get(dep_node).map(|&node_index| self.fingerprints[node_index])
}

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

pub fn node_count(&self) -> usize {
self.index.len()
}
}

impl<'a, K: DepKind + Decodable<opaque::Decoder<'a>>> Decodable<opaque::Decoder<'a>>
Expand Down Expand Up @@ -121,7 +148,10 @@ impl<'a, K: DepKind + Decodable<opaque::Decoder<'a>>> Decodable<opaque::Decoder<
})?;
}

Ok(SerializedDepGraph { nodes, fingerprints, edge_list_indices, edge_list_data })
let index: FxHashMap<_, _> =
nodes.iter_enumerated().map(|(idx, &dep_node)| (dep_node, idx)).collect();

Ok(SerializedDepGraph { nodes, fingerprints, edge_list_indices, edge_list_data, index })
}
}

Expand Down

0 comments on commit a50f1e9

Please sign in to comment.