Skip to content

Commit b679d8a

Browse files
committed
Address review conversations
* Fix double panic by lift the mem::forget back to where it needs to be * Remove query name from expect_job panic * Remove name field from struct because of the above * Change from `if let` to `match` for one unwrap. But with a match it cannot use the unwrap method because it will not typecheck
1 parent 983cf9c commit b679d8a

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

compiler/rustc_query_system/src/query/plumbing.rs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ enum QueryResult {
4646

4747
impl QueryResult {
4848
/// Unwraps the query job expecting that it has started.
49-
fn expect_job(self, query_name: &'static str) -> QueryJob {
49+
fn expect_job(self) -> QueryJob {
5050
match self {
5151
Self::Started(job) => job,
5252
Self::Poisoned => {
53-
panic!("job for query '{}' failed to start and was poisoned", query_name)
53+
panic!("job for query failed to start and was poisoned")
5454
}
5555
}
5656
}
@@ -107,7 +107,6 @@ where
107107
{
108108
state: &'tcx QueryState<K>,
109109
key: K,
110-
query_name: &'static str,
111110
}
112111

113112
#[cold]
@@ -173,18 +172,18 @@ where
173172
let key = self.key;
174173
let state = self.state;
175174

175+
// Forget ourself so our destructor won't poison the query
176+
mem::forget(self);
177+
176178
// Mark as complete before we remove the job from the active state
177179
// so no other thread can re-execute this query.
178180
cache.complete(key, result, dep_node_index);
179181

180182
let job = {
181183
let mut lock = state.active.lock_shard_by_value(&key);
182-
lock.remove(&key).unwrap().expect_job(self.query_name)
184+
lock.remove(&key).unwrap().expect_job()
183185
};
184186

185-
// Forget ourself so our destructor won't poison the query
186-
mem::forget(self);
187-
188187
job.signal_complete();
189188
}
190189
}
@@ -200,7 +199,7 @@ where
200199
let state = self.state;
201200
let job = {
202201
let mut shard = state.active.lock_shard_by_value(&self.key);
203-
let job = shard.remove(&self.key).unwrap().expect_job(self.query_name);
202+
let job = shard.remove(&self.key).unwrap().expect_job();
204203

205204
shard.insert(self.key, QueryResult::Poisoned);
206205
job
@@ -286,13 +285,15 @@ where
286285
// poisoned due to a panic instead.
287286
let lock = query.query_state(qcx).active.get_shard_by_value(&key).lock();
288287

289-
if let Some(QueryResult::Poisoned) = lock.get(&key) {
290-
panic!("query '{}' not cached due to poisoning", query.name())
288+
match lock.get(&key) {
289+
Some(QueryResult::Poisoned) => {
290+
panic!("query '{}' not cached due to poisoning", query.name())
291+
}
292+
_ => panic!(
293+
"query '{}' result must be in the cache or the query must be poisoned after a wait",
294+
query.name()
295+
),
291296
}
292-
panic!(
293-
"query '{}' result must in the cache or the query must be poisoned after a wait",
294-
query.name()
295-
)
296297
})
297298
};
298299

@@ -391,7 +392,7 @@ where
391392
Qcx: QueryContext,
392393
{
393394
// Use `JobOwner` so the query will be poisoned if executing it panics.
394-
let job_owner = JobOwner { state, key, query_name: query.name() };
395+
let job_owner = JobOwner { state, key };
395396

396397
debug_assert_eq!(qcx.dep_context().dep_graph().is_fully_enabled(), INCR);
397398

0 commit comments

Comments
 (0)