Skip to content

Commit 59babd8

Browse files
committed
add some comments and debug! calls to "obligation forest"
1 parent 761808e commit 59babd8

File tree

1 file changed

+35
-18
lines changed
  • src/librustc_data_structures/obligation_forest

1 file changed

+35
-18
lines changed

src/librustc_data_structures/obligation_forest/mod.rs

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,16 @@ pub trait ObligationProcessor {
4343
obligation: &mut Self::Obligation)
4444
-> Result<Option<Vec<Self::Obligation>>, Self::Error>;
4545

46-
fn process_backedge<'c, I>(&mut self, cycle: I,
46+
/// As we do the cycle check, we invoke this callback when we
47+
/// encounter an actual cycle. `cycle` is an iterator that starts
48+
/// at the start of the cycle in the stack and walks **toward the
49+
/// top**.
50+
///
51+
/// In other words, if we had O1 which required O2 which required
52+
/// O3 which required O1, we would give an iterator yielding O1,
53+
/// O2, O3 (O1 is not yielded twice).
54+
fn process_backedge<'c, I>(&mut self,
55+
cycle: I,
4756
_marker: PhantomData<&'c Self::Obligation>)
4857
where I: Clone + Iterator<Item=&'c Self::Obligation>;
4958
}
@@ -239,8 +248,8 @@ impl<O: ForestObligation> ObligationForest<O> {
239248
}
240249
}
241250
Entry::Vacant(v) => {
242-
debug!("register_obligation_at({:?}, {:?}) - ok",
243-
obligation, parent);
251+
debug!("register_obligation_at({:?}, {:?}) - ok, new index is {}",
252+
obligation, parent, self.nodes.len());
244253
v.insert(NodeIndex::new(self.nodes.len()));
245254
self.cache_list.push(obligation.as_predicate().clone());
246255
self.nodes.push(Node::new(parent, obligation));
@@ -376,6 +385,9 @@ impl<O: ForestObligation> ObligationForest<O> {
376385
where P: ObligationProcessor<Obligation=O>
377386
{
378387
let mut stack = self.scratch.take().unwrap();
388+
debug_assert!(stack.is_empty());
389+
390+
debug!("process_cycles()");
379391

380392
for index in 0..self.nodes.len() {
381393
// For rustc-benchmarks/inflate-0.1.0 this state test is extremely
@@ -389,6 +401,9 @@ impl<O: ForestObligation> ObligationForest<O> {
389401
}
390402
}
391403

404+
debug!("process_cycles: complete");
405+
406+
debug_assert!(stack.is_empty());
392407
self.scratch = Some(stack);
393408
}
394409

@@ -402,21 +417,6 @@ impl<O: ForestObligation> ObligationForest<O> {
402417
NodeState::OnDfsStack => {
403418
let index =
404419
stack.iter().rposition(|n| *n == index).unwrap();
405-
// I need a Clone closure
406-
#[derive(Clone)]
407-
struct GetObligation<'a, O: 'a>(&'a [Node<O>]);
408-
impl<'a, 'b, O> FnOnce<(&'b usize,)> for GetObligation<'a, O> {
409-
type Output = &'a O;
410-
extern "rust-call" fn call_once(self, args: (&'b usize,)) -> &'a O {
411-
&self.0[*args.0].obligation
412-
}
413-
}
414-
impl<'a, 'b, O> FnMut<(&'b usize,)> for GetObligation<'a, O> {
415-
extern "rust-call" fn call_mut(&mut self, args: (&'b usize,)) -> &'a O {
416-
&self.0[*args.0].obligation
417-
}
418-
}
419-
420420
processor.process_backedge(stack[index..].iter().map(GetObligation(&self.nodes)),
421421
PhantomData);
422422
}
@@ -645,3 +645,20 @@ impl<O> Node<O> {
645645
}
646646
}
647647
}
648+
649+
// I need a Clone closure
650+
#[derive(Clone)]
651+
struct GetObligation<'a, O: 'a>(&'a [Node<O>]);
652+
653+
impl<'a, 'b, O> FnOnce<(&'b usize,)> for GetObligation<'a, O> {
654+
type Output = &'a O;
655+
extern "rust-call" fn call_once(self, args: (&'b usize,)) -> &'a O {
656+
&self.0[*args.0].obligation
657+
}
658+
}
659+
660+
impl<'a, 'b, O> FnMut<(&'b usize,)> for GetObligation<'a, O> {
661+
extern "rust-call" fn call_mut(&mut self, args: (&'b usize,)) -> &'a O {
662+
&self.0[*args.0].obligation
663+
}
664+
}

0 commit comments

Comments
 (0)