about summary refs log tree commit diff
path: root/compiler/rustc_interface
diff options
context:
space:
mode:
authorNicholas Nethercote <n.nethercote@gmail.com>2022-10-07 11:57:25 +1100
committerNicholas Nethercote <n.nethercote@gmail.com>2022-10-19 07:23:14 +1100
commit134e9d36ce5316c0da61923c0182dc547db9ba46 (patch)
tree68fd0ac841b1f3ef6761a658729df315d0f3a0af /compiler/rustc_interface
parent2a62c92b25a8fbaf0fdd0fa8f8baabf7be9d9a91 (diff)
downloadrust-134e9d36ce5316c0da61923c0182dc547db9ba46.tar.gz
rust-134e9d36ce5316c0da61923c0182dc547db9ba46.zip
Inline and remove `scoped_thread`.
It has a single call site, and removing it slightly improves the
confusing tangle of nested closures present at startup.
Diffstat (limited to 'compiler/rustc_interface')
-rw-r--r--compiler/rustc_interface/src/util.rs24
1 files changed, 9 insertions, 15 deletions
diff --git a/compiler/rustc_interface/src/util.rs b/compiler/rustc_interface/src/util.rs
index 3a9e491e289..fa2a085f53c 100644
--- a/compiler/rustc_interface/src/util.rs
+++ b/compiler/rustc_interface/src/util.rs
@@ -130,33 +130,27 @@ fn get_stack_size() -> Option<usize> {
     env::var_os("RUST_MIN_STACK").is_none().then_some(STACK_SIZE)
 }
 
-/// Like a `thread::Builder::spawn` followed by a `join()`, but avoids the need
-/// for `'static` bounds.
-#[cfg(not(parallel_compiler))]
-fn scoped_thread<F: FnOnce() -> R + Send, R: Send>(cfg: thread::Builder, f: F) -> R {
-    // SAFETY: join() is called immediately, so any closure captures are still
-    // alive.
-    match unsafe { cfg.spawn_unchecked(f) }.unwrap().join() {
-        Ok(v) => v,
-        Err(e) => panic::resume_unwind(e),
-    }
-}
-
 #[cfg(not(parallel_compiler))]
 pub fn run_in_thread_pool_with_globals<F: FnOnce() -> R + Send, R: Send>(
     edition: Edition,
     _threads: usize,
     f: F,
 ) -> R {
+    // The thread pool is a single thread in the non-parallel compiler.
     let mut cfg = thread::Builder::new().name("rustc".to_string());
-
     if let Some(size) = get_stack_size() {
         cfg = cfg.stack_size(size);
     }
 
-    let main_handler = move || rustc_span::create_session_globals_then(edition, f);
+    let f = move || rustc_span::create_session_globals_then(edition, f);
 
-    scoped_thread(cfg, main_handler)
+    // This avoids the need for `'static` bounds.
+    //
+    // SAFETY: join() is called immediately, so any closure captures are still alive.
+    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.