Skip to content

Commit d52eb4f

Browse files
committed
Don't require each rustc_interface tool to opt-in to parallel_rustc support
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.
1 parent 993deaa commit d52eb4f

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,
@@ -288,6 +283,10 @@ pub struct Config {
288283
#[allow(rustc::bad_opt_access)]
289284
pub fn run_compiler<R: Send>(config: Config, f: impl FnOnce(&Compiler) -> R + Send) -> R {
290285
trace!("run_compiler");
286+
287+
// Set parallel mode before thread pool creation, which will create `Lock`s.
288+
rustc_data_structures::sync::set_dyn_thread_safe_mode(config.opts.unstable_opts.threads > 1);
289+
291290
util::run_in_thread_pool_with_globals(
292291
config.opts.edition,
293292
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)