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
4 changed files with 7 additions and 8 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue