Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start-up clean-up #74122

Merged
merged 4 commits into from
Jul 11, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Change some function names.
A couple of these are quite long, but they do a much better job of
explaining what they do, which was non-obvious before.
  • Loading branch information
nnethercote committed Jul 10, 2020
commit bf7078615b868f7359bff58933fd5236fabe7280
16 changes: 8 additions & 8 deletions src/librustc_interface/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,7 @@ pub struct Config {
pub registry: Registry,
}

pub fn run_compiler_in_existing_thread_pool<R>(
config: Config,
f: impl FnOnce(&Compiler) -> R,
) -> R {
pub fn create_compiler_and_run<R>(config: Config, f: impl FnOnce(&Compiler) -> R) -> R {
let registry = &config.registry;
let (sess, codegen_backend) = util::create_session(
config.opts,
Expand Down Expand Up @@ -204,17 +201,20 @@ pub fn run_compiler_in_existing_thread_pool<R>(
pub fn run_compiler<R: Send>(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<R: Send>(edition: edition::Edition, f: impl FnOnce() -> R + Send) -> R {
pub fn setup_callbacks_and_run_in_default_thread_pool_with_globals<R: Send>(
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)
}
6 changes: 3 additions & 3 deletions src/librustc_interface/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ pub fn scoped_thread<F: FnOnce() -> R + Send, R: Send>(cfg: thread::Builder, f:
}

#[cfg(not(parallel_compiler))]
pub fn spawn_thread_pool<F: FnOnce() -> R + Send, R: Send>(
pub fn setup_callbacks_and_run_in_thread_pool_with_globals<F: FnOnce() -> R + Send, R: Send>(
edition: Edition,
_threads: usize,
stderr: &Option<Arc<Mutex<Vec<u8>>>>,
Expand Down Expand Up @@ -157,7 +157,7 @@ pub fn spawn_thread_pool<F: FnOnce() -> R + Send, R: Send>(
}

#[cfg(parallel_compiler)]
pub fn spawn_thread_pool<F: FnOnce() -> R + Send, R: Send>(
pub fn setup_callbacks_and_run_in_thread_pool_with_globals<F: FnOnce() -> R + Send, R: Send>(
edition: Edition,
threads: usize,
stderr: &Option<Arc<Mutex<Vec<u8>>>>,
Expand Down Expand Up @@ -186,7 +186,7 @@ pub fn spawn_thread_pool<F: FnOnce() -> 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), || {
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
5 changes: 4 additions & 1 deletion src/librustdoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down