Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

catch unwind in parallel mode during wfcheck #97307

Merged
merged 1 commit into from
Jun 27, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions compiler/rustc_data_structures/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use crate::owning_ref::{Erased, OwningRef};
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;
Expand All @@ -41,7 +42,6 @@ cfg_if! {
}

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
Expand Down Expand Up @@ -339,7 +339,10 @@ cfg_if! {
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();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does rayon support .collect::<Result<Vec<()>, Box<dyn Any + Send>>()? That would be faster than iterating over all elements to check if any is Err I think.

Copy link
Member Author

@SparrowLii SparrowLii May 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We indeed need to iterate over all elements, not just know if any of them is Err. Because the err message will be output during the iteration. This is relatively consistent with the behavior in serial mode.

ps.into_iter().for_each(|p| if let Err(panic) = p {
resume_unwind(panic)
});
}

pub type MetadataRef = OwningRef<Box<dyn Erased + Send + Sync>, [u8]>;
Expand Down