Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit e35db42

Browse files
lcnrcuviper
authored andcommittedJan 23, 2025
add cache to AmbiguityCausesVisitor
(cherry picked from commit 94bf8f0)
1 parent 953a1a0 commit e35db42

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;
@@ -626,6 +626,7 @@ fn compute_intercrate_ambiguity_causes<'tcx>(
626626
}
627627

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

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

637638
fn visit_goal(&mut self, goal: &InspectGoal<'_, 'tcx>) {
639+
if !self.cache.insert(goal.goal()) {
640+
return;
641+
}
642+
638643
let infcx = goal.infcx();
639644
for cand in goal.candidates() {
640645
cand.visit_nested_in_probe(self);
@@ -759,5 +764,10 @@ fn search_ambiguity_causes<'tcx>(
759764
goal: Goal<'tcx, ty::Predicate<'tcx>>,
760765
causes: &mut FxIndexSet<IntercrateAmbiguityCause<'tcx>>,
761766
) {
762-
infcx.probe(|_| infcx.visit_proof_tree(goal, &mut AmbiguityCausesVisitor { causes }));
767+
infcx.probe(|_| {
768+
infcx.visit_proof_tree(goal, &mut AmbiguityCausesVisitor {
769+
cache: Default::default(),
770+
causes,
771+
})
772+
});
763773
}

0 commit comments

Comments
 (0)
Failed to load comments.