Drop AST on a separate thread and prefetch hir_crate

This commit is contained in:
John Kåre Alsaker
2024-03-02 18:32:42 +01:00
parent efcbb94dcc
commit ef9403371f
4 changed files with 26 additions and 3 deletions

View File

@@ -43,7 +43,7 @@ pub use self::freeze::{FreezeLock, FreezeReadGuard, FreezeWriteGuard};
pub use self::lock::{Lock, LockGuard, Mode};
pub use self::mode::{is_dyn_thread_safe, set_dyn_thread_safe_mode};
pub use self::parallel::{
join, par_for_each_in, par_map, parallel_guard, scope, try_par_for_each_in,
join, par_for_each_in, par_map, parallel_guard, scope, spawn, try_par_for_each_in,
};
pub use self::vec::{AppendOnlyIndexVec, AppendOnlyVec};
pub use self::worker_local::{Registry, WorkerLocal};

View File

@@ -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