Skip to content

Commit 0d9fba1

Browse files
committed
Add useful panic messages if queries fail to start
1 parent fc561f0 commit 0d9fba1

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

compiler/rustc_query_system/src/query/plumbing.rs

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use rustc_data_structures::stack::ensure_sufficient_stack;
1919
use rustc_data_structures::sync::Lock;
2020
#[cfg(parallel_compiler)]
2121
use rustc_data_structures::{outline, sync};
22-
use rustc_errors::{DiagnosticBuilder, ErrorGuaranteed, FatalError, StashKey};
22+
use rustc_errors::{DiagnosticBuilder, ErrorGuaranteed, StashKey};
2323
use rustc_span::{Span, DUMMY_SP};
2424
use std::cell::Cell;
2525
use std::collections::hash_map::Entry;
@@ -45,11 +45,13 @@ enum QueryResult {
4545
}
4646

4747
impl QueryResult {
48-
/// Unwraps the query job and if poisoned will raise a [`FatalError`]
49-
fn unwrap(self) -> QueryJob {
48+
/// Unwraps the query job expecting that it has started.
49+
fn expect_job(self, query_name: &'static str) -> QueryJob {
5050
match self {
5151
Self::Started(job) => job,
52-
Self::Poisoned => FatalError.raise(),
52+
Self::Poisoned => {
53+
panic!("job for query {} failed to start and was poisoned", query_name)
54+
}
5355
}
5456
}
5557
}
@@ -105,6 +107,7 @@ where
105107
{
106108
state: &'tcx QueryState<K>,
107109
key: K,
110+
query_name: &'static str,
108111
}
109112

110113
#[cold]
@@ -163,9 +166,10 @@ where
163166
{
164167
/// Completes the query by updating the query cache with the `result`,
165168
/// signals the waiter and forgets the JobOwner, so it won't poison the query
166-
fn complete<C>(self, cache: &C, result: C::Value, dep_node_index: DepNodeIndex)
169+
fn complete<C, Q>(self, q: Q, cache: &C, result: C::Value, dep_node_index: DepNodeIndex)
167170
where
168171
C: QueryCache<Key = K>,
172+
Q: QueryConfig<Qcx>,
169173
{
170174
let key = self.key;
171175
let state = self.state;
@@ -179,7 +183,7 @@ where
179183

180184
let job = {
181185
let mut lock = state.active.lock_shard_by_value(&key);
182-
lock.remove(&key).unwrap().unwrap()
186+
lock.remove(&key).unwrap().expect_job(q.name())
183187
};
184188

185189
job.signal_complete();
@@ -197,7 +201,7 @@ where
197201
let state = self.state;
198202
let job = {
199203
let mut shard = state.active.lock_shard_by_value(&self.key);
200-
let job = shard.remove(&self.key).unwrap().unwrap();
204+
let job = shard.remove(&self.key).unwrap().expect_job(self.query_name);
201205

202206
shard.insert(self.key, QueryResult::Poisoned);
203207
job
@@ -282,7 +286,7 @@ where
282286
// We didn't find the query result in the query cache. Check if it was
283287
// poisoned due to a panic instead.
284288
let lock = query.query_state(qcx).active.get_shard_by_value(&key).lock();
285-
lock.get(&key).unwrap();
289+
lock.get(&key).expect_job(query.name());
286290
panic!(
287291
"query result must in the cache or the query must be poisoned after a wait"
288292
);
@@ -362,7 +366,9 @@ where
362366
// so we just return the error.
363367
cycle_error(query, qcx, id, span)
364368
}
365-
QueryResult::Poisoned => FatalError.raise(),
369+
QueryResult::Poisoned => {
370+
panic!("job for query {} failed to start and was poisoned", query.name())
371+
}
366372
}
367373
}
368374
}
@@ -382,7 +388,7 @@ where
382388
Qcx: QueryContext,
383389
{
384390
// Use `JobOwner` so the query will be poisoned if executing it panics.
385-
let job_owner = JobOwner { state, key };
391+
let job_owner = JobOwner { state, key, query_name: query.name() };
386392

387393
debug_assert_eq!(qcx.dep_context().dep_graph().is_fully_enabled(), INCR);
388394

@@ -437,7 +443,7 @@ where
437443
}
438444
}
439445
}
440-
job_owner.complete(cache, result, dep_node_index);
446+
job_owner.complete(cache, q, result, dep_node_index);
441447

442448
(result, Some(dep_node_index))
443449
}

0 commit comments

Comments
 (0)