Skip to content

Commit 81135c9

Browse files
committed
Auto merge of #50134 - andjo403:jobserver, r=michaelwoerister
make rustdoc test follow the jobserver limit of threads fix that to many threads is executing at the same time when rustdoc test is executed.
2 parents 5ec6637 + ed318dd commit 81135c9

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

src/librustc/session/mod.rs

+13-4
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ pub struct Session {
156156

157157
/// Loaded up early on in the initialization of this `Session` to avoid
158158
/// false positives about a job server in our environment.
159-
pub jobserver_from_env: Option<Client>,
159+
pub jobserver: Client,
160160

161161
/// Metadata about the allocators for the current crate being compiled
162162
pub has_global_allocator: Once<bool>,
@@ -1128,14 +1128,23 @@ pub fn build_session_(
11281128
// positives, or in other words we try to execute this before we open
11291129
// any file descriptors ourselves.
11301130
//
1131+
// Pick a "reasonable maximum" if we don't otherwise have
1132+
// a jobserver in our environment, capping out at 32 so we
1133+
// don't take everything down by hogging the process run queue.
1134+
// The fixed number is used to have deterministic compilation
1135+
// across machines.
1136+
//
11311137
// Also note that we stick this in a global because there could be
11321138
// multiple `Session` instances in this process, and the jobserver is
11331139
// per-process.
1134-
jobserver_from_env: unsafe {
1135-
static mut GLOBAL_JOBSERVER: *mut Option<Client> = 0 as *mut _;
1140+
jobserver: unsafe {
1141+
static mut GLOBAL_JOBSERVER: *mut Client = 0 as *mut _;
11361142
static INIT: std::sync::Once = std::sync::ONCE_INIT;
11371143
INIT.call_once(|| {
1138-
GLOBAL_JOBSERVER = Box::into_raw(Box::new(Client::from_env()));
1144+
let client = Client::from_env().unwrap_or_else(|| {
1145+
Client::new(32).expect("failed to create jobserver")
1146+
});
1147+
GLOBAL_JOBSERVER = Box::into_raw(Box::new(client));
11391148
});
11401149
(*GLOBAL_JOBSERVER).clone()
11411150
},

src/librustc_trans/back/write.rs

+1-8
Original file line numberDiff line numberDiff line change
@@ -1007,13 +1007,6 @@ pub fn start_async_translation(tcx: TyCtxt,
10071007
metadata_config.time_passes = false;
10081008
allocator_config.time_passes = false;
10091009

1010-
let client = sess.jobserver_from_env.clone().unwrap_or_else(|| {
1011-
// Pick a "reasonable maximum" if we don't otherwise have a jobserver in
1012-
// our environment, capping out at 32 so we don't take everything down
1013-
// by hogging the process run queue.
1014-
Client::new(32).expect("failed to create jobserver")
1015-
});
1016-
10171010
let (shared_emitter, shared_emitter_main) = SharedEmitter::new();
10181011
let (trans_worker_send, trans_worker_receive) = channel();
10191012

@@ -1023,7 +1016,7 @@ pub fn start_async_translation(tcx: TyCtxt,
10231016
trans_worker_send,
10241017
coordinator_receive,
10251018
total_cgus,
1026-
client,
1019+
sess.jobserver.clone(),
10271020
time_graph.clone(),
10281021
Arc::new(modules_config),
10291022
Arc::new(metadata_config),

0 commit comments

Comments
 (0)