Skip to content

Commit 4f167ce

Browse files
committed
Offload try_collect_active_jobs.
1 parent 30381f3 commit 4f167ce

File tree

2 files changed

+37
-25
lines changed

2 files changed

+37
-25
lines changed

src/librustc/ty/query/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ use rustc_attr as attr;
5454
use rustc_span::symbol::Symbol;
5555
use rustc_span::{Span, DUMMY_SP};
5656
use std::borrow::Cow;
57-
use std::convert::TryFrom;
5857
use std::ops::Deref;
5958
use std::sync::Arc;
6059

src/librustc/ty/query/plumbing.rs

Lines changed: 37 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use crate::dep_graph::{DepKind, DepNode, DepNodeIndex, SerializedDepNodeIndex};
66
use crate::ty::query::caches::QueryCache;
77
use crate::ty::query::config::{QueryAccessors, QueryConfig, QueryDescription};
8-
use crate::ty::query::job::{QueryInfo, QueryJob, QueryJobId, QueryShardJobId};
8+
use crate::ty::query::job::{QueryInfo, QueryJob, QueryJobId, QueryJobInfo, QueryShardJobId};
99
use crate::ty::query::Query;
1010
use crate::ty::tls;
1111
use crate::ty::{self, TyCtxt};
@@ -20,6 +20,7 @@ use rustc_errors::{struct_span_err, Diagnostic, DiagnosticBuilder, FatalError, H
2020
use rustc_span::source_map::DUMMY_SP;
2121
use rustc_span::Span;
2222
use std::collections::hash_map::Entry;
23+
use std::convert::TryFrom;
2324
use std::fmt::Debug;
2425
use std::hash::{Hash, Hasher};
2526
use std::mem;
@@ -110,6 +111,36 @@ impl<'tcx, K, V, C: QueryCache<K, V>> QueryStateImpl<'tcx, K, V, C> {
110111
let shards = self.shards.lock_shards();
111112
shards.iter().all(|shard| shard.active.is_empty())
112113
}
114+
115+
#[inline]
116+
pub(super) fn try_collect_active_jobs(
117+
&self,
118+
kind: DepKind,
119+
make_query: impl Fn(K) -> Query<'tcx> + Copy,
120+
jobs: &mut FxHashMap<QueryJobId, QueryJobInfo<'tcx>>,
121+
) -> Option<()>
122+
where
123+
K: Clone,
124+
{
125+
// We use try_lock_shards here since we are called from the
126+
// deadlock handler, and this shouldn't be locked.
127+
let shards = self.shards.try_lock_shards()?;
128+
let shards = shards.iter().enumerate();
129+
jobs.extend(shards.flat_map(|(shard_id, shard)| {
130+
shard.active.iter().filter_map(move |(k, v)| {
131+
if let QueryResult::Started(ref job) = *v {
132+
let id =
133+
QueryJobId { job: job.id, shard: u16::try_from(shard_id).unwrap(), kind };
134+
let info = QueryInfo { span: job.span, query: make_query(k.clone()) };
135+
Some((id, QueryJobInfo { info, job: job.clone() }))
136+
} else {
137+
None
138+
}
139+
})
140+
}));
141+
142+
Some(())
143+
}
113144
}
114145

115146
impl<'tcx, K, V, C: QueryCache<K, V>> Default for QueryStateImpl<'tcx, K, V, C> {
@@ -905,29 +936,11 @@ macro_rules! define_queries_inner {
905936
let mut jobs = FxHashMap::default();
906937

907938
$(
908-
// We use try_lock_shards here since we are called from the
909-
// deadlock handler, and this shouldn't be locked.
910-
let shards = self.$name.shards.try_lock_shards()?;
911-
let shards = shards.iter().enumerate();
912-
jobs.extend(shards.flat_map(|(shard_id, shard)| {
913-
shard.active.iter().filter_map(move |(k, v)| {
914-
if let QueryResult::Started(ref job) = *v {
915-
let id = QueryJobId {
916-
job: job.id,
917-
shard: u16::try_from(shard_id).unwrap(),
918-
kind:
919-
<queries::$name<'tcx> as QueryAccessors<'tcx>>::DEP_KIND,
920-
};
921-
let info = QueryInfo {
922-
span: job.span,
923-
query: Query::$name(k.clone())
924-
};
925-
Some((id, QueryJobInfo { info, job: job.clone() }))
926-
} else {
927-
None
928-
}
929-
})
930-
}));
939+
self.$name.try_collect_active_jobs(
940+
<queries::$name<'tcx> as QueryAccessors<'tcx>>::DEP_KIND,
941+
Query::$name,
942+
&mut jobs,
943+
)?;
931944
)*
932945

933946
Some(jobs)

0 commit comments

Comments
 (0)