Skip to content

Commit e7c9469

Browse files
authored
Rollup merge of #85583 - cjgillot:no-previous-dg, r=petrochenkov
Get rid of PreviousDepGraph. Its only role is to access the `SerializedDepGraph`.
2 parents 9d4a644 + a50f1e9 commit e7c9469

File tree

7 files changed

+49
-79
lines changed

7 files changed

+49
-79
lines changed

compiler/rustc_incremental/src/persist/load.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use rustc_data_structures::fx::FxHashMap;
44
use rustc_hir::definitions::DefPathTable;
5-
use rustc_middle::dep_graph::{PreviousDepGraph, SerializedDepGraph, WorkProduct, WorkProductId};
5+
use rustc_middle::dep_graph::{SerializedDepGraph, WorkProduct, WorkProductId};
66
use rustc_middle::ty::query::OnDiskCache;
77
use rustc_serialize::opaque::Decoder;
88
use rustc_serialize::Decodable;
@@ -22,8 +22,8 @@ pub enum LoadResult<T> {
2222
Error { message: String },
2323
}
2424

25-
impl LoadResult<(PreviousDepGraph, WorkProductMap)> {
26-
pub fn open(self, sess: &Session) -> (PreviousDepGraph, WorkProductMap) {
25+
impl LoadResult<(SerializedDepGraph, WorkProductMap)> {
26+
pub fn open(self, sess: &Session) -> (SerializedDepGraph, WorkProductMap) {
2727
match self {
2828
LoadResult::Error { message } => {
2929
sess.warn(&message);
@@ -84,7 +84,7 @@ impl<T> MaybeAsync<T> {
8484
}
8585
}
8686

87-
pub type DepGraphFuture = MaybeAsync<LoadResult<(PreviousDepGraph, WorkProductMap)>>;
87+
pub type DepGraphFuture = MaybeAsync<LoadResult<(SerializedDepGraph, WorkProductMap)>>;
8888

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

188-
LoadResult::Ok { data: (PreviousDepGraph::new(dep_graph), prev_work_products) }
188+
LoadResult::Ok { data: (dep_graph, prev_work_products) }
189189
}
190190
}
191191
}))

