Navigation Menu

Skip to content

Commit

Permalink
introduce a stack depth
Browse files Browse the repository at this point in the history
  • Loading branch information
nikomatsakis committed Jun 11, 2019
1 parent db1dfb2 commit e64a7bf
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/librustc/traits/select.rs
Expand Up @@ -185,6 +185,9 @@ struct TraitObligationStack<'prev, 'tcx: 'prev> {
in_cycle: Cell<bool>,

previous: TraitObligationStackList<'prev, 'tcx>,

/// Number of parent frames plus one -- so the topmost frame has depth 1.
depth: usize,
}

#[derive(Clone, Default)]
Expand Down Expand Up @@ -662,8 +665,10 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
obligation: &PredicateObligation<'tcx>,
) -> Result<EvaluationResult, OverflowError> {
self.evaluation_probe(|this| {
this.evaluate_predicate_recursively(TraitObligationStackList::empty(),
obligation.clone())
this.evaluate_predicate_recursively(
TraitObligationStackList::empty(),
obligation.clone(),
)
})
}

Expand Down Expand Up @@ -3743,6 +3748,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
fresh_trait_ref,
in_cycle: Cell::new(false),
previous: previous_stack,
depth: previous_stack.depth() + 1,
}
}

Expand Down Expand Up @@ -3957,6 +3963,14 @@ impl<'o, 'tcx> TraitObligationStackList<'o, 'tcx> {
fn head(&self) -> Option<&'o TraitObligationStack<'o, 'tcx>> {
self.head
}

fn depth(&self) -> usize {
if let Some(head) = self.head {
head.depth
} else {
0
}
}
}

impl<'o, 'tcx> Iterator for TraitObligationStackList<'o, 'tcx> {
Expand Down

0 comments on commit e64a7bf

Please sign in to comment.