Skip to content

Commit a51006b

Browse files
authored
Rollup merge of #108555 - Zoxc:par-fix, r=cjgillot
Fix a race in the query system This fixes an issue where in between the `job` removal and `complete` call the query neither has a job nor a result, allowing another thread to start executing it again. r? ``@cjgillot``
2 parents 19604c2 + 10b08e3 commit a51006b

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

compiler/rustc_query_system/src/query/plumbing.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ use std::collections::hash_map::Entry;
2525
use std::fmt::Debug;
2626
use std::hash::Hash;
2727
use std::mem;
28-
use std::ptr;
2928
use thin_vec::ThinVec;
3029

3130
use super::QueryConfig;
@@ -250,13 +249,16 @@ where
250249
where
251250
C: QueryCache<Key = K>,
252251
{
253-
// We can move out of `self` here because we `mem::forget` it below
254-
let key = unsafe { ptr::read(&self.key) };
252+
let key = self.key;
255253
let state = self.state;
256254

257255
// Forget ourself so our destructor won't poison the query
258256
mem::forget(self);
259257

258+
// Mark as complete before we remove the job from the active state
259+
// so no other thread can re-execute this query.
260+
cache.complete(key, result, dep_node_index);
261+
260262
let job = {
261263
#[cfg(parallel_compiler)]
262264
let mut lock = state.active.get_shard_by_value(&key).lock();
@@ -267,7 +269,6 @@ where
267269
QueryResult::Poisoned => panic!(),
268270
}
269271
};
270-
cache.complete(key, result, dep_node_index);
271272

272273
job.signal_complete();
273274
}

0 commit comments

Comments
 (0)