1
1
use crate :: dep_graph:: DepKind ;
2
2
use crate :: ty:: context:: TyCtxt ;
3
+ use crate :: ty:: query:: config:: QueryContext ;
3
4
use crate :: ty:: query:: plumbing:: CycleError ;
4
5
use crate :: ty:: query:: Query ;
5
6
use crate :: ty:: tls;
@@ -27,13 +28,13 @@ use {
27
28
28
29
/// Represents a span and a query key.
29
30
#[ derive( Clone , Debug ) ]
30
- pub struct QueryInfo < ' tcx > {
31
+ pub struct QueryInfo < CTX : QueryContext > {
31
32
/// The span corresponding to the reason for which this query was required.
32
33
pub span : Span ,
33
- pub query : Query < ' tcx > ,
34
+ pub query : CTX :: Query ,
34
35
}
35
36
36
- type QueryMap < ' tcx > = FxHashMap < QueryJobId , QueryJobInfo < ' tcx > > ;
37
+ type QueryMap < ' tcx > = FxHashMap < QueryJobId , QueryJobInfo < TyCtxt < ' tcx > > > ;
37
38
38
39
/// A value uniquely identifiying an active query job within a shard in the query cache.
39
40
#[ derive( Copy , Clone , Eq , PartialEq , Hash ) ]
@@ -72,19 +73,19 @@ impl QueryJobId {
72
73
}
73
74
74
75
#[ cfg( parallel_compiler) ]
75
- fn latch < ' a , ' tcx > ( self , map : & ' a QueryMap < ' tcx > ) -> Option < & ' a QueryLatch < ' tcx > > {
76
+ fn latch < ' a , ' tcx > ( self , map : & ' a QueryMap < ' tcx > ) -> Option < & ' a QueryLatch < TyCtxt < ' tcx > > > {
76
77
map. get ( & self ) . unwrap ( ) . job . latch . as_ref ( )
77
78
}
78
79
}
79
80
80
- pub struct QueryJobInfo < ' tcx > {
81
- pub info : QueryInfo < ' tcx > ,
82
- pub job : QueryJob < ' tcx > ,
81
+ pub struct QueryJobInfo < CTX : QueryContext > {
82
+ pub info : QueryInfo < CTX > ,
83
+ pub job : QueryJob < CTX > ,
83
84
}
84
85
85
86
/// Represents an active query job.
86
87
#[ derive( Clone ) ]
87
- pub struct QueryJob < ' tcx > {
88
+ pub struct QueryJob < CTX : QueryContext > {
88
89
pub id : QueryShardJobId ,
89
90
90
91
/// The span corresponding to the reason for which this query was required.
@@ -95,12 +96,12 @@ pub struct QueryJob<'tcx> {
95
96
96
97
/// The latch that is used to wait on this job.
97
98
#[ cfg( parallel_compiler) ]
98
- latch : Option < QueryLatch < ' tcx > > ,
99
+ latch : Option < QueryLatch < CTX > > ,
99
100
100
- dummy : PhantomData < QueryLatch < ' tcx > > ,
101
+ dummy : PhantomData < QueryLatch < CTX > > ,
101
102
}
102
103
103
- impl < ' tcx > QueryJob < ' tcx > {
104
+ impl < CTX : QueryContext > QueryJob < CTX > {
104
105
/// Creates a new query job.
105
106
pub fn new ( id : QueryShardJobId , span : Span , parent : Option < QueryJobId > ) -> Self {
106
107
QueryJob {
@@ -114,15 +115,15 @@ impl<'tcx> QueryJob<'tcx> {
114
115
}
115
116
116
117
#[ cfg( parallel_compiler) ]
117
- pub ( super ) fn latch ( & mut self , _id : QueryJobId ) -> QueryLatch < ' tcx > {
118
+ pub ( super ) fn latch ( & mut self , _id : QueryJobId ) -> QueryLatch < CTX > {
118
119
if self . latch . is_none ( ) {
119
120
self . latch = Some ( QueryLatch :: new ( ) ) ;
120
121
}
121
122
self . latch . as_ref ( ) . unwrap ( ) . clone ( )
122
123
}
123
124
124
125
#[ cfg( not( parallel_compiler) ) ]
125
- pub ( super ) fn latch ( & mut self , id : QueryJobId ) -> QueryLatch < ' tcx > {
126
+ pub ( super ) fn latch ( & mut self , id : QueryJobId ) -> QueryLatch < CTX > {
126
127
QueryLatch { id, dummy : PhantomData }
127
128
}
128
129
@@ -138,14 +139,18 @@ impl<'tcx> QueryJob<'tcx> {
138
139
139
140
#[ cfg( not( parallel_compiler) ) ]
140
141
#[ derive( Clone ) ]
141
- pub ( super ) struct QueryLatch < ' tcx > {
142
+ pub ( super ) struct QueryLatch < CTX > {
142
143
id : QueryJobId ,
143
- dummy : PhantomData < & ' tcx ( ) > ,
144
+ dummy : PhantomData < CTX > ,
144
145
}
145
146
146
147
#[ cfg( not( parallel_compiler) ) ]
147
- impl < ' tcx > QueryLatch < ' tcx > {
148
- pub ( super ) fn find_cycle_in_stack ( & self , tcx : TyCtxt < ' tcx > , span : Span ) -> CycleError < ' tcx > {
148
+ impl < ' tcx > QueryLatch < TyCtxt < ' tcx > > {
149
+ pub ( super ) fn find_cycle_in_stack (
150
+ & self ,
151
+ tcx : TyCtxt < ' tcx > ,
152
+ span : Span ,
153
+ ) -> CycleError < TyCtxt < ' tcx > > {
149
154
let query_map = tcx. queries . try_collect_active_jobs ( ) . unwrap ( ) ;
150
155
151
156
// Get the current executing query (waiter) and find the waitee amongst its parents
@@ -181,44 +186,50 @@ impl<'tcx> QueryLatch<'tcx> {
181
186
}
182
187
183
188
#[ cfg( parallel_compiler) ]
184
- struct QueryWaiter < ' tcx > {
189
+ struct QueryWaiter < CTX : QueryContext > {
185
190
query : Option < QueryJobId > ,
186
191
condvar : Condvar ,
187
192
span : Span ,
188
- cycle : Lock < Option < CycleError < ' tcx > > > ,
193
+ cycle : Lock < Option < CycleError < CTX > > > ,
189
194
}
190
195
191
196
#[ cfg( parallel_compiler) ]
192
- impl < ' tcx > QueryWaiter < ' tcx > {
197
+ impl < CTX : QueryContext > QueryWaiter < CTX > {
193
198
fn notify ( & self , registry : & rayon_core:: Registry ) {
194
199
rayon_core:: mark_unblocked ( registry) ;
195
200
self . condvar . notify_one ( ) ;
196
201
}
197
202
}
198
203
199
204
#[ cfg( parallel_compiler) ]
200
- struct QueryLatchInfo < ' tcx > {
205
+ struct QueryLatchInfo < CTX : QueryContext > {
201
206
complete : bool ,
202
- waiters : Vec < Lrc < QueryWaiter < ' tcx > > > ,
207
+ waiters : Vec < Lrc < QueryWaiter < CTX > > > ,
203
208
}
204
209
205
210
#[ cfg( parallel_compiler) ]
206
211
#[ derive( Clone ) ]
207
- pub ( super ) struct QueryLatch < ' tcx > {
208
- info : Lrc < Mutex < QueryLatchInfo < ' tcx > > > ,
212
+ pub ( super ) struct QueryLatch < CTX : QueryContext > {
213
+ info : Lrc < Mutex < QueryLatchInfo < CTX > > > ,
209
214
}
210
215
211
216
#[ cfg( parallel_compiler) ]
212
- impl < ' tcx > QueryLatch < ' tcx > {
217
+ impl < CTX : QueryContext > QueryLatch < CTX > {
213
218
fn new ( ) -> Self {
214
219
QueryLatch {
215
220
info : Lrc :: new ( Mutex :: new ( QueryLatchInfo { complete : false , waiters : Vec :: new ( ) } ) ) ,
216
221
}
217
222
}
223
+ }
218
224
225
+ #[ cfg( parallel_compiler) ]
226
+ impl < ' tcx > QueryLatch < TyCtxt < ' tcx > > {
219
227
/// Awaits for the query job to complete.
220
- #[ cfg( parallel_compiler) ]
221
- pub ( super ) fn wait_on ( & self , tcx : TyCtxt < ' tcx > , span : Span ) -> Result < ( ) , CycleError < ' tcx > > {
228
+ pub ( super ) fn wait_on (
229
+ & self ,
230
+ tcx : TyCtxt < ' tcx > ,
231
+ span : Span ,
232
+ ) -> Result < ( ) , CycleError < TyCtxt < ' tcx > > > {
222
233
tls:: with_related_context ( tcx, move |icx| {
223
234
let waiter = Lrc :: new ( QueryWaiter {
224
235
query : icx. query ,
@@ -237,9 +248,12 @@ impl<'tcx> QueryLatch<'tcx> {
237
248
}
238
249
} )
239
250
}
251
+ }
240
252
253
+ #[ cfg( parallel_compiler) ]
254
+ impl < CTX : QueryContext > QueryLatch < CTX > {
241
255
/// Awaits the caller on this latch by blocking the current thread.
242
- fn wait_on_inner ( & self , waiter : & Lrc < QueryWaiter < ' tcx > > ) {
256
+ fn wait_on_inner ( & self , waiter : & Lrc < QueryWaiter < CTX > > ) {
243
257
let mut info = self . info . lock ( ) ;
244
258
if !info. complete {
245
259
// We push the waiter on to the `waiters` list. It can be accessed inside
@@ -273,7 +287,7 @@ impl<'tcx> QueryLatch<'tcx> {
273
287
274
288
/// Removes a single waiter from the list of waiters.
275
289
/// This is used to break query cycles.
276
- fn extract_waiter ( & self , waiter : usize ) -> Lrc < QueryWaiter < ' tcx > > {
290
+ fn extract_waiter ( & self , waiter : usize ) -> Lrc < QueryWaiter < CTX > > {
277
291
let mut info = self . info . lock ( ) ;
278
292
debug_assert ! ( !info. complete) ;
279
293
// Remove the waiter from the list of waiters
@@ -427,7 +441,7 @@ fn pick_query<'a, 'tcx, T, F: Fn(&T) -> (Span, QueryJobId)>(
427
441
fn remove_cycle < ' tcx > (
428
442
query_map : & QueryMap < ' tcx > ,
429
443
jobs : & mut Vec < QueryJobId > ,
430
- wakelist : & mut Vec < Lrc < QueryWaiter < ' tcx > > > ,
444
+ wakelist : & mut Vec < Lrc < QueryWaiter < TyCtxt < ' tcx > > > > ,
431
445
tcx : TyCtxt < ' tcx > ,
432
446
) -> bool {
433
447
let mut visited = FxHashSet :: default ( ) ;
0 commit comments