Skip to content

Commit 7d84f4f

Browse files
committed
Offload try_collect_active_jobs.
1 parent 5dc7c2e commit 7d84f4f

File tree

2 files changed

+37
-26
lines changed

2 files changed

+37
-26
lines changed

src/librustc/ty/query/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ use rustc_span::symbol::Symbol;
5757
use rustc_span::{Span, DUMMY_SP};
5858
use std::borrow::Cow;
5959
use std::collections::BTreeMap;
60-
use std::convert::TryFrom;
6160
use std::ops::Deref;
6261
use std::sync::Arc;
6362

src/librustc/ty/query/plumbing.rs

+37-25
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
//! generate the actual methods on tcx which find and execute the provider,
33
//! manage the caches, and so forth.
44
5-
use crate::dep_graph::{DepNode, DepNodeIndex, SerializedDepNodeIndex};
5+
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,35 @@ 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+
pub(super) fn try_collect_active_jobs(
116+
&self,
117+
kind: DepKind,
118+
make_query: fn(K) -> Query<'tcx>,
119+
jobs: &mut FxHashMap<QueryJobId, QueryJobInfo<'tcx>>,
120+
) -> Option<()>
121+
where
122+
K: Clone,
123+
{
124+
// We use try_lock_shards here since we are called from the
125+
// deadlock handler, and this shouldn't be locked.
126+
let shards = self.shards.try_lock_shards()?;
127+
let shards = shards.iter().enumerate();
128+
jobs.extend(shards.flat_map(|(shard_id, shard)| {
129+
shard.active.iter().filter_map(move |(k, v)| {
130+
if let QueryResult::Started(ref job) = *v {
131+
let id =
132+
QueryJobId { job: job.id, shard: u16::try_from(shard_id).unwrap(), kind };
133+
let info = QueryInfo { span: job.span, query: make_query(k.clone()) };
134+
Some((id, QueryJobInfo { info, job: job.clone() }))
135+
} else {
136+
None
137+
}
138+
})
139+
}));
140+
141+
Some(())
142+
}
113143
}
114144

115145
impl<'tcx, K, V, C: QueryCache<K, V>> Default for QueryStateImpl<'tcx, K, V, C> {
@@ -1135,29 +1165,11 @@ macro_rules! define_queries_struct {
11351165
let mut jobs = FxHashMap::default();
11361166

11371167
$(
1138-
// We use try_lock_shards here since we are called from the
1139-
// deadlock handler, and this shouldn't be locked.
1140-
let shards = self.$name.shards.try_lock_shards()?;
1141-
let shards = shards.iter().enumerate();
1142-
jobs.extend(shards.flat_map(|(shard_id, shard)| {
1143-
shard.active.iter().filter_map(move |(k, v)| {
1144-
if let QueryResult::Started(ref job) = *v {
1145-
let id = QueryJobId {
1146-
job: job.id,
1147-
shard: u16::try_from(shard_id).unwrap(),
1148-
kind:
1149-
<queries::$name<'tcx> as QueryAccessors<'tcx>>::DEP_KIND,
1150-
};
1151-
let info = QueryInfo {
1152-
span: job.span,
1153-
query: Query::$name(k.clone())
1154-
};
1155-
Some((id, QueryJobInfo { info, job: job.clone() }))
1156-
} else {
1157-
None
1158-
}
1159-
})
1160-
}));
1168+
self.$name.try_collect_active_jobs(
1169+
<queries::$name<'tcx> as QueryAccessors<'tcx>>::DEP_KIND,
1170+
Query::$name,
1171+
&mut jobs,
1172+
)?;
11611173
)*
11621174

11631175
Some(jobs)

0 commit comments

Comments
 (0)