Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 5730173

Browse files
committed
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
1 parent bb45f5d commit 5730173

File tree

4 files changed

+7
-8
lines changed

4 files changed

+7
-8
lines changed

compiler/rustc_interface/src/interface.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,8 @@ pub struct Config {
186186
}
187187

188188
pub fn create_compiler_and_run<R>(config: Config, f: impl FnOnce(&Compiler) -> R) -> R {
189+
crate::callbacks::setup_callbacks();
190+
189191
let registry = &config.registry;
190192
let (mut sess, codegen_backend) = util::create_session(
191193
config.opts,
@@ -238,7 +240,7 @@ pub fn create_compiler_and_run<R>(config: Config, f: impl FnOnce(&Compiler) -> R
238240
pub fn run_compiler<R: Send>(mut config: Config, f: impl FnOnce(&Compiler) -> R + Send) -> R {
239241
tracing::trace!("run_compiler");
240242
let stderr = config.stderr.take();
241-
util::setup_callbacks_and_run_in_thread_pool_with_globals(
243+
util::run_in_thread_pool_with_globals(
242244
config.opts.edition,
243245
config.opts.debugging_opts.threads,
244246
&stderr,

compiler/rustc_interface/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ mod proc_macro_decls;
1515
mod queries;
1616
pub mod util;
1717

18+
pub use callbacks::setup_callbacks;
1819
pub use interface::{run_compiler, Config};
1920
pub use passes::{DEFAULT_EXTERN_QUERY_PROVIDERS, DEFAULT_QUERY_PROVIDERS};
2021
pub use queries::Queries;

compiler/rustc_interface/src/util.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ fn scoped_thread<F: FnOnce() -> R + Send, R: Send>(cfg: thread::Builder, f: F) -
128128
}
129129

130130
#[cfg(not(parallel_compiler))]
131-
pub fn setup_callbacks_and_run_in_thread_pool_with_globals<F: FnOnce() -> R + Send, R: Send>(
131+
pub fn run_in_thread_pool_with_globals<F: FnOnce() -> R + Send, R: Send>(
132132
edition: Edition,
133133
_threads: usize,
134134
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
140140
cfg = cfg.stack_size(size);
141141
}
142142

143-
crate::callbacks::setup_callbacks();
144-
145143
let main_handler = move || {
146144
rustc_span::create_session_globals_then(edition, || {
147145
io::set_output_capture(stderr.clone());
@@ -176,14 +174,12 @@ unsafe fn handle_deadlock() {
176174
}
177175

178176
#[cfg(parallel_compiler)]
179-
pub fn setup_callbacks_and_run_in_thread_pool_with_globals<F: FnOnce() -> R + Send, R: Send>(
177+
pub fn run_in_thread_pool_with_globals<F: FnOnce() -> R + Send, R: Send>(
180178
edition: Edition,
181179
threads: usize,
182180
stderr: &Option<Arc<Mutex<Vec<u8>>>>,
183181
f: F,
184182
) -> R {
185-
crate::callbacks::setup_callbacks();
186-
187183
let mut config = rayon::ThreadPoolBuilder::new()
188184
.thread_name(|_| "rustc".to_string())
189185
.acquire_thread_handler(jobserver::acquire_thread)

src/librustdoc/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,7 @@ fn main_args(at_args: &[String]) -> MainResult {
688688
Ok(opts) => opts,
689689
Err(code) => return if code == 0 { Ok(()) } else { Err(ErrorReported) },
690690
};
691-
rustc_interface::util::setup_callbacks_and_run_in_thread_pool_with_globals(
691+
rustc_interface::util::run_in_thread_pool_with_globals(
692692
options.edition,
693693
1, // this runs single-threaded, even in a parallel compiler
694694
&None,

0 commit comments

Comments
 (0)