diff options
| author | lcnr <rust@lcnr.de> | 2025-01-17 10:01:45 +0100 |
|---|---|---|
| committer | Josh Stone <jistone@redhat.com> | 2025-01-23 11:48:40 -0800 |
| commit | 882a0b520866020bf2830fce0b63291b29bb8d3a (patch) | |
| tree | 1dbd1a2e647214fc53ae75393b9ea4dbbc319607 | |
| parent | fed7b2b17103f02b9e56a88552ba0490063fd32c (diff) | |
| download | rust-882a0b520866020bf2830fce0b63291b29bb8d3a.tar.gz rust-882a0b520866020bf2830fce0b63291b29bb8d3a.zip | |
add cache to `AmbiguityCausesVisitor`
(cherry picked from commit 94bf8f04f402a2410ab85a6e6b9e542e3942b2a2)
| -rw-r--r-- | compiler/rustc_trait_selection/src/traits/coherence.rs | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/compiler/rustc_trait_selection/src/traits/coherence.rs b/compiler/rustc_trait_selection/src/traits/coherence.rs index 2e4fd10a330..d59f408b806 100644 --- a/compiler/rustc_trait_selection/src/traits/coherence.rs +++ b/compiler/rustc_trait_selection/src/traits/coherence.rs @@ -6,7 +6,7 @@ use std::fmt::Debug; -use rustc_data_structures::fx::FxIndexSet; +use rustc_data_structures::fx::{FxHashSet, FxIndexSet}; use rustc_errors::{Diag, EmissionGuarantee}; use rustc_hir::def::DefKind; use rustc_hir::def_id::DefId; @@ -627,6 +627,7 @@ fn compute_intercrate_ambiguity_causes<'tcx>( } struct AmbiguityCausesVisitor<'a, 'tcx> { + cache: FxHashSet<Goal<'tcx, ty::Predicate<'tcx>>>, causes: &'a mut FxIndexSet<IntercrateAmbiguityCause<'tcx>>, } @@ -636,6 +637,10 @@ impl<'a, 'tcx> ProofTreeVisitor<'tcx> for AmbiguityCausesVisitor<'a, 'tcx> { } fn visit_goal(&mut self, goal: &InspectGoal<'_, 'tcx>) { + if !self.cache.insert(goal.goal()) { + return; + } + let infcx = goal.infcx(); for cand in goal.candidates() { cand.visit_nested_in_probe(self); @@ -760,5 +765,10 @@ fn search_ambiguity_causes<'tcx>( goal: Goal<'tcx, ty::Predicate<'tcx>>, causes: &mut FxIndexSet<IntercrateAmbiguityCause<'tcx>>, ) { - infcx.probe(|_| infcx.visit_proof_tree(goal, &mut AmbiguityCausesVisitor { causes })); + infcx.probe(|_| { + infcx.visit_proof_tree(goal, &mut AmbiguityCausesVisitor { + cache: Default::default(), + causes, + }) + }); } |
