@@ -36,7 +36,8 @@ use syntax_pos::Span;
3636use syntax:: codemap:: DUMMY_SP ;
3737
3838pub 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 > > ,
4041}
4142
4243pub ( super ) struct QueryValue < T > {
@@ -58,7 +59,8 @@ impl<T> QueryValue<T> {
5859impl < ' tcx , M : QueryConfig < ' tcx > > QueryMap < ' tcx , M > {
5960 pub ( super ) fn new ( ) -> QueryMap < ' tcx , M > {
6061 QueryMap {
61- map : FxHashMap ( ) ,
62+ results : FxHashMap ( ) ,
63+ active : FxHashMap ( ) ,
6264 }
6365 }
6466}
@@ -111,15 +113,15 @@ impl<'a, 'tcx, Q: QueryDescription<'tcx>> JobOwner<'a, 'tcx, Q> {
111113 let map = Q :: query_map ( tcx) ;
112114 loop {
113115 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 ( ) ) {
115122 Entry :: Occupied ( entry) => {
116123 match * entry. get ( ) {
117124 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- } ,
123125 QueryResult :: Poisoned => FatalError . raise ( ) ,
124126 }
125127 }
@@ -161,7 +163,11 @@ impl<'a, 'tcx, Q: QueryDescription<'tcx>> JobOwner<'a, 'tcx, Q> {
161163 mem:: forget ( self ) ;
162164
163165 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+ }
165171
166172 job. signal_complete ( ) ;
167173 }
@@ -205,7 +211,7 @@ impl<'a, 'tcx, Q: QueryDescription<'tcx>> JobOwner<'a, 'tcx, Q> {
205211impl < ' a , ' tcx , Q : QueryDescription < ' tcx > > Drop for JobOwner < ' a , ' tcx , Q > {
206212 fn drop ( & mut self ) {
207213 // 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 ) ;
209215 // Also signal the completion of the job, so waiters
210216 // will continue execution
211217 self . job . signal_complete ( ) ;
0 commit comments