diff options
| author | bors <bors@rust-lang.org> | 2023-10-24 06:30:10 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-10-24 06:30:10 +0000 |
| commit | cc13d045f42e2cf2359bda28f0273e42488b168d (patch) | |
| tree | 373e61763313b41349bafb994870b8ac5d555c39 /compiler/rustc_data_structures/src/sync/parallel.rs | |
| parent | d32b1583dff13eba9b8e3e79a59fcd8b08b7635f (diff) | |
| parent | ddc76e232aac96d7ca30735aa78d9ea8ae43d721 (diff) | |
| download | rust-cc13d045f42e2cf2359bda28f0273e42488b168d.tar.gz rust-cc13d045f42e2cf2359bda28f0273e42488b168d.zip | |
Auto merge of #3138 - rust-lang:rustup-2023-10-24, r=RalfJung
Automatic Rustup
Diffstat (limited to 'compiler/rustc_data_structures/src/sync/parallel.rs')
| -rw-r--r-- | compiler/rustc_data_structures/src/sync/parallel.rs | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/compiler/rustc_data_structures/src/sync/parallel.rs b/compiler/rustc_data_structures/src/sync/parallel.rs index 1944ddfb710..39dddb59569 100644 --- a/compiler/rustc_data_structures/src/sync/parallel.rs +++ b/compiler/rustc_data_structures/src/sync/parallel.rs @@ -77,6 +77,15 @@ mod disabled { }) } + pub fn try_par_for_each_in<T: IntoIterator, E: Copy>( + t: T, + mut for_each: impl FnMut(T::Item) -> Result<(), E>, + ) -> Result<(), E> { + parallel_guard(|guard| { + t.into_iter().fold(Ok(()), |ret, i| guard.run(|| for_each(i)).unwrap_or(ret).and(ret)) + }) + } + pub fn par_map<T: IntoIterator, R, C: FromIterator<R>>( t: T, mut map: impl FnMut(<<T as IntoIterator>::IntoIter as Iterator>::Item) -> R, @@ -167,6 +176,26 @@ mod enabled { }); } + pub fn try_par_for_each_in< + T: IntoIterator + IntoParallelIterator<Item = <T as IntoIterator>::Item>, + E: Copy + Send, + >( + t: T, + for_each: impl Fn(<T as IntoIterator>::Item) -> Result<(), E> + DynSync + DynSend, + ) -> Result<(), E> { + parallel_guard(|guard| { + if mode::is_dyn_thread_safe() { + let for_each = FromDyn::from(for_each); + t.into_par_iter() + .fold_with(Ok(()), |ret, i| guard.run(|| for_each(i)).unwrap_or(ret).and(ret)) + .reduce(|| Ok(()), |a, b| a.and(b)) + } else { + t.into_iter() + .fold(Ok(()), |ret, i| guard.run(|| for_each(i)).unwrap_or(ret).and(ret)) + } + }) + } + pub fn par_map< I, T: IntoIterator<Item = I> + IntoParallelIterator<Item = I>, |
