Skip to content

Commit e15383c

Browse files
committed
Move the DepNode construction to librustc_query_system.
1 parent 8f3e96d commit e15383c

File tree

8 files changed

+46
-36
lines changed

8 files changed

+46
-36
lines changed

Diff for: src/librustc_middle/dep_graph/dep_node.rs

+2-23
Original file line numberDiff line numberDiff line change
@@ -183,31 +183,10 @@ macro_rules! define_dep_nodes {
183183
// tuple args
184184
$({
185185
erase!($tuple_arg_ty);
186-
let hash = DepNodeParams::to_fingerprint(&arg, _tcx);
187-
let dep_node = DepNode {
188-
kind: DepKind::$variant,
189-
hash
190-
};
191-
192-
#[cfg(debug_assertions)]
193-
{
194-
if !dep_node.kind.can_reconstruct_query_key() &&
195-
(_tcx.sess.opts.debugging_opts.incremental_info ||
196-
_tcx.sess.opts.debugging_opts.query_dep_graph)
197-
{
198-
_tcx.dep_graph.register_dep_node_debug_str(dep_node, || {
199-
arg.to_debug_str(_tcx)
200-
});
201-
}
202-
}
203-
204-
return dep_node;
186+
return DepNode::construct(_tcx, DepKind::$variant, &arg)
205187
})*
206188

207-
DepNode {
208-
kind: DepKind::$variant,
209-
hash: Fingerprint::ZERO,
210-
}
189+
return DepNode::construct(_tcx, DepKind::$variant, &())
211190
}
212191
)*
213192
}

