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

print query map for deadlock when using parallel front end #118169

Merged
merged 2 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
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
16 changes: 11 additions & 5 deletions compiler/rustc_query_system/src/query/job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub struct QueryInfo {
pub type QueryMap = FxHashMap<QueryJobId, QueryJobInfo>;

/// A value uniquely identifying an active query job.
#[derive(Copy, Clone, Eq, PartialEq, Hash)]
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub struct QueryJobId(pub NonZeroU64);

impl QueryJobId {
Expand All @@ -62,14 +62,14 @@ impl QueryJobId {
}
}

#[derive(Clone)]
#[derive(Clone, Debug)]
pub struct QueryJobInfo {
pub query: QueryStackFrame,
pub job: QueryJob,
}

/// Represents an active query job.
#[derive(Clone)]
#[derive(Clone, Debug)]
pub struct QueryJob {
pub id: QueryJobId,

Expand Down Expand Up @@ -182,6 +182,7 @@ impl QueryJobId {
}

#[cfg(parallel_compiler)]
#[derive(Debug)]
struct QueryWaiter {
query: Option<QueryJobId>,
condvar: Condvar,
Expand All @@ -198,13 +199,14 @@ impl QueryWaiter {
}

#[cfg(parallel_compiler)]
#[derive(Debug)]
struct QueryLatchInfo {
complete: bool,
waiters: Vec<Arc<QueryWaiter>>,
}

#[cfg(parallel_compiler)]
#[derive(Clone)]
#[derive(Clone, Debug)]
pub(super) struct QueryLatch {
info: Arc<Mutex<QueryLatchInfo>>,
}
Expand Down Expand Up @@ -540,7 +542,11 @@ pub fn deadlock(query_map: QueryMap, registry: &rayon_core::Registry) {
// X to Y due to Rayon waiting and a true dependency from Y to X. The algorithm here
// only considers the true dependency and won't detect a cycle.
if !found_cycle {
panic!("deadlock detected");
if query_map.len() == 0 {
panic!("deadlock detected without any query!")
} else {
panic!("deadlock detected! current query map:\n{:#?}", query_map);
}
}

// FIXME: Ensure this won't cause a deadlock before we return
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_query_system/src/query/plumbing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ where
}
}

#[derive(Clone)]
#[derive(Clone, Debug)]
pub(crate) struct CycleError {
/// The query and related span that uses the cycle.
pub usage: Option<(Span, QueryStackFrame)>,
Expand Down