From 5730173763b32ada60d7653ca987562ba0dc66f6 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Fri, 25 Jun 2021 13:03:39 +0200 Subject: [PATCH] Move setup_callbacks call to create_compiler_and_run This ensures that it is called even when run_in_thread_pool_with_globals is avoided and reduces code duplication between the parallel and non-parallel version of run_in_thread_pool_with_globals --- compiler/rustc_interface/src/interface.rs | 4 +++- compiler/rustc_interface/src/lib.rs | 1 + compiler/rustc_interface/src/util.rs | 8 ++------ src/librustdoc/lib.rs | 2 +- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/compiler/rustc_interface/src/interface.rs b/compiler/rustc_interface/src/interface.rs index 237aef1cf23..8bd24487b78 100644 --- a/compiler/rustc_interface/src/interface.rs +++ b/compiler/rustc_interface/src/interface.rs @@ -186,6 +186,8 @@ pub struct Config { } pub fn create_compiler_and_run(config: Config, f: impl FnOnce(&Compiler) -> R) -> R { + crate::callbacks::setup_callbacks(); + let registry = &config.registry; let (mut sess, codegen_backend) = util::create_session( config.opts, @@ -238,7 +240,7 @@ pub fn create_compiler_and_run(config: Config, f: impl FnOnce(&Compiler) -> R pub fn run_compiler(mut config: Config, f: impl FnOnce(&Compiler) -> R + Send) -> R { tracing::trace!("run_compiler"); let stderr = config.stderr.take(); - util::setup_callbacks_and_run_in_thread_pool_with_globals( + util::run_in_thread_pool_with_globals( config.opts.edition, config.opts.debugging_opts.threads, &stderr, diff --git a/compiler/rustc_interface/src/lib.rs b/compiler/rustc_interface/src/lib.rs index eebeabbd452..dcad3036cc2 100644 --- a/compiler/rustc_interface/src/lib.rs +++ b/compiler/rustc_interface/src/lib.rs @@ -15,6 +15,7 @@ mod proc_macro_decls; mod queries; pub mod util; +pub use callbacks::setup_callbacks; pub use interface::{run_compiler, Config}; pub use passes::{DEFAULT_EXTERN_QUERY_PROVIDERS, DEFAULT_QUERY_PROVIDERS}; pub use queries::Queries; diff --git a/compiler/rustc_interface/src/util.rs b/compiler/rustc_interface/src/util.rs index f74cadfebac..d206f2644e0 100644 --- a/compiler/rustc_interface/src/util.rs +++ b/compiler/rustc_interface/src/util.rs @@ -128,7 +128,7 @@ fn scoped_thread R + Send, R: Send>(cfg: thread::Builder, f: F) - } #[cfg(not(parallel_compiler))] -pub fn setup_callbacks_and_run_in_thread_pool_with_globals R + Send, R: Send>( +pub fn run_in_thread_pool_with_globals R + Send, R: Send>( edition: Edition, _threads: usize, stderr: &Option>>>, @@ -140,8 +140,6 @@ pub fn setup_callbacks_and_run_in_thread_pool_with_globals R + Se cfg = cfg.stack_size(size); } - crate::callbacks::setup_callbacks(); - let main_handler = move || { rustc_span::create_session_globals_then(edition, || { io::set_output_capture(stderr.clone()); @@ -176,14 +174,12 @@ unsafe fn handle_deadlock() { } #[cfg(parallel_compiler)] -pub fn setup_callbacks_and_run_in_thread_pool_with_globals R + Send, R: Send>( +pub fn run_in_thread_pool_with_globals R + Send, R: Send>( edition: Edition, threads: usize, stderr: &Option>>>, f: F, ) -> R { - crate::callbacks::setup_callbacks(); - let mut config = rayon::ThreadPoolBuilder::new() .thread_name(|_| "rustc".to_string()) .acquire_thread_handler(jobserver::acquire_thread) diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 68028604fa4..c3205165040 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -688,7 +688,7 @@ fn main_args(at_args: &[String]) -> MainResult { Ok(opts) => opts, Err(code) => return if code == 0 { Ok(()) } else { Err(ErrorReported) }, }; - rustc_interface::util::setup_callbacks_and_run_in_thread_pool_with_globals( + rustc_interface::util::run_in_thread_pool_with_globals( options.edition, 1, // this runs single-threaded, even in a parallel compiler &None,