From ef9403371f2d4759cd7b0d0a276e63aae2ce68fe Mon Sep 17 00:00:00 2001 From: John Kåre Alsaker Date: Sat, 2 Mar 2024 18:32:42 +0100 Subject: Drop AST on a separate thread and prefetch `hir_crate` --- compiler/rustc_data_structures/src/sync/parallel.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'compiler/rustc_data_structures/src/sync/parallel.rs') diff --git a/compiler/rustc_data_structures/src/sync/parallel.rs b/compiler/rustc_data_structures/src/sync/parallel.rs index ba3c85ef5b1..64db39cc4c6 100644 --- a/compiler/rustc_data_structures/src/sync/parallel.rs +++ b/compiler/rustc_data_structures/src/sync/parallel.rs @@ -93,6 +93,17 @@ macro_rules! parallel { }; } +pub fn spawn(func: impl FnOnce() + DynSend + 'static) { + if mode::is_dyn_thread_safe() { + let func = FromDyn::from(func); + rayon_core::spawn(|| { + (func.into_inner())(); + }); + } else { + func() + } +} + // This function only works when `mode::is_dyn_thread_safe()`. pub fn scope<'scope, OP, R>(op: OP) -> R where -- cgit 1.4.1-3-g733a5