Skip to content

Commit c86f948

Browse files
committed
introduce ProvisionalEvaluationCache
1 parent 35f5ef6 commit c86f948

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

src/librustc/traits/select.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,8 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
606606
debug!("select({:?})", obligation);
607607
debug_assert!(!obligation.predicate.has_escaping_bound_vars());
608608

609-
let stack = self.push_stack(TraitObligationStackList::empty(), obligation);
609+
let pec = &ProvisionalEvaluationCache::default();
610+
let stack = self.push_stack(TraitObligationStackList::empty(pec), obligation);
610611

611612
let candidate = match self.candidate_from_obligation(&stack) {
612613
Err(SelectionError::Overflow) => {
@@ -666,7 +667,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
666667
) -> Result<EvaluationResult, OverflowError> {
667668
self.evaluation_probe(|this| {
668669
this.evaluate_predicate_recursively(
669-
TraitObligationStackList::empty(),
670+
TraitObligationStackList::empty(&ProvisionalEvaluationCache::default()),
670671
obligation.clone(),
671672
)
672673
})
@@ -3968,6 +3969,10 @@ impl<'o, 'tcx> TraitObligationStack<'o, 'tcx> {
39683969
TraitObligationStackList::with(self)
39693970
}
39703971

3972+
fn cache(&self) -> &'o ProvisionalEvaluationCache<'tcx> {
3973+
self.previous.cache
3974+
}
3975+
39713976
fn iter(&'o self) -> TraitObligationStackList<'o, 'tcx> {
39723977
self.list()
39733978
}
@@ -3992,18 +3997,24 @@ impl<'o, 'tcx> TraitObligationStack<'o, 'tcx> {
39923997
}
39933998
}
39943999

4000+
#[derive(Default)]
4001+
struct ProvisionalEvaluationCache<'tcx> {
4002+
_dummy: Vec<&'tcx ()>,
4003+
}
4004+
39954005
#[derive(Copy, Clone)]
39964006
struct TraitObligationStackList<'o, 'tcx: 'o> {
4007+
cache: &'o ProvisionalEvaluationCache<'tcx>,
39974008
head: Option<&'o TraitObligationStack<'o, 'tcx>>,
39984009
}
39994010

40004011
impl<'o, 'tcx> TraitObligationStackList<'o, 'tcx> {
4001-
fn empty() -> TraitObligationStackList<'o, 'tcx> {
4002-
TraitObligationStackList { head: None }
4012+
fn empty(cache: &'o ProvisionalEvaluationCache<'tcx>) -> TraitObligationStackList<'o, 'tcx> {
4013+
TraitObligationStackList { cache, head: None }
40034014
}
40044015

40054016
fn with(r: &'o TraitObligationStack<'o, 'tcx>) -> TraitObligationStackList<'o, 'tcx> {
4006-
TraitObligationStackList { head: Some(r) }
4017+
TraitObligationStackList { cache: r.cache(), head: Some(r) }
40074018
}
40084019

40094020
fn head(&self) -> Option<&'o TraitObligationStack<'o, 'tcx>> {

0 commit comments

Comments
 (0)