Skip to content

Parallel query tweaks #56983

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

Merged
merged 4 commits into from
Dec 25, 2018
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
26 changes: 9 additions & 17 deletions src/librustc/ty/query/job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,12 +290,12 @@ fn cycle_check<'tcx>(query: Lrc<QueryJob<'tcx>>,
stack: &mut Vec<(Span, Lrc<QueryJob<'tcx>>)>,
visited: &mut FxHashSet<*const QueryJob<'tcx>>
) -> Option<Option<Waiter<'tcx>>> {
if visited.contains(&query.as_ptr()) {
if !visited.insert(query.as_ptr()) {
return if let Some(p) = stack.iter().position(|q| q.1.as_ptr() == query.as_ptr()) {
// We detected a query cycle, fix up the initial span and return Some

// Remove previous stack entries
stack.splice(0..p, iter::empty());
stack.drain(0..p);
// Replace the span for the first query with the cycle cause
stack[0].0 = span;
Some(None)
Expand All @@ -304,8 +304,7 @@ fn cycle_check<'tcx>(query: Lrc<QueryJob<'tcx>>,
}
}

// Mark this query is visited and add it to the stack
visited.insert(query.as_ptr());
// Query marked as visited is added it to the stack
stack.push((span, query.clone()));

// Visit all the waiters
Expand All @@ -330,7 +329,7 @@ fn connected_to_root<'tcx>(
visited: &mut FxHashSet<*const QueryJob<'tcx>>
) -> bool {
// We already visited this or we're deliberately ignoring it
if visited.contains(&query.as_ptr()) {
if !visited.insert(query.as_ptr()) {
return false;
}

Expand All @@ -339,8 +338,6 @@ fn connected_to_root<'tcx>(
return true;
}

visited.insert(query.as_ptr());

visit_waiters(query, |_, successor| {
if connected_to_root(successor, visited) {
Some(None)
Expand Down Expand Up @@ -390,11 +387,9 @@ fn remove_cycle<'tcx>(
DUMMY_SP,
&mut stack,
&mut visited) {
// Reverse the stack so earlier entries require later entries
stack.reverse();

// The stack is a vector of pairs of spans and queries
let (mut spans, queries): (Vec<_>, Vec<_>) = stack.into_iter().unzip();
// The stack is a vector of pairs of spans and queries; reverse it so that
// the earlier entries require later entries
let (mut spans, queries): (Vec<_>, Vec<_>) = stack.into_iter().rev().unzip();

// Shift the spans so that queries are matched with the span for their waitee
spans.rotate_right(1);
Expand All @@ -411,7 +406,7 @@ fn remove_cycle<'tcx>(

// Find the queries in the cycle which are
// connected to queries outside the cycle
let entry_points: Vec<_> = stack.iter().filter_map(|(span, query)| {
let entry_points = stack.iter().filter_map(|(span, query)| {
if query.parent.is_none() {
// This query is connected to the root (it has no query parent)
Some((*span, query.clone(), None))
Expand All @@ -436,10 +431,7 @@ fn remove_cycle<'tcx>(
Some((*span, query.clone(), Some(waiter)))
}
}
}).collect();

let entry_points: Vec<(Span, Lrc<QueryJob<'tcx>>, Option<(Span, Lrc<QueryJob<'tcx>>)>)>
= entry_points;
}).collect::<Vec<(Span, Lrc<QueryJob<'tcx>>, Option<(Span, Lrc<QueryJob<'tcx>>)>)>>();

// Deterministically pick an entry point
let (_, entry_point, usage) = pick_query(tcx, &entry_points, |e| (e.0, e.1.clone()));
Expand Down
6 changes: 1 addition & 5 deletions src/librustc/ty/query/on_disk_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,11 +398,7 @@ impl<'sess> OnDiskCache<'sess> {
-> Option<T>
where T: Decodable
{
let pos = if let Some(&pos) = index.get(&dep_node_index) {
pos
} else {
return None
};
let pos = index.get(&dep_node_index).cloned()?;

// Initialize the cnum_map using the value from the thread which finishes the closure first
self.cnum_map.init_nonlocking_same(|| {
Expand Down