(
&self,
input: Vec<A>,
f: F,
)
| 184 | } |
| 185 | |
| 186 | pub(crate) fn run_maybe_parallel< |
| 187 | A: Send, |
| 188 | B: Send, |
| 189 | E: Send, |
| 190 | F: Fn(A) -> Result<B, E> + Send + Sync, |
| 191 | >( |
| 192 | &self, |
| 193 | input: Vec<A>, |
| 194 | f: F, |
| 195 | ) -> Result<Vec<B>, E> { |
| 196 | if self.config().parallel_compilation { |
| 197 | #[cfg(feature = "parallel-compilation")] |
| 198 | { |
| 199 | use rayon::prelude::*; |
| 200 | // If we collect into Result<Vec<B>, E> directly, the returned error is not |
| 201 | // deterministic, because any error could be returned early. So we first materialize |
| 202 | // all results in order and then return the first error deterministically, or Ok(_). |
| 203 | return input |
| 204 | .into_par_iter() |
| 205 | .map(|a| f(a)) |
| 206 | .collect::<Vec<Result<B, E>>>() |
| 207 | .into_iter() |
| 208 | .collect::<Result<Vec<B>, E>>(); |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | // In case the parallel-compilation feature is disabled or the parallel_compilation config |
| 213 | // was turned off dynamically fallback to the non-parallel version. |
| 214 | input |
| 215 | .into_iter() |
| 216 | .map(|a| f(a)) |
| 217 | .collect::<Result<Vec<B>, E>>() |
| 218 | } |
| 219 | |
| 220 | #[cfg(any(feature = "cranelift", feature = "winch"))] |
| 221 | pub(crate) fn run_maybe_parallel_mut< |
no test coverage detected