Skip to content

Commit 7d55044

Browse files
committed
Move functions around.
In particular, it has bugged me for some time that `process_cycles` is currently located before `mark_still_waiting_nodes` despite being called afterwards.
1 parent a8207b1 commit 7d55044

File tree

1 file changed

+59
-59
lines changed
  • src/librustc_data_structures/obligation_forest

1 file changed

+59
-59
lines changed

src/librustc_data_structures/obligation_forest/mod.rs

+59-59
Original file line numberDiff line numberDiff line change
@@ -520,57 +520,6 @@ impl<O: ForestObligation> ObligationForest<O> {
520520
}
521521
}
522522

523-
/// Report cycles between all `Success` nodes that aren't still waiting.
524-
/// This must be called after `mark_still_waiting_nodes`.
525-
fn process_cycles<P>(&self, processor: &mut P)
526-
where P: ObligationProcessor<Obligation=O>
527-
{
528-
let mut stack = vec![];
529-
530-
debug!("process_cycles()");
531-
532-
for (index, node) in self.nodes.iter().enumerate() {
533-
// For some benchmarks this state test is extremely hot. It's a win
534-
// to handle the no-op cases immediately to avoid the cost of the
535-
// function call.
536-
if let NodeState::Success(waiting) = node.state.get() {
537-
if !self.is_still_waiting(waiting) {
538-
self.find_cycles_from_node(&mut stack, processor, index);
539-
}
540-
}
541-
}
542-
543-
debug!("process_cycles: complete");
544-
545-
debug_assert!(stack.is_empty());
546-
}
547-
548-
fn find_cycles_from_node<P>(&self, stack: &mut Vec<usize>, processor: &mut P, index: usize)
549-
where P: ObligationProcessor<Obligation=O>
550-
{
551-
let node = &self.nodes[index];
552-
if let NodeState::Success(waiting) = node.state.get() {
553-
if !self.is_still_waiting(waiting) {
554-
match stack.iter().rposition(|&n| n == index) {
555-
None => {
556-
stack.push(index);
557-
for &index in node.dependents.iter() {
558-
self.find_cycles_from_node(stack, processor, index);
559-
}
560-
stack.pop();
561-
}
562-
Some(rpos) => {
563-
// Cycle detected.
564-
processor.process_backedge(
565-
stack[rpos..].iter().map(GetObligation(&self.nodes)),
566-
PhantomData
567-
);
568-
}
569-
}
570-
}
571-
}
572-
}
573-
574523
/// Returns a vector of obligations for `p` and all of its
575524
/// ancestors, putting them into the error state in the process.
576525
fn error_at(&self, mut index: usize) -> Vec<O> {
@@ -604,6 +553,18 @@ impl<O: ForestObligation> ObligationForest<O> {
604553
trace
605554
}
606555

556+
/// Mark all `Success` nodes that depend on a pending node as still
557+
/// waiting. Upon completion, any `Success` nodes that aren't still waiting
558+
/// can be removed by `compress`.
559+
fn mark_still_waiting_nodes(&self) {
560+
for node in &self.nodes {
561+
if node.state.get() == NodeState::Pending {
562+
// This call site is hot.
563+
self.inlined_mark_dependents_as_still_waiting(node);
564+
}
565+
}
566+
}
567+
607568
// This always-inlined function is for the hot call site.
608569
#[inline(always)]
609570
fn inlined_mark_dependents_as_still_waiting(&self, node: &Node<O>) {
@@ -625,14 +586,53 @@ impl<O: ForestObligation> ObligationForest<O> {
625586
self.inlined_mark_dependents_as_still_waiting(node)
626587
}
627588

628-
/// Mark all `Success` nodes that depend on a pending node as still
629-
/// waiting. Upon completion, any `Success` nodes that aren't still waiting
630-
/// can be removed by `compress`.
631-
fn mark_still_waiting_nodes(&self) {
632-
for node in &self.nodes {
633-
if node.state.get() == NodeState::Pending {
634-
// This call site is hot.
635-
self.inlined_mark_dependents_as_still_waiting(node);
589+
/// Report cycles between all `Success` nodes that aren't still waiting.
590+
/// This must be called after `mark_still_waiting_nodes`.
591+
fn process_cycles<P>(&self, processor: &mut P)
592+
where P: ObligationProcessor<Obligation=O>
593+
{
594+
let mut stack = vec![];
595+
596+
debug!("process_cycles()");
597+
598+
for (index, node) in self.nodes.iter().enumerate() {
599+
// For some benchmarks this state test is extremely hot. It's a win
600+
// to handle the no-op cases immediately to avoid the cost of the
601+
// function call.
602+
if let NodeState::Success(waiting) = node.state.get() {
603+
if !self.is_still_waiting(waiting) {
604+
self.find_cycles_from_node(&mut stack, processor, index);
605+
}
606+
}
607+
}
608+
609+
debug!("process_cycles: complete");
610+
611+
debug_assert!(stack.is_empty());
612+
}
613+
614+
fn find_cycles_from_node<P>(&self, stack: &mut Vec<usize>, processor: &mut P, index: usize)
615+
where P: ObligationProcessor<Obligation=O>
616+
{
617+
let node = &self.nodes[index];
618+
if let NodeState::Success(waiting) = node.state.get() {
619+
if !self.is_still_waiting(waiting) {
620+
match stack.iter().rposition(|&n| n == index) {
621+
None => {
622+
stack.push(index);
623+
for &index in node.dependents.iter() {
624+
self.find_cycles_from_node(stack, processor, index);
625+
}
626+
stack.pop();
627+
}
628+
Some(rpos) => {
629+
// Cycle detected.
630+
processor.process_backedge(
631+
stack[rpos..].iter().map(GetObligation(&self.nodes)),
632+
PhantomData
633+
);
634+
}
635+
}
636636
}
637637
}
638638
}

0 commit comments

Comments
 (0)