Diff for: src/librustc_middle/dep_graph/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ impl<'tcx> DepContext for TyCtxt<'tcx> {
9898
fn debug_dep_tasks(&self) -> bool {
9999
self.sess.opts.debugging_opts.dep_tasks
100100
}
101+
fn debug_dep_node(&self) -> bool {
102+
self.sess.opts.debugging_opts.incremental_info
103+
|| self.sess.opts.debugging_opts.query_dep_graph
104+
}
101105

102106
fn try_force_from_dep_node(&self, dep_node: &DepNode) -> bool {
103107
// FIXME: This match is just a workaround for incremental bugs and should

Diff for: src/librustc_middle/ty/query/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::dep_graph::{self, DepConstructor, DepNode, DepNodeParams};
1+
use crate::dep_graph::{self, DepNode, DepNodeParams};
22
use crate::hir::exports::Export;
33
use crate::hir::map;
44
use crate::infer::canonical::{self, Canonical};

Diff for: src/librustc_middle/ty/query/plumbing.rs

-6
Original file line numberDiff line numberDiff line change
@@ -348,12 +348,6 @@ macro_rules! define_queries_inner {
348348
&tcx.queries.$name
349349
}
350350

351-
#[allow(unused)]
352-
#[inline(always)]
353-
fn to_dep_node(tcx: TyCtxt<$tcx>, key: &Self::Key) -> DepNode {
354-
DepConstructor::$node(tcx, *key)
355-
}
356-
357351
#[inline]
358352
fn compute(tcx: TyCtxt<'tcx>, key: Self::Key) -> Self::Value {
359353
let provider = tcx.queries.providers.get(key.query_crate())

Diff for: src/librustc_query_system/dep_graph/dep_node.rs

+24
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,24 @@ impl<K: DepKind> DepNode<K> {
6464
debug_assert!(!kind.has_params());
6565
DepNode { kind, hash: Fingerprint::ZERO }
6666
}
67+
68+
pub fn construct<Ctxt, Key>(tcx: Ctxt, kind: K, arg: &Key) -> DepNode<K>
69+
where
70+
Ctxt: crate::query::QueryContext<DepKind = K>,
71+
Key: DepNodeParams<Ctxt>,
72+
{
73+
let hash = arg.to_fingerprint(tcx);
74+
let dep_node = DepNode { kind, hash };
75+
76+
#[cfg(debug_assertions)]
77+
{
78+
if !kind.can_reconstruct_query_key() && tcx.debug_dep_node() {
79+
tcx.dep_graph().register_dep_node_debug_str(dep_node, || arg.to_debug_str(tcx));
80+
}
81+
}
82+
83+
return dep_node;
84+
}
6785
}
6886

6987
impl<K: DepKind> fmt::Debug for DepNode<K> {
@@ -120,6 +138,12 @@ where
120138
}
121139
}
122140

141+
impl<Ctxt: DepContext> DepNodeParams<Ctxt> for () {
142+
fn to_fingerprint(&self, _: Ctxt) -> Fingerprint {
143+
Fingerprint::ZERO
144+
}
145+
}
146+
123147
/// A "work product" corresponds to a `.o` (or other) file that we
124148
/// save in between runs. These IDs do not have a `DefId` but rather
125149
/// some independent path or string that persists between runs without

Diff for: src/librustc_query_system/dep_graph/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ pub trait DepContext: Copy {
2828
fn create_stable_hashing_context(&self) -> Self::StableHashingContext;
2929

3030
fn debug_dep_tasks(&self) -> bool;
31+
fn debug_dep_node(&self) -> bool;
3132

3233
/// Try to force a dep node to execute and see if it's green.
3334
fn try_force_from_dep_node(&self, dep_node: &DepNode<Self::DepKind>) -> bool;

Diff for: src/librustc_query_system/query/config.rs

+11-5
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ pub(crate) struct QueryVtable<CTX: QueryContext, K, V> {
2828
pub anon: bool,
2929
pub dep_kind: CTX::DepKind,
3030
pub eval_always: bool,
31-
pub to_dep_node: fn(CTX, &K) -> DepNode<CTX::DepKind>,
3231

3332
// Don't use this method to compute query results, instead use the methods on TyCtxt
3433
pub compute: fn(CTX, K) -> V,
@@ -40,8 +39,11 @@ pub(crate) struct QueryVtable<CTX: QueryContext, K, V> {
4039
}
4140

4241
impl<CTX: QueryContext, K, V> QueryVtable<CTX, K, V> {
43-
pub(crate) fn to_dep_node(&self, tcx: CTX, key: &K) -> DepNode<CTX::DepKind> {
44-
(self.to_dep_node)(tcx, key)
42+
pub(crate) fn to_dep_node(&self, tcx: CTX, key: &K) -> DepNode<CTX::DepKind>
43+
where
44+
K: crate::dep_graph::DepNodeParams<CTX>,
45+
{
46+
DepNode::construct(tcx, self.dep_kind, key)
4547
}
4648

4749
pub(crate) fn compute(&self, tcx: CTX, key: K) -> V {
@@ -79,7 +81,12 @@ pub trait QueryAccessors<CTX: QueryContext>: QueryConfig<CTX> {
7981
// Don't use this method to access query results, instead use the methods on TyCtxt
8082
fn query_state<'a>(tcx: CTX) -> &'a QueryState<CTX, Self::Cache>;
8183

82-
fn to_dep_node(tcx: CTX, key: &Self::Key) -> DepNode<CTX::DepKind>;
84+
fn to_dep_node(tcx: CTX, key: &Self::Key) -> DepNode<CTX::DepKind>
85+
where
86+
Self::Key: crate::dep_graph::DepNodeParams<CTX>,
87+
{
88+
DepNode::construct(tcx, Self::DEP_KIND, key)
89+
}
8390

8491
// Don't use this method to compute query results, instead use the methods on TyCtxt
8592
fn compute(tcx: CTX, key: Self::Key) -> Self::Value;
@@ -117,7 +124,6 @@ where
117124
const VTABLE: QueryVtable<CTX, Q::Key, Q::Value> = QueryVtable {
118125
anon: Q::ANON,
119126
dep_kind: Q::DEP_KIND,
120-
to_dep_node: Q::to_dep_node,
121127
eval_always: Q::EVAL_ALWAYS,
122128
compute: Q::compute,
123129
hash_result: Q::hash_result,

Diff for: src/librustc_query_system/query/plumbing.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ fn try_execute_query<CTX, C>(
392392
) -> C::Stored
393393
where
394394
C: QueryCache,
395-
C::Key: Eq + Clone + Debug,
395+
C::Key: Eq + Clone + Debug + crate::dep_graph::DepNodeParams<CTX>,
396396
C::Stored: Clone,
397397
CTX: QueryContext,
398398
{
@@ -616,6 +616,7 @@ where
616616
pub fn get_query<Q, CTX>(tcx: CTX, span: Span, key: Q::Key) -> Q::Stored
617617
where
618618
Q: QueryDescription<CTX>,
619+
Q::Key: crate::dep_graph::DepNodeParams<CTX>,
619620
CTX: QueryContext,
620621
{
621622
debug!("ty::query::get_query<{}>(key={:?}, span={:?})", Q::NAME, key, span);
@@ -642,6 +643,7 @@ where
642643
pub fn ensure_query<Q, CTX>(tcx: CTX, key: Q::Key)
643644
where
644645
Q: QueryDescription<CTX>,
646+
Q::Key: crate::dep_graph::DepNodeParams<CTX>,
645647
CTX: QueryContext,
646648
{
647649
if Q::EVAL_ALWAYS {

0 commit comments

Comments
 (0)