-
-
Notifications
You must be signed in to change notification settings - Fork 14.5k
Remove deterministic picking from query cycle handling #152229
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
Open
Zoxc
wants to merge
1
commit into
rust-lang:main
Choose a base branch
from
Zoxc:rem-det-pick
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+34
−65
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -377,27 +377,6 @@ fn connected_to_root<'tcx>( | |||||
| .is_some() | ||||||
| } | ||||||
|
|
||||||
| // Deterministically pick an query from a list | ||||||
| fn pick_query<'a, 'tcx, T, F>(query_map: &QueryMap<'tcx>, queries: &'a [T], f: F) -> &'a T | ||||||
| where | ||||||
| F: Fn(&T) -> (Span, QueryJobId), | ||||||
| { | ||||||
| // Deterministically pick an entry point | ||||||
| // FIXME: Sort this instead | ||||||
| queries | ||||||
| .iter() | ||||||
| .min_by_key(|v| { | ||||||
| let (span, query) = f(v); | ||||||
| let hash = query.frame(query_map).hash; | ||||||
| // Prefer entry points which have valid spans for nicer error messages | ||||||
| // We add an integer to the tuple ensuring that entry points | ||||||
| // with valid spans are picked first | ||||||
| let span_cmp = if span == DUMMY_SP { 1 } else { 0 }; | ||||||
| (span_cmp, hash) | ||||||
| }) | ||||||
| .unwrap() | ||||||
| } | ||||||
|
|
||||||
| /// Looks for query cycles starting from the last query in `jobs`. | ||||||
| /// If a cycle is found, all queries in the cycle is removed from `jobs` and | ||||||
| /// the function return true. | ||||||
|
|
@@ -431,48 +410,58 @@ fn remove_cycle<'tcx>( | |||||
| } | ||||||
| } | ||||||
|
|
||||||
| struct EntryPoint { | ||||||
| query_in_cycle: QueryJobId, | ||||||
| waiter: Option<(Span, QueryJobId)>, | ||||||
| } | ||||||
|
|
||||||
| // Find the queries in the cycle which are | ||||||
| // connected to queries outside the cycle | ||||||
| let entry_points = stack | ||||||
| .iter() | ||||||
| .filter_map(|&(span, query)| { | ||||||
| if query.parent(query_map).is_none() { | ||||||
| .filter_map(|&(_, query_in_cycle)| { | ||||||
| if query_in_cycle.parent(query_map).is_none() { | ||||||
| // This query is connected to the root (it has no query parent) | ||||||
| Some((span, query, None)) | ||||||
|
|
||||||
| Some(EntryPoint { query_in_cycle, waiter: None }) | ||||||
| } else { | ||||||
| let mut waiters = Vec::new(); | ||||||
| // Find all the direct waiters who lead to the root | ||||||
| visit_waiters(query_map, query, |span, waiter| { | ||||||
| let mut waiter_on_cycle = None; | ||||||
| // Find a direct waiter who leads to the root | ||||||
| visit_waiters(query_map, query_in_cycle, |span, waiter| { | ||||||
| // Mark all the other queries in the cycle as already visited | ||||||
| let mut visited = FxHashSet::from_iter(stack.iter().map(|q| q.1)); | ||||||
|
|
||||||
| if connected_to_root(query_map, waiter, &mut visited) { | ||||||
| waiters.push((span, waiter)); | ||||||
| waiter_on_cycle = Some((span, waiter)); | ||||||
| Some(None) | ||||||
| } else { | ||||||
| None | ||||||
| } | ||||||
|
|
||||||
| None | ||||||
| }); | ||||||
| if waiters.is_empty() { | ||||||
| None | ||||||
| } else { | ||||||
| // Deterministically pick one of the waiters to show to the user | ||||||
| let waiter = *pick_query(query_map, &waiters, |s| *s); | ||||||
| Some((span, query, Some(waiter))) | ||||||
| } | ||||||
|
|
||||||
| waiter_on_cycle.map(|waiter_on_cycle| EntryPoint { | ||||||
| query_in_cycle, | ||||||
| waiter: Some(waiter_on_cycle), | ||||||
| }) | ||||||
| } | ||||||
| }) | ||||||
| .collect::<Vec<(Span, QueryJobId, Option<(Span, QueryJobId)>)>>(); | ||||||
| .collect::<Vec<EntryPoint>>(); | ||||||
|
|
||||||
| // Deterministically pick an entry point | ||||||
| let (_, entry_point, usage) = pick_query(query_map, &entry_points, |e| (e.0, e.1)); | ||||||
| // Pick an entry point, preferring ones with waiters | ||||||
| let entry_point = entry_points | ||||||
| .iter() | ||||||
| .find(|entry_point| entry_point.waiter.is_some()) | ||||||
| .unwrap_or(entry_points.first().unwrap()); | ||||||
|
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
|
||||||
|
|
||||||
| // Shift the stack so that our entry point is first | ||||||
| let entry_point_pos = stack.iter().position(|(_, query)| query == entry_point); | ||||||
| let entry_point_pos = | ||||||
| stack.iter().position(|(_, query)| *query == entry_point.query_in_cycle); | ||||||
| if let Some(pos) = entry_point_pos { | ||||||
| stack.rotate_left(pos); | ||||||
| } | ||||||
|
|
||||||
| let usage = usage.as_ref().map(|(span, query)| (*span, query.frame(query_map))); | ||||||
| let usage = | ||||||
| entry_point.waiter.as_ref().map(|(span, query)| (*span, query.frame(query_map))); | ||||||
|
|
||||||
| // Create the cycle error | ||||||
| let error = CycleError { | ||||||
|
|
||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Nit: stray empty line.