From fd9ef69adf631a96ffad2d777653ae2554909866 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Wed, 18 Oct 2023 08:47:17 +0000 Subject: Avoid a `track_errors` by bubbling up most errors from `check_well_formed` --- .../rustc_data_structures/src/sync/parallel.rs | 29 ++++++++++++++++++++++ 1 file changed, 29 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 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: 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: T, mut map: impl FnMut(<::IntoIter as Iterator>::Item) -> R, @@ -167,6 +176,26 @@ mod enabled { }); } + pub fn try_par_for_each_in< + T: IntoIterator + IntoParallelIterator::Item>, + E: Copy + Send, + >( + t: T, + for_each: impl Fn(::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 + IntoParallelIterator, -- cgit 1.4.1-3-g733a5