-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
Add coherency check for query cycle breaking #153953
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -54,13 +54,12 @@ pub(crate) struct QueryJobInfo<'tcx> { | |
|
|
||
| pub(crate) fn find_cycle_in_stack<'tcx>( | ||
| id: QueryJobId, | ||
| job_map: QueryJobMap<'tcx>, | ||
| current_job: &Option<QueryJobId>, | ||
| job_map: &QueryJobMap<'tcx>, | ||
| mut current_job: Option<QueryJobId>, | ||
| span: Span, | ||
| ) -> CycleError<'tcx> { | ||
| ) -> Option<CycleError<'tcx>> { | ||
| // Find the waitee amongst `current_job` parents | ||
| let mut cycle = Vec::new(); | ||
| let mut current_job = Option::clone(current_job); | ||
|
|
||
| while let Some(job) = current_job { | ||
| let info = &job_map.map[&job]; | ||
|
|
@@ -79,13 +78,13 @@ pub(crate) fn find_cycle_in_stack<'tcx>( | |
| let parent = info.job.parent?; | ||
| respan(info.job.span, job_map.frame_of(parent).clone()) | ||
| }; | ||
| return CycleError { usage, cycle }; | ||
| return Some(CycleError { usage, cycle }); | ||
| } | ||
|
|
||
| current_job = info.job.parent; | ||
| } | ||
|
|
||
| panic!("did not find a cycle") | ||
| None | ||
| } | ||
|
|
||
| /// Finds the job closest to the root with a `DepKind` matching the `DepKind` of `id` and returns | ||
|
|
@@ -324,6 +323,21 @@ fn remove_cycle<'tcx>( | |
| .collect(), | ||
| }; | ||
|
|
||
| if cfg!(debug_assertions) | ||
| && let Some(query_waiting_on_cycle) = entry_point.query_waiting_on_cycle | ||
| && let Some(expected) = find_cycle_in_stack( | ||
| query_waiting_on_cycle.1, | ||
| job_map, | ||
| stack.last().map(|&(_, job)| job), | ||
| query_waiting_on_cycle.0, | ||
| ) | ||
| { | ||
| if error != expected { | ||
| panic!( | ||
| "CycleError coherency check failed:\n expected: {expected:#?}\n got: {error:#?}" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of "expected" and "got", would it be better to indicate the single-threaded result and the multi-threaded result? It's conceivable that the single-threaded one might be wrong.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, does "coherency" have a particular meaning. It makes me think of trait coherency, which is unrelated. "Consistency" might be better, it doesn't have a Rust-specific meaning, e.g. "inconsistent query cycle detection: ...". |
||
| ); | ||
| } | ||
| } | ||
| // We unwrap `resumable` here since there must always be one | ||
| // edge which is resumable / waited using a query latch | ||
| let (waitee_query, waiter_idx) = resumable.unwrap(); | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -14,7 +14,7 @@ use rustc_data_structures::sync::Lock; | |||||
| use rustc_macros::{Decodable, Encodable, HashStable_Generic, symbols}; | ||||||
|
|
||||||
| use crate::edit_distance::find_best_match_for_name; | ||||||
| use crate::{DUMMY_SP, Edition, Span, with_session_globals}; | ||||||
| use crate::{DUMMY_SP, Edition, Span, are_session_globals_set, with_session_globals}; | ||||||
|
|
||||||
| #[cfg(test)] | ||||||
| mod tests; | ||||||
|
|
@@ -2545,6 +2545,10 @@ impl Symbol { | |||||
| }) | ||||||
| } | ||||||
|
|
||||||
| pub fn opt_as_str(&self) -> Option<&str> { | ||||||
| are_session_globals_set().then(|| self.as_str()) | ||||||
| } | ||||||
|
|
||||||
| pub fn as_u32(self) -> u32 { | ||||||
| self.0.as_u32() | ||||||
| } | ||||||
|
|
@@ -2586,13 +2590,21 @@ impl Symbol { | |||||
|
|
||||||
| impl fmt::Debug for Symbol { | ||||||
| fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||||||
| fmt::Debug::fmt(self.as_str(), f) | ||||||
| if let Some(s) = self.opt_as_str() { | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Together with a comment #153953 (comment) explaining why it's acceptable. |
||||||
| fmt::Debug::fmt(s, f) | ||||||
| } else { | ||||||
| fmt::Debug::fmt(&self.0, f) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will just print a number, e.g.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Symbols should never be used in contexts in which this path can be triggered, it's better to continue panicking here.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
That thread doesn't have anything answering my question.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This context is the cycle detection thread
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you add a comment explaining this use? |
||||||
| } | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| impl fmt::Display for Symbol { | ||||||
| fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||||||
| fmt::Display::fmt(self.as_str(), f) | ||||||
| if let Some(s) = self.opt_as_str() { | ||||||
| fmt::Display::fmt(s, f) | ||||||
| } else { | ||||||
| fmt::Debug::fmt(&self.0, f) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here. |
||||||
| } | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are no added comments in this commit. An explanatory comment here would be useful. Something like "compare the single-threaded cycle detection against the multi-threaded cycle detection".