about summary refs log tree commit diff
path: root/src/librustc_query_system
diff options
context:
space:
mode:
authorCamille GILLOT <gillot.camille@gmail.com>2020-03-28 13:51:37 +0100
committerCamille GILLOT <gillot.camille@gmail.com>2020-05-01 14:48:14 +0200
commite15383cce12a3bf33ec0475fd78cf786f57c3140 (patch)
tree859ba2f752eda44f83e98c3ee7b1f5994f26588f /src/librustc_query_system
parent8f3e96d6589fad610107fa05ba80fc708965561b (diff)
Move the DepNode construction to librustc_query_system.
Diffstat (limited to 'src/librustc_query_system')
-rw-r--r--src/librustc_query_system/dep_graph/dep_node.rs24
-rw-r--r--src/librustc_query_system/dep_graph/mod.rs1
-rw-r--r--src/librustc_query_system/query/config.rs16
-rw-r--r--src/librustc_query_system/query/plumbing.rs4
4 files changed, 39 insertions, 6 deletions
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<K: DepKind> DepNode<K> {
         debug_assert!(!kind.has_params());
         DepNode { kind, hash: Fingerprint::ZERO }
     }
+
+    pub fn construct<Ctxt, Key>(tcx: Ctxt, kind: K, arg: &Key) -> DepNode<K>
+    where
+        Ctxt: crate::query::QueryContext<DepKind = K>,
+        Key: DepNodeParams<Ctxt>,
+    {
+        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<K: DepKind> fmt::Debug for DepNode<K> {
@@ -120,6 +138,12 @@ where
     }
 }
 
+impl<Ctxt: DepContext> DepNodeParams<Ctxt> 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<Self::DepKind>) -> 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<CTX: QueryContext, K, V> {
     pub anon: bool,
     pub dep_kind: CTX::DepKind,
     pub eval_always: bool,
-    pub to_dep_node: fn(CTX, &K) -> DepNode<CTX::DepKind>,
 
     // 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<CTX: QueryContext, K, V> {
 }
 
 impl<CTX: QueryContext, K, V> QueryVtable<CTX, K, V> {
-    pub(crate) fn to_dep_node(&self, tcx: CTX, key: &K) -> DepNode<CTX::DepKind> {
-        (self.to_dep_node)(tcx, key)
+    pub(crate) fn to_dep_node(&self, tcx: CTX, key: &K) -> DepNode<CTX::DepKind>
+    where
+        K: crate::dep_graph::DepNodeParams<CTX>,
+    {
+        DepNode::construct(tcx, self.dep_kind, key)
     }
 
     pub(crate) fn compute(&self, tcx: CTX, key: K) -> V {
@@ -79,7 +81,12 @@ pub trait QueryAccessors<CTX: QueryContext>: QueryConfig<CTX> {
     // Don't use this method to access query results, instead use the methods on TyCtxt
     fn query_state<'a>(tcx: CTX) -> &'a QueryState<CTX, Self::Cache>;
 
-    fn to_dep_node(tcx: CTX, key: &Self::Key) -> DepNode<CTX::DepKind>;
+    fn to_dep_node(tcx: CTX, key: &Self::Key) -> DepNode<CTX::DepKind>
+    where
+        Self::Key: crate::dep_graph::DepNodeParams<CTX>,
+    {
+        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<CTX, Q::Key, Q::Value> = 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<CTX, C>(
 ) -> C::Stored
 where
     C: QueryCache,
-    C::Key: Eq + Clone + Debug,
+    C::Key: Eq + Clone + Debug + crate::dep_graph::DepNodeParams<CTX>,
     C::Stored: Clone,
     CTX: QueryContext,
 {
@@ -616,6 +616,7 @@ where
 pub fn get_query<Q, CTX>(tcx: CTX, span: Span, key: Q::Key) -> Q::Stored
 where
     Q: QueryDescription<CTX>,
+    Q::Key: crate::dep_graph::DepNodeParams<CTX>,
     CTX: QueryContext,
 {
     debug!("ty::query::get_query<{}>(key={:?}, span={:?})", Q::NAME, key, span);
@@ -642,6 +643,7 @@ where
 pub fn ensure_query<Q, CTX>(tcx: CTX, key: Q::Key)
 where
     Q: QueryDescription<CTX>,
+    Q::Key: crate::dep_graph::DepNodeParams<CTX>,
     CTX: QueryContext,
 {
     if Q::EVAL_ALWAYS {