Skip to content

Commit fd3d2d4

Browse files
committed
Don't hold the active queries lock while calling make_query
1 parent ad8304a commit fd3d2d4

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

compiler/rustc_query_system/src/query/plumbing.rs

+11-4
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ where
6969
make_query: fn(Qcx, K) -> QueryStackFrame<D>,
7070
jobs: &mut QueryMap<D>,
7171
) -> Option<()> {
72+
let mut active = Vec::new();
73+
7274
#[cfg(parallel_compiler)]
7375
{
7476
// We use try_lock_shards here since we are called from the
@@ -77,8 +79,7 @@ where
7779
for shard in shards.iter() {
7880
for (k, v) in shard.iter() {
7981
if let QueryResult::Started(ref job) = *v {
80-
let query = make_query(qcx, *k);
81-
jobs.insert(job.id, QueryJobInfo { query, job: job.clone() });
82+
active.push((*k, job.clone()));
8283
}
8384
}
8485
}
@@ -91,12 +92,18 @@ where
9192
// really hurt much.)
9293
for (k, v) in self.active.try_lock()?.iter() {
9394
if let QueryResult::Started(ref job) = *v {
94-
let query = make_query(qcx, *k);
95-
jobs.insert(job.id, QueryJobInfo { query, job: job.clone() });
95+
active.push((*k, job.clone()));
9696
}
9797
}
9898
}
9999

100+
// Call `make_query` while we're not holding a `self.active` lock as `make_query` may call
101+
// queries leading to a deadlock.
102+
for (key, job) in active {
103+
let query = make_query(qcx, key);
104+
jobs.insert(job.id, QueryJobInfo { query, job });
105+
}
106+
100107
Some(())
101108
}
102109
}

0 commit comments

Comments
 (0)