1515use dep_graph:: { DepNodeIndex , DepNode , DepKind , DepNodeColor , OpenTask } ;
1616use errors:: DiagnosticBuilder ;
1717use errors:: Level ;
18- use errors:: FatalError ;
1918use ty:: tls;
2019use ty:: { TyCtxt } ;
2120use ty:: query:: Query ;
2221use ty:: query:: config:: { QueryConfig , QueryDescription } ;
23- use ty:: query:: job:: { QueryJob , QueryResult , QueryInfo } ;
22+ use ty:: query:: job:: { QueryJob , QueryInfo } ;
2423use ty:: item_path;
2524
2625use util:: common:: { profq_msg, ProfileQueriesMsg , QueryMsg } ;
@@ -36,8 +35,12 @@ use syntax_pos::Span;
3635use syntax:: source_map:: DUMMY_SP ;
3736
3837pub struct QueryCache < ' tcx , D : QueryConfig < ' tcx > + ?Sized > {
38+ /// Completed queries have their result stored here
3939 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 > > > ,
4144}
4245
4346pub ( super ) struct QueryValue < T > {
@@ -209,12 +212,7 @@ impl<'a, 'tcx, Q: QueryDescription<'tcx>> JobOwner<'a, 'tcx, Q> {
209212 return TryGetJob :: JobCompleted ( result) ;
210213 }
211214 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 ( ) ,
218216 RawEntryMut :: Vacant ( entry) => {
219217 // No job entry for this query. Return a new one to be started later
220218 return tls:: with_related_context ( tcx, |icx| {
@@ -236,7 +234,7 @@ impl<'a, 'tcx, Q: QueryDescription<'tcx>> JobOwner<'a, 'tcx, Q> {
236234 entry. insert_hashed_nocheck (
237235 key_hash,
238236 key. clone ( ) ,
239- QueryResult :: Started ( job) ) ;
237+ job) ;
240238 TryGetJob :: NotYetStarted ( owner)
241239 } )
242240 }
@@ -313,10 +311,11 @@ impl<'a, 'tcx, Q: QueryDescription<'tcx>> Drop for JobOwner<'a, 'tcx, Q> {
313311 #[ inline( never) ]
314312 #[ cold]
315313 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.
320319 self . job . signal_complete ( ) ;
321320 }
322321}
0 commit comments