about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNicholas Nethercote <nnethercote@mozilla.com>2019-12-09 14:51:59 +1100
committerNicholas Nethercote <nnethercote@mozilla.com>2019-12-13 08:36:25 +1100
commitcb212938d424a94695e35bb92e20613a2af72a0f (patch)
tree0aad08fc2b045636b199dfec5019c725ab4e9043
parent76916d7a4b948119de05135e8d797cf0d40bfd58 (diff)
downloadrust-cb212938d424a94695e35bb92e20613a2af72a0f.tar.gz
rust-cb212938d424a94695e35bb92e20613a2af72a0f.zip
Avoid re-processing nodes in `find_cycles_from_node`.
-rw-r--r--src/librustc_data_structures/obligation_forest/mod.rs12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/librustc_data_structures/obligation_forest/mod.rs b/src/librustc_data_structures/obligation_forest/mod.rs
index 0ee751d33c9..b1931ca459f 100644
--- a/src/librustc_data_structures/obligation_forest/mod.rs
+++ b/src/librustc_data_structures/obligation_forest/mod.rs
@@ -584,7 +584,7 @@ impl<O: ForestObligation> ObligationForest<O> {
             // function call.
             if let NodeState::Success(waiting) = node.state.get() {
                 if !self.is_still_waiting(waiting) {
-                    self.find_cycles_from_node(&mut stack, processor, index);
+                    self.find_cycles_from_node(&mut stack, processor, index, index);
                 }
             }
         }
@@ -592,7 +592,8 @@ impl<O: ForestObligation> ObligationForest<O> {
         debug_assert!(stack.is_empty());
     }
 
-    fn find_cycles_from_node<P>(&self, stack: &mut Vec<usize>, processor: &mut P, index: usize)
+    fn find_cycles_from_node<P>(&self, stack: &mut Vec<usize>, processor: &mut P, min_index: usize,
+                                index: usize)
         where P: ObligationProcessor<Obligation=O>
     {
         let node = &self.nodes[index];
@@ -601,8 +602,11 @@ impl<O: ForestObligation> ObligationForest<O> {
                 match stack.iter().rposition(|&n| n == index) {
                     None => {
                         stack.push(index);
-                        for &index in node.dependents.iter() {
-                            self.find_cycles_from_node(stack, processor, index);
+                        for &dep_index in node.dependents.iter() {
+                            // The index check avoids re-considering a node.
+                            if dep_index >= min_index {
+                                self.find_cycles_from_node(stack, processor, min_index, dep_index);
+                            }
                         }
                         stack.pop();
                     }