@@ -34,26 +34,26 @@ pub struct QueryInfo<CTX: QueryContext> {
34
34
pub query : CTX :: Query ,
35
35
}
36
36
37
- type QueryMap < ' tcx > = FxHashMap < QueryJobId , QueryJobInfo < TyCtxt < ' tcx > > > ;
37
+ type QueryMap < ' tcx > = FxHashMap < QueryJobId < DepKind > , QueryJobInfo < TyCtxt < ' tcx > > > ;
38
38
39
39
/// A value uniquely identifiying an active query job within a shard in the query cache.
40
40
#[ derive( Copy , Clone , Eq , PartialEq , Hash ) ]
41
41
pub struct QueryShardJobId ( pub NonZeroU32 ) ;
42
42
43
43
/// A value uniquely identifiying an active query job.
44
44
#[ derive( Copy , Clone , Eq , PartialEq , Hash ) ]
45
- pub struct QueryJobId {
45
+ pub struct QueryJobId < K > {
46
46
/// Which job within a shard is this
47
47
pub job : QueryShardJobId ,
48
48
49
49
/// In which shard is this job
50
50
pub shard : u16 ,
51
51
52
52
/// What kind of query this job is
53
- pub kind : DepKind ,
53
+ pub kind : K ,
54
54
}
55
55
56
- impl QueryJobId {
56
+ impl QueryJobId < DepKind > {
57
57
pub fn new ( job : QueryShardJobId , shard : usize , kind : DepKind ) -> Self {
58
58
QueryJobId { job, shard : u16:: try_from ( shard) . unwrap ( ) , kind }
59
59
}
@@ -68,7 +68,7 @@ impl QueryJobId {
68
68
}
69
69
70
70
#[ cfg( parallel_compiler) ]
71
- fn parent ( self , map : & QueryMap < ' _ > ) -> Option < QueryJobId > {
71
+ fn parent ( self , map : & QueryMap < ' _ > ) -> Option < QueryJobId < DepKind > > {
72
72
map. get ( & self ) . unwrap ( ) . job . parent
73
73
}
74
74
@@ -92,7 +92,7 @@ pub struct QueryJob<CTX: QueryContext> {
92
92
pub span : Span ,
93
93
94
94
/// 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 > > ,
96
96
97
97
/// The latch that is used to wait on this job.
98
98
#[ cfg( parallel_compiler) ]
@@ -103,7 +103,7 @@ pub struct QueryJob<CTX: QueryContext> {
103
103
104
104
impl < CTX : QueryContext > QueryJob < CTX > {
105
105
/// 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 {
107
107
QueryJob {
108
108
id,
109
109
span,
@@ -115,15 +115,15 @@ impl<CTX: QueryContext> QueryJob<CTX> {
115
115
}
116
116
117
117
#[ 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 > {
119
119
if self . latch . is_none ( ) {
120
120
self . latch = Some ( QueryLatch :: new ( ) ) ;
121
121
}
122
122
self . latch . as_ref ( ) . unwrap ( ) . clone ( )
123
123
}
124
124
125
125
#[ 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 > {
127
127
QueryLatch { id, dummy : PhantomData }
128
128
}
129
129
@@ -139,8 +139,8 @@ impl<CTX: QueryContext> QueryJob<CTX> {
139
139
140
140
#[ cfg( not( parallel_compiler) ) ]
141
141
#[ derive( Clone ) ]
142
- pub ( super ) struct QueryLatch < CTX > {
143
- id : QueryJobId ,
142
+ pub ( super ) struct QueryLatch < CTX : QueryContext > {
143
+ id : QueryJobId < CTX :: DepKind > ,
144
144
dummy : PhantomData < CTX > ,
145
145
}
146
146
@@ -187,7 +187,7 @@ impl<'tcx> QueryLatch<TyCtxt<'tcx>> {
187
187
188
188
#[ cfg( parallel_compiler) ]
189
189
struct QueryWaiter < CTX : QueryContext > {
190
- query : Option < QueryJobId > ,
190
+ query : Option < QueryJobId < CTX :: DepKind > > ,
191
191
condvar : Condvar ,
192
192
span : Span ,
193
193
cycle : Lock < Option < CycleError < CTX > > > ,
@@ -297,7 +297,7 @@ impl<CTX: QueryContext> QueryLatch<CTX> {
297
297
298
298
/// A resumable waiter of a query. The usize is the index into waiters in the query's latch
299
299
#[ cfg( parallel_compiler) ]
300
- type Waiter = ( QueryJobId , usize ) ;
300
+ type Waiter = ( QueryJobId < DepKind > , usize ) ;
301
301
302
302
/// Visits all the non-resumable and resumable waiters of a query.
303
303
/// Only waiters in a query are visited.
@@ -311,11 +311,11 @@ type Waiter = (QueryJobId, usize);
311
311
#[ cfg( parallel_compiler) ]
312
312
fn visit_waiters < ' tcx , F > (
313
313
query_map : & QueryMap < ' tcx > ,
314
- query : QueryJobId ,
314
+ query : QueryJobId < DepKind > ,
315
315
mut visit : F ,
316
316
) -> Option < Option < Waiter > >
317
317
where
318
- F : FnMut ( Span , QueryJobId ) -> Option < Option < Waiter > > ,
318
+ F : FnMut ( Span , QueryJobId < DepKind > ) -> Option < Option < Waiter > > ,
319
319
{
320
320
// Visit the parent query which is a non-resumable waiter since it's on the same stack
321
321
if let Some ( parent) = query. parent ( query_map) {
@@ -346,10 +346,10 @@ where
346
346
#[ cfg( parallel_compiler) ]
347
347
fn cycle_check < ' tcx > (
348
348
query_map : & QueryMap < ' tcx > ,
349
- query : QueryJobId ,
349
+ query : QueryJobId < DepKind > ,
350
350
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 > > ,
353
353
) -> Option < Option < Waiter > > {
354
354
if !visited. insert ( query) {
355
355
return if let Some ( p) = stack. iter ( ) . position ( |q| q. 1 == query) {
@@ -387,8 +387,8 @@ fn cycle_check<'tcx>(
387
387
#[ cfg( parallel_compiler) ]
388
388
fn connected_to_root < ' tcx > (
389
389
query_map : & QueryMap < ' tcx > ,
390
- query : QueryJobId ,
391
- visited : & mut FxHashSet < QueryJobId > ,
390
+ query : QueryJobId < DepKind > ,
391
+ visited : & mut FxHashSet < QueryJobId < DepKind > > ,
392
392
) -> bool {
393
393
// We already visited this or we're deliberately ignoring it
394
394
if !visited. insert ( query) {
@@ -408,7 +408,7 @@ fn connected_to_root<'tcx>(
408
408
409
409
// Deterministically pick an query from a list
410
410
#[ 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 > ) > (
412
412
query_map : & QueryMap < ' tcx > ,
413
413
tcx : TyCtxt < ' tcx > ,
414
414
queries : & ' a [ T ] ,
@@ -440,7 +440,7 @@ fn pick_query<'a, 'tcx, T, F: Fn(&T) -> (Span, QueryJobId)>(
440
440
#[ cfg( parallel_compiler) ]
441
441
fn remove_cycle < ' tcx > (
442
442
query_map : & QueryMap < ' tcx > ,
443
- jobs : & mut Vec < QueryJobId > ,
443
+ jobs : & mut Vec < QueryJobId < DepKind > > ,
444
444
wakelist : & mut Vec < Lrc < QueryWaiter < TyCtxt < ' tcx > > > > ,
445
445
tcx : TyCtxt < ' tcx > ,
446
446
) -> bool {
@@ -495,7 +495,7 @@ fn remove_cycle<'tcx>(
495
495
}
496
496
}
497
497
} )
498
- . collect :: < Vec < ( Span , QueryJobId , Option < ( Span , QueryJobId ) > ) > > ( ) ;
498
+ . collect :: < Vec < ( Span , QueryJobId < DepKind > , Option < ( Span , QueryJobId < DepKind > ) > ) > > ( ) ;
499
499
500
500
// Deterministically pick an entry point
501
501
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) {
575
575
576
576
let mut wakelist = Vec :: new ( ) ;
577
577
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 ( ) ;
579
579
580
580
let mut found_cycle = false ;
581
581
0 commit comments