Skip to content

Commit 1d83208

Browse files
committed
De-genericize the dep graph.
By removing the generic `D` parameter from `DepGraph`, `DepGraphData`, `CurrentDepGraph`, `SerializedDepGraph`, `SerializedNodeHeader`, and `EncoderState`.
1 parent 32e6a1a commit 1d83208

6 files changed

Lines changed: 88 additions & 100 deletions

File tree

compiler/rustc_incremental/src/persist/load.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::sync::Arc;
66
use rustc_data_structures::memmap::Mmap;
77
use rustc_data_structures::unord::UnordMap;
88
use rustc_hashes::Hash64;
9-
use rustc_middle::dep_graph::{DepGraph, DepsType, SerializedDepGraph, WorkProductMap};
9+
use rustc_middle::dep_graph::{DepGraph, SerializedDepGraph, WorkProductMap};
1010
use rustc_middle::query::on_disk_cache::OnDiskCache;
1111
use rustc_serialize::Decodable;
1212
use rustc_serialize::opaque::MemDecoder;
@@ -171,7 +171,7 @@ fn load_dep_graph(sess: &Session) -> LoadResult<(Arc<SerializedDepGraph>, WorkPr
171171
return LoadResult::DataOutOfDate;
172172
}
173173

174-
let dep_graph = SerializedDepGraph::decode::<DepsType>(&mut decoder);
174+
let dep_graph = SerializedDepGraph::decode(&mut decoder);
175175

176176
LoadResult::Ok { data: (dep_graph, prev_work_products) }
177177
}

compiler/rustc_middle/src/dep_graph/graph.rs

Lines changed: 40 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,14 @@ use {super::debug::EdgeFilter, std::env};
2525

2626
use super::query::DepGraphQuery;
2727
use super::serialized::{GraphEncoder, SerializedDepGraph, SerializedDepNodeIndex};
28-
use super::{DepContext, DepKind, DepNode, Deps, HasDepContext, WorkProductId};
28+
use super::{DepContext, DepKind, DepNode, Deps, DepsType, HasDepContext, WorkProductId};
2929
use crate::dep_graph::edges::EdgesVec;
3030
use crate::ty::TyCtxt;
3131
use crate::verify_ich::incremental_verify_ich;
3232

