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

Add ParallelGuard type to handle unwinding in parallel sections #115144

Merged
merged 5 commits into from
Aug 30, 2023

Conversation

Zoxc
Copy link
Contributor

@Zoxc Zoxc commented Aug 23, 2023

This adds a ParallelGuard type to handle unwinding in parallel sections instead of manually dealing with panics in each parallel operation. This also adds proper panic handling to the join operation.

cc @SparrowLii

@rustbot
Copy link
Collaborator

rustbot commented Aug 23, 2023

r? @compiler-errors

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 23, 2023
@rust-log-analyzer

This comment has been minimized.

Copy link
Member

@compiler-errors compiler-errors left a comment

Choose a reason for hiding this comment

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

r=me with or without

/// continuing with unwinding. It's also used for the non-parallel code to ensure error message
/// output match the parallel compiler for testing purposes.
pub struct ParallelGuard {
panic: Lock<Option<Box<dyn Any + std::marker::Send + 'static>>>,
Copy link
Member

Choose a reason for hiding this comment

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

Should we implement Drop for ParallelGuard to make sure we never drop a panic on the floor without handling it? unwind will need to get reworked below if so.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I initially went for Drop, but I ended up preferring the explicit unwinding of the unwind calls.

Copy link
Member

@compiler-errors compiler-errors Aug 23, 2023

Choose a reason for hiding this comment

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

I think having the explicit unwind calls is better. I just wonder if we should protect against missing unwind calls somehow... anyways, I don't feel particularly strongly about it.

@compiler-errors
Copy link
Member

@bors delegate+

@bors
Copy link
Contributor

bors commented Aug 23, 2023

✌️ @Zoxc, you can now approve this pull request!

If @compiler-errors told you to "r=me" after making some further change, please make that change, then do @bors r=@compiler-errors

@Zoxc
Copy link
Contributor Author

Zoxc commented Aug 23, 2023

@bors r=@compiler-errors

@bors
Copy link
Contributor

bors commented Aug 23, 2023

📌 Commit d0a3e77e7b4c4c787451780e8abeb3eab4ec4353 has been approved by compiler-errors

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 23, 2023
@Zoxc
Copy link
Contributor Author

Zoxc commented Aug 24, 2023

I've changed to the Lock to Mutex for compatibility with #111713, since Lock no longer use Sync / Send traits and can't be used with Rayon.

@SparrowLii
Copy link
Member

Thanks!

resume_unwind(panic);
}
let guard = ParallelGuard::new();
let r = t.into_iter().filter_map(|i| guard.run(|| map(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.

Wouldn't this non-deterministically pick one of the panics if multiple happen? For FatalErrorMarker that is fine as it is a ZST, but for other panics it may not be.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't see why that would be problematic. No panic would be guaranteed to "win" in a concurrent setting. FatalErrorMarker is the only exception (not technically a panic) that we need to handle.

@Zoxc
Copy link
Contributor Author

Zoxc commented Aug 26, 2023

I've changed this to use a function taking a closure, that way unwinding is guaranteed to be done if needed.

@SparrowLii
Copy link
Member

SparrowLii commented Aug 29, 2023

@Zoxc I think you have to r=reviewer again

@Zoxc
Copy link
Contributor Author

Zoxc commented Aug 29, 2023

I think the changes is significant enough to warrant a re-review.

@rustbot ready

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 29, 2023
@compiler-errors
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Aug 30, 2023

📌 Commit 9074443d3f84d7f7ae5e110f6f92100ddf8c344f has been approved by compiler-errors

It is now in the queue for this repository.

@bors bors removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 30, 2023
@bors
Copy link
Contributor

bors commented Aug 30, 2023

☔ The latest upstream changes (presumably #111713) made this pull request unmergeable. Please resolve the merge conflicts.

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Aug 30, 2023
@Zoxc
Copy link
Contributor Author

Zoxc commented Aug 30, 2023

@bors r=@compiler-errors

@bors
Copy link
Contributor

bors commented Aug 30, 2023

📌 Commit c303c8a has been approved by compiler-errors

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Aug 30, 2023
@bors
Copy link
Contributor

bors commented Aug 30, 2023

⌛ Testing commit c303c8a with merge 59a8294...

@bors
Copy link
Contributor

bors commented Aug 30, 2023

☀️ Test successful - checks-actions
Approved by: compiler-errors
Pushing 59a8294 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Aug 30, 2023
@bors bors merged commit 59a8294 into rust-lang:master Aug 30, 2023
11 checks passed
@rustbot rustbot added this to the 1.74.0 milestone Aug 30, 2023
@Zoxc Zoxc deleted the parallel-guard branch August 30, 2023 21:49
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (59a8294): comparison URL.

Overall result: ✅ improvements - no action needed

@rustbot label: -perf-regression

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.4% [-0.4%, -0.4%] 1
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
0.9% [0.5%, 1.3%] 2
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-1.6% [-2.0%, -1.2%] 2
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -0.3% [-2.0%, 1.3%] 4

Cycles

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.5% [-2.5%, -2.5%] 1
All ❌✅ (primary) - - 0

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 630.996s -> 633.863s (0.45%)
Artifact size: 316.52 MiB -> 316.71 MiB (0.06%)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants