diff options
| author | Mark Rousskov <mark.simulacrum@gmail.com> | 2021-09-19 14:02:38 -0400 |
|---|---|---|
| committer | Mark Rousskov <mark.simulacrum@gmail.com> | 2021-09-23 12:56:59 -0400 |
| commit | 0222556c077110516356c205948d1dd12edc5588 (patch) | |
| tree | 660a5bb0ca4f1234f983421736fa62f3db4fb528 /compiler/rustc_interface/src | |
| parent | 0132f8258ae0fbc4f2b461b28d510222d22aa979 (diff) | |
| download | rust-0222556c077110516356c205948d1dd12edc5588.tar.gz rust-0222556c077110516356c205948d1dd12edc5588.zip | |
Simplify scoped_thread
Avoids a bunch of manual pointer manipulation.
Diffstat (limited to 'compiler/rustc_interface/src')
| -rw-r--r-- | compiler/rustc_interface/src/lib.rs | 1 | ||||
| -rw-r--r-- | compiler/rustc_interface/src/util.rs | 24 |
2 files changed, 6 insertions, 19 deletions
diff --git a/compiler/rustc_interface/src/lib.rs b/compiler/rustc_interface/src/lib.rs index c7424b9e2a1..2fc3759968f 100644 --- a/compiler/rustc_interface/src/lib.rs +++ b/compiler/rustc_interface/src/lib.rs @@ -1,6 +1,7 @@ #![feature(bool_to_option)] #![feature(box_patterns)] #![feature(internal_output_capture)] +#![feature(thread_spawn_unchecked)] #![feature(nll)] #![feature(once_cell)] #![recursion_limit = "256"] diff --git a/compiler/rustc_interface/src/util.rs b/compiler/rustc_interface/src/util.rs index 3d90a6c9345..24975702b87 100644 --- a/compiler/rustc_interface/src/util.rs +++ b/compiler/rustc_interface/src/util.rs @@ -115,25 +115,11 @@ fn get_stack_size() -> Option<usize> { /// for `'static` bounds. #[cfg(not(parallel_compiler))] pub fn scoped_thread<F: FnOnce() -> R + Send, R: Send>(cfg: thread::Builder, f: F) -> R { - struct Ptr(*mut ()); - unsafe impl Send for Ptr {} - unsafe impl Sync for Ptr {} - - let mut f = Some(f); - let run = Ptr(&mut f as *mut _ as *mut ()); - let mut result = None; - let result_ptr = Ptr(&mut result as *mut _ as *mut ()); - - let thread = cfg.spawn(move || { - let _ = (&run, &result_ptr); - let run = unsafe { (*(run.0 as *mut Option<F>)).take().unwrap() }; - let result = unsafe { &mut *(result_ptr.0 as *mut Option<R>) }; - *result = Some(run()); - }); - - match thread.unwrap().join() { - Ok(()) => result.unwrap(), - Err(p) => panic::resume_unwind(p), + // 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), } } |
