Skip to content

Commit 3e13141

Browse files
committed
1. add EarlyErrorHandler::initialize_checked_jobserver to share code
2. rename jobserver::check to jobserver::initialize_checked
1 parent 50232ff commit 3e13141

File tree

4 files changed

+15
-12
lines changed

4 files changed

+15
-12
lines changed

compiler/rustc_data_structures/src/jobserver.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ fn default_client() -> Client {
5252

5353
static GLOBAL_CLIENT_CHECKED: OnceLock<Client> = OnceLock::new();
5454

55-
pub fn check(report_warning: impl FnOnce(&'static str)) {
55+
pub fn initialize_checked(report_warning: impl FnOnce(&'static str)) {
5656
let client_checked = match &*GLOBAL_CLIENT {
5757
Ok(client) => client.clone(),
5858
Err(e) => {

compiler/rustc_interface/src/interface.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ use crate::util;
33
use rustc_ast::token;
44
use rustc_ast::{LitKind, MetaItemKind};
55
use rustc_codegen_ssa::traits::CodegenBackend;
6-
use rustc_data_structures::{defer, jobserver};
76
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
87
use rustc_data_structures::stable_hasher::StableHasher;
98
use rustc_data_structures::sync::Lrc;
9+
use rustc_data_structures::{defer, jobserver};
1010
use rustc_errors::registry::Registry;
1111
use rustc_errors::{ErrorGuaranteed, Handler};
1212
use rustc_lint::LintStore;
@@ -382,12 +382,10 @@ pub fn run_compiler<R: Send>(config: Config, f: impl FnOnce(&Compiler) -> R + Se
382382
// Set parallel mode before thread pool creation, which will create `Lock`s.
383383
rustc_data_structures::sync::set_dyn_thread_safe_mode(config.opts.unstable_opts.threads > 1);
384384

385-
let handler = EarlyErrorHandler::new(config.opts.error_format);
386385
// Check jobserver before run_in_thread_pool_with_globals, which call jobserver::acquire_thread
387-
jobserver::check(|err| {
388-
handler.early_warn_with_note(err, "the build environment is likely misconfigured")
389-
});
390-
386+
let handler = EarlyErrorHandler::new(config.opts.error_format);
387+
handler.initialize_checked_jobserver();
388+
391389
util::run_in_thread_pool_with_globals(
392390
config.opts.edition,
393391
config.opts.unstable_opts.threads,

compiler/rustc_interface/src/tests.rs

+3
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ fn mk_session(handler: &mut EarlyErrorHandler, matches: getopts::Matches) -> (Se
3636
output_file: None,
3737
temps_dir,
3838
};
39+
40+
handler.initialize_checked_jobserver();
41+
3942
let sess = build_session(
4043
handler,
4144
sessopts,

compiler/rustc_session/src/session.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -1469,11 +1469,6 @@ pub fn build_session(
14691469
let asm_arch =
14701470
if target_cfg.allow_asm { InlineAsmArch::from_str(&target_cfg.arch).ok() } else { None };
14711471

1472-
// Check jobserver before getting `jobserver::client`.
1473-
jobserver::check(|err| {
1474-
handler.early_warn_with_note(err, "the build environment is likely misconfigured")
1475-
});
1476-
14771472
let sess = Session {
14781473
target: target_cfg,
14791474
host,
@@ -1791,6 +1786,13 @@ impl EarlyErrorHandler {
17911786
) {
17921787
self.handler.struct_warn(msg).note(note).emit()
17931788
}
1789+
1790+
pub fn initialize_checked_jobserver(&self) {
1791+
// initialize jobserver before getting `jobserver::client` and `build_session`.
1792+
jobserver::initialize_checked(|err| {
1793+
self.early_warn_with_note(err, "the build environment is likely misconfigured")
1794+
});
1795+
}
17941796
}
17951797

17961798
fn mk_emitter(output: ErrorOutputType) -> Box<DynEmitter> {

0 commit comments

Comments
 (0)