]> git.lizzy.rs Git - rust.git/commitdiff
query: insert visited queries more eagerly
authorljedrz <ljedrz@gmail.com>
Wed, 19 Dec 2018 12:14:03 +0000 (13:14 +0100)
committerljedrz <ljedrz@gmail.com>
Wed, 19 Dec 2018 14:15:04 +0000 (15:15 +0100)
src/librustc/ty/query/job.rs

index 2e6cd8e0ec3d90ba79008218484c13bcae50cf56..559093b8f1893266aa599de54a80e2ad742cf66f 100644 (file)
@@ -290,7 +290,7 @@ 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
 
@@ -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
@@ -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;
     }
 
@@ -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)