Rollup merge of #119086 - RossSmyth:query_panics, r=compiler-errors
Query panic!() to useful diagnostic Changes some more ICEs from bare panic!()s Adds an `expect_job()` helper method as that is a moral equivalent of what was happening at the uses. re:#118955
This commit is contained in:
commit
093bd0888a
@ -44,6 +44,18 @@ enum QueryResult {
|
|||||||
Poisoned,
|
Poisoned,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl QueryResult {
|
||||||
|
/// Unwraps the query job expecting that it has started.
|
||||||
|
fn expect_job(self) -> QueryJob {
|
||||||
|
match self {
|
||||||
|
Self::Started(job) => job,
|
||||||
|
Self::Poisoned => {
|
||||||
|
panic!("job for query failed to start and was poisoned")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<K> QueryState<K>
|
impl<K> QueryState<K>
|
||||||
where
|
where
|
||||||
K: Eq + Hash + Copy + Debug,
|
K: Eq + Hash + Copy + Debug,
|
||||||
@ -169,10 +181,7 @@ where
|
|||||||
|
|
||||||
let job = {
|
let job = {
|
||||||
let mut lock = state.active.lock_shard_by_value(&key);
|
let mut lock = state.active.lock_shard_by_value(&key);
|
||||||
match lock.remove(&key).unwrap() {
|
lock.remove(&key).unwrap().expect_job()
|
||||||
QueryResult::Started(job) => job,
|
|
||||||
QueryResult::Poisoned => panic!(),
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
job.signal_complete();
|
job.signal_complete();
|
||||||
@ -190,10 +199,8 @@ where
|
|||||||
let state = self.state;
|
let state = self.state;
|
||||||
let job = {
|
let job = {
|
||||||
let mut shard = state.active.lock_shard_by_value(&self.key);
|
let mut shard = state.active.lock_shard_by_value(&self.key);
|
||||||
let job = match shard.remove(&self.key).unwrap() {
|
let job = shard.remove(&self.key).unwrap().expect_job();
|
||||||
QueryResult::Started(job) => job,
|
|
||||||
QueryResult::Poisoned => panic!(),
|
|
||||||
};
|
|
||||||
shard.insert(self.key, QueryResult::Poisoned);
|
shard.insert(self.key, QueryResult::Poisoned);
|
||||||
job
|
job
|
||||||
};
|
};
|
||||||
@ -277,11 +284,14 @@ where
|
|||||||
// We didn't find the query result in the query cache. Check if it was
|
// We didn't find the query result in the query cache. Check if it was
|
||||||
// poisoned due to a panic instead.
|
// poisoned due to a panic instead.
|
||||||
let lock = query.query_state(qcx).active.get_shard_by_value(&key).lock();
|
let lock = query.query_state(qcx).active.get_shard_by_value(&key).lock();
|
||||||
|
|
||||||
match lock.get(&key) {
|
match lock.get(&key) {
|
||||||
// The query we waited on panicked. Continue unwinding here.
|
Some(QueryResult::Poisoned) => {
|
||||||
Some(QueryResult::Poisoned) => FatalError.raise(),
|
panic!("query '{}' not cached due to poisoning", query.name())
|
||||||
|
}
|
||||||
_ => panic!(
|
_ => panic!(
|
||||||
"query result must in the cache or the query must be poisoned after a wait"
|
"query '{}' result must be in the cache or the query must be poisoned after a wait",
|
||||||
|
query.name()
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user