15
15
use dep_graph:: { DepNodeIndex , DepNode , DepKind , DepNodeColor , OpenTask } ;
16
16
use errors:: DiagnosticBuilder ;
17
17
use errors:: Level ;
18
- use errors:: FatalError ;
19
18
use ty:: tls;
20
19
use ty:: { TyCtxt } ;
21
20
use ty:: query:: Query ;
22
21
use ty:: query:: config:: { QueryConfig , QueryDescription } ;
23
- use ty:: query:: job:: { QueryJob , QueryResult , QueryInfo } ;
22
+ use ty:: query:: job:: { QueryJob , QueryInfo } ;
24
23
use ty:: item_path;
25
24
26
25
use util:: common:: { profq_msg, ProfileQueriesMsg , QueryMsg } ;
@@ -36,8 +35,12 @@ use syntax_pos::Span;
36
35
use syntax:: source_map:: DUMMY_SP ;
37
36
38
37
pub struct QueryCache < ' tcx , D : QueryConfig < ' tcx > + ?Sized > {
38
+ /// Completed queries have their result stored here
39
39
pub ( super ) results : FxHashMap < D :: Key , QueryValue < D :: Value > > ,
40
- pub ( super ) active : FxHashMap < D :: Key , QueryResult < ' tcx > > ,
40
+
41
+ /// Queries under execution will have an entry in this map.
42
+ /// The query job inside can be used to await for completion of queries.
43
+ pub ( super ) active : FxHashMap < D :: Key , Lrc < QueryJob < ' tcx > > > ,
41
44
}
42
45
43
46
pub ( super ) struct QueryValue < T > {
@@ -209,12 +212,7 @@ impl<'a, 'tcx, Q: QueryDescription<'tcx>> JobOwner<'a, 'tcx, Q> {
209
212
return TryGetJob :: JobCompleted ( result) ;
210
213
}
211
214
let job = match lock. active . raw_entry_mut ( ) . from_key_hashed_nocheck ( key_hash, key) {
212
- RawEntryMut :: Occupied ( entry) => {
213
- match * entry. get ( ) {
214
- QueryResult :: Started ( ref job) => job. clone ( ) ,
215
- QueryResult :: Poisoned => FatalError . raise ( ) ,
216
- }
217
- }
215
+ RawEntryMut :: Occupied ( entry) => entry. get ( ) . clone ( ) ,
218
216
RawEntryMut :: Vacant ( entry) => {
219
217
// No job entry for this query. Return a new one to be started later
220
218
return tls:: with_related_context ( tcx, |icx| {
@@ -236,7 +234,7 @@ impl<'a, 'tcx, Q: QueryDescription<'tcx>> JobOwner<'a, 'tcx, Q> {
236
234
entry. insert_hashed_nocheck (
237
235
key_hash,
238
236
key. clone ( ) ,
239
- QueryResult :: Started ( job) ) ;
237
+ job) ;
240
238
TryGetJob :: NotYetStarted ( owner)
241
239
} )
242
240
}
@@ -313,10 +311,11 @@ impl<'a, 'tcx, Q: QueryDescription<'tcx>> Drop for JobOwner<'a, 'tcx, Q> {
313
311
#[ inline( never) ]
314
312
#[ cold]
315
313
fn drop ( & mut self ) {
316
- // Poison the query so jobs waiting on it panic
317
- self . cache . borrow_mut ( ) . active . insert ( self . key . clone ( ) , QueryResult :: Poisoned ) ;
318
- // Also signal the completion of the job, so waiters
319
- // will continue execution
314
+ // This job failed to execute due to a panic.
315
+ // Remove it from the list of active queries
316
+ self . cache . borrow_mut ( ) . active . remove ( & self . key ) ;
317
+ // Signal that the job not longer executes, so the waiters will continue execution.
318
+ // The waiters will try to execute the query which may result in them panicking too.
320
319
self . job . signal_complete ( ) ;
321
320
}
322
321
}
0 commit comments