]> git.lizzy.rs Git - rust.git/commitdiff
Move assertion inwards.
authorCamille GILLOT <gillot.camille@gmail.com>
Mon, 2 Nov 2020 22:09:03 +0000 (23:09 +0100)
committerCamille GILLOT <gillot.camille@gmail.com>
Sun, 22 Aug 2021 18:23:29 +0000 (20:23 +0200)
`with_taks_impl` is only called from `with_eval_always_task` and
`with_task` . The former is only used in query invocation, while the
latter is also used to start the `tcx` and to trigger codegen.

This move should not change significantly the number of calls to this
assertion.

compiler/rustc_query_system/src/dep_graph/graph.rs
compiler/rustc_query_system/src/query/plumbing.rs

index 9c3dad8bd63499caa9204a38ea434506dcb19feb..21f9d51e7af309ed249867d19aa30d17bfd7ff49 100644 (file)
@@ -11,6 +11,7 @@
 use parking_lot::Mutex;
 use smallvec::{smallvec, SmallVec};
 use std::collections::hash_map::Entry;
+use std::fmt::Debug;
 use std::hash::Hash;
 use std::marker::PhantomData;
 use std::sync::atomic::Ordering::Relaxed;
@@ -208,7 +209,7 @@ pub fn with_ignore<OP, R>(&self, op: OP) -> R
     ///   `arg` parameter.
     ///
     /// [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/incremental-compilation.html
-    pub fn with_task<Ctxt: HasDepContext<DepKind = K>, A, R>(
+    pub fn with_task<Ctxt: HasDepContext<DepKind = K>, A: Debug, R>(
         &self,
         key: DepNode<K>,
         cx: Ctxt,
@@ -234,7 +235,7 @@ pub fn with_task<Ctxt: HasDepContext<DepKind = K>, A, R>(
         )
     }
 
-    fn with_task_impl<Ctxt: HasDepContext<DepKind = K>, A, R>(
+    fn with_task_impl<Ctxt: HasDepContext<DepKind = K>, A: Debug, R>(
         &self,
         key: DepNode<K>,
         cx: Ctxt,
@@ -244,6 +245,20 @@ fn with_task_impl<Ctxt: HasDepContext<DepKind = K>, A, R>(
         hash_result: impl FnOnce(&mut Ctxt::StableHashingContext, &R) -> Option<Fingerprint>,
     ) -> (R, DepNodeIndex) {
         if let Some(ref data) = self.data {
+            // If the following assertion triggers, it can have two reasons:
+            // 1. Something is wrong with DepNode creation, either here or
+            //    in `DepGraph::try_mark_green()`.
+            // 2. Two distinct query keys get mapped to the same `DepNode`
+            //    (see for example #48923).
+            assert!(
+                !self.dep_node_exists(&key),
+                "forcing query with already existing `DepNode`\n\
+                 - query-key: {:?}\n\
+                 - dep-node: {:?}",
+                arg,
+                key
+            );
+
             let dcx = cx.dep_context();
             let task_deps = create_task(key).map(Lock::new);
             let result = K::with_deps(task_deps.as_ref(), || task(cx, arg));
@@ -359,7 +374,7 @@ pub fn with_anon_task<Ctxt: DepContext<DepKind = K>, OP, R>(
 
     /// Executes something within an "eval-always" task which is a task
     /// that runs whenever anything changes.
-    pub fn with_eval_always_task<Ctxt: HasDepContext<DepKind = K>, A, R>(
+    pub fn with_eval_always_task<Ctxt: HasDepContext<DepKind = K>, A: Debug, R>(
         &self,
         key: DepNode<K>,
         cx: Ctxt,
index 55739cbf1d8ac07be21e1290657c411a3f32b6c1..86097042da016ff28c7d2f25ddf0ab01f1466f40 100644 (file)
@@ -646,20 +646,6 @@ fn force_query_with_job<C, CTX>(
     C: QueryCache,
     CTX: QueryContext,
 {
-    // If the following assertion triggers, it can have two reasons:
-    // 1. Something is wrong with DepNode creation, either here or
-    //    in `DepGraph::try_mark_green()`.
-    // 2. Two distinct query keys get mapped to the same `DepNode`
-    //    (see for example #48923).
-    assert!(
-        !tcx.dep_context().dep_graph().dep_node_exists(&dep_node),
-        "forcing query with already existing `DepNode`\n\
-                 - query-key: {:?}\n\
-                 - dep-node: {:?}",
-        key,
-        dep_node
-    );
-
     let prof_timer = tcx.dep_context().profiler().query_provider();
 
     let ((result, dep_node_index), diagnostics) = with_diagnostics(|diagnostics| {