Skip to content

Commit

Permalink
Avoid a track_errors by bubbling up most errors from `check_well_fo…
Browse files Browse the repository at this point in the history
…rmed`
  • Loading branch information
oli-obk committed Oct 17, 2023
1 parent a00c09e commit f61b59e
Show file tree
Hide file tree
Showing 32 changed files with 294 additions and 254 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_data_structures/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub use worker_local::{Registry, WorkerLocal};
mod parallel;
#[cfg(parallel_compiler)]
pub use parallel::scope;
pub use parallel::{join, par_for_each_in, par_map, parallel_guard};
pub use parallel::{join, par_for_each_in, par_map, parallel_guard, try_par_for_each_in};

pub use std::sync::atomic::Ordering;
pub use std::sync::atomic::Ordering::SeqCst;
Expand Down
25 changes: 25 additions & 0 deletions compiler/rustc_data_structures/src/sync/parallel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -167,6 +176,22 @@ mod enabled {
});
}

pub fn try_par_for_each_in<I, T: IntoIterator<Item = I> + IntoParallelIterator<Item = I>, E>(
t: T,
for_each: impl Fn(I) -> 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(Ok(()), |ret, i| guard.run(|| for_each(i)).unwrap_or(ret).and(ret))
} 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>,
Expand Down
Loading

0 comments on commit f61b59e

Please sign in to comment.