Skip to content

Commit b993c24

Browse files
committed
Rename QueryResult to ActiveKeyStatus
1 parent 1e9be1b commit b993c24

1 file changed

Lines changed: 25 additions & 13 deletions

File tree

compiler/rustc_query_system/src/query/plumbing.rs

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,34 @@ fn equivalent_key<K: Eq, V>(k: &K) -> impl Fn(&(K, V)) -> bool + '_ {
3434
move |x| x.0 == *k
3535
}
3636

37+
/// For a particular query, keeps track of "active" keys, i.e. keys whose
38+
/// evaluation has started but has not yet finished successfully.
39+
///
40+
/// (Successful query evaluation for a key is represented by an entry in the
41+
/// query's in-memory cache.)
3742
pub struct QueryState<'tcx, K> {
38-
active: Sharded<hashbrown::HashTable<(K, QueryResult<'tcx>)>>,
43+
active: Sharded<hashbrown::HashTable<(K, ActiveKeyStatus<'tcx>)>>,
3944
}
4045

41-
/// Indicates the state of a query for a given key in a query map.
42-
enum QueryResult<'tcx> {
43-
/// An already executing query. The query job can be used to await for its completion.
46+
/// For a particular query and key, tracks the status of a query evaluation
47+
/// that has started, but has not yet finished successfully.
48+
///
49+
/// (Successful query evaluation for a key is represented by an entry in the
50+
/// query's in-memory cache.)
51+
enum ActiveKeyStatus<'tcx> {
52+
/// Some thread is already evaluating the query for this key.
53+
///
54+
/// The enclosed [`QueryJob`] can be used to wait for it to finish.
4455
Started(QueryJob<'tcx>),
4556

4657
/// The query panicked. Queries trying to wait on this will raise a fatal error which will
4758
/// silently panic.
4859
Poisoned,
4960
}
5061

51-
impl<'tcx> QueryResult<'tcx> {
52-
/// Unwraps the query job expecting that it has started.
62+
impl<'tcx> ActiveKeyStatus<'tcx> {
63+
/// Obtains the enclosed [`QueryJob`], or panics if this query evaluation
64+
/// was poisoned by a panic.
5365
fn expect_job(self) -> QueryJob<'tcx> {
5466
match self {
5567
Self::Started(job) => job,
@@ -77,9 +89,9 @@ where
7789
) -> Option<()> {
7890
let mut active = Vec::new();
7991

80-
let mut collect = |iter: LockGuard<'_, HashTable<(K, QueryResult<'tcx>)>>| {
92+
let mut collect = |iter: LockGuard<'_, HashTable<(K, ActiveKeyStatus<'tcx>)>>| {
8193
for (k, v) in iter.iter() {
82-
if let QueryResult::Started(ref job) = *v {
94+
if let ActiveKeyStatus::Started(ref job) = *v {
8395
active.push((*k, job.clone()));
8496
}
8597
}
@@ -223,7 +235,7 @@ where
223235
Err(_) => panic!(),
224236
Ok(occupied) => {
225237
let ((key, value), vacant) = occupied.remove();
226-
vacant.insert((key, QueryResult::Poisoned));
238+
vacant.insert((key, ActiveKeyStatus::Poisoned));
227239
value.expect_job()
228240
}
229241
}
@@ -320,7 +332,7 @@ where
320332
let shard = query.query_state(qcx).active.lock_shard_by_hash(key_hash);
321333
match shard.find(key_hash, equivalent_key(&key)) {
322334
// The query we waited on panicked. Continue unwinding here.
323-
Some((_, QueryResult::Poisoned)) => FatalError.raise(),
335+
Some((_, ActiveKeyStatus::Poisoned)) => FatalError.raise(),
324336
_ => panic!(
325337
"query '{}' result must be in the cache or the query must be poisoned after a wait",
326338
query.name()
@@ -374,7 +386,7 @@ where
374386
// state map.
375387
let id = qcx.next_job_id();
376388
let job = QueryJob::new(id, span, current_job_id);
377-
entry.insert((key, QueryResult::Started(job)));
389+
entry.insert((key, ActiveKeyStatus::Started(job)));
378390

379391
// Drop the lock before we start executing the query
380392
drop(state_lock);
@@ -383,7 +395,7 @@ where
383395
}
384396
Entry::Occupied(mut entry) => {
385397
match &mut entry.get_mut().1 {
386-
QueryResult::Started(job) => {
398+
ActiveKeyStatus::Started(job) => {
387399
if sync::is_dyn_thread_safe() {
388400
// Get the latch out
389401
let latch = job.latch();
@@ -401,7 +413,7 @@ where
401413
// so we just return the error.
402414
cycle_error(query, qcx, id, span)
403415
}
404-
QueryResult::Poisoned => FatalError.raise(),
416+
ActiveKeyStatus::Poisoned => FatalError.raise(),
405417
}
406418
}
407419
}

0 commit comments

Comments
 (0)