@@ -36,7 +36,8 @@ use syntax_pos::Span;
36
36
use syntax:: codemap:: DUMMY_SP ;
37
37
38
38
pub struct QueryMap < ' tcx , D : QueryConfig < ' tcx > + ?Sized > {
39
- pub ( super ) map : FxHashMap < D :: Key , QueryResult < ' tcx , QueryValue < D :: Value > > > ,
39
+ pub ( super ) results : FxHashMap < D :: Key , QueryValue < D :: Value > > ,
40
+ pub ( super ) active : FxHashMap < D :: Key , QueryResult < ' tcx > > ,
40
41
}
41
42
42
43
pub ( super ) struct QueryValue < T > {
@@ -58,7 +59,8 @@ impl<T> QueryValue<T> {
58
59
impl < ' tcx , M : QueryConfig < ' tcx > > QueryMap < ' tcx , M > {
59
60
pub ( super ) fn new ( ) -> QueryMap < ' tcx , M > {
60
61
QueryMap {
61
- map : FxHashMap ( ) ,
62
+ results : FxHashMap ( ) ,
63
+ active : FxHashMap ( ) ,
62
64
}
63
65
}
64
66
}
@@ -111,15 +113,15 @@ impl<'a, 'tcx, Q: QueryDescription<'tcx>> JobOwner<'a, 'tcx, Q> {
111
113
let map = Q :: query_map ( tcx) ;
112
114
loop {
113
115
let mut lock = map. borrow_mut ( ) ;
114
- let job = match lock. map . entry ( ( * key) . clone ( ) ) {
116
+ if let Some ( value) = lock. results . get ( key) {
117
+ profq_msg ! ( tcx, ProfileQueriesMsg :: CacheHit ) ;
118
+ let result = Ok ( ( value. value . clone ( ) , value. index ) ) ;
119
+ return TryGetJob :: JobCompleted ( result) ;
120
+ }
121
+ let job = match lock. active . entry ( ( * key) . clone ( ) ) {
115
122
Entry :: Occupied ( entry) => {
116
123
match * entry. get ( ) {
117
124
QueryResult :: Started ( ref job) => job. clone ( ) ,
118
- QueryResult :: Complete ( ref value) => {
119
- profq_msg ! ( tcx, ProfileQueriesMsg :: CacheHit ) ;
120
- let result = Ok ( ( value. value . clone ( ) , value. index ) ) ;
121
- return TryGetJob :: JobCompleted ( result) ;
122
- } ,
123
125
QueryResult :: Poisoned => FatalError . raise ( ) ,
124
126
}
125
127
}
@@ -161,7 +163,11 @@ impl<'a, 'tcx, Q: QueryDescription<'tcx>> JobOwner<'a, 'tcx, Q> {
161
163
mem:: forget ( self ) ;
162
164
163
165
let value = QueryValue :: new ( result. clone ( ) , dep_node_index) ;
164
- map. borrow_mut ( ) . map . insert ( key, QueryResult :: Complete ( value) ) ;
166
+ {
167
+ let mut lock = map. borrow_mut ( ) ;
168
+ lock. active . remove ( & key) ;
169
+ lock. results . insert ( key, value) ;
170
+ }
165
171
166
172
job. signal_complete ( ) ;
167
173
}
@@ -205,7 +211,7 @@ impl<'a, 'tcx, Q: QueryDescription<'tcx>> JobOwner<'a, 'tcx, Q> {
205
211
impl < ' a , ' tcx , Q : QueryDescription < ' tcx > > Drop for JobOwner < ' a , ' tcx , Q > {
206
212
fn drop ( & mut self ) {
207
213
// Poison the query so jobs waiting on it panic
208
- self . map . borrow_mut ( ) . map . insert ( self . key . clone ( ) , QueryResult :: Poisoned ) ;
214
+ self . map . borrow_mut ( ) . active . insert ( self . key . clone ( ) , QueryResult :: Poisoned ) ;
209
215
// Also signal the completion of the job, so waiters
210
216
// will continue execution
211
217
self . job . signal_complete ( ) ;
0 commit comments