Skip to content

Commit 4124617

Browse files
committed
Auto merge of #113606 - jyn514:parallel-compiler-cleanup, r=cjgillot
Don't require each rustc_interface tool to opt-in to parallel_compiler Previously, forgetting to call `interface::set_thread_safe_mode` would cause the following ICE: ``` thread 'rustc' panicked at 'uninitialized dyn_thread_safe mode!', /rustc/dfe0683138de0959b6ab6a039b54d9347f6a6355/compiler/rustc_data_structures/src/sync.rs:74:18 ``` This calls `set_thread_safe_mode` in `interface::run_compiler` to avoid requiring it in the caller. Fixes `tests/run-make-fulldeps/issue-19371` when parallel-compiler is enabled. r? `@SparrowLii` cc #75760
2 parents 4c8bb79 + d52eb4f commit 4124617

File tree

4 files changed

+5
-12
lines changed

4 files changed

+5
-12
lines changed

compiler/rustc_driver_impl/src/lib.rs

-3
Original file line numberDiff line numberDiff line change
@@ -279,9 +279,6 @@ fn run_compiler(
279279

280280
let sopts = config::build_session_options(&mut early_error_handler, &matches);
281281

282-
// Set parallel mode before thread pool creation, which will create `Lock`s.
283-
interface::set_thread_safe_mode(&sopts.unstable_opts);
284-
285282
if let Some(ref code) = matches.opt_str("explain") {
286283
handle_explain(&early_error_handler, diagnostics_registry(), code, sopts.color);
287284
return Ok(());

compiler/rustc_interface/src/interface.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,6 @@ impl Compiler {
5959
}
6060
}
6161

62-
#[allow(rustc::bad_opt_access)]
63-
pub fn set_thread_safe_mode(sopts: &config::UnstableOptions) {
64-
rustc_data_structures::sync::set_dyn_thread_safe_mode(sopts.threads > 1);
65-
}
66-
6762
/// Converts strings provided as `--cfg [cfgspec]` into a `crate_cfg`.
6863
pub fn parse_cfgspecs(
6964
handler: &EarlyErrorHandler,
@@ -289,6 +284,10 @@ pub struct Config {
289284
#[allow(rustc::bad_opt_access)]
290285
pub fn run_compiler<R: Send>(config: Config, f: impl FnOnce(&Compiler) -> R + Send) -> R {
291286
trace!("run_compiler");
287+
288+
// Set parallel mode before thread pool creation, which will create `Lock`s.
289+
rustc_data_structures::sync::set_dyn_thread_safe_mode(config.opts.unstable_opts.threads > 1);
290+
292291
util::run_in_thread_pool_with_globals(
293292
config.opts.edition,
294293
config.opts.unstable_opts.threads,

src/librustdoc/lib.rs

-3
Original file line numberDiff line numberDiff line change
@@ -744,9 +744,6 @@ fn main_args(handler: &mut EarlyErrorHandler, at_args: &[String]) -> MainResult
744744
}
745745
};
746746

747-
// Set parallel mode before error handler creation, which will create `Lock`s.
748-
interface::set_thread_safe_mode(&options.unstable_opts);
749-
750747
let diag = core::new_handler(
751748
options.error_format,
752749
None,

tests/run-make-fulldeps/issue-19371/foo.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,6 @@ fn compile(code: String, output: PathBuf, sysroot: PathBuf) {
6868
let ongoing_codegen = queries.ongoing_codegen()?;
6969
queries.linker(ongoing_codegen)
7070
});
71-
linker.unwrap().link();
71+
linker.unwrap().link().unwrap();
7272
});
7373
}

0 commit comments

Comments
 (0)