diff options
| author | lcnr <rust@lcnr.de> | 2025-01-17 10:01:45 +0100 |
|---|---|---|
| committer | Josh Stone <jistone@redhat.com> | 2025-01-23 08:45:25 -0800 |
| commit | e35db4245bf73e30a7b6883c9333db24ff87e34d (patch) | |
| tree | 8575e3c73f6fd8d98e8f4d4fa73dd67d11d009b6 | |
| parent | 953a1a0031a5277cdb6e2776ab48c6773c3ded07 (diff) | |
| download | rust-e35db4245bf73e30a7b6883c9333db24ff87e34d.tar.gz rust-e35db4245bf73e30a7b6883c9333db24ff87e34d.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 190e34618d2..e27143f1396 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; @@ -626,6 +626,7 @@ fn compute_intercrate_ambiguity_causes<'tcx>( } struct AmbiguityCausesVisitor<'a, 'tcx> { + cache: FxHashSet<Goal<'tcx, ty::Predicate<'tcx>>>, causes: &'a mut FxIndexSet<IntercrateAmbiguityCause<'tcx>>, } @@ -635,6 +636,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); @@ -759,5 +764,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, + }) + }); } |
