diff --git a/src/librustc_interface/interface.rs b/src/librustc_interface/interface.rs index f89be02099e..e50622a0053 100644 --- a/src/librustc_interface/interface.rs +++ b/src/librustc_interface/interface.rs @@ -159,10 +159,7 @@ pub struct Config { pub registry: Registry, } -pub fn run_compiler_in_existing_thread_pool( - config: Config, - f: impl FnOnce(&Compiler) -> R, -) -> R { +pub fn create_compiler_and_run(config: Config, f: impl FnOnce(&Compiler) -> R) -> R { let registry = &config.registry; let (sess, codegen_backend) = util::create_session( config.opts, @@ -204,17 +201,20 @@ pub fn run_compiler_in_existing_thread_pool( pub fn run_compiler(mut config: Config, f: impl FnOnce(&Compiler) -> R + Send) -> R { log::trace!("run_compiler"); let stderr = config.stderr.take(); - util::spawn_thread_pool( + util::setup_callbacks_and_run_in_thread_pool_with_globals( config.opts.edition, config.opts.debugging_opts.threads, &stderr, - || run_compiler_in_existing_thread_pool(config, f), + || create_compiler_and_run(config, f), ) } -pub fn default_thread_pool(edition: edition::Edition, f: impl FnOnce() -> R + Send) -> R { +pub fn setup_callbacks_and_run_in_default_thread_pool_with_globals( + edition: edition::Edition, + f: impl FnOnce() -> R + Send, +) -> R { // the 1 here is duplicating code in config.opts.debugging_opts.threads // which also defaults to 1; it ultimately doesn't matter as the default // isn't threaded, and just ignores this parameter - util::spawn_thread_pool(edition, 1, &None, f) + util::setup_callbacks_and_run_in_thread_pool_with_globals(edition, 1, &None, f) } diff --git a/src/librustc_interface/util.rs b/src/librustc_interface/util.rs index dc82219b332..fb5f3581b6d 100644 --- a/src/librustc_interface/util.rs +++ b/src/librustc_interface/util.rs @@ -128,7 +128,7 @@ pub fn scoped_thread R + Send, R: Send>(cfg: thread::Builder, f: } #[cfg(not(parallel_compiler))] -pub fn spawn_thread_pool R + Send, R: Send>( +pub fn setup_callbacks_and_run_in_thread_pool_with_globals R + Send, R: Send>( edition: Edition, _threads: usize, stderr: &Option>>>, @@ -157,7 +157,7 @@ pub fn spawn_thread_pool R + Send, R: Send>( } #[cfg(parallel_compiler)] -pub fn spawn_thread_pool R + Send, R: Send>( +pub fn setup_callbacks_and_run_in_thread_pool_with_globals R + Send, R: Send>( edition: Edition, threads: usize, stderr: &Option>>>, @@ -186,7 +186,7 @@ pub fn spawn_thread_pool R + Send, R: Send>( // span_session_globals are captured and set on the new // threads. ty::tls::with_thread_locals sets up thread local // callbacks from librustc_ast. - let main_handler = move |thread: ThreadBuilder| { + let main_handler = move |thread: rayon::ThreadBuilder| { rustc_ast::SESSION_GLOBALS.set(ast_session_globals, || { rustc_span::SESSION_GLOBALS.set(span_session_globals, || { ty::tls::GCX_PTR.set(&Lock::new(0), || { diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index db98ec5d0a7..80cc5182bef 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -376,7 +376,7 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt registry: rustc_driver::diagnostics_registry(), }; - interface::run_compiler_in_existing_thread_pool(config, |compiler| { + interface::create_compiler_and_run(config, |compiler| { compiler.enter(|queries| { let sess = compiler.session(); diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index b02880ab4d3..57151e2b200 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -437,7 +437,10 @@ fn main_args(args: &[String]) -> i32 { Ok(opts) => opts, Err(code) => return code, }; - rustc_interface::interface::default_thread_pool(options.edition, move || main_options(options)) + rustc_interface::interface::setup_callbacks_and_run_in_default_thread_pool_with_globals( + options.edition, + move || main_options(options), + ) } fn wrap_return(diag: &rustc_errors::Handler, res: Result<(), String>) -> i32 {