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
This commit is contained in:
parent
bb45f5db78
commit
5730173763
@ -186,6 +186,8 @@ pub struct Config {
|
||||
}
|
||||
|
||||
pub fn create_compiler_and_run<R>(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<R>(config: Config, f: impl FnOnce(&Compiler) -> R
|
||||
pub fn run_compiler<R: Send>(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,
|
||||
|
@ -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;
|
||||
|
@ -128,7 +128,7 @@ fn scoped_thread<F: FnOnce() -> R + Send, R: Send>(cfg: thread::Builder, f: F) -
|
||||
}
|
||||
|
||||
#[cfg(not(parallel_compiler))]
|
||||
pub fn setup_callbacks_and_run_in_thread_pool_with_globals<F: FnOnce() -> R + Send, R: Send>(
|
||||
pub fn run_in_thread_pool_with_globals<F: FnOnce() -> R + Send, R: Send>(
|
||||
edition: Edition,
|
||||
_threads: usize,
|
||||
stderr: &Option<Arc<Mutex<Vec<u8>>>>,
|
||||
@ -140,8 +140,6 @@ pub fn setup_callbacks_and_run_in_thread_pool_with_globals<F: FnOnce() -> 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<F: FnOnce() -> R + Send, R: Send>(
|
||||
pub fn run_in_thread_pool_with_globals<F: FnOnce() -> R + Send, R: Send>(
|
||||
edition: Edition,
|
||||
threads: usize,
|
||||
stderr: &Option<Arc<Mutex<Vec<u8>>>>,
|
||||
f: F,
|
||||
) -> R {
|
||||
crate::callbacks::setup_callbacks();
|
||||
|
||||
let mut config = rayon::ThreadPoolBuilder::new()
|
||||
.thread_name(|_| "rustc".to_string())
|
||||
.acquire_thread_handler(jobserver::acquire_thread)
|
||||
|
@ -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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user