about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2023-03-01 01:20:26 +0100
committerGitHub <noreply@github.com>2023-03-01 01:20:26 +0100
commita51006b8d2a1d61a1f1e52e0eb0e1e5ac8aaa183 (patch)
tree6ebf5d4cb44e7d452eaa6c4f2ac844065431483f
parent19604c2362c0b7687b32bf9ca442078564de1dab (diff)
parent10b08e3c9c935da0295fc57ac7dbad99778068e7 (diff)
downloadrust-a51006b8d2a1d61a1f1e52e0eb0e1e5ac8aaa183.tar.gz
rust-a51006b8d2a1d61a1f1e52e0eb0e1e5ac8aaa183.zip
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``
-rw-r--r--compiler/rustc_query_system/src/query/plumbing.rs9
1 files changed, 5 insertions, 4 deletions
diff --git a/compiler/rustc_query_system/src/query/plumbing.rs b/compiler/rustc_query_system/src/query/plumbing.rs
index 586bd38fbb8..5f003fa70e1 100644
--- a/compiler/rustc_query_system/src/query/plumbing.rs
+++ b/compiler/rustc_query_system/src/query/plumbing.rs
@@ -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;
@@ -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();
@@ -267,7 +269,6 @@ where
                 QueryResult::Poisoned => panic!(),
             }
         };
-        cache.complete(key, result, dep_node_index);
 
         job.signal_complete();
     }