Skip to content

Commit 232364a

Browse files
committed
Generalise QueryLatch.
1 parent a51ad88 commit 232364a

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

src/librustc/ty/query/config.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
use crate::dep_graph::SerializedDepNodeIndex;
44
use crate::ty::query::caches::QueryCache;
5+
use crate::ty::query::job::QueryJobId;
56
use crate::ty::query::plumbing::CycleError;
67
use crate::ty::query::QueryState;
78
use rustc_data_structures::profiling::ProfileCategory;
@@ -30,6 +31,9 @@ pub trait QueryContext: DepContext {
3031

3132
/// Get string representation from DefPath.
3233
fn def_path_str(&self, def_id: DefId) -> String;
34+
35+
/// Get the query information from the TLS context.
36+
fn read_query_job<R>(&self, op: impl FnOnce(Option<QueryJobId<Self::DepKind>>) -> R) -> R;
3337
}
3438

3539
pub(crate) trait QueryAccessors<CTX: QueryContext>: QueryConfig<CTX> {

src/librustc/ty/query/job.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,13 @@ pub struct QueryJobId<K> {
5353
pub kind: K,
5454
}
5555

56-
impl QueryJobId<DepKind> {
57-
pub fn new(job: QueryShardJobId, shard: usize, kind: DepKind) -> Self {
56+
impl<K> QueryJobId<K> {
57+
pub fn new(job: QueryShardJobId, shard: usize, kind: K) -> Self {
5858
QueryJobId { job, shard: u16::try_from(shard).unwrap(), kind }
5959
}
60+
}
6061

62+
impl QueryJobId<DepKind> {
6163
fn query<'tcx>(self, map: &QueryMap<'tcx>) -> Query<'tcx> {
6264
map.get(&self).unwrap().info.query.clone()
6365
}
@@ -223,16 +225,16 @@ impl<CTX: QueryContext> QueryLatch<CTX> {
223225
}
224226

225227
#[cfg(parallel_compiler)]
226-
impl<'tcx> QueryLatch<TyCtxt<'tcx>> {
228+
impl<K, CTX> QueryLatch<CTX>
229+
where
230+
K: rustc_query_system::dep_graph::DepKind,
231+
CTX: QueryContext<DepKind = K>,
232+
{
227233
/// Awaits for the query job to complete.
228-
pub(super) fn wait_on(
229-
&self,
230-
tcx: TyCtxt<'tcx>,
231-
span: Span,
232-
) -> Result<(), CycleError<TyCtxt<'tcx>>> {
233-
tls::with_related_context(tcx, move |icx| {
234+
pub(super) fn wait_on(&self, tcx: CTX, span: Span) -> Result<(), CycleError<CTX>> {
235+
tcx.read_query_job(move |query| {
234236
let waiter = Lrc::new(QueryWaiter {
235-
query: icx.query,
237+
query,
236238
span,
237239
cycle: Lock::new(None),
238240
condvar: Condvar::new(),

src/librustc/ty/query/plumbing.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,10 @@ impl QueryContext for TyCtxt<'tcx> {
367367
fn def_path_str(&self, def_id: DefId) -> String {
368368
TyCtxt::def_path_str(*self, def_id)
369369
}
370+
371+
fn read_query_job<R>(&self, op: impl FnOnce(Option<QueryJobId<Self::DepKind>>) -> R) -> R {
372+
tls::with_related_context(*self, move |icx| op(icx.query))
373+
}
370374
}
371375

372376
impl<'tcx> TyCtxt<'tcx> {

0 commit comments

Comments
 (0)