Skip to content

Commit 07ee56e

Browse files
committed
Stop parametrizing DepGraph by Deps.
1 parent 190c668 commit 07ee56e

File tree

7 files changed

+94
-67
lines changed

7 files changed

+94
-67
lines changed

compiler/rustc_incremental/src/persist/save.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::errors;
33
use rustc_data_structures::fx::FxIndexMap;
44
use rustc_data_structures::sync::join;
55
use rustc_middle::dep_graph::{
6-
DepGraph, SerializedDepGraph, WorkProduct, WorkProductId, WorkProductMap,
6+
DepGraph, DepsType, SerializedDepGraph, WorkProduct, WorkProductId, WorkProductMap,
77
};
88
use rustc_middle::ty::TyCtxt;
99
use rustc_serialize::opaque::{FileEncodeResult, FileEncoder};
@@ -171,7 +171,7 @@ pub(crate) fn build_dep_graph(
171171
// First encode the commandline arguments hash
172172
sess.opts.dep_tracking_hash(false).encode(&mut encoder);
173173

174-
Some(DepGraph::new(
174+
Some(DepGraph::new::<DepsType>(
175175
&sess.prof,
176176
prev_graph,
177177
prev_work_products,

compiler/rustc_middle/src/dep_graph/mod.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub use rustc_query_system::dep_graph::{
1616
pub use dep_node::{dep_kinds, label_strs, DepKind, DepNode, DepNodeExt};
1717
pub(crate) use dep_node::{make_compile_codegen_unit, make_compile_mono_item};
1818

19-
pub type DepGraph = rustc_query_system::dep_graph::DepGraph<DepsType>;
19+
pub type DepGraph = rustc_query_system::dep_graph::DepGraph;
2020

2121
pub type DepKindStruct<'tcx> = rustc_query_system::dep_graph::DepKindStruct<TyCtxt<'tcx>>;
2222

@@ -30,8 +30,6 @@ impl Deps for DepsType {
3030
}
3131

3232
impl<'tcx> DepContext for TyCtxt<'tcx> {
33-
type Deps = DepsType;
34-
3533
#[inline]
3634
fn with_stable_hashing_context<R>(self, f: impl FnOnce(StableHashingContext<'_>) -> R) -> R {
3735
TyCtxt::with_stable_hashing_context(self, f)

compiler/rustc_query_impl/src/plumbing.rs

-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ impl<'tcx> std::ops::Deref for QueryCtxt<'tcx> {
5151
}
5252

5353
impl<'tcx> HasDepContext for QueryCtxt<'tcx> {
54-
type Deps = rustc_middle::dep_graph::DepsType;
5554
type DepContext = TyCtxt<'tcx>;
5655

5756
#[inline]

compiler/rustc_query_system/src/dep_graph/graph.rs

+32-32
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ use crate::query::{QueryContext, QuerySideEffects};
2626
use {super::debug::EdgeFilter, std::env};
2727

2828
#[derive(Clone)]
29-
pub struct DepGraph<D: Deps> {
30-
data: Option<Lrc<DepGraphData<D>>>,
29+
pub struct DepGraph {
30+
data: Option<Lrc<DepGraphData>>,
3131

3232
/// This field is used for assigning DepNodeIndices when running in
3333
/// non-incremental mode. Even in non-incremental mode we make sure that
@@ -73,12 +73,12 @@ impl DepNodeColor {
7373
}
7474
}
7575

76-
pub(crate) struct DepGraphData<D: Deps> {
76+
pub(crate) struct DepGraphData {
7777
/// The new encoding of the dependency graph, optimized for red/green
7878
/// tracking. The `current` field is the dependency graph of only the
7979
/// current compilation session: We don't merge the previous dep-graph into
8080
/// current one anymore, but we do reference shared data to save space.
81-
current: CurrentDepGraph<D>,
81+
current: CurrentDepGraph,
8282

8383
/// The dep-graph from the previous compilation session. It contains all
8484
/// nodes and edges as well as all fingerprints of nodes that have them.
@@ -111,18 +111,18 @@ where
111111
stable_hasher.finish()
112112
}
113113

114-
impl<D: Deps> DepGraph<D> {
115-
pub fn new(
114+
impl DepGraph {
115+
pub fn new<D: Deps>(
116116
profiler: &SelfProfilerRef,
117117
prev_graph: SerializedDepGraph,
118118
prev_work_products: WorkProductMap,
119119
encoder: FileEncoder,
120120
record_graph: bool,
121121
record_stats: bool,
122-
) -> DepGraph<D> {
122+
) -> DepGraph {
123123
let prev_graph_node_count = prev_graph.node_count();
124124

125-
let current = CurrentDepGraph::new(
125+
let current = CurrentDepGraph::new::<D>(
126126
profiler,
127127
prev_graph_node_count,
128128
encoder,
@@ -179,12 +179,12 @@ impl<D: Deps> DepGraph<D> {
179179
}
180180
}
181181

182-
pub fn new_disabled() -> DepGraph<D> {
182+
pub fn new_disabled() -> DepGraph {
183183
DepGraph { data: None, virtual_dep_node_index: Lrc::new(AtomicU32::new(0)) }
184184
}
185185

186186
#[inline]
187-
pub(crate) fn data(&self) -> Option<&DepGraphData<D>> {
187+
pub(crate) fn data(&self) -> Option<&DepGraphData> {
188188
self.data.as_deref()
189189
}
190190

@@ -273,7 +273,7 @@ impl<D: Deps> DepGraph<D> {
273273
}
274274

275275
#[inline(always)]
276-
pub fn with_task<Ctxt: HasDepContext<Deps = D>, A: Debug, R>(
276+
pub fn with_task<Ctxt: HasDepContext, A: Debug, R>(
277277
&self,
278278
key: DepNode,
279279
cx: Ctxt,
@@ -287,7 +287,7 @@ impl<D: Deps> DepGraph<D> {
287287
}
288288
}
289289

290-
pub fn with_anon_task<Tcx: DepContext<Deps = D>, OP, R>(
290+
pub fn with_anon_task<Tcx: DepContext, OP, R>(
291291
&self,
292292
cx: Tcx,
293293
dep_kind: DepKind,
@@ -303,7 +303,7 @@ impl<D: Deps> DepGraph<D> {
303303
}
304304
}
305305

306-
impl<D: Deps> DepGraphData<D> {
306+
impl DepGraphData {
307307
/// Starts a new dep-graph task. Dep-graph tasks are specified
308308
/// using a free function (`task`) and **not** a closure -- this
309309
/// is intentional because we want to exercise tight control over
@@ -332,7 +332,7 @@ impl<D: Deps> DepGraphData<D> {
332332
///
333333
/// [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/queries/incremental-compilation.html
334334
#[inline(always)]
335-
pub(crate) fn with_task<Ctxt: HasDepContext<Deps = D>, A: Debug, R>(
335+
pub(crate) fn with_task<Ctxt: HasDepContext, A: Debug, R>(
336336
&self,
337337
key: DepNode,
338338
cx: Ctxt,
@@ -397,7 +397,7 @@ impl<D: Deps> DepGraphData<D> {
397397

398398
/// Executes something within an "anonymous" task, that is, a task the
399399
/// `DepNode` of which is determined by the list of inputs it read from.
400-
pub(crate) fn with_anon_task<Tcx: DepContext<Deps = D>, OP, R>(
400+
pub(crate) fn with_anon_task<Tcx: DepContext, OP, R>(
401401
&self,
402402
cx: Tcx,
403403
dep_kind: DepKind,
@@ -456,7 +456,7 @@ impl<D: Deps> DepGraphData<D> {
456456
}
457457
}
458458

459-
impl<D: Deps> DepGraph<D> {
459+
impl DepGraph {
460460
#[inline]
461461
pub fn read_index(&self, dep_node_index: DepNodeIndex) {
462462
if let Some(ref data) = self.data {
@@ -527,7 +527,7 @@ impl<D: Deps> DepGraph<D> {
527527
/// FIXME: If the code is changed enough for this node to be marked before requiring the
528528
/// caller's node, we suppose that those changes will be enough to mark this node red and
529529
/// force a recomputation using the "normal" way.
530-
pub fn with_feed_task<Ctxt: DepContext<Deps = D>, A: Debug, R: Debug>(
530+
pub fn with_feed_task<Ctxt: DepContext, A: Debug, R: Debug>(
531531
&self,
532532
node: DepNode,
533533
cx: Ctxt,
@@ -615,7 +615,7 @@ impl<D: Deps> DepGraph<D> {
615615
}
616616
}
617617

618-
impl<D: Deps> DepGraphData<D> {
618+
impl DepGraphData {
619619
#[inline]
620620
fn dep_node_index_of_opt(&self, dep_node: &DepNode) -> Option<DepNodeIndex> {
621621
if let Some(prev_index) = self.previous.node_to_index_opt(dep_node) {
@@ -661,7 +661,7 @@ impl<D: Deps> DepGraphData<D> {
661661
}
662662
}
663663

664-
impl<D: Deps> DepGraph<D> {
664+
impl DepGraph {
665665
#[inline]
666666
pub fn dep_node_exists(&self, dep_node: &DepNode) -> bool {
667667
self.data.as_ref().is_some_and(|data| data.dep_node_exists(dep_node))
@@ -710,7 +710,7 @@ impl<D: Deps> DepGraph<D> {
710710
None
711711
}
712712

713-
pub fn try_mark_green<Qcx: QueryContext<Deps = D>>(
713+
pub fn try_mark_green<Qcx: QueryContext>(
714714
&self,
715715
qcx: Qcx,
716716
dep_node: &DepNode,
@@ -719,13 +719,13 @@ impl<D: Deps> DepGraph<D> {
719719
}
720720
}
721721

722-
impl<D: Deps> DepGraphData<D> {
722+
impl DepGraphData {
723723
/// Try to mark a node index for the node dep_node.
724724
///
725725
/// A node will have an index, when it's already been marked green, or when we can mark it
726726
/// green. This function will mark the current task as a reader of the specified node, when
727727
/// a node index can be found for that node.
728-
pub(crate) fn try_mark_green<Qcx: QueryContext<Deps = D>>(
728+
pub(crate) fn try_mark_green<Qcx: QueryContext>(
729729
&self,
730730
qcx: Qcx,
731731
dep_node: &DepNode,
@@ -750,7 +750,7 @@ impl<D: Deps> DepGraphData<D> {
750750
}
751751

752752
#[instrument(skip(self, qcx, parent_dep_node_index, frame), level = "debug")]
753-
fn try_mark_parent_green<Qcx: QueryContext<Deps = D>>(
753+
fn try_mark_parent_green<Qcx: QueryContext>(
754754
&self,
755755
qcx: Qcx,
756756
parent_dep_node_index: SerializedDepNodeIndex,
@@ -838,7 +838,7 @@ impl<D: Deps> DepGraphData<D> {
838838

839839
/// Try to mark a dep-node which existed in the previous compilation session as green.
840840
#[instrument(skip(self, qcx, prev_dep_node_index, frame), level = "debug")]
841-
fn try_mark_previous_green<Qcx: QueryContext<Deps = D>>(
841+
fn try_mark_previous_green<Qcx: QueryContext>(
842842
&self,
843843
qcx: Qcx,
844844
prev_dep_node_index: SerializedDepNodeIndex,
@@ -909,7 +909,7 @@ impl<D: Deps> DepGraphData<D> {
909909
/// This may be called concurrently on multiple threads for the same dep node.
910910
#[cold]
911911
#[inline(never)]
912-
fn emit_side_effects<Qcx: QueryContext<Deps = D>>(
912+
fn emit_side_effects<Qcx: QueryContext>(
913913
&self,
914914
qcx: Qcx,
915915
dep_node_index: DepNodeIndex,
@@ -933,7 +933,7 @@ impl<D: Deps> DepGraphData<D> {
933933
}
934934
}
935935

936-
impl<D: Deps> DepGraph<D> {
936+
impl DepGraph {
937937
/// Returns true if the given node has been marked as red during the
938938
/// current compilation session. Used in various assertions
939939
pub fn is_red(&self, dep_node: &DepNode) -> bool {
@@ -1069,8 +1069,8 @@ rustc_index::newtype_index! {
10691069
/// `new_node_to_index` and `data`, or `prev_index_to_index` and `data`. When
10701070
/// manipulating both, we acquire `new_node_to_index` or `prev_index_to_index`
10711071
/// first, and `data` second.
1072-
pub(super) struct CurrentDepGraph<D: Deps> {
1073-
encoder: Steal<GraphEncoder<D>>,
1072+
pub(super) struct CurrentDepGraph {
1073+
encoder: Steal<GraphEncoder>,
10741074
new_node_to_index: Sharded<FxHashMap<DepNode, DepNodeIndex>>,
10751075
prev_index_to_index: Lock<IndexVec<SerializedDepNodeIndex, Option<DepNodeIndex>>>,
10761076

@@ -1109,8 +1109,8 @@ pub(super) struct CurrentDepGraph<D: Deps> {
11091109
node_intern_event_id: Option<EventId>,
11101110
}
11111111

1112-
impl<D: Deps> CurrentDepGraph<D> {
1113-
fn new(
1112+
impl CurrentDepGraph {
1113+
fn new<D: Deps>(
11141114
profiler: &SelfProfilerRef,
11151115
prev_graph_node_count: usize,
11161116
encoder: FileEncoder,
@@ -1146,7 +1146,7 @@ impl<D: Deps> CurrentDepGraph<D> {
11461146
.map(EventId::from_label);
11471147

11481148
CurrentDepGraph {
1149-
encoder: Steal::new(GraphEncoder::new(
1149+
encoder: Steal::new(GraphEncoder::new::<D>(
11501150
encoder,
11511151
prev_graph_node_count,
11521152
record_graph,
@@ -1392,7 +1392,7 @@ impl DepNodeColorMap {
13921392

13931393
#[inline(never)]
13941394
#[cold]
1395-
pub(crate) fn print_markframe_trace<D: Deps>(graph: &DepGraph<D>, frame: Option<&MarkFrame<'_>>) {
1395+
pub(crate) fn print_markframe_trace(graph: &DepGraph, frame: Option<&MarkFrame<'_>>) {
13961396
let data = graph.data.as_ref().unwrap();
13971397

13981398
eprintln!("there was a panic while trying to force a dep node");

compiler/rustc_query_system/src/dep_graph/mod.rs

+3-8
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,11 @@ use std::panic;
2020
use self::graph::{print_markframe_trace, MarkFrame};
2121

2222
pub trait DepContext: Copy {
23-
type Deps: Deps;
24-
2523
/// Create a hashing context for hashing new results.
2624
fn with_stable_hashing_context<R>(self, f: impl FnOnce(StableHashingContext<'_>) -> R) -> R;
2725

2826
/// Access the DepGraph.
29-
fn dep_graph(&self) -> &DepGraph<Self::Deps>;
27+
fn dep_graph(&self) -> &DepGraph;
3028

3129
/// Access the profiler.
3230
fn profiler(&self) -> &SelfProfilerRef;
@@ -80,7 +78,7 @@ pub trait DepContext: Copy {
8078
}
8179
}
8280

83-
pub trait Deps {
81+
pub trait Deps: 'static {
8482
/// We use this for most things when incr. comp. is turned off.
8583
const DEP_KIND_NULL: DepKind;
8684

@@ -93,14 +91,12 @@ pub trait Deps {
9391
}
9492

9593
pub trait HasDepContext: Copy {
96-
type Deps: self::Deps;
97-
type DepContext: self::DepContext<Deps = Self::Deps>;
94+
type DepContext: self::DepContext;
9895

9996
fn dep_context(&self) -> &Self::DepContext;
10097
}
10198

10299
impl<T: DepContext> HasDepContext for T {
103-
type Deps = T::Deps;
104100
type DepContext = Self;
105101

106102
fn dep_context(&self) -> &Self::DepContext {
@@ -109,7 +105,6 @@ impl<T: DepContext> HasDepContext for T {
109105
}
110106

111107
impl<T: HasDepContext, Q: Copy> HasDepContext for (T, Q) {
112-
type Deps = T::Deps;
113108
type DepContext = T::DepContext;
114109

115110
fn dep_context(&self) -> &Self::DepContext {

0 commit comments

Comments
 (0)