@@ -7,13 +7,11 @@ use rustc_errors::{struct_span_err, Diagnostic, DiagnosticBuilder, Handler, Leve
7
7
use rustc_session:: Session ;
8
8
use rustc_span:: Span ;
9
9
10
- use std:: convert:: TryFrom ;
11
10
use std:: hash:: Hash ;
12
- use std:: num:: NonZeroU32 ;
11
+ use std:: num:: NonZeroU64 ;
13
12
14
13
#[ cfg( parallel_compiler) ]
15
14
use {
16
- crate :: dep_graph:: DepKind ,
17
15
parking_lot:: { Condvar , Mutex } ,
18
16
rustc_data_structures:: fx:: FxHashSet ,
19
17
rustc_data_structures:: sync:: Lock ,
@@ -33,80 +31,57 @@ pub struct QueryInfo {
33
31
pub query : QueryStackFrame ,
34
32
}
35
33
36
- pub type QueryMap < D > = FxHashMap < QueryJobId < D > , QueryJobInfo < D > > ;
37
-
38
- /// A value uniquely identifying an active query job within a shard in the query cache.
39
- #[ derive( Copy , Clone , Eq , PartialEq , Hash ) ]
40
- pub struct QueryShardJobId ( pub NonZeroU32 ) ;
34
+ pub type QueryMap = FxHashMap < QueryJobId , QueryJobInfo > ;
41
35
42
36
/// A value uniquely identifying an active query job.
43
37
#[ derive( Copy , Clone , Eq , PartialEq , Hash ) ]
44
- pub struct QueryJobId < D > {
45
- /// Which job within a shard is this
46
- pub job : QueryShardJobId ,
47
-
48
- /// In which shard is this job
49
- pub shard : u16 ,
38
+ pub struct QueryJobId ( pub NonZeroU64 ) ;
50
39
51
- /// What kind of query this job is.
52
- pub kind : D ,
53
- }
54
-
55
- impl < D > QueryJobId < D >
56
- where
57
- D : Copy + Clone + Eq + Hash ,
58
- {
59
- pub fn new ( job : QueryShardJobId , shard : usize , kind : D ) -> Self {
60
- QueryJobId { job, shard : u16:: try_from ( shard) . unwrap ( ) , kind }
61
- }
62
-
63
- fn query ( self , map : & QueryMap < D > ) -> QueryStackFrame {
40
+ impl QueryJobId {
41
+ fn query ( self , map : & QueryMap ) -> QueryStackFrame {
64
42
map. get ( & self ) . unwrap ( ) . query . clone ( )
65
43
}
66
44
67
45
#[ cfg( parallel_compiler) ]
68
- fn span ( self , map : & QueryMap < D > ) -> Span {
46
+ fn span ( self , map : & QueryMap ) -> Span {
69
47
map. get ( & self ) . unwrap ( ) . job . span
70
48
}
71
49
72
50
#[ cfg( parallel_compiler) ]
73
- fn parent ( self , map : & QueryMap < D > ) -> Option < QueryJobId < D > > {
51
+ fn parent ( self , map : & QueryMap ) -> Option < QueryJobId > {
74
52
map. get ( & self ) . unwrap ( ) . job . parent
75
53
}
76
54
77
55
#[ cfg( parallel_compiler) ]
78
- fn latch < ' a > ( self , map : & ' a QueryMap < D > ) -> Option < & ' a QueryLatch < D > > {
56
+ fn latch < ' a > ( self , map : & ' a QueryMap ) -> Option < & ' a QueryLatch > {
79
57
map. get ( & self ) . unwrap ( ) . job . latch . as_ref ( )
80
58
}
81
59
}
82
60
83
- pub struct QueryJobInfo < D > {
61
+ pub struct QueryJobInfo {
84
62
pub query : QueryStackFrame ,
85
- pub job : QueryJob < D > ,
63
+ pub job : QueryJob ,
86
64
}
87
65
88
66
/// Represents an active query job.
89
67
#[ derive( Clone ) ]
90
- pub struct QueryJob < D > {
91
- pub id : QueryShardJobId ,
68
+ pub struct QueryJob {
69
+ pub id : QueryJobId ,
92
70
93
71
/// The span corresponding to the reason for which this query was required.
94
72
pub span : Span ,
95
73
96
74
/// The parent query job which created this job and is implicitly waiting on it.
97
- pub parent : Option < QueryJobId < D > > ,
75
+ pub parent : Option < QueryJobId > ,
98
76
99
77
/// The latch that is used to wait on this job.
100
78
#[ cfg( parallel_compiler) ]
101
- latch : Option < QueryLatch < D > > ,
79
+ latch : Option < QueryLatch > ,
102
80
}
103
81
104
- impl < D > QueryJob < D >
105
- where
106
- D : Copy + Clone + Eq + Hash ,
107
- {
82
+ impl QueryJob {
108
83
/// Creates a new query job.
109
- pub fn new ( id : QueryShardJobId , span : Span , parent : Option < QueryJobId < D > > ) -> Self {
84
+ pub fn new ( id : QueryJobId , span : Span , parent : Option < QueryJobId > ) -> Self {
110
85
QueryJob {
111
86
id,
112
87
span,
117
92
}
118
93
119
94
#[ cfg( parallel_compiler) ]
120
- pub ( super ) fn latch ( & mut self ) -> QueryLatch < D > {
95
+ pub ( super ) fn latch ( & mut self ) -> QueryLatch {
121
96
if self . latch . is_none ( ) {
122
97
self . latch = Some ( QueryLatch :: new ( ) ) ;
123
98
}
@@ -139,16 +114,13 @@ where
139
114
}
140
115
141
116
#[ cfg( not( parallel_compiler) ) ]
142
- impl < D > QueryJobId < D >
143
- where
144
- D : Copy + Clone + Eq + Hash ,
145
- {
117
+ impl QueryJobId {
146
118
#[ cold]
147
119
#[ inline( never) ]
148
120
pub ( super ) fn find_cycle_in_stack (
149
121
& self ,
150
- query_map : QueryMap < D > ,
151
- current_job : & Option < QueryJobId < D > > ,
122
+ query_map : QueryMap ,
123
+ current_job : & Option < QueryJobId > ,
152
124
span : Span ,
153
125
) -> CycleError {
154
126
// Find the waitee amongst `current_job` parents
@@ -184,50 +156,43 @@ where
184
156
}
185
157
186
158
#[ cfg( parallel_compiler) ]
187
- struct QueryWaiter < D > {
188
- query : Option < QueryJobId < D > > ,
159
+ struct QueryWaiter {
160
+ query : Option < QueryJobId > ,
189
161
condvar : Condvar ,
190
162
span : Span ,
191
163
cycle : Lock < Option < CycleError > > ,
192
164
}
193
165
194
166
#[ cfg( parallel_compiler) ]
195
- impl < D > QueryWaiter < D > {
167
+ impl QueryWaiter {
196
168
fn notify ( & self , registry : & rayon_core:: Registry ) {
197
169
rayon_core:: mark_unblocked ( registry) ;
198
170
self . condvar . notify_one ( ) ;
199
171
}
200
172
}
201
173
202
174
#[ cfg( parallel_compiler) ]
203
- struct QueryLatchInfo < D > {
175
+ struct QueryLatchInfo {
204
176
complete : bool ,
205
- waiters : Vec < Lrc < QueryWaiter < D > > > ,
177
+ waiters : Vec < Lrc < QueryWaiter > > ,
206
178
}
207
179
208
180
#[ cfg( parallel_compiler) ]
209
181
#[ derive( Clone ) ]
210
- pub ( super ) struct QueryLatch < D > {
211
- info : Lrc < Mutex < QueryLatchInfo < D > > > ,
182
+ pub ( super ) struct QueryLatch {
183
+ info : Lrc < Mutex < QueryLatchInfo > > ,
212
184
}
213
185
214
186
#[ cfg( parallel_compiler) ]
215
- impl < D : Eq + Hash > QueryLatch < D > {
187
+ impl QueryLatch {
216
188
fn new ( ) -> Self {
217
189
QueryLatch {
218
190
info : Lrc :: new ( Mutex :: new ( QueryLatchInfo { complete : false , waiters : Vec :: new ( ) } ) ) ,
219
191
}
220
192
}
221
- }
222
193
223
- #[ cfg( parallel_compiler) ]
224
- impl < D > QueryLatch < D > {
225
194
/// Awaits for the query job to complete.
226
- pub ( super ) fn wait_on (
227
- & self ,
228
- query : Option < QueryJobId < D > > ,
229
- span : Span ,
230
- ) -> Result < ( ) , CycleError > {
195
+ pub ( super ) fn wait_on ( & self , query : Option < QueryJobId > , span : Span ) -> Result < ( ) , CycleError > {
231
196
let waiter =
232
197
Lrc :: new ( QueryWaiter { query, span, cycle : Lock :: new ( None ) , condvar : Condvar :: new ( ) } ) ;
233
198
self . wait_on_inner ( & waiter) ;
@@ -242,7 +207,7 @@ impl<D> QueryLatch<D> {
242
207
}
243
208
244
209
/// Awaits the caller on this latch by blocking the current thread.
245
- fn wait_on_inner ( & self , waiter : & Lrc < QueryWaiter < D > > ) {
210
+ fn wait_on_inner ( & self , waiter : & Lrc < QueryWaiter > ) {
246
211
let mut info = self . info . lock ( ) ;
247
212
if !info. complete {
248
213
// We push the waiter on to the `waiters` list. It can be accessed inside
@@ -276,7 +241,7 @@ impl<D> QueryLatch<D> {
276
241
277
242
/// Removes a single waiter from the list of waiters.
278
243
/// This is used to break query cycles.
279
- fn extract_waiter ( & self , waiter : usize ) -> Lrc < QueryWaiter < D > > {
244
+ fn extract_waiter ( & self , waiter : usize ) -> Lrc < QueryWaiter > {
280
245
let mut info = self . info . lock ( ) ;
281
246
debug_assert ! ( !info. complete) ;
282
247
// Remove the waiter from the list of waiters
@@ -286,7 +251,7 @@ impl<D> QueryLatch<D> {
286
251
287
252
/// A resumable waiter of a query. The usize is the index into waiters in the query's latch
288
253
#[ cfg( parallel_compiler) ]
289
- type Waiter < D > = ( QueryJobId < D > , usize ) ;
254
+ type Waiter = ( QueryJobId , usize ) ;
290
255
291
256
/// Visits all the non-resumable and resumable waiters of a query.
292
257
/// Only waiters in a query are visited.
@@ -298,14 +263,9 @@ type Waiter<D> = (QueryJobId<D>, usize);
298
263
/// required information to resume the waiter.
299
264
/// If all `visit` calls returns None, this function also returns None.
300
265
#[ cfg( parallel_compiler) ]
301
- fn visit_waiters < D , F > (
302
- query_map : & QueryMap < D > ,
303
- query : QueryJobId < D > ,
304
- mut visit : F ,
305
- ) -> Option < Option < Waiter < D > > >
266
+ fn visit_waiters < F > ( query_map : & QueryMap , query : QueryJobId , mut visit : F ) -> Option < Option < Waiter > >
306
267
where
307
- D : Copy + Clone + Eq + Hash ,
308
- F : FnMut ( Span , QueryJobId < D > ) -> Option < Option < Waiter < D > > > ,
268
+ F : FnMut ( Span , QueryJobId ) -> Option < Option < Waiter > > ,
309
269
{
310
270
// Visit the parent query which is a non-resumable waiter since it's on the same stack
311
271
if let Some ( parent) = query. parent ( query_map) {
@@ -334,16 +294,13 @@ where
334
294
/// If a cycle is detected, this initial value is replaced with the span causing
335
295
/// the cycle.
336
296
#[ cfg( parallel_compiler) ]
337
- fn cycle_check < D > (
338
- query_map : & QueryMap < D > ,
339
- query : QueryJobId < D > ,
297
+ fn cycle_check (
298
+ query_map : & QueryMap ,
299
+ query : QueryJobId ,
340
300
span : Span ,
341
- stack : & mut Vec < ( Span , QueryJobId < D > ) > ,
342
- visited : & mut FxHashSet < QueryJobId < D > > ,
343
- ) -> Option < Option < Waiter < D > > >
344
- where
345
- D : Copy + Clone + Eq + Hash ,
346
- {
301
+ stack : & mut Vec < ( Span , QueryJobId ) > ,
302
+ visited : & mut FxHashSet < QueryJobId > ,
303
+ ) -> Option < Option < Waiter > > {
347
304
if !visited. insert ( query) {
348
305
return if let Some ( p) = stack. iter ( ) . position ( |q| q. 1 == query) {
349
306
// We detected a query cycle, fix up the initial span and return Some
@@ -378,14 +335,11 @@ where
378
335
/// from `query` without going through any of the queries in `visited`.
379
336
/// This is achieved with a depth first search.
380
337
#[ cfg( parallel_compiler) ]
381
- fn connected_to_root < D > (
382
- query_map : & QueryMap < D > ,
383
- query : QueryJobId < D > ,
384
- visited : & mut FxHashSet < QueryJobId < D > > ,
385
- ) -> bool
386
- where
387
- D : Copy + Clone + Eq + Hash ,
388
- {
338
+ fn connected_to_root (
339
+ query_map : & QueryMap ,
340
+ query : QueryJobId ,
341
+ visited : & mut FxHashSet < QueryJobId > ,
342
+ ) -> bool {
389
343
// We already visited this or we're deliberately ignoring it
390
344
if !visited. insert ( query) {
391
345
return false ;
@@ -404,10 +358,9 @@ where
404
358
405
359
// Deterministically pick an query from a list
406
360
#[ cfg( parallel_compiler) ]
407
- fn pick_query < ' a , D , T , F > ( query_map : & QueryMap < D > , queries : & ' a [ T ] , f : F ) -> & ' a T
361
+ fn pick_query < ' a , T , F > ( query_map : & QueryMap , queries : & ' a [ T ] , f : F ) -> & ' a T
408
362
where
409
- D : Copy + Clone + Eq + Hash ,
410
- F : Fn ( & T ) -> ( Span , QueryJobId < D > ) ,
363
+ F : Fn ( & T ) -> ( Span , QueryJobId ) ,
411
364
{
412
365
// Deterministically pick an entry point
413
366
// FIXME: Sort this instead
@@ -431,10 +384,10 @@ where
431
384
/// If a cycle was not found, the starting query is removed from `jobs` and
432
385
/// the function returns false.
433
386
#[ cfg( parallel_compiler) ]
434
- fn remove_cycle < D : DepKind > (
435
- query_map : & QueryMap < D > ,
436
- jobs : & mut Vec < QueryJobId < D > > ,
437
- wakelist : & mut Vec < Lrc < QueryWaiter < D > > > ,
387
+ fn remove_cycle (
388
+ query_map : & QueryMap ,
389
+ jobs : & mut Vec < QueryJobId > ,
390
+ wakelist : & mut Vec < Lrc < QueryWaiter > > ,
438
391
) -> bool {
439
392
let mut visited = FxHashSet :: default ( ) ;
440
393
let mut stack = Vec :: new ( ) ;
@@ -489,7 +442,7 @@ fn remove_cycle<D: DepKind>(
489
442
}
490
443
}
491
444
} )
492
- . collect :: < Vec < ( Span , QueryJobId < D > , Option < ( Span , QueryJobId < D > ) > ) > > ( ) ;
445
+ . collect :: < Vec < ( Span , QueryJobId , Option < ( Span , QueryJobId ) > ) > > ( ) ;
493
446
494
447
// Deterministically pick an entry point
495
448
let ( _, entry_point, usage) = pick_query ( query_map, & entry_points, |e| ( e. 0 , e. 1 ) ) ;
@@ -544,7 +497,7 @@ pub fn deadlock<CTX: QueryContext>(tcx: CTX, registry: &rayon_core::Registry) {
544
497
545
498
let mut wakelist = Vec :: new ( ) ;
546
499
let query_map = tcx. try_collect_active_jobs ( ) . unwrap ( ) ;
547
- let mut jobs: Vec < QueryJobId < CTX :: DepKind > > = query_map. keys ( ) . cloned ( ) . collect ( ) ;
500
+ let mut jobs: Vec < QueryJobId > = query_map. keys ( ) . cloned ( ) . collect ( ) ;
548
501
549
502
let mut found_cycle = false ;
550
503
@@ -630,7 +583,7 @@ pub(crate) fn report_cycle<'a>(
630
583
631
584
pub fn print_query_stack < CTX : QueryContext > (
632
585
tcx : CTX ,
633
- mut current_query : Option < QueryJobId < CTX :: DepKind > > ,
586
+ mut current_query : Option < QueryJobId > ,
634
587
handler : & Handler ,
635
588
num_frames : Option < usize > ,
636
589
) -> usize {
0 commit comments