Skip to content

Commit

Permalink
Rollup merge of rust-lang#118709 - oksbsb:fix-job-server, r=petrochenkov
Browse files Browse the repository at this point in the history
fix jobserver GLOBAL_CLIENT_CHECKED uninitialized before use

override rust-lang#118589, resolve merge conflict

`@petrochenkov` `@SparrowLii`

Thanks!
  • Loading branch information
matthiaskrgr authored Dec 7, 2023
2 parents 2079ccb + cf1cecc commit e97a3fa
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 12 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_data_structures/src/jobserver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ fn default_client() -> Client {

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

pub fn check(report_warning: impl FnOnce(&'static str)) {
pub fn initialize_checked(report_warning: impl FnOnce(&'static str)) {
let client_checked = match &*GLOBAL_CLIENT {
Ok(client) => client.clone(),
Err(e) => {
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_interface/src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,10 @@ pub fn run_compiler<R: Send>(config: Config, f: impl FnOnce(&Compiler) -> R + Se
// Set parallel mode before thread pool creation, which will create `Lock`s.
rustc_data_structures::sync::set_dyn_thread_safe_mode(config.opts.unstable_opts.threads > 1);

// Check jobserver before run_in_thread_pool_with_globals, which call jobserver::acquire_thread
let early_handler = EarlyErrorHandler::new(config.opts.error_format);
early_handler.initialize_checked_jobserver();

util::run_in_thread_pool_with_globals(
config.opts.edition,
config.opts.unstable_opts.threads,
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_interface/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ use std::sync::Arc;

fn mk_session(matches: getopts::Matches) -> (Session, Cfg) {
let mut early_handler = EarlyErrorHandler::new(ErrorOutputType::default());
early_handler.initialize_checked_jobserver();

let registry = registry::Registry::new(&[]);
let sessopts = build_session_options(&mut early_handler, &matches);
let temps_dir = sessopts.unstable_opts.temps_dir.as_deref().map(PathBuf::from);
Expand Down
23 changes: 12 additions & 11 deletions compiler/rustc_session/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1474,17 +1474,6 @@ pub fn build_session(
let asm_arch =
if target_cfg.allow_asm { InlineAsmArch::from_str(&target_cfg.arch).ok() } else { None };

// Check jobserver before getting `jobserver::client`.
jobserver::check(|err| {
#[allow(rustc::untranslatable_diagnostic)]
#[allow(rustc::diagnostic_outside_of_impl)]
parse_sess
.span_diagnostic
.struct_warn(err)
.note("the build environment is likely misconfigured")
.emit()
});

let sess = Session {
target: target_cfg,
host,
Expand Down Expand Up @@ -1792,6 +1781,18 @@ impl EarlyErrorHandler {
pub fn early_warn(&self, msg: impl Into<DiagnosticMessage>) {
self.handler.struct_warn(msg).emit()
}

pub fn initialize_checked_jobserver(&self) {
// initialize jobserver before getting `jobserver::client` and `build_session`.
jobserver::initialize_checked(|err| {
#[allow(rustc::untranslatable_diagnostic)]
#[allow(rustc::diagnostic_outside_of_impl)]
self.handler
.struct_warn(err)
.note("the build environment is likely misconfigured")
.emit()
});
}
}

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

0 comments on commit e97a3fa

Please sign in to comment.