about summary refs log tree commit diff
path: root/compiler/rustc_query_impl
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2025-05-01 04:11:52 +0000
committerbors <bors@rust-lang.org>2025-05-01 04:11:52 +0000
commit6e23095adf9209614a45f7f75fea36dad7b92afb (patch)
tree557f1c5045bf650590df145d8391fb7a454c5676 /compiler/rustc_query_impl
parent0c33fe2c3d3eecadd17a84b110bb067288a64f1c (diff)
parent08b27ffbe89c26d0307b524c4f920bcc704ba23d (diff)
downloadrust-6e23095adf9209614a45f7f75fea36dad7b92afb.tar.gz
rust-6e23095adf9209614a45f7f75fea36dad7b92afb.zip
Auto merge of #140145 - Zoxc:job-server-proxy, r=SparrowLii
Add a jobserver proxy to ensure at least one token is always held

This adds a jobserver proxy to ensure at least one token is always held by `rustc`. Currently with `-Z threads` `rustc` can temporarily give up all its tokens, causing `cargo` to spawn additional `rustc` instances beyond the job limit.

The current behavior causes an issue with `cargo fix` which has a global lock preventing concurrent `rustc` instances, but it also holds a jobserver token, causing a deadlock when `rustc` gives up its token. That is fixed by this PR.

Fixes https://github.com/rust-lang/rust/issues/67385.
Fixes https://github.com/rust-lang/rust/issues/133873.
Fixes https://github.com/rust-lang/rust/issues/140093.
Diffstat (limited to 'compiler/rustc_query_impl')
-rw-r--r--compiler/rustc_query_impl/src/plumbing.rs6
1 files changed, 6 insertions, 0 deletions
diff --git a/compiler/rustc_query_impl/src/plumbing.rs b/compiler/rustc_query_impl/src/plumbing.rs
index d11fa8bad9b..9fbbcdc7556 100644
--- a/compiler/rustc_query_impl/src/plumbing.rs
+++ b/compiler/rustc_query_impl/src/plumbing.rs
@@ -4,6 +4,7 @@
 
 use std::num::NonZero;
 
+use rustc_data_structures::jobserver::Proxy;
 use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
 use rustc_data_structures::sync::{DynSend, DynSync};
 use rustc_data_structures::unord::UnordMap;
@@ -70,6 +71,11 @@ impl<'tcx> QueryContext for QueryCtxt<'tcx> {
     type QueryInfo = QueryStackDeferred<'tcx>;
 
     #[inline]
+    fn jobserver_proxy(&self) -> &Proxy {
+        &*self.jobserver_proxy
+    }
+
+    #[inline]
     fn next_job_id(self) -> QueryJobId {
         QueryJobId(
             NonZero::new(self.query_system.jobs.fetch_add(1, std::sync::atomic::Ordering::Relaxed))