diff --git a/src/librustc_middle/dep_graph/dep_node.rs b/src/librustc_middle/dep_graph/dep_node.rs index f4a4aab844c..33037900880 100644 --- a/src/librustc_middle/dep_graph/dep_node.rs +++ b/src/librustc_middle/dep_graph/dep_node.rs @@ -183,31 +183,10 @@ macro_rules! define_dep_nodes { // tuple args $({ erase!($tuple_arg_ty); - let hash = DepNodeParams::to_fingerprint(&arg, _tcx); - let dep_node = DepNode { - kind: DepKind::$variant, - hash - }; - - #[cfg(debug_assertions)] - { - if !dep_node.kind.can_reconstruct_query_key() && - (_tcx.sess.opts.debugging_opts.incremental_info || - _tcx.sess.opts.debugging_opts.query_dep_graph) - { - _tcx.dep_graph.register_dep_node_debug_str(dep_node, || { - arg.to_debug_str(_tcx) - }); - } - } - - return dep_node; + return DepNode::construct(_tcx, DepKind::$variant, &arg) })* - DepNode { - kind: DepKind::$variant, - hash: Fingerprint::ZERO, - } + return DepNode::construct(_tcx, DepKind::$variant, &()) } )* } diff --git a/src/librustc_middle/dep_graph/mod.rs b/src/librustc_middle/dep_graph/mod.rs index 4786426792c..207c6d0fbff 100644 --- a/src/librustc_middle/dep_graph/mod.rs +++ b/src/librustc_middle/dep_graph/mod.rs @@ -98,6 +98,10 @@ impl<'tcx> DepContext for TyCtxt<'tcx> { fn debug_dep_tasks(&self) -> bool { self.sess.opts.debugging_opts.dep_tasks } + fn debug_dep_node(&self) -> bool { + self.sess.opts.debugging_opts.incremental_info + || self.sess.opts.debugging_opts.query_dep_graph + } fn try_force_from_dep_node(&self, dep_node: &DepNode) -> bool { // FIXME: This match is just a workaround for incremental bugs and should diff --git a/src/librustc_middle/ty/query/mod.rs b/src/librustc_middle/ty/query/mod.rs index 899479e65a7..105b0f8f2cf 100644 --- a/src/librustc_middle/ty/query/mod.rs +++ b/src/librustc_middle/ty/query/mod.rs @@ -1,4 +1,4 @@ -use crate::dep_graph::{self, DepConstructor, DepNode, DepNodeParams}; +use crate::dep_graph::{self, DepNode, DepNodeParams}; use crate::hir::exports::Export; use crate::hir::map; use crate::infer::canonical::{self, Canonical}; diff --git a/src/librustc_middle/ty/query/plumbing.rs b/src/librustc_middle/ty/query/plumbing.rs index e4237df5923..d6d4335e938 100644 --- a/src/librustc_middle/ty/query/plumbing.rs +++ b/src/librustc_middle/ty/query/plumbing.rs @@ -348,12 +348,6 @@ macro_rules! define_queries_inner { &tcx.queries.$name } - #[allow(unused)] - #[inline(always)] - fn to_dep_node(tcx: TyCtxt<$tcx>, key: &Self::Key) -> DepNode { - DepConstructor::$node(tcx, *key) - } - #[inline] fn compute(tcx: TyCtxt<'tcx>, key: Self::Key) -> Self::Value { let provider = tcx.queries.providers.get(key.query_crate()) diff --git a/src/librustc_query_system/dep_graph/dep_node.rs b/src/librustc_query_system/dep_graph/dep_node.rs index 99eb3cdc0b0..36343365ab6 100644 --- a/src/librustc_query_system/dep_graph/dep_node.rs +++ b/src/librustc_query_system/dep_graph/dep_node.rs @@ -64,6 +64,24 @@ impl DepNode { debug_assert!(!kind.has_params()); DepNode { kind, hash: Fingerprint::ZERO } } + + pub fn construct(tcx: Ctxt, kind: K, arg: &Key) -> DepNode + where + Ctxt: crate::query::QueryContext, + Key: DepNodeParams, + { + let hash = arg.to_fingerprint(tcx); + let dep_node = DepNode { kind, hash }; + + #[cfg(debug_assertions)] + { + if !kind.can_reconstruct_query_key() && tcx.debug_dep_node() { + tcx.dep_graph().register_dep_node_debug_str(dep_node, || arg.to_debug_str(tcx)); + } + } + + return dep_node; + } } impl fmt::Debug for DepNode { @@ -120,6 +138,12 @@ where } } +impl DepNodeParams for () { + fn to_fingerprint(&self, _: Ctxt) -> Fingerprint { + Fingerprint::ZERO + } +} + /// A "work product" corresponds to a `.o` (or other) file that we /// save in between runs. These IDs do not have a `DefId` but rather /// some independent path or string that persists between runs without diff --git a/src/librustc_query_system/dep_graph/mod.rs b/src/librustc_query_system/dep_graph/mod.rs index fbc91575ede..f571e902211 100644 --- a/src/librustc_query_system/dep_graph/mod.rs +++ b/src/librustc_query_system/dep_graph/mod.rs @@ -28,6 +28,7 @@ pub trait DepContext: Copy { fn create_stable_hashing_context(&self) -> Self::StableHashingContext; fn debug_dep_tasks(&self) -> bool; + fn debug_dep_node(&self) -> bool; /// Try to force a dep node to execute and see if it's green. fn try_force_from_dep_node(&self, dep_node: &DepNode) -> bool; diff --git a/src/librustc_query_system/query/config.rs b/src/librustc_query_system/query/config.rs index a334e897e40..f031b54346f 100644 --- a/src/librustc_query_system/query/config.rs +++ b/src/librustc_query_system/query/config.rs @@ -28,7 +28,6 @@ pub(crate) struct QueryVtable { pub anon: bool, pub dep_kind: CTX::DepKind, pub eval_always: bool, - pub to_dep_node: fn(CTX, &K) -> DepNode, // Don't use this method to compute query results, instead use the methods on TyCtxt pub compute: fn(CTX, K) -> V, @@ -40,8 +39,11 @@ pub(crate) struct QueryVtable { } impl QueryVtable { - pub(crate) fn to_dep_node(&self, tcx: CTX, key: &K) -> DepNode { - (self.to_dep_node)(tcx, key) + pub(crate) fn to_dep_node(&self, tcx: CTX, key: &K) -> DepNode + where + K: crate::dep_graph::DepNodeParams, + { + DepNode::construct(tcx, self.dep_kind, key) } pub(crate) fn compute(&self, tcx: CTX, key: K) -> V { @@ -79,7 +81,12 @@ pub trait QueryAccessors: QueryConfig { // Don't use this method to access query results, instead use the methods on TyCtxt fn query_state<'a>(tcx: CTX) -> &'a QueryState; - fn to_dep_node(tcx: CTX, key: &Self::Key) -> DepNode; + fn to_dep_node(tcx: CTX, key: &Self::Key) -> DepNode + where + Self::Key: crate::dep_graph::DepNodeParams, + { + DepNode::construct(tcx, Self::DEP_KIND, key) + } // Don't use this method to compute query results, instead use the methods on TyCtxt fn compute(tcx: CTX, key: Self::Key) -> Self::Value; @@ -117,7 +124,6 @@ where const VTABLE: QueryVtable = QueryVtable { anon: Q::ANON, dep_kind: Q::DEP_KIND, - to_dep_node: Q::to_dep_node, eval_always: Q::EVAL_ALWAYS, compute: Q::compute, hash_result: Q::hash_result, diff --git a/src/librustc_query_system/query/plumbing.rs b/src/librustc_query_system/query/plumbing.rs index 74a2288cfa7..d94f6bc300b 100644 --- a/src/librustc_query_system/query/plumbing.rs +++ b/src/librustc_query_system/query/plumbing.rs @@ -392,7 +392,7 @@ fn try_execute_query( ) -> C::Stored where C: QueryCache, - C::Key: Eq + Clone + Debug, + C::Key: Eq + Clone + Debug + crate::dep_graph::DepNodeParams, C::Stored: Clone, CTX: QueryContext, { @@ -616,6 +616,7 @@ where pub fn get_query(tcx: CTX, span: Span, key: Q::Key) -> Q::Stored where Q: QueryDescription, + Q::Key: crate::dep_graph::DepNodeParams, CTX: QueryContext, { debug!("ty::query::get_query<{}>(key={:?}, span={:?})", Q::NAME, key, span); @@ -642,6 +643,7 @@ where pub fn ensure_query(tcx: CTX, key: Q::Key) where Q: QueryDescription, + Q::Key: crate::dep_graph::DepNodeParams, CTX: QueryContext, { if Q::EVAL_ALWAYS {