compiler/rustc_incremental/src/persist/save.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use rustc_data_structures::fx::FxHashMap;
22
use rustc_data_structures::sync::join;
3-
use rustc_middle::dep_graph::{DepGraph, PreviousDepGraph, WorkProduct, WorkProductId};
3+
use rustc_middle::dep_graph::{DepGraph, SerializedDepGraph, WorkProduct, WorkProductId};
44
use rustc_middle::ty::TyCtxt;
55
use rustc_serialize::opaque::{FileEncodeResult, FileEncoder};
66
use rustc_serialize::Encodable as RustcEncodable;
@@ -186,7 +186,7 @@ fn encode_query_cache(tcx: TyCtxt<'_>, encoder: &mut FileEncoder) -> FileEncodeR
186186

187187
pub fn build_dep_graph(
188188
sess: &Session,
189-
prev_graph: PreviousDepGraph,
189+
prev_graph: SerializedDepGraph,
190190
prev_work_products: FxHashMap<WorkProductId, WorkProduct>,
191191
) -> Option<DepGraph> {
192192
if sess.opts.incremental.is_none() {

compiler/rustc_middle/src/dep_graph/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ crate use dep_node::{make_compile_codegen_unit, make_compile_mono_item};
1818
pub type DepGraph = rustc_query_system::dep_graph::DepGraph<DepKind>;
1919
pub type TaskDeps = rustc_query_system::dep_graph::TaskDeps<DepKind>;
2020
pub type DepGraphQuery = rustc_query_system::dep_graph::DepGraphQuery<DepKind>;
21-
pub type PreviousDepGraph = rustc_query_system::dep_graph::PreviousDepGraph<DepKind>;
2221
pub type SerializedDepGraph = rustc_query_system::dep_graph::SerializedDepGraph<DepKind>;
2322
pub type EdgeFilter = rustc_query_system::dep_graph::debug::EdgeFilter<DepKind>;
2423

compiler/rustc_query_system/src/dep_graph/graph.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@ use std::marker::PhantomData;
1919
use std::mem;
2020
use std::sync::atomic::Ordering::Relaxed;
2121

22-
use super::prev::PreviousDepGraph;
2322
use super::query::DepGraphQuery;
24-
use super::serialized::{GraphEncoder, SerializedDepNodeIndex};
23+
use super::serialized::{GraphEncoder, SerializedDepGraph, SerializedDepNodeIndex};
2524
use super::{DepContext, DepKind, DepNode, HasDepContext, WorkProductId};
2625
use crate::query::QueryContext;
2726

@@ -78,7 +77,7 @@ struct DepGraphData<K: DepKind> {
7877

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

8382
colors: DepNodeColorMap,
8483

@@ -109,7 +108,7 @@ where
109108

110109
impl<K: DepKind> DepGraph<K> {
111110
pub fn new(
112-
prev_graph: PreviousDepGraph<K>,
111+
prev_graph: SerializedDepGraph<K>,
113112
prev_work_products: FxHashMap<WorkProductId, WorkProduct>,
114113
encoder: FileEncoder,
115114
record_graph: bool,
@@ -857,7 +856,7 @@ rustc_index::newtype_index! {
857856
/// For this reason, we avoid storing `DepNode`s more than once as map
858857
/// keys. The `new_node_to_index` map only contains nodes not in the previous
859858
/// graph, and we map nodes in the previous graph to indices via a two-step
860-
/// mapping. `PreviousDepGraph` maps from `DepNode` to `SerializedDepNodeIndex`,
859+
/// mapping. `SerializedDepGraph` maps from `DepNode` to `SerializedDepNodeIndex`,
861860
/// and the `prev_index_to_index` vector (which is more compact and faster than
862861
/// using a map) maps from `SerializedDepNodeIndex` to `DepNodeIndex`.
863862
///
@@ -982,7 +981,7 @@ impl<K: DepKind> CurrentDepGraph<K> {
982981
fn intern_node(
983982
&self,
984983
profiler: &SelfProfilerRef,
985-
prev_graph: &PreviousDepGraph<K>,
984+
prev_graph: &SerializedDepGraph<K>,
986985
key: DepNode<K>,
987986
edges: EdgesVec,
988987
fingerprint: Option<Fingerprint>,
@@ -1080,7 +1079,7 @@ impl<K: DepKind> CurrentDepGraph<K> {
10801079
fn promote_node_and_deps_to_current(
10811080
&self,
10821081
profiler: &SelfProfilerRef,
1083-
prev_graph: &PreviousDepGraph<K>,
1082+
prev_graph: &SerializedDepGraph<K>,
10841083
prev_index: SerializedDepNodeIndex,
10851084
) -> DepNodeIndex {
10861085
self.debug_assert_not_in_new_nodes(prev_graph, prev_index);
@@ -1112,7 +1111,7 @@ impl<K: DepKind> CurrentDepGraph<K> {
11121111
#[inline]
11131112
fn debug_assert_not_in_new_nodes(
11141113
&self,
1115-
prev_graph: &PreviousDepGraph<K>,
1114+
prev_graph: &SerializedDepGraph<K>,
11161115
prev_index: SerializedDepNodeIndex,
11171116
) {
11181117
let node = &prev_graph.index_to_node(prev_index);

compiler/rustc_query_system/src/dep_graph/mod.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
pub mod debug;
22
mod dep_node;
33
mod graph;
4-
mod prev;
54
mod query;
65
mod serialized;
76

87
pub use dep_node::{DepNode, DepNodeParams, WorkProductId};
98
pub use graph::{hash_result, DepGraph, DepNodeColor, DepNodeIndex, TaskDeps, WorkProduct};
10-
pub use prev::PreviousDepGraph;
119
pub use query::DepGraphQuery;
1210
pub use serialized::{SerializedDepGraph, SerializedDepNodeIndex};
1311

compiler/rustc_query_system/src/dep_graph/prev.rs

-56
This file was deleted.

compiler/rustc_query_system/src/dep_graph/serialized.rs

+35-5
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,19 @@ rustc_index::newtype_index! {
3737
#[derive(Debug)]
3838
pub struct SerializedDepGraph<K: DepKind> {
3939
/// The set of all DepNodes in the graph
40-
pub nodes: IndexVec<SerializedDepNodeIndex, DepNode<K>>,
40+
nodes: IndexVec<SerializedDepNodeIndex, DepNode<K>>,
4141
/// The set of all Fingerprints in the graph. Each Fingerprint corresponds to
4242
/// the DepNode at the same index in the nodes vector.
43-
pub fingerprints: IndexVec<SerializedDepNodeIndex, Fingerprint>,
43+
fingerprints: IndexVec<SerializedDepNodeIndex, Fingerprint>,
4444
/// For each DepNode, stores the list of edges originating from that
4545
/// DepNode. Encoded as a [start, end) pair indexing into edge_list_data,
4646
/// which holds the actual DepNodeIndices of the target nodes.
47-
pub edge_list_indices: IndexVec<SerializedDepNodeIndex, (u32, u32)>,
47+
edge_list_indices: IndexVec<SerializedDepNodeIndex, (u32, u32)>,
4848
/// A flattened list of all edge targets in the graph. Edge sources are
4949
/// implicit in edge_list_indices.
50-
pub edge_list_data: Vec<SerializedDepNodeIndex>,
50+
edge_list_data: Vec<SerializedDepNodeIndex>,
51+
/// Reciprocal map to `nodes`.
52+
index: FxHashMap<DepNode<K>, SerializedDepNodeIndex>,
5153
}
5254

5355
impl<K: DepKind> Default for SerializedDepGraph<K> {
@@ -57,6 +59,7 @@ impl<K: DepKind> Default for SerializedDepGraph<K> {
5759
fingerprints: Default::default(),
5860
edge_list_indices: Default::default(),
5961
edge_list_data: Default::default(),
62+
index: Default::default(),
6063
}
6164
}
6265
}
@@ -67,6 +70,30 @@ impl<K: DepKind> SerializedDepGraph<K> {
6770
let targets = self.edge_list_indices[source];
6871
&self.edge_list_data[targets.0 as usize..targets.1 as usize]
6972
}
73+
74+
#[inline]
75+
pub fn index_to_node(&self, dep_node_index: SerializedDepNodeIndex) -> DepNode<K> {
76+
self.nodes[dep_node_index]
77+
}
78+
79+
#[inline]
80+
pub fn node_to_index_opt(&self, dep_node: &DepNode<K>) -> Option<SerializedDepNodeIndex> {
81+
self.index.get(dep_node).cloned()
82+
}
83+
84+
#[inline]
85+
pub fn fingerprint_of(&self, dep_node: &DepNode<K>) -> Option<Fingerprint> {
86+
self.index.get(dep_node).map(|&node_index| self.fingerprints[node_index])
87+
}
88+
89+
#[inline]
90+
pub fn fingerprint_by_index(&self, dep_node_index: SerializedDepNodeIndex) -> Fingerprint {
91+
self.fingerprints[dep_node_index]
92+
}
93+
94+
pub fn node_count(&self) -> usize {
95+
self.index.len()
96+
}
7097
}
7198

7299
impl<'a, K: DepKind + Decodable<opaque::Decoder<'a>>> Decodable<opaque::Decoder<'a>>
@@ -121,7 +148,10 @@ impl<'a, K: DepKind + Decodable<opaque::Decoder<'a>>> Decodable<opaque::Decoder<
121148
})?;
122149
}
123150

124-
Ok(SerializedDepGraph { nodes, fingerprints, edge_list_indices, edge_list_data })
151+
let index: FxHashMap<_, _> =
152+
nodes.iter_enumerated().map(|(idx, &dep_node)| (dep_node, idx)).collect();
153+
154+
Ok(SerializedDepGraph { nodes, fingerprints, edge_list_indices, edge_list_data, index })
125155
}
126156
}
127157

0 commit comments

Comments
 (0)