Skip to content

Commit 882a0b5

Browse files
lcnrcuviper
authored andcommitted
add cache to AmbiguityCausesVisitor
(cherry picked from commit 94bf8f0)
1 parent fed7b2b commit 882a0b5

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

compiler/rustc_trait_selection/src/traits/coherence.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
77
use std::fmt::Debug;
88

9-
use rustc_data_structures::fx::FxIndexSet;
9+
use rustc_data_structures::fx::{FxHashSet, FxIndexSet};
1010
use rustc_errors::{Diag, EmissionGuarantee};
1111
use rustc_hir::def::DefKind;
1212
use rustc_hir::def_id::DefId;
@@ -627,6 +627,7 @@ fn compute_intercrate_ambiguity_causes<'tcx>(
627627
}
628628

629629
struct AmbiguityCausesVisitor<'a, 'tcx> {
630+
cache: FxHashSet<Goal<'tcx, ty::Predicate<'tcx>>>,
630631
causes: &'a mut FxIndexSet<IntercrateAmbiguityCause<'tcx>>,
631632
}
632633

@@ -636,6 +637,10 @@ impl<'a, 'tcx> ProofTreeVisitor<'tcx> for AmbiguityCausesVisitor<'a, 'tcx> {
636637
}
637638

638639
fn visit_goal(&mut self, goal: &InspectGoal<'_, 'tcx>) {
640+
if !self.cache.insert(goal.goal()) {
641+
return;
642+
}
643+
639644
let infcx = goal.infcx();
640645
for cand in goal.candidates() {
641646
cand.visit_nested_in_probe(self);
@@ -760,5 +765,10 @@ fn search_ambiguity_causes<'tcx>(
760765
goal: Goal<'tcx, ty::Predicate<'tcx>>,
761766
causes: &mut FxIndexSet<IntercrateAmbiguityCause<'tcx>>,
762767
) {
763-
infcx.probe(|_| infcx.visit_proof_tree(goal, &mut AmbiguityCausesVisitor { causes }));
768+
infcx.probe(|_| {
769+
infcx.visit_proof_tree(goal, &mut AmbiguityCausesVisitor {
770+
cache: Default::default(),
771+
causes,
772+
})
773+
});
764774
}

0 commit comments

Comments
 (0)