Skip to content

Commit db9d3a5

Browse files
committed
Auto merge of #67398 - Mark-Simulacrum:no-jobserver-herds, r=<try>
Communicate over stderr jobserver token acquiring/releasing This set of commits revises the jobserver communication inside rustc to always go through a shim around the real jobserver crate to allow us to inform Cargo of when tokens are intended to be acquired/released. The Cargo side of this hasn't yet been implemented at all yet.
2 parents 19bd934 + 0689914 commit db9d3a5

File tree

15 files changed

+195
-83
lines changed

15 files changed

+195
-83
lines changed

Cargo.lock

+12-3
Original file line numberDiff line numberDiff line change
@@ -3151,7 +3151,6 @@ dependencies = [
31513151
"chalk-engine",
31523152
"fmt_macros",
31533153
"graphviz",
3154-
"jobserver",
31553154
"log",
31563155
"measureme",
31573156
"num_cpus",
@@ -3166,6 +3165,7 @@ dependencies = [
31663165
"rustc_feature",
31673166
"rustc_fs_util",
31683167
"rustc_index",
3168+
"rustc_jobserver",
31693169
"rustc_macros",
31703170
"rustc_session",
31713171
"rustc_target",
@@ -3464,7 +3464,6 @@ version = "0.0.0"
34643464
dependencies = [
34653465
"bitflags",
34663466
"cc",
3467-
"jobserver",
34683467
"libc",
34693468
"log",
34703469
"memmap",
@@ -3478,6 +3477,7 @@ dependencies = [
34783477
"rustc_fs_util",
34793478
"rustc_incremental",
34803479
"rustc_index",
3480+
"rustc_jobserver",
34813481
"rustc_session",
34823482
"rustc_target",
34833483
"serialize",
@@ -3511,7 +3511,6 @@ dependencies = [
35113511
"ena",
35123512
"graphviz",
35133513
"indexmap",
3514-
"jobserver",
35153514
"lazy_static 1.3.0",
35163515
"log",
35173516
"measureme",
@@ -3623,6 +3622,7 @@ dependencies = [
36233622
"rustc_data_structures",
36243623
"rustc_errors",
36253624
"rustc_incremental",
3625+
"rustc_jobserver",
36263626
"rustc_lint",
36273627
"rustc_metadata",
36283628
"rustc_mir",
@@ -3643,6 +3643,15 @@ dependencies = [
36433643
"tempfile",
36443644
]
36453645

3646+
[[package]]
3647+
name = "rustc_jobserver"
3648+
version = "0.0.0"
3649+
dependencies = [
3650+
"jobserver",
3651+
"lazy_static 1.3.0",
3652+
"serialize",
3653+
]
3654+
36463655
[[package]]
36473656
name = "rustc_lexer"
36483657
version = "0.1.0"

src/librustc/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ arena = { path = "../libarena" }
1414
bitflags = "1.2.1"
1515
fmt_macros = { path = "../libfmt_macros" }
1616
graphviz = { path = "../libgraphviz" }
17-
jobserver = "0.1"
17+
rustc_jobserver = { path = "../librustc_jobserver" }
1818
num_cpus = "1.0"
1919
scoped-tls = "1.0"
2020
log = { version = "0.4", features = ["release_max_level_info", "std"] }

src/librustc/ty/query/job.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ use std::ptr;
1212
#[cfg(parallel_compiler)]
1313
use {
1414
parking_lot::{Mutex, Condvar},
15-
rustc_data_structures::{jobserver, OnDrop},
15+
rustc_data_structures::{OnDrop},
16+
rustc_jobserver as jobserver,
1617
rustc_data_structures::fx::FxHashSet,
1718
rustc_data_structures::stable_hasher::{StableHasher, HashStable},
1819
rustc_data_structures::sync::Lock,

src/librustc_codegen_ssa/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ num_cpus = "1.0"
1616
memmap = "0.7"
1717
log = "0.4.5"
1818
libc = "0.2.44"
19-
jobserver = "0.1.11"
2019
tempfile = "3.1"
2120

2221
rustc_serialize = { path = "../libserialize", package = "serialize" }
@@ -33,3 +32,4 @@ rustc_index = { path = "../librustc_index" }
3332
rustc_target = { path = "../librustc_target" }
3433
rustc_error_codes = { path = "../librustc_error_codes" }
3534
rustc_session = { path = "../librustc_session" }
35+
rustc_jobserver = { path = "../librustc_jobserver" }

src/librustc_codegen_ssa/back/write.rs

+13-26
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,10 @@ use rustc_target::spec::MergeFunctions;
3030
use syntax::attr;
3131
use syntax_pos::hygiene::ExpnId;
3232
use syntax_pos::symbol::{Symbol, sym};
33-
use jobserver::{Client, Acquired};
33+
use rustc_jobserver::Acquired;
3434

3535
use std::any::Any;
3636
use std::fs;
37-
use std::io;
3837
use std::mem;
3938
use std::path::{Path, PathBuf};
4039
use std::str;
@@ -433,7 +432,6 @@ pub fn start_async_codegen<B: ExtraBackendMethods>(
433432
codegen_worker_send,
434433
coordinator_receive,
435434
total_cgus,
436-
sess.jobserver.clone(),
437435
Arc::new(modules_config),
438436
Arc::new(metadata_config),
439437
Arc::new(allocator_config),
@@ -890,7 +888,7 @@ fn execute_lto_work_item<B: ExtraBackendMethods>(
890888
}
891889

892890
pub enum Message<B: WriteBackendMethods> {
893-
Token(io::Result<Acquired>),
891+
Token(Acquired),
894892
NeedsFatLTO {
895893
result: FatLTOInput<B>,
896894
worker_id: usize,
@@ -938,7 +936,6 @@ fn start_executing_work<B: ExtraBackendMethods>(
938936
codegen_worker_send: Sender<Message<B>>,
939937
coordinator_receive: Receiver<Box<dyn Any + Send>>,
940938
total_cgus: usize,
941-
jobserver: Client,
942939
modules_config: Arc<ModuleConfig>,
943940
metadata_config: Arc<ModuleConfig>,
944941
allocator_config: Arc<ModuleConfig>,
@@ -981,9 +978,9 @@ fn start_executing_work<B: ExtraBackendMethods>(
981978
// get tokens on `coordinator_receive` which will
982979
// get managed in the main loop below.
983980
let coordinator_send2 = coordinator_send.clone();
984-
let helper = jobserver.into_helper_thread(move |token| {
981+
let helper = rustc_jobserver::helper_thread(move |token| {
985982
drop(coordinator_send2.send(Box::new(Message::Token::<B>(token))));
986-
}).expect("failed to spawn helper thread");
983+
});
987984

988985
let mut each_linked_rlib_for_lto = Vec::new();
989986
drop(link::each_linked_rlib(crate_info, &mut |cnum, path| {
@@ -1374,25 +1371,15 @@ fn start_executing_work<B: ExtraBackendMethods>(
13741371
// this to spawn a new unit of work, or it may get dropped
13751372
// immediately if we have no more work to spawn.
13761373
Message::Token(token) => {
1377-
match token {
1378-
Ok(token) => {
1379-
tokens.push(token);
1380-
1381-
if main_thread_worker_state == MainThreadWorkerState::LLVMing {
1382-
// If the main thread token is used for LLVM work
1383-
// at the moment, we turn that thread into a regular
1384-
// LLVM worker thread, so the main thread is free
1385-
// to react to codegen demand.
1386-
main_thread_worker_state = MainThreadWorkerState::Idle;
1387-
running += 1;
1388-
}
1389-
}
1390-
Err(e) => {
1391-
let msg = &format!("failed to acquire jobserver token: {}", e);
1392-
shared_emitter.fatal(msg);
1393-
// Exit the coordinator thread
1394-
panic!("{}", msg)
1395-
}
1374+
tokens.push(token);
1375+
1376+
if main_thread_worker_state == MainThreadWorkerState::LLVMing {
1377+
// If the main thread token is used for LLVM work
1378+
// at the moment, we turn that thread into a regular
1379+
// LLVM worker thread, so the main thread is free
1380+
// to react to codegen demand.
1381+
main_thread_worker_state = MainThreadWorkerState::Idle;
1382+
running += 1;
13961383
}
13971384
}
13981385

src/librustc_data_structures/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ doctest = false
1313
ena = "0.13.1"
1414
indexmap = "1"
1515
log = "0.4"
16-
jobserver_crate = { version = "0.1.13", package = "jobserver" }
1716
lazy_static = "1"
1817
rustc_serialize = { path = "../libserialize", package = "serialize" }
1918
graphviz = { path = "../libgraphviz" }

src/librustc_data_structures/jobserver.rs

-42
This file was deleted.

src/librustc_data_structures/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ pub mod flock;
7474
pub mod fx;
7575
pub mod stable_map;
7676
pub mod graph;
77-
pub mod jobserver;
7877
pub mod obligation_forest;
7978
pub mod owning_ref;
8079
pub mod ptr_key;

src/librustc_interface/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ rustc = { path = "../librustc" }
2323
rustc_incremental = { path = "../librustc_incremental" }
2424
rustc_traits = { path = "../librustc_traits" }
2525
rustc_data_structures = { path = "../librustc_data_structures" }
26+
rustc_jobserver = { path = "../librustc_jobserver" }
2627
rustc_codegen_ssa = { path = "../librustc_codegen_ssa" }
2728
rustc_codegen_utils = { path = "../librustc_codegen_utils" }
2829
rustc_codegen_llvm = { path = "../librustc_codegen_llvm", optional = true }

src/librustc_interface/interface.rs

+14
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,20 @@ pub fn run_compiler_in_existing_thread_pool<R>(
181181

182182
pub fn run_compiler<R: Send>(mut config: Config, f: impl FnOnce(&Compiler) -> R + Send) -> R {
183183
let stderr = config.stderr.take();
184+
185+
if config.opts.debugging_opts.jobserver_token_requests {
186+
if let config::ErrorOutputType::Json { .. } = config.opts.error_format {
187+
if stderr.is_some() {
188+
panic!("Non-default output not supported with -Zjobserver-token-requests");
189+
}
190+
} else {
191+
panic!("-Zjobserver-token-requests can only be specified if using \
192+
JSON error output type");
193+
}
194+
}
195+
196+
rustc_jobserver::initialize(config.opts.debugging_opts.jobserver_token_requests);
197+
184198
util::spawn_thread_pool(
185199
config.opts.edition,
186200
config.opts.debugging_opts.threads,

src/librustc_interface/util.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc::ty;
66
use rustc::lint;
77
use rustc_codegen_utils::codegen_backend::CodegenBackend;
88
#[cfg(parallel_compiler)]
9-
use rustc_data_structures::jobserver;
9+
use rustc_jobserver as jobserver;
1010
use rustc_data_structures::sync::{Lock, Lrc};
1111
use rustc_data_structures::stable_hasher::StableHasher;
1212
use rustc_data_structures::fingerprint::Fingerprint;

src/librustc_jobserver/Cargo.toml

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[package]
2+
authors = ["The Rust Project Developers"]
3+
name = "rustc_jobserver"
4+
version = "0.0.0"
5+
edition = "2018"
6+
7+
[lib]
8+
name = "rustc_jobserver"
9+
path = "lib.rs"
10+
doctest = false
11+
12+
[dependencies]
13+
jobserver_crate = { version = "0.1.13", package = "jobserver" }
14+
lazy_static = "1"
15+
rustc_serialize = { path = "../libserialize", package = "serialize" }

0 commit comments

Comments
 (0)