diff options
| author | León Orell Valerian Liehr <me@fmease.dev> | 2024-01-03 16:08:23 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-01-03 16:08:23 +0100 |
| commit | 093bd0888a07dea9983358c9f1f8e295fd4c68de (patch) | |
| tree | 51865b7f637ca19c448b1ccb7743c95c87f69317 | |
| parent | e51e98dde6a60637b6a71b8105245b629ac3fe77 (diff) | |
| parent | 0d421c5acec8719875d8261838cb6d047fe9b23b (diff) | |
| download | rust-093bd0888a07dea9983358c9f1f8e295fd4c68de.tar.gz rust-093bd0888a07dea9983358c9f1f8e295fd4c68de.zip | |
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
| -rw-r--r-- | compiler/rustc_query_system/src/query/plumbing.rs | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/compiler/rustc_query_system/src/query/plumbing.rs b/compiler/rustc_query_system/src/query/plumbing.rs index 34f2c01f890..51842664eeb 100644 --- a/compiler/rustc_query_system/src/query/plumbing.rs +++ b/compiler/rustc_query_system/src/query/plumbing.rs @@ -44,6 +44,18 @@ enum QueryResult { 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> where K: Eq + Hash + Copy + Debug, @@ -169,10 +181,7 @@ where let job = { let mut lock = state.active.lock_shard_by_value(&key); - match lock.remove(&key).unwrap() { - QueryResult::Started(job) => job, - QueryResult::Poisoned => panic!(), - } + lock.remove(&key).unwrap().expect_job() }; job.signal_complete(); @@ -190,10 +199,8 @@ where let state = self.state; let job = { let mut shard = state.active.lock_shard_by_value(&self.key); - let job = match shard.remove(&self.key).unwrap() { - QueryResult::Started(job) => job, - QueryResult::Poisoned => panic!(), - }; + let job = shard.remove(&self.key).unwrap().expect_job(); + shard.insert(self.key, QueryResult::Poisoned); job }; @@ -277,11 +284,14 @@ where // We didn't find the query result in the query cache. Check if it was // poisoned due to a panic instead. let lock = query.query_state(qcx).active.get_shard_by_value(&key).lock(); + match lock.get(&key) { - // The query we waited on panicked. Continue unwinding here. - Some(QueryResult::Poisoned) => FatalError.raise(), + Some(QueryResult::Poisoned) => { + panic!("query '{}' not cached due to poisoning", query.name()) + } _ => 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() ), } }) |
