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

Fix waiting on a query that panicked #115198

Merged
merged 1 commit into from
Aug 26, 2023
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
13 changes: 12 additions & 1 deletion compiler/rustc_query_system/src/query/plumbing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,18 @@ where
match result {
Ok(()) => {
let Some((v, index)) = query.query_cache(qcx).lookup(&key) else {
cold_path(|| panic!("value must be in cache after waiting"))
cold_path(|| {
// We didn't find the query result in the query cache. Check if it was
// poisoned due to a panic instead.
let lock = query.query_state(qcx).active.get_shard_by_value(&key).lock();
match lock.get(&key) {
// The query we waited on panicked. Continue unwinding here.
Some(QueryResult::Poisoned) => FatalError.raise(),
_ => panic!(
"query result must in the cache or the query must be poisoned after a wait"
),
}
Comment on lines +304 to +313
Copy link
Contributor

Choose a reason for hiding this comment

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

The only possible course of action is unwinding. Should we replace the match by an assertion?

Suggested change
// We didn't find the query result in the query cache. Check if it was
// poisoned due to a panic instead.
let lock = query.query_state(qcx).active.get_shard_by_value(&key).lock();
match lock.get(&key) {
// The query we waited on panicked. Continue unwinding here.
Some(QueryResult::Poisoned) => FatalError.raise(),
_ => panic!(
"query result must in the cache or the query must be poisoned after a wait"
),
}
// We didn't find the query result in the query cache. Check if it was
// poisoned due to a panic instead.
debug_assert!(
matches!(
query.query_state(qcx).active.get_shard_by_value(&key).lock().get(&key),
Some(QueryResult::Poisoned),
),
"query result must in the cache or the query must be poisoned after a wait",
);
// The query we waited on panicked. Continue unwinding here.
FatalError.raise()

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 feel like the current version makes it more clear that we should only call FatalError.raise() once we observe the QueryResult::Poisoned case. I don't think I want to downgrade to a debug_assert without some more testing of the parallel compiler. This path is also not terribly hot.

})
};

qcx.dep_context().profiler().query_cache_hit(index.into());
Expand Down
Loading