Skip to content

Commit

Permalink
Rollup merge of rust-lang#108555 - Zoxc:par-fix, r=cjgillot
Browse files Browse the repository at this point in the history
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`
  • Loading branch information
matthiaskrgr authored Feb 28, 2023
2 parents 38aa943 + 10b08e3 commit 0beb3a1
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions compiler/rustc_query_system/src/query/plumbing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ use std::collections::hash_map::Entry;
use std::fmt::Debug;
use std::hash::Hash;
use std::mem;
use std::ptr;
use thin_vec::ThinVec;

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

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

// Mark as complete before we remove the job from the active state
// so no other thread can re-execute this query.
cache.complete(key, result, dep_node_index);

let job = {
#[cfg(parallel_compiler)]
let mut lock = state.active.get_shard_by_value(&key).lock();
Expand All @@ -267,7 +269,6 @@ where
QueryResult::Poisoned => panic!(),
}
};
cache.complete(key, result, dep_node_index);

job.signal_complete();
}
Expand Down

0 comments on commit 0beb3a1

Please sign in to comment.