Skip to content

Commit 2a52436

Browse files
committed
Generalise QueryJobId.
1 parent ee9781c commit 2a52436

File tree

3 files changed

+30
-30
lines changed

3 files changed

+30
-30
lines changed

src/librustc/ty/context.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1603,7 +1603,7 @@ nop_list_lift! {substs; GenericArg<'a> => GenericArg<'tcx>}
16031603
pub mod tls {
16041604
use super::{ptr_eq, GlobalCtxt, TyCtxt};
16051605

1606-
use crate::dep_graph::TaskDeps;
1606+
use crate::dep_graph::{DepKind, TaskDeps};
16071607
use crate::ty::query;
16081608
use rustc_data_structures::sync::{self, Lock};
16091609
use rustc_data_structures::thin_vec::ThinVec;
@@ -1630,7 +1630,7 @@ pub mod tls {
16301630

16311631
/// The current query job, if any. This is updated by `JobOwner::start` in
16321632
/// `ty::query::plumbing` when executing a query.
1633-
pub query: Option<query::QueryJobId>,
1633+
pub query: Option<query::QueryJobId<DepKind>>,
16341634

16351635
/// Where to store diagnostics for the current query job, if any.
16361636
/// This is updated by `JobOwner::start` in `ty::query::plumbing` when executing a query.

src/librustc/ty/query/job.rs

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -34,26 +34,26 @@ pub struct QueryInfo<CTX: QueryContext> {
3434
pub query: CTX::Query,
3535
}
3636

37-
type QueryMap<'tcx> = FxHashMap<QueryJobId, QueryJobInfo<TyCtxt<'tcx>>>;
37+
type QueryMap<'tcx> = FxHashMap<QueryJobId<DepKind>, QueryJobInfo<TyCtxt<'tcx>>>;
3838

3939
/// A value uniquely identifiying an active query job within a shard in the query cache.
4040
#[derive(Copy, Clone, Eq, PartialEq, Hash)]
4141
pub struct QueryShardJobId(pub NonZeroU32);
4242

4343
/// A value uniquely identifiying an active query job.
4444
#[derive(Copy, Clone, Eq, PartialEq, Hash)]
45-
pub struct QueryJobId {
45+
pub struct QueryJobId<K> {
4646
/// Which job within a shard is this
4747
pub job: QueryShardJobId,
4848

4949
/// In which shard is this job
5050
pub shard: u16,
5151

5252
/// What kind of query this job is
53-
pub kind: DepKind,
53+
pub kind: K,
5454
}
5555

56-
impl QueryJobId {
56+
impl QueryJobId<DepKind> {
5757
pub fn new(job: QueryShardJobId, shard: usize, kind: DepKind) -> Self {
5858
QueryJobId { job, shard: u16::try_from(shard).unwrap(), kind }
5959
}
@@ -68,7 +68,7 @@ impl QueryJobId {
6868
}
6969

7070
#[cfg(parallel_compiler)]
71-
fn parent(self, map: &QueryMap<'_>) -> Option<QueryJobId> {
71+
fn parent(self, map: &QueryMap<'_>) -> Option<QueryJobId<DepKind>> {
7272
map.get(&self).unwrap().job.parent
7373
}
7474

@@ -92,7 +92,7 @@ pub struct QueryJob<CTX: QueryContext> {
9292
pub span: Span,
9393

9494
/// The parent query job which created this job and is implicitly waiting on it.
95-
pub parent: Option<QueryJobId>,
95+
pub parent: Option<QueryJobId<CTX::DepKind>>,
9696

9797
/// The latch that is used to wait on this job.
9898
#[cfg(parallel_compiler)]
@@ -103,7 +103,7 @@ pub struct QueryJob<CTX: QueryContext> {
103103

104104
impl<CTX: QueryContext> QueryJob<CTX> {
105105
/// Creates a new query job.
106-
pub fn new(id: QueryShardJobId, span: Span, parent: Option<QueryJobId>) -> Self {
106+
pub fn new(id: QueryShardJobId, span: Span, parent: Option<QueryJobId<CTX::DepKind>>) -> Self {
107107
QueryJob {
108108
id,
109109
span,
@@ -115,15 +115,15 @@ impl<CTX: QueryContext> QueryJob<CTX> {
115115
}
116116

117117
#[cfg(parallel_compiler)]
118-
pub(super) fn latch(&mut self, _id: QueryJobId) -> QueryLatch<CTX> {
118+
pub(super) fn latch(&mut self, _id: QueryJobId<CTX::DepKind>) -> QueryLatch<CTX> {
119119
if self.latch.is_none() {
120120
self.latch = Some(QueryLatch::new());
121121
}
122122
self.latch.as_ref().unwrap().clone()
123123
}
124124

125125
#[cfg(not(parallel_compiler))]
126-
pub(super) fn latch(&mut self, id: QueryJobId) -> QueryLatch<CTX> {
126+
pub(super) fn latch(&mut self, id: QueryJobId<CTX::DepKind>) -> QueryLatch<CTX> {
127127
QueryLatch { id, dummy: PhantomData }
128128
}
129129

@@ -139,8 +139,8 @@ impl<CTX: QueryContext> QueryJob<CTX> {
139139

140140
#[cfg(not(parallel_compiler))]
141141
#[derive(Clone)]
142-
pub(super) struct QueryLatch<CTX> {
143-
id: QueryJobId,
142+
pub(super) struct QueryLatch<CTX: QueryContext> {
143+
id: QueryJobId<CTX::DepKind>,
144144
dummy: PhantomData<CTX>,
145145
}
146146

@@ -187,7 +187,7 @@ impl<'tcx> QueryLatch<TyCtxt<'tcx>> {
187187

188188
#[cfg(parallel_compiler)]
189189
struct QueryWaiter<CTX: QueryContext> {
190-
query: Option<QueryJobId>,
190+
query: Option<QueryJobId<CTX::DepKind>>,
191191
condvar: Condvar,
192192
span: Span,
193193
cycle: Lock<Option<CycleError<CTX>>>,
@@ -297,7 +297,7 @@ impl<CTX: QueryContext> QueryLatch<CTX> {
297297

298298
/// A resumable waiter of a query. The usize is the index into waiters in the query's latch
299299
#[cfg(parallel_compiler)]
300-
type Waiter = (QueryJobId, usize);
300+
type Waiter = (QueryJobId<DepKind>, usize);
301301

302302
/// Visits all the non-resumable and resumable waiters of a query.
303303
/// Only waiters in a query are visited.
@@ -311,11 +311,11 @@ type Waiter = (QueryJobId, usize);
311311
#[cfg(parallel_compiler)]
312312
fn visit_waiters<'tcx, F>(
313313
query_map: &QueryMap<'tcx>,
314-
query: QueryJobId,
314+
query: QueryJobId<DepKind>,
315315
mut visit: F,
316316
) -> Option<Option<Waiter>>
317317
where
318-
F: FnMut(Span, QueryJobId) -> Option<Option<Waiter>>,
318+
F: FnMut(Span, QueryJobId<DepKind>) -> Option<Option<Waiter>>,
319319
{
320320
// Visit the parent query which is a non-resumable waiter since it's on the same stack
321321
if let Some(parent) = query.parent(query_map) {
@@ -346,10 +346,10 @@ where
346346
#[cfg(parallel_compiler)]
347347
fn cycle_check<'tcx>(
348348
query_map: &QueryMap<'tcx>,
349-
query: QueryJobId,
349+
query: QueryJobId<DepKind>,
350350
span: Span,
351-
stack: &mut Vec<(Span, QueryJobId)>,
352-
visited: &mut FxHashSet<QueryJobId>,
351+
stack: &mut Vec<(Span, QueryJobId<DepKind>)>,
352+
visited: &mut FxHashSet<QueryJobId<DepKind>>,
353353
) -> Option<Option<Waiter>> {
354354
if !visited.insert(query) {
355355
return if let Some(p) = stack.iter().position(|q| q.1 == query) {
@@ -387,8 +387,8 @@ fn cycle_check<'tcx>(
387387
#[cfg(parallel_compiler)]
388388
fn connected_to_root<'tcx>(
389389
query_map: &QueryMap<'tcx>,
390-
query: QueryJobId,
391-
visited: &mut FxHashSet<QueryJobId>,
390+
query: QueryJobId<DepKind>,
391+
visited: &mut FxHashSet<QueryJobId<DepKind>>,
392392
) -> bool {
393393
// We already visited this or we're deliberately ignoring it
394394
if !visited.insert(query) {
@@ -408,7 +408,7 @@ fn connected_to_root<'tcx>(
408408

409409
// Deterministically pick an query from a list
410410
#[cfg(parallel_compiler)]
411-
fn pick_query<'a, 'tcx, T, F: Fn(&T) -> (Span, QueryJobId)>(
411+
fn pick_query<'a, 'tcx, T, F: Fn(&T) -> (Span, QueryJobId<DepKind>)>(
412412
query_map: &QueryMap<'tcx>,
413413
tcx: TyCtxt<'tcx>,
414414
queries: &'a [T],
@@ -440,7 +440,7 @@ fn pick_query<'a, 'tcx, T, F: Fn(&T) -> (Span, QueryJobId)>(
440440
#[cfg(parallel_compiler)]
441441
fn remove_cycle<'tcx>(
442442
query_map: &QueryMap<'tcx>,
443-
jobs: &mut Vec<QueryJobId>,
443+
jobs: &mut Vec<QueryJobId<DepKind>>,
444444
wakelist: &mut Vec<Lrc<QueryWaiter<TyCtxt<'tcx>>>>,
445445
tcx: TyCtxt<'tcx>,
446446
) -> bool {
@@ -495,7 +495,7 @@ fn remove_cycle<'tcx>(
495495
}
496496
}
497497
})
498-
.collect::<Vec<(Span, QueryJobId, Option<(Span, QueryJobId)>)>>();
498+
.collect::<Vec<(Span, QueryJobId<DepKind>, Option<(Span, QueryJobId<DepKind>)>)>>();
499499

500500
// Deterministically pick an entry point
501501
let (_, entry_point, usage) = pick_query(query_map, tcx, &entry_points, |e| (e.0, e.1));
@@ -575,7 +575,7 @@ fn deadlock(tcx: TyCtxt<'_>, registry: &rayon_core::Registry) {
575575

576576
let mut wakelist = Vec::new();
577577
let query_map = tcx.queries.try_collect_active_jobs().unwrap();
578-
let mut jobs: Vec<QueryJobId> = query_map.keys().cloned().collect();
578+
let mut jobs: Vec<QueryJobId<DepKind>> = query_map.keys().cloned().collect();
579579

580580
let mut found_cycle = false;
581581

src/librustc/ty/query/plumbing.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ impl<CTX: QueryContext, C: QueryCache<CTX>> QueryState<CTX, C> {
104104
&self,
105105
kind: DepKind,
106106
make_query: fn(C::Key) -> CTX::Query,
107-
jobs: &mut FxHashMap<QueryJobId, QueryJobInfo<CTX>>,
107+
jobs: &mut FxHashMap<QueryJobId<CTX::DepKind>, QueryJobInfo<CTX>>,
108108
) -> Option<()>
109109
where
110110
C::Key: Clone,
@@ -158,7 +158,7 @@ where
158158
{
159159
state: &'tcx QueryState<CTX, C>,
160160
key: C::Key,
161-
id: QueryJobId,
161+
id: QueryJobId<CTX::DepKind>,
162162
}
163163

164164
impl<'tcx, C> JobOwner<'tcx, TyCtxt<'tcx>, C>
@@ -375,7 +375,7 @@ impl<'tcx> TyCtxt<'tcx> {
375375
#[inline(always)]
376376
fn start_query<F, R>(
377377
self,
378-
token: QueryJobId,
378+
token: QueryJobId<DepKind>,
379379
diagnostics: Option<&Lock<ThinVec<Diagnostic>>>,
380380
compute: F,
381381
) -> R
@@ -1171,7 +1171,7 @@ macro_rules! define_queries_struct {
11711171

11721172
pub(crate) fn try_collect_active_jobs(
11731173
&self
1174-
) -> Option<FxHashMap<QueryJobId, QueryJobInfo<TyCtxt<'tcx>>>> {
1174+
) -> Option<FxHashMap<QueryJobId<crate::dep_graph::DepKind>, QueryJobInfo<TyCtxt<'tcx>>>> {
11751175
let mut jobs = FxHashMap::default();
11761176

11771177
$(

0 commit comments

Comments
 (0)