diff options
| author | John Kåre Alsaker <john.kare.alsaker@gmail.com> | 2025-04-22 07:02:27 +0200 |
|---|---|---|
| committer | John Kåre Alsaker <john.kare.alsaker@gmail.com> | 2025-04-29 07:20:13 +0200 |
| commit | cff9efde748b6027fe9f135ddd5aaf8a3276601d (patch) | |
| tree | 8d6877af6e5f512fd0b7615ddb25632516dad48f /compiler/rustc_query_system | |
| parent | 25cdf1f67463c9365d8d83778c933ec7480e940b (diff) | |
| download | rust-cff9efde748b6027fe9f135ddd5aaf8a3276601d.tar.gz rust-cff9efde748b6027fe9f135ddd5aaf8a3276601d.zip | |
Add a jobserver proxy to ensure at least one token is always held
Diffstat (limited to 'compiler/rustc_query_system')
| -rw-r--r-- | compiler/rustc_query_system/src/query/job.rs | 11 | ||||
| -rw-r--r-- | compiler/rustc_query_system/src/query/mod.rs | 3 | ||||
| -rw-r--r-- | compiler/rustc_query_system/src/query/plumbing.rs | 2 |
3 files changed, 10 insertions, 6 deletions
diff --git a/compiler/rustc_query_system/src/query/job.rs b/compiler/rustc_query_system/src/query/job.rs index de35cd79ea2..6321abc5087 100644 --- a/compiler/rustc_query_system/src/query/job.rs +++ b/compiler/rustc_query_system/src/query/job.rs @@ -7,7 +7,6 @@ use std::sync::Arc; use parking_lot::{Condvar, Mutex}; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; -use rustc_data_structures::jobserver; use rustc_errors::{Diag, DiagCtxtHandle}; use rustc_hir::def::DefKind; use rustc_session::Session; @@ -207,12 +206,13 @@ impl<I> QueryLatch<I> { /// Awaits for the query job to complete. pub(super) fn wait_on( &self, + qcx: impl QueryContext, query: Option<QueryJobId>, span: Span, ) -> Result<(), CycleError<I>> { let waiter = Arc::new(QueryWaiter { query, span, cycle: Mutex::new(None), condvar: Condvar::new() }); - self.wait_on_inner(&waiter); + self.wait_on_inner(qcx, &waiter); // FIXME: Get rid of this lock. We have ownership of the QueryWaiter // although another thread may still have a Arc reference so we cannot // use Arc::get_mut @@ -224,7 +224,7 @@ impl<I> QueryLatch<I> { } /// Awaits the caller on this latch by blocking the current thread. - fn wait_on_inner(&self, waiter: &Arc<QueryWaiter<I>>) { + fn wait_on_inner(&self, qcx: impl QueryContext, waiter: &Arc<QueryWaiter<I>>) { let mut info = self.info.lock(); if !info.complete { // We push the waiter on to the `waiters` list. It can be accessed inside @@ -237,11 +237,12 @@ impl<I> QueryLatch<I> { // we have to be in the `wait` call. This is ensured by the deadlock handler // getting the self.info lock. rayon_core::mark_blocked(); - jobserver::release_thread(); + let proxy = qcx.jobserver_proxy(); + proxy.release_thread(); waiter.condvar.wait(&mut info); // Release the lock before we potentially block in `acquire_thread` drop(info); - jobserver::acquire_thread(); + proxy.acquire_thread(); } } diff --git a/compiler/rustc_query_system/src/query/mod.rs b/compiler/rustc_query_system/src/query/mod.rs index ef21af7dafb..a87f598674e 100644 --- a/compiler/rustc_query_system/src/query/mod.rs +++ b/compiler/rustc_query_system/src/query/mod.rs @@ -16,6 +16,7 @@ mod caches; pub use self::caches::{DefIdCache, DefaultCache, QueryCache, SingleCache, VecCache}; mod config; +use rustc_data_structures::jobserver::Proxy; use rustc_data_structures::sync::{DynSend, DynSync}; use rustc_errors::DiagInner; use rustc_hashes::Hash64; @@ -151,6 +152,8 @@ pub enum QuerySideEffect { pub trait QueryContext: HasDepContext { type QueryInfo: Clone; + fn jobserver_proxy(&self) -> &Proxy; + fn next_job_id(self) -> QueryJobId; /// Get the query information from the TLS context. diff --git a/compiler/rustc_query_system/src/query/plumbing.rs b/compiler/rustc_query_system/src/query/plumbing.rs index 6ea8e3b9200..3c1fc731784 100644 --- a/compiler/rustc_query_system/src/query/plumbing.rs +++ b/compiler/rustc_query_system/src/query/plumbing.rs @@ -297,7 +297,7 @@ where // With parallel queries we might just have to wait on some other // thread. - let result = latch.wait_on(current, span); + let result = latch.wait_on(qcx, current, span); match result { Ok(()) => { |
