@@ -16,12 +16,11 @@ use dep_graph::{DepNodeIndex, DepNode, DepKind, DepNodeColor};
16
16
use errors:: DiagnosticBuilder ;
17
17
use errors:: Level ;
18
18
use errors:: Diagnostic ;
19
- use errors:: FatalError ;
20
19
use ty:: tls;
21
20
use ty:: { TyCtxt } ;
22
21
use ty:: query:: Query ;
23
22
use ty:: query:: config:: { QueryConfig , QueryDescription } ;
24
- use ty:: query:: job:: { QueryJob , QueryResult , QueryInfo } ;
23
+ use ty:: query:: job:: { QueryJob , QueryInfo } ;
25
24
use ty:: item_path;
26
25
27
26
use util:: common:: { profq_msg, ProfileQueriesMsg , QueryMsg } ;
@@ -35,8 +34,12 @@ use syntax_pos::Span;
35
34
use syntax:: source_map:: DUMMY_SP ;
36
35
37
36
pub struct QueryCache < ' tcx , D : QueryConfig < ' tcx > + ?Sized > {
37
+ /// Completed queries have their result stored here
38
38
pub ( super ) results : FxHashMap < D :: Key , QueryValue < D :: Value > > ,
39
- pub ( super ) active : FxHashMap < D :: Key , QueryResult < ' tcx > > ,
39
+
40
+ /// Queries under execution will have an entry in this map.
41
+ /// The query job inside can be used to await for completion of queries.
42
+ pub ( super ) active : FxHashMap < D :: Key , Lrc < QueryJob < ' tcx > > > ,
40
43
}
41
44
42
45
pub ( super ) struct QueryValue < T > {
@@ -127,12 +130,7 @@ impl<'a, 'tcx, Q: QueryDescription<'tcx>> JobOwner<'a, 'tcx, Q> {
127
130
return TryGetJob :: JobCompleted ( result) ;
128
131
}
129
132
let job = match lock. active . entry ( ( * key) . clone ( ) ) {
130
- Entry :: Occupied ( entry) => {
131
- match * entry. get ( ) {
132
- QueryResult :: Started ( ref job) => job. clone ( ) ,
133
- QueryResult :: Poisoned => FatalError . raise ( ) ,
134
- }
135
- }
133
+ Entry :: Occupied ( entry) => entry. get ( ) . clone ( ) ,
136
134
Entry :: Vacant ( entry) => {
137
135
// No job entry for this query. Return a new one to be started later
138
136
return tls:: with_related_context ( tcx, |icx| {
@@ -149,7 +147,7 @@ impl<'a, 'tcx, Q: QueryDescription<'tcx>> JobOwner<'a, 'tcx, Q> {
149
147
job : job. clone ( ) ,
150
148
key : ( * key) . clone ( ) ,
151
149
} ;
152
- entry. insert ( QueryResult :: Started ( job) ) ;
150
+ entry. insert ( job) ;
153
151
TryGetJob :: NotYetStarted ( owner)
154
152
} )
155
153
}
@@ -231,10 +229,11 @@ impl<'a, 'tcx, Q: QueryDescription<'tcx>> JobOwner<'a, 'tcx, Q> {
231
229
232
230
impl < ' a , ' tcx , Q : QueryDescription < ' tcx > > Drop for JobOwner < ' a , ' tcx , Q > {
233
231
fn drop ( & mut self ) {
234
- // Poison the query so jobs waiting on it panic
235
- self . cache . borrow_mut ( ) . active . insert ( self . key . clone ( ) , QueryResult :: Poisoned ) ;
236
- // Also signal the completion of the job, so waiters
237
- // will continue execution
232
+ // This job failed to execute due to a panic.
233
+ // Remove it from the list of active queries
234
+ self . cache . borrow_mut ( ) . active . remove ( & self . key ) ;
235
+ // Signal that the job not longer executes, so the waiters will continue execution.
236
+ // The waiters will try to execute the query which may result in them panicking too.
238
237
self . job . signal_complete ( ) ;
239
238
}
240
239
}
@@ -709,8 +708,6 @@ macro_rules! define_queries_inner {
709
708
[ $( $modifiers: tt) * ] fn $name: ident: $node: ident( $K: ty) -> $V: ty, ) * ) => {
710
709
711
710
use std:: mem;
712
- #[ cfg( parallel_queries) ]
713
- use ty:: query:: job:: QueryResult ;
714
711
use rustc_data_structures:: sync:: Lock ;
715
712
use {
716
713
rustc_data_structures:: stable_hasher:: HashStable ,
@@ -747,13 +744,7 @@ macro_rules! define_queries_inner {
747
744
// deadlock handler, and this shouldn't be locked
748
745
$(
749
746
jobs. extend(
750
- self . $name. try_lock( ) . unwrap( ) . active. values( ) . filter_map( |v|
751
- if let QueryResult :: Started ( ref job) = * v {
752
- Some ( job. clone( ) )
753
- } else {
754
- None
755
- }
756
- )
747
+ self . $name. try_lock( ) . unwrap( ) . active. values( ) . cloned( )
757
748
) ;
758
749
) *
759
750
0 commit comments