提交 2f3ddd9f 编写于 作者: B bors

Auto merge of #97307 - SparrowLii:parallel, r=cjgillot

catch unwind in parallel mode during wfcheck

Update #75760
When performing wfcheck, from the test results, the parallel mode will stop all checks when an `item`'s check failed, (e.g. the first ui test failure raised from [here](https://github.com/rust-lang/rust/blob/master/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs#L249))while the serial mode will output each `item`'s check result via `catch_unwind`. This leads to inconsistencies in the final output of the two mode.
In my local environment, this modification prevents the following ui tests from failing when set `parallel-compiler = true` in `config.toml`:

```
    [ui] src/test\ui\associated-types\defaults-cyclic-fail-1.rs
    [ui] src/test\ui\associated-types\defaults-cyclic-fail-2.rs
    [ui] src/test\ui\associated-types\hr-associated-type-bound-2.rs
    [ui] src/test\ui\associated-types\impl-wf-cycle-1.rs
    [ui] src/test\ui\associated-types\impl-wf-cycle-2.rs
    [ui] src/test\ui\issues\issue-20413.rs
    [ui] src/test\ui\parallel_test\defaults-cyclic-fail-para.rs
```
......@@ -21,6 +21,7 @@
use std::collections::HashMap;
use std::hash::{BuildHasher, Hash};
use std::ops::{Deref, DerefMut};
use std::panic::{catch_unwind, resume_unwind, AssertUnwindSafe};
pub use std::sync::atomic::Ordering;
pub use std::sync::atomic::Ordering::SeqCst;
......@@ -41,7 +42,6 @@ impl<T: ?Sized> Sync for T {}
}
use std::ops::Add;
use std::panic::{resume_unwind, catch_unwind, AssertUnwindSafe};
/// This is a single threaded variant of `AtomicU64`, `AtomicUsize`, etc.
/// It has explicit ordering arguments and is only intended for use with
......@@ -339,7 +339,10 @@ pub fn par_for_each_in<T: IntoParallelIterator>(
t: T,
for_each: impl Fn(T::Item) + Sync + Send,
) {
t.into_par_iter().for_each(for_each)
let ps: Vec<_> = t.into_par_iter().map(|i| catch_unwind(AssertUnwindSafe(|| for_each(i)))).collect();
ps.into_iter().for_each(|p| if let Err(panic) = p {
resume_unwind(panic)
});
}
pub type MetadataRef = OwningRef<Box<dyn Erased + Send + Sync>, [u8]>;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册