about summary refs log tree commit diff
path: root/compiler/rustc_interface/src
diff options
context:
space:
mode:
authorjyn <github@jyn.dev>2023-07-11 22:53:23 -0500
committerjyn <github@jyn.dev>2023-07-11 22:55:23 -0500
commitd52eb4f99aebfb1077063c9e65c365e550eb1fb2 (patch)
tree81f33f1878efa63c9878581f20d44e745647f057 /compiler/rustc_interface/src
parent993deaa0bf8bab9dd3eadfd1fbeb093328e95afe (diff)
downloadrust-d52eb4f99aebfb1077063c9e65c365e550eb1fb2.tar.gz
rust-d52eb4f99aebfb1077063c9e65c365e550eb1fb2.zip
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.
Diffstat (limited to 'compiler/rustc_interface/src')
-rw-r--r--compiler/rustc_interface/src/interface.rs9
1 files changed, 4 insertions, 5 deletions
diff --git a/compiler/rustc_interface/src/interface.rs b/compiler/rustc_interface/src/interface.rs
index 953c2e4b8f8..6e233fde0f4 100644
--- a/compiler/rustc_interface/src/interface.rs
+++ b/compiler/rustc_interface/src/interface.rs
@@ -59,11 +59,6 @@ impl Compiler {
     }
 }
 
-#[allow(rustc::bad_opt_access)]
-pub fn set_thread_safe_mode(sopts: &config::UnstableOptions) {
-    rustc_data_structures::sync::set_dyn_thread_safe_mode(sopts.threads > 1);
-}
-
 /// Converts strings provided as `--cfg [cfgspec]` into a `crate_cfg`.
 pub fn parse_cfgspecs(
     handler: &EarlyErrorHandler,
@@ -288,6 +283,10 @@ pub struct Config {
 #[allow(rustc::bad_opt_access)]
 pub fn run_compiler<R: Send>(config: Config, f: impl FnOnce(&Compiler) -> R + Send) -> R {
     trace!("run_compiler");
+
+    // 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);
+
     util::run_in_thread_pool_with_globals(
         config.opts.edition,
         config.opts.unstable_opts.threads,