Replace a spawn_unchecked with spawn_scoped.

This commit is contained in:
Nicholas Nethercote 2022-10-08 07:43:15 +11:00
parent ec409f95bf
commit 63db9e540c

View file

@ -136,20 +136,24 @@ pub(crate) fn run_in_thread_pool_with_globals<F: FnOnce() -> R + Send, R: Send>(
f: F, f: F,
) -> R { ) -> R {
// The thread pool is a single thread in the non-parallel compiler. // The thread pool is a single thread in the non-parallel compiler.
let mut cfg = thread::Builder::new().name("rustc".to_string()); thread::scope(|s| {
if let Some(size) = get_stack_size() { let mut builder = thread::Builder::new().name("rustc".to_string());
cfg = cfg.stack_size(size); if let Some(size) = get_stack_size() {
} builder = builder.stack_size(size);
}
let f = move || rustc_span::create_session_globals_then(edition, f); // `unwrap` is ok here because `spawn_scoped` only panics if the thread
// name contains null bytes.
let r = builder
.spawn_scoped(s, move || rustc_span::create_session_globals_then(edition, f))
.unwrap()
.join();
// This avoids the need for `'static` bounds. match r {
// Ok(v) => v,
// SAFETY: join() is called immediately, so any closure captures are still alive. Err(e) => panic::resume_unwind(e),
match unsafe { cfg.spawn_unchecked(f) }.unwrap().join() { }
Ok(v) => v, })
Err(e) => panic::resume_unwind(e),
}
} }
/// Creates a new thread and forwards information in thread locals to it. /// Creates a new thread and forwards information in thread locals to it.