about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJohn Kåre Alsaker <john.kare.alsaker@gmail.com>2023-06-06 04:49:09 +0200
committerJohn Kåre Alsaker <john.kare.alsaker@gmail.com>2023-06-06 04:51:34 +0200
commitfd3d2d49f2527efd2decad3a6194b82e26137bd8 (patch)
tree5a1b701042775fdfd446c723096a5cb8ef2043c0
parentad8304a0d5280de30856b39c19df7b306957e878 (diff)
downloadrust-fd3d2d49f2527efd2decad3a6194b82e26137bd8.tar.gz
rust-fd3d2d49f2527efd2decad3a6194b82e26137bd8.zip
Don't hold the active queries lock while calling `make_query`
-rw-r--r--compiler/rustc_query_system/src/query/plumbing.rs15
1 files changed, 11 insertions, 4 deletions
diff --git a/compiler/rustc_query_system/src/query/plumbing.rs b/compiler/rustc_query_system/src/query/plumbing.rs
index 730e4c8d30d..b2bc33c7e0d 100644
--- a/compiler/rustc_query_system/src/query/plumbing.rs
+++ b/compiler/rustc_query_system/src/query/plumbing.rs
@@ -69,6 +69,8 @@ where
         make_query: fn(Qcx, K) -> QueryStackFrame<D>,
         jobs: &mut QueryMap<D>,
     ) -> Option<()> {
+        let mut active = Vec::new();
+
         #[cfg(parallel_compiler)]
         {
             // We use try_lock_shards here since we are called from the
@@ -77,8 +79,7 @@ where
             for shard in shards.iter() {
                 for (k, v) in shard.iter() {
                     if let QueryResult::Started(ref job) = *v {
-                        let query = make_query(qcx, *k);
-                        jobs.insert(job.id, QueryJobInfo { query, job: job.clone() });
+                        active.push((*k, job.clone()));
                     }
                 }
             }
@@ -91,12 +92,18 @@ where
             // really hurt much.)
             for (k, v) in self.active.try_lock()?.iter() {
                 if let QueryResult::Started(ref job) = *v {
-                    let query = make_query(qcx, *k);
-                    jobs.insert(job.id, QueryJobInfo { query, job: job.clone() });
+                    active.push((*k, job.clone()));
                 }
             }
         }
 
+        // Call `make_query` while we're not holding a `self.active` lock as `make_query` may call
+        // queries leading to a deadlock.
+        for (key, job) in active {
+            let query = make_query(qcx, key);
+            jobs.insert(job.id, QueryJobInfo { query, job });
+        }
+
         Some(())
     }
 }