@@ -33,22 +33,34 @@ fn equivalent_key<K: Eq, V>(k: &K) -> impl Fn(&(K, V)) -> bool + '_ {
3333 move |x| x. 0 == * k
3434}
3535
36+ /// For a particular query, keeps track of "active" keys, i.e. keys whose
37+ /// evaluation has started but has not yet finished successfully.
38+ ///
39+ /// (Successful query evaluation for a key is represented by an entry in the
40+ /// query's in-memory cache.)
3641pub struct QueryState < ' tcx , K > {
37- active : Sharded < hash_table:: HashTable < ( K , QueryResult < ' tcx > ) > > ,
42+ active : Sharded < hash_table:: HashTable < ( K , ActiveKeyStatus < ' tcx > ) > > ,
3843}
3944
40- /// Indicates the state of a query for a given key in a query map.
41- enum QueryResult < ' tcx > {
42- /// An already executing query. The query job can be used to await for its completion.
45+ /// For a particular query and key, tracks the status of a query evaluation
46+ /// that has started, but has not yet finished successfully.
47+ ///
48+ /// (Successful query evaluation for a key is represented by an entry in the
49+ /// query's in-memory cache.)
50+ enum ActiveKeyStatus < ' tcx > {
51+ /// Some thread is already evaluating the query for this key.
52+ ///
53+ /// The enclosed [`QueryJob`] can be used to wait for it to finish.
4354 Started ( QueryJob < ' tcx > ) ,
4455
4556 /// The query panicked. Queries trying to wait on this will raise a fatal error which will
4657 /// silently panic.
4758 Poisoned ,
4859}
4960
50- impl < ' tcx > QueryResult < ' tcx > {
51- /// Unwraps the query job expecting that it has started.
61+ impl < ' tcx > ActiveKeyStatus < ' tcx > {
62+ /// Obtains the enclosed [`QueryJob`], or panics if this query evaluation
63+ /// was poisoned by a panic.
5264 fn expect_job ( self ) -> QueryJob < ' tcx > {
5365 match self {
5466 Self :: Started ( job) => job,
7688 ) -> Option < ( ) > {
7789 let mut active = Vec :: new ( ) ;
7890
79- let mut collect = |iter : LockGuard < ' _ , HashTable < ( K , QueryResult < ' tcx > ) > > | {
91+ let mut collect = |iter : LockGuard < ' _ , HashTable < ( K , ActiveKeyStatus < ' tcx > ) > > | {
8092 for ( k, v) in iter. iter ( ) {
81- if let QueryResult :: Started ( ref job) = * v {
93+ if let ActiveKeyStatus :: Started ( ref job) = * v {
8294 active. push ( ( * k, job. clone ( ) ) ) ;
8395 }
8496 }
@@ -222,7 +234,7 @@ where
222234 Err ( _) => panic ! ( ) ,
223235 Ok ( occupied) => {
224236 let ( ( key, value) , vacant) = occupied. remove ( ) ;
225- vacant. insert ( ( key, QueryResult :: Poisoned ) ) ;
237+ vacant. insert ( ( key, ActiveKeyStatus :: Poisoned ) ) ;
226238 value. expect_job ( )
227239 }
228240 }
@@ -319,7 +331,7 @@ where
319331 let shard = query. query_state ( qcx) . active . lock_shard_by_hash ( key_hash) ;
320332 match shard. find ( key_hash, equivalent_key ( & key) ) {
321333 // The query we waited on panicked. Continue unwinding here.
322- Some ( ( _, QueryResult :: Poisoned ) ) => FatalError . raise ( ) ,
334+ Some ( ( _, ActiveKeyStatus :: Poisoned ) ) => FatalError . raise ( ) ,
323335 _ => panic ! (
324336 "query '{}' result must be in the cache or the query must be poisoned after a wait" ,
325337 query. name( )
@@ -373,7 +385,7 @@ where
373385 // state map.
374386 let id = qcx. next_job_id ( ) ;
375387 let job = QueryJob :: new ( id, span, current_job_id) ;
376- entry. insert ( ( key, QueryResult :: Started ( job) ) ) ;
388+ entry. insert ( ( key, ActiveKeyStatus :: Started ( job) ) ) ;
377389
378390 // Drop the lock before we start executing the query
379391 drop ( state_lock) ;
@@ -382,7 +394,7 @@ where
382394 }
383395 Entry :: Occupied ( mut entry) => {
384396 match & mut entry. get_mut ( ) . 1 {
385- QueryResult :: Started ( job) => {
397+ ActiveKeyStatus :: Started ( job) => {
386398 if sync:: is_dyn_thread_safe ( ) {
387399 // Get the latch out
388400 let latch = job. latch ( ) ;
@@ -400,7 +412,7 @@ where
400412 // so we just return the error.
401413 cycle_error ( query, qcx, id, span)
402414 }
403- QueryResult :: Poisoned => FatalError . raise ( ) ,
415+ ActiveKeyStatus :: Poisoned => FatalError . raise ( ) ,
404416 }
405417 }
406418 }
0 commit comments