33-
pub struct DepGraph<D: Deps> {
34-
data: Option<Arc<DepGraphData<D>>>,
33+
#[derive(Clone)]
34+
pub struct DepGraph {
35+
data: Option<Arc<DepGraphData>>,
3536

3637
/// This field is used for assigning DepNodeIndices when running in
3738
/// non-incremental mode. Even in non-incremental mode we make sure that
@@ -40,17 +41,6 @@ pub struct DepGraph<D: Deps> {
4041
virtual_dep_node_index: Arc<AtomicU32>,
4142
}
4243

43-
/// Manual clone impl that does not require `D: Clone`.
44-
impl<D: Deps> Clone for DepGraph<D> {
45-
fn clone(&self) -> Self {
46-
let Self { data, virtual_dep_node_index } = self;
47-
Self {
48-
data: Option::<Arc<_>>::clone(data),
49-
virtual_dep_node_index: Arc::clone(virtual_dep_node_index),
50-
}
51-
}
52-
}
53-
5444
rustc_index::newtype_index! {
5545
pub struct DepNodeIndex {}
5646
}
@@ -84,12 +74,12 @@ pub(super) enum DepNodeColor {
8474
Unknown,
8575
}
8676

87-
pub struct DepGraphData<D: Deps> {
77+
pub struct DepGraphData {
8878
/// The new encoding of the dependency graph, optimized for red/green
8979
/// tracking. The `current` field is the dependency graph of only the
9080
/// current compilation session: We don't merge the previous dep-graph into
9181
/// current one anymore, but we do reference shared data to save space.
92-
current: CurrentDepGraph<D>,
82+
current: CurrentDepGraph,
9383

9484
/// The dep-graph from the previous compilation session. It contains all
9585
/// nodes and edges as well as all fingerprints of nodes that have them.
@@ -120,13 +110,13 @@ where
120110
stable_hasher.finish()
121111
}
122112

123-
impl<D: Deps> DepGraph<D> {
113+
impl DepGraph {
124114
pub fn new(
125115
session: &Session,
126116
prev_graph: Arc<SerializedDepGraph>,
127117
prev_work_products: WorkProductMap,
128118
encoder: FileEncoder,
129-
) -> DepGraph<D> {
119+
) -> DepGraph {
130120
let prev_graph_node_count = prev_graph.node_count();
131121

132122
let current =
@@ -136,15 +126,15 @@ impl<D: Deps> DepGraph<D> {
136126

137127
// Instantiate a node with zero dependencies only once for anonymous queries.
138128
let _green_node_index = current.alloc_new_node(
139-
DepNode { kind: D::DEP_KIND_ANON_ZERO_DEPS, hash: current.anon_id_seed.into() },
129+
DepNode { kind: DepsType::DEP_KIND_ANON_ZERO_DEPS, hash: current.anon_id_seed.into() },
140130
EdgesVec::new(),
141131
Fingerprint::ZERO,
142132
);
143133
assert_eq!(_green_node_index, DepNodeIndex::SINGLETON_ZERO_DEPS_ANON_NODE);
144134

145135
// Instantiate a dependy-less red node only once for anonymous queries.
146136
let red_node_index = current.alloc_new_node(
147-
DepNode { kind: D::DEP_KIND_RED, hash: Fingerprint::ZERO.into() },
137+
DepNode { kind: DepsType::DEP_KIND_RED, hash: Fingerprint::ZERO.into() },
148138
EdgesVec::new(),
149139
Fingerprint::ZERO,
150140
);
@@ -168,12 +158,12 @@ impl<D: Deps> DepGraph<D> {
168158
}
169159
}
170160

171-
pub fn new_disabled() -> DepGraph<D> {
161+
pub fn new_disabled() -> DepGraph {
172162
DepGraph { data: None, virtual_dep_node_index: Arc::new(AtomicU32::new(0)) }
173163
}
174164

175165
#[inline]
176-
pub fn data(&self) -> Option<&DepGraphData<D>> {
166+
pub fn data(&self) -> Option<&DepGraphData> {
177167
self.data.as_deref()
178168
}
179169

@@ -191,7 +181,7 @@ impl<D: Deps> DepGraph<D> {
191181

192182
pub fn assert_ignored(&self) {
193183
if let Some(..) = self.data {
194-
D::read_deps(|task_deps| {
184+
DepsType::read_deps(|task_deps| {
195185
assert_matches!(
196186
task_deps,
197187
TaskDepsRef::Ignore,
@@ -205,7 +195,7 @@ impl<D: Deps> DepGraph<D> {
205195
where
206196
OP: FnOnce() -> R,
207197
{
208-
D::with_deps(TaskDepsRef::Ignore, op)
198+
DepsType::with_deps(TaskDepsRef::Ignore, op)
209199
}
210200

211201
/// Used to wrap the deserialization of a query result from disk,
@@ -258,11 +248,11 @@ impl<D: Deps> DepGraph<D> {
258248
where
259249
OP: FnOnce() -> R,
260250
{
261-
D::with_deps(TaskDepsRef::Forbid, op)
251+
DepsType::with_deps(TaskDepsRef::Forbid, op)
262252
}
263253

264254
#[inline(always)]
265-
pub fn with_task<Ctxt: HasDepContext<Deps = D>, A: Debug, R>(
255+
pub fn with_task<Ctxt: HasDepContext<Deps = DepsType>, A: Debug, R>(
266256
&self,
267257
key: DepNode,
268258
cx: Ctxt,
@@ -276,7 +266,7 @@ impl<D: Deps> DepGraph<D> {
276266
}
277267
}
278268

279-
pub fn with_anon_task<Tcx: DepContext<Deps = D>, OP, R>(
269+
pub fn with_anon_task<Tcx: DepContext<Deps = DepsType>, OP, R>(
280270
&self,
281271
cx: Tcx,
282272
dep_kind: DepKind,
@@ -296,7 +286,7 @@ impl<D: Deps> DepGraph<D> {
296286
}
297287
}
298288

299-
impl<D: Deps> DepGraphData<D> {
289+
impl DepGraphData {
300290
/// Starts a new dep-graph task. Dep-graph tasks are specified
301291
/// using a free function (`task`) and **not** a closure -- this
302292
/// is intentional because we want to exercise tight control over
@@ -325,7 +315,7 @@ impl<D: Deps> DepGraphData<D> {
325315
///
326316
/// [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/queries/incremental-compilation.html
327317
#[inline(always)]
328-
pub fn with_task<Ctxt: HasDepContext<Deps = D>, A: Debug, R>(
318+
pub fn with_task<Ctxt: HasDepContext<Deps = DepsType>, A: Debug, R>(
329319
&self,
330320
key: DepNode,
331321
cx: Ctxt,
@@ -350,7 +340,7 @@ impl<D: Deps> DepGraphData<D> {
350340
},
351341
);
352342

353-
let with_deps = |task_deps| D::with_deps(task_deps, || task(cx, arg));
343+
let with_deps = |task_deps| DepsType::with_deps(task_deps, || task(cx, arg));
354344
let (result, edges) = if cx.dep_context().is_eval_always(key.kind) {
355345
(with_deps(TaskDepsRef::EvalAlways), EdgesVec::new())
356346
} else {
@@ -379,7 +369,7 @@ impl<D: Deps> DepGraphData<D> {
379369
/// FIXME: This could perhaps return a `WithDepNode` to ensure that the
380370
/// user of this function actually performs the read; we'll have to see
381371
/// how to make that work with `anon` in `execute_job_incr`, though.
382-
pub fn with_anon_task_inner<Tcx: DepContext<Deps = D>, OP, R>(
372+
pub fn with_anon_task_inner<Tcx: DepContext<Deps = DepsType>, OP, R>(
383373
&self,
384374
cx: Tcx,
385375
dep_kind: DepKind,
@@ -397,7 +387,7 @@ impl<D: Deps> DepGraphData<D> {
397387
None,
398388
128,
399389
));
400-
let result = D::with_deps(TaskDepsRef::Allow(&task_deps), op);
390+
let result = DepsType::with_deps(TaskDepsRef::Allow(&task_deps), op);
401391
let task_deps = task_deps.into_inner();
402392
let reads = task_deps.reads;
403393

@@ -448,7 +438,7 @@ impl<D: Deps> DepGraphData<D> {
448438
}
449439

450440
/// Intern the new `DepNode` with the dependencies up-to-now.
451-
fn hash_result_and_alloc_node<Ctxt: DepContext<Deps = D>, R>(
441+
fn hash_result_and_alloc_node<Ctxt: DepContext<Deps = DepsType>, R>(
452442
&self,
453443
cx: &Ctxt,
454444
node: DepNode,
@@ -466,11 +456,11 @@ impl<D: Deps> DepGraphData<D> {
466456
}
467457
}
468458

469-
impl<D: Deps> DepGraph<D> {
459+
impl DepGraph {
470460
#[inline]
471461
pub fn read_index(&self, dep_node_index: DepNodeIndex) {
472462
if let Some(ref data) = self.data {
473-
D::read_deps(|task_deps| {
463+
DepsType::read_deps(|task_deps| {
474464
let mut task_deps = match task_deps {
475465
TaskDepsRef::Allow(deps) => deps.lock(),
476466
TaskDepsRef::EvalAlways => {
@@ -527,7 +517,7 @@ impl<D: Deps> DepGraph<D> {
527517
#[inline]
528518
pub fn record_diagnostic<'tcx>(&self, tcx: TyCtxt<'tcx>, diagnostic: &DiagInner) {
529519
if let Some(ref data) = self.data {
530-
D::read_deps(|task_deps| match task_deps {
520+
DepsType::read_deps(|task_deps| match task_deps {
531521
TaskDepsRef::EvalAlways | TaskDepsRef::Ignore => return,
532522
TaskDepsRef::Forbid | TaskDepsRef::Allow(..) => {
533523
self.read_index(data.encode_diagnostic(tcx, diagnostic));
@@ -563,7 +553,7 @@ impl<D: Deps> DepGraph<D> {
563553
/// FIXME: If the code is changed enough for this node to be marked before requiring the
564554
/// caller's node, we suppose that those changes will be enough to mark this node red and
565555
/// force a recomputation using the "normal" way.
566-
pub fn with_feed_task<Ctxt: DepContext<Deps = D>, R>(
556+
pub fn with_feed_task<Ctxt: DepContext<Deps = DepsType>, R>(
567557
&self,
568558
node: DepNode,
569559
cx: Ctxt,
@@ -604,7 +594,7 @@ impl<D: Deps> DepGraph<D> {
604594
}
605595

606596
let mut edges = EdgesVec::new();
607-
D::read_deps(|task_deps| match task_deps {
597+
DepsType::read_deps(|task_deps| match task_deps {
608598
TaskDepsRef::Allow(deps) => edges.extend(deps.lock().reads.iter().copied()),
609599
TaskDepsRef::EvalAlways => {
610600
edges.push(DepNodeIndex::FOREVER_RED_NODE);
@@ -626,7 +616,7 @@ impl<D: Deps> DepGraph<D> {
626616
}
627617
}
628618

629-
impl<D: Deps> DepGraphData<D> {
619+
impl DepGraphData {
630620
fn assert_dep_node_not_yet_allocated_in_current_session<S: std::fmt::Display>(
631621
&self,
632622
sess: &Session,
@@ -688,7 +678,7 @@ impl<D: Deps> DepGraphData<D> {
688678
// Use `send_new` so we get an unique index, even though the dep node is not.
689679
let dep_node_index = self.current.encoder.send_new(
690680
DepNode {
691-
kind: D::DEP_KIND_SIDE_EFFECT,
681+
kind: DepsType::DEP_KIND_SIDE_EFFECT,
692682
hash: PackedFingerprint::from(Fingerprint::ZERO),
693683
},
694684
Fingerprint::ZERO,
@@ -705,7 +695,7 @@ impl<D: Deps> DepGraphData<D> {
705695
/// refer to a node created used `encode_diagnostic` in the previous session.
706696
#[inline]
707697
fn force_diagnostic_node<'tcx>(&self, tcx: TyCtxt<'tcx>, prev_index: SerializedDepNodeIndex) {
708-
D::with_deps(TaskDepsRef::Ignore, || {
698+
DepsType::with_deps(TaskDepsRef::Ignore, || {
709699
let side_effect = tcx.load_side_effect(prev_index).unwrap();
710700

711701
match &side_effect {
@@ -721,7 +711,7 @@ impl<D: Deps> DepGraphData<D> {
721711
prev_index,
722712
&self.colors,
723713
DepNode {
724-
kind: D::DEP_KIND_SIDE_EFFECT,
714+
kind: DepsType::DEP_KIND_SIDE_EFFECT,
725715
hash: PackedFingerprint::from(Fingerprint::ZERO),
726716
},
727717
Fingerprint::ZERO,
@@ -799,7 +789,7 @@ impl<D: Deps> DepGraphData<D> {
799789
}
800790
}
801791

802-
impl<D: Deps> DepGraph<D> {
792+
impl DepGraph {
803793
/// Checks whether a previous work product exists for `v` and, if
804794
/// so, return the path that leads to it. Used to skip doing work.
805795
pub fn previous_work_product(&self, v: &WorkProductId) -> Option<WorkProduct> {
@@ -864,7 +854,7 @@ impl<D: Deps> DepGraph<D> {
864854
}
865855
}
866856

867-
impl<D: Deps> DepGraphData<D> {
857+
impl DepGraphData {
868858
/// Try to mark a node index for the node dep_node.
869859
///
870860
/// A node will have an index, when it's already been marked green, or when we can mark it
@@ -1029,7 +1019,7 @@ impl<D: Deps> DepGraphData<D> {
10291019
}
10301020
}
10311021

1032-
impl<D: Deps> DepGraph<D> {
1022+
impl DepGraph {
10331023
/// Returns true if the given node has been marked as red during the
10341024
/// current compilation session. Used in various assertions
10351025
pub fn is_red(&self, dep_node: &DepNode) -> bool {
@@ -1163,8 +1153,8 @@ rustc_index::newtype_index! {
11631153
/// `anon_node_to_index` and `data`, or `prev_index_to_index` and `data`. When
11641154
/// manipulating both, we acquire `anon_node_to_index` or `prev_index_to_index`
11651155
/// first, and `data` second.
1166-
pub(super) struct CurrentDepGraph<D: Deps> {
1167-
encoder: GraphEncoder<D>,
1156+
pub(super) struct CurrentDepGraph {
1157+
encoder: GraphEncoder,
11681158
anon_node_to_index: ShardedHashMap<DepNode, DepNodeIndex>,
11691159

11701160
/// This is used to verify that fingerprints do not change between the creation of a node
@@ -1202,7 +1192,7 @@ pub(super) struct CurrentDepGraph<D: Deps> {
12021192
pub(super) total_duplicate_read_count: AtomicU64,
12031193
}
12041194

1205-
impl<D: Deps> CurrentDepGraph<D> {
1195+
impl CurrentDepGraph {
12061196
fn new(
12071197
session: &Session,
12081198
prev_graph_node_count: usize,
@@ -1436,7 +1426,7 @@ impl DepNodeColorMap {
14361426

14371427
#[inline(never)]
14381428
#[cold]
1439-
pub(crate) fn print_markframe_trace<D: Deps>(graph: &DepGraph<D>, frame: &MarkFrame<'_>) {
1429+
pub(crate) fn print_markframe_trace(graph: &DepGraph, frame: &MarkFrame<'_>) {
14401430
let data = graph.data.as_ref().unwrap();
14411431

14421432
eprintln!("there was a panic while trying to force a dep node");
@@ -1456,7 +1446,7 @@ pub(crate) fn print_markframe_trace<D: Deps>(graph: &DepGraph<D>, frame: &MarkFr
14561446

14571447
#[cold]
14581448
#[inline(never)]
1459-
fn panic_on_forbidden_read<D: Deps>(data: &DepGraphData<D>, dep_node_index: DepNodeIndex) -> ! {
1449+
fn panic_on_forbidden_read(data: &DepGraphData, dep_node_index: DepNodeIndex) -> ! {
14601450
// We have to do an expensive reverse-lookup of the DepNode that
14611451
// corresponds to `dep_node_index`, but that's OK since we are about
14621452
// to ICE anyway.

compiler/rustc_middle/src/dep_graph/mod.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub use self::dep_node::{
1010
DepKind, DepNode, DepNodeKey, WorkProductId, dep_kind_from_label, dep_kinds, label_strs,
1111
};
1212
pub use self::graph::{
13-
DepGraphData, DepNodeIndex, TaskDepsRef, WorkProduct, WorkProductMap, hash_result,
13+
DepGraph, DepGraphData, DepNodeIndex, TaskDepsRef, WorkProduct, WorkProductMap, hash_result,
1414
};
1515
use self::graph::{MarkFrame, print_markframe_trace};
1616
pub use self::query::DepGraphQuery;
@@ -34,7 +34,7 @@ pub trait DepContext: Copy {
3434
fn with_stable_hashing_context<R>(self, f: impl FnOnce(StableHashingContext<'_>) -> R) -> R;
3535

3636
/// Access the DepGraph.
37-
fn dep_graph(&self) -> &graph::DepGraph<Self::Deps>;
37+
fn dep_graph(&self) -> &DepGraph;
3838

3939
/// Access the profiler.
4040
fn profiler(&self) -> &SelfProfilerRef;
@@ -179,8 +179,6 @@ impl FingerprintStyle {
179179
}
180180
}
181181

182-
pub type DepGraph = graph::DepGraph<DepsType>;
183-
184182
pub type DepKindVTable<'tcx> = dep_node::DepKindVTable<TyCtxt<'tcx>>;
185183

186184
pub struct DepsType;

0 commit comments

Comments
 (0)