Skip to content

Commit a51ad88

Browse files
committed
Decouple from DepKind.
1 parent 2a52436 commit a51ad88

File tree

4 files changed

+22
-12
lines changed

4 files changed

+22
-12
lines changed

src/librustc/dep_graph/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ pub type PreviousDepGraph = rustc_query_system::dep_graph::PreviousDepGraph<DepK
2727
pub type SerializedDepGraph = rustc_query_system::dep_graph::SerializedDepGraph<DepKind>;
2828

2929
impl rustc_query_system::dep_graph::DepKind for DepKind {
30+
const NULL: Self = DepKind::Null;
31+
3032
fn is_eval_always(&self) -> bool {
3133
DepKind::is_eval_always(self)
3234
}
@@ -82,6 +84,10 @@ impl rustc_query_system::dep_graph::DepKind for DepKind {
8284
op(icx.task_deps)
8385
})
8486
}
87+
88+
fn can_reconstruct_query_key(&self) -> bool {
89+
DepKind::can_reconstruct_query_key(self)
90+
}
8591
}
8692

8793
impl<'tcx> DepContext for TyCtxt<'tcx> {

src/librustc/ty/query/config.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
//! Query configuration and description traits.
22
3-
use crate::dep_graph::DepKind;
43
use crate::dep_graph::SerializedDepNodeIndex;
54
use crate::ty::query::caches::QueryCache;
65
use crate::ty::query::plumbing::CycleError;
@@ -23,7 +22,7 @@ pub trait QueryConfig<CTX> {
2322
type Value: Clone;
2423
}
2524

26-
pub trait QueryContext: DepContext<DepKind = DepKind> {
25+
pub trait QueryContext: DepContext {
2726
type Query;
2827

2928
/// Access the session.

src/librustc/ty/query/plumbing.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//! generate the actual methods on tcx which find and execute the provider,
33
//! manage the caches, and so forth.
44
5-
use crate::dep_graph::{DepKind, DepNode, DepNodeIndex, SerializedDepNodeIndex};
5+
use crate::dep_graph::{DepNodeIndex, SerializedDepNodeIndex};
66
use crate::ty::query::caches::QueryCache;
77
use crate::ty::query::config::{QueryContext, QueryDescription};
88
use crate::ty::query::job::{QueryInfo, QueryJob, QueryJobId, QueryJobInfo, QueryShardJobId};
@@ -17,6 +17,7 @@ use rustc_data_structures::sharded::Sharded;
1717
use rustc_data_structures::sync::{Lock, LockGuard};
1818
use rustc_data_structures::thin_vec::ThinVec;
1919
use rustc_errors::{struct_span_err, Diagnostic, DiagnosticBuilder, FatalError, Handler, Level};
20+
use rustc_query_system::dep_graph::{DepKind, DepNode};
2021
use rustc_session::Session;
2122
use rustc_span::def_id::DefId;
2223
use rustc_span::source_map::DUMMY_SP;
@@ -102,7 +103,7 @@ impl<CTX: QueryContext, C: QueryCache<CTX>> QueryState<CTX, C> {
102103

103104
pub(super) fn try_collect_active_jobs(
104105
&self,
105-
kind: DepKind,
106+
kind: CTX::DepKind,
106107
make_query: fn(C::Key) -> CTX::Query,
107108
jobs: &mut FxHashMap<QueryJobId<CTX::DepKind>, QueryJobInfo<CTX>>,
108109
) -> Option<()>
@@ -375,7 +376,7 @@ impl<'tcx> TyCtxt<'tcx> {
375376
#[inline(always)]
376377
fn start_query<F, R>(
377378
self,
378-
token: QueryJobId<DepKind>,
379+
token: QueryJobId<crate::dep_graph::DepKind>,
379380
diagnostics: Option<&Lock<ThinVec<Diagnostic>>>,
380381
compute: F,
381382
) -> R
@@ -570,7 +571,7 @@ impl<'tcx> TyCtxt<'tcx> {
570571
// Fast path for when incr. comp. is off. `to_dep_node` is
571572
// expensive for some `DepKind`s.
572573
if !self.dep_graph.is_fully_enabled() {
573-
let null_dep_node = DepNode::new_no_params(crate::dep_graph::DepKind::Null);
574+
let null_dep_node = DepNode::new_no_params(DepKind::NULL);
574575
return self.force_query_with_job::<Q>(key, job, null_dep_node).0;
575576
}
576577

@@ -634,7 +635,7 @@ impl<'tcx> TyCtxt<'tcx> {
634635
key: Q::Key,
635636
prev_dep_node_index: SerializedDepNodeIndex,
636637
dep_node_index: DepNodeIndex,
637-
dep_node: &DepNode,
638+
dep_node: &DepNode<crate::dep_graph::DepKind>,
638639
) -> Q::Value {
639640
// Note this function can be called concurrently from the same query
640641
// We must ensure that this is handled correctly.
@@ -689,7 +690,7 @@ impl<'tcx> TyCtxt<'tcx> {
689690
fn incremental_verify_ich<Q: QueryDescription<TyCtxt<'tcx>>>(
690691
self,
691692
result: &Q::Value,
692-
dep_node: &DepNode,
693+
dep_node: &DepNode<crate::dep_graph::DepKind>,
693694
dep_node_index: DepNodeIndex,
694695
) {
695696
use rustc_data_structures::fingerprint::Fingerprint;
@@ -716,8 +717,8 @@ impl<'tcx> TyCtxt<'tcx> {
716717
fn force_query_with_job<Q: QueryDescription<TyCtxt<'tcx>> + 'tcx>(
717718
self,
718719
key: Q::Key,
719-
job: JobOwner<'tcx, TyCtxt<'tcx>, Q::Cache>,
720-
dep_node: DepNode,
720+
job: JobOwner<'tcx, Self, Q::Cache>,
721+
dep_node: DepNode<crate::dep_graph::DepKind>,
721722
) -> (Q::Value, DepNodeIndex) {
722723
// If the following assertion triggers, it can have two reasons:
723724
// 1. Something is wrong with DepNode creation, either here or
@@ -754,7 +755,7 @@ impl<'tcx> TyCtxt<'tcx> {
754755
prof_timer.finish_with_query_invocation_id(dep_node_index.into());
755756

756757
if unlikely!(!diagnostics.is_empty()) {
757-
if dep_node.kind != crate::dep_graph::DepKind::Null {
758+
if dep_node.kind != DepKind::NULL {
758759
self.queries.on_disk_cache.store_diagnostics(dep_node_index, diagnostics);
759760
}
760761
}
@@ -803,7 +804,7 @@ impl<'tcx> TyCtxt<'tcx> {
803804
self,
804805
key: Q::Key,
805806
span: Span,
806-
dep_node: DepNode,
807+
dep_node: DepNode<crate::dep_graph::DepKind>,
807808
) {
808809
// We may be concurrently trying both execute and force a query.
809810
// Ensure that only one of them runs the query.

src/librustc_query_system/dep_graph/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ pub trait DepContext: Copy {
5454

5555
/// Describe the different families of dependency nodes.
5656
pub trait DepKind: Copy + fmt::Debug + Eq + Ord + Hash {
57+
const NULL: Self;
58+
5759
/// Return whether this kind always require evaluation.
5860
fn is_eval_always(&self) -> bool;
5961

@@ -72,4 +74,6 @@ pub trait DepKind: Copy + fmt::Debug + Eq + Ord + Hash {
7274
fn read_deps<OP>(op: OP) -> ()
7375
where
7476
OP: for<'a> FnOnce(Option<&'a Lock<TaskDeps<Self>>>) -> ();
77+
78+
fn can_reconstruct_query_key(&self) -> bool;
7579
}

0 commit comments

Comments
 (0)