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 f3e5a95

Browse files
committedAug 9, 2024
Auto merge of #128828 - lcnr:search-graph-11, r=<try>
[try-me] `-Znext-solver` caching try-job: x86_64-fuchsia r? `@compiler-errors`
2 parents 97e7252 + ad501b4 commit f3e5a95

File tree

13 files changed

+729
-600
lines changed

13 files changed

+729
-600
lines changed
 

‎compiler/rustc_middle/src/arena.rs

-4
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,6 @@ macro_rules! arena_types {
6161
[] dtorck_constraint: rustc_middle::traits::query::DropckConstraint<'tcx>,
6262
[] candidate_step: rustc_middle::traits::query::CandidateStep<'tcx>,
6363
[] autoderef_bad_ty: rustc_middle::traits::query::MethodAutoderefBadTy<'tcx>,
64-
[] canonical_goal_evaluation:
65-
rustc_type_ir::solve::inspect::CanonicalGoalEvaluationStep<
66-
rustc_middle::ty::TyCtxt<'tcx>
67-
>,
6864
[] query_region_constraints: rustc_middle::infer::canonical::QueryRegionConstraints<'tcx>,
6965
[] type_op_subtype:
7066
rustc_middle::infer::canonical::Canonical<'tcx,

‎compiler/rustc_middle/src/ty/context.rs

-9
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,6 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
107107
self.mk_predefined_opaques_in_body(data)
108108
}
109109
type DefiningOpaqueTypes = &'tcx ty::List<LocalDefId>;
110-
type CanonicalGoalEvaluationStepRef =
111-
&'tcx solve::inspect::CanonicalGoalEvaluationStep<TyCtxt<'tcx>>;
112110
type CanonicalVars = CanonicalVarInfos<'tcx>;
113111
fn mk_canonical_var_infos(self, infos: &[ty::CanonicalVarInfo<Self>]) -> Self::CanonicalVars {
114112
self.mk_canonical_var_infos(infos)
@@ -277,13 +275,6 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
277275
self.debug_assert_args_compatible(def_id, args);
278276
}
279277

280-
fn intern_canonical_goal_evaluation_step(
281-
self,
282-
step: solve::inspect::CanonicalGoalEvaluationStep<TyCtxt<'tcx>>,
283-
) -> &'tcx solve::inspect::CanonicalGoalEvaluationStep<TyCtxt<'tcx>> {
284-
self.arena.alloc(step)
285-
}
286-
287278
fn mk_type_list_from_iter<I, T>(self, args: I) -> T::Output
288279
where
289280
I: Iterator<Item = T>,

‎compiler/rustc_next_trait_solver/src/solve/inspect/build.rs

+14-92
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@
55
//! see the comment on [ProofTreeBuilder].
66
77
use std::marker::PhantomData;
8-
use std::mem;
98

109
use derive_where::derive_where;
1110
use rustc_type_ir::inherent::*;
12-
use rustc_type_ir::{self as ty, search_graph, Interner};
11+
use rustc_type_ir::{self as ty, Interner};
1312

1413
use crate::delegate::SolverDelegate;
1514
use crate::solve::eval_ctxt::canonical;
@@ -94,31 +93,10 @@ impl<I: Interner> WipGoalEvaluation<I> {
9493
}
9594
}
9695

97-
#[derive_where(PartialEq, Eq; I: Interner)]
98-
pub(in crate::solve) enum WipCanonicalGoalEvaluationKind<I: Interner> {
99-
Overflow,
100-
CycleInStack,
101-
ProvisionalCacheHit,
102-
Interned { final_revision: I::CanonicalGoalEvaluationStepRef },
103-
}
104-
105-
impl<I: Interner> std::fmt::Debug for WipCanonicalGoalEvaluationKind<I> {
106-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
107-
match self {
108-
Self::Overflow => write!(f, "Overflow"),
109-
Self::CycleInStack => write!(f, "CycleInStack"),
110-
Self::ProvisionalCacheHit => write!(f, "ProvisionalCacheHit"),
111-
Self::Interned { final_revision: _ } => {
112-
f.debug_struct("Interned").finish_non_exhaustive()
113-
}
114-
}
115-
}
116-
}
117-
11896
#[derive_where(PartialEq, Eq, Debug; I: Interner)]
11997
struct WipCanonicalGoalEvaluation<I: Interner> {
12098
goal: CanonicalInput<I>,
121-
kind: Option<WipCanonicalGoalEvaluationKind<I>>,
99+
encountered_overflow: bool,
122100
/// Only used for uncached goals. After we finished evaluating
123101
/// the goal, this is interned and moved into `kind`.
124102
final_revision: Option<WipCanonicalGoalEvaluationStep<I>>,
@@ -127,25 +105,17 @@ struct WipCanonicalGoalEvaluation<I: Interner> {
127105

128106
impl<I: Interner> WipCanonicalGoalEvaluation<I> {
129107
fn finalize(self) -> inspect::CanonicalGoalEvaluation<I> {
130-
// We've already interned the final revision in
131-
// `fn finalize_canonical_goal_evaluation`.
132-
assert!(self.final_revision.is_none());
133-
let kind = match self.kind.unwrap() {
134-
WipCanonicalGoalEvaluationKind::Overflow => {
108+
inspect::CanonicalGoalEvaluation {
109+
goal: self.goal,
110+
kind: if self.encountered_overflow {
111+
assert!(self.final_revision.is_none());
135112
inspect::CanonicalGoalEvaluationKind::Overflow
136-
}
137-
WipCanonicalGoalEvaluationKind::CycleInStack => {
138-
inspect::CanonicalGoalEvaluationKind::CycleInStack
139-
}
140-
WipCanonicalGoalEvaluationKind::ProvisionalCacheHit => {
141-
inspect::CanonicalGoalEvaluationKind::ProvisionalCacheHit
142-
}
143-
WipCanonicalGoalEvaluationKind::Interned { final_revision } => {
113+
} else {
114+
let final_revision = self.final_revision.unwrap().finalize();
144115
inspect::CanonicalGoalEvaluationKind::Evaluation { final_revision }
145-
}
146-
};
147-
148-
inspect::CanonicalGoalEvaluation { goal: self.goal, kind, result: self.result.unwrap() }
116+
},
117+
result: self.result.unwrap(),
118+
}
149119
}
150120
}
151121

@@ -308,7 +278,7 @@ impl<D: SolverDelegate<Interner = I>, I: Interner> ProofTreeBuilder<D> {
308278
) -> ProofTreeBuilder<D> {
309279
self.nested(|| WipCanonicalGoalEvaluation {
310280
goal,
311-
kind: None,
281+
encountered_overflow: false,
312282
final_revision: None,
313283
result: None,
314284
})
@@ -329,11 +299,11 @@ impl<D: SolverDelegate<Interner = I>, I: Interner> ProofTreeBuilder<D> {
329299
}
330300
}
331301

332-
pub fn canonical_goal_evaluation_kind(&mut self, kind: WipCanonicalGoalEvaluationKind<I>) {
302+
pub fn canonical_goal_evaluation_overflow(&mut self) {
333303
if let Some(this) = self.as_mut() {
334304
match this {
335305
DebugSolver::CanonicalGoalEvaluation(canonical_goal_evaluation) => {
336-
assert_eq!(canonical_goal_evaluation.kind.replace(kind), None);
306+
canonical_goal_evaluation.encountered_overflow = true;
337307
}
338308
_ => unreachable!(),
339309
};
@@ -547,51 +517,3 @@ impl<D: SolverDelegate<Interner = I>, I: Interner> ProofTreeBuilder<D> {
547517
}
548518
}
549519
}
550-
551-
impl<D, I> search_graph::ProofTreeBuilder<I> for ProofTreeBuilder<D>
552-
where
553-
D: SolverDelegate<Interner = I>,
554-
I: Interner,
555-
{
556-
fn try_apply_proof_tree(
557-
&mut self,
558-
proof_tree: Option<I::CanonicalGoalEvaluationStepRef>,
559-
) -> bool {
560-
if !self.is_noop() {
561-
if let Some(final_revision) = proof_tree {
562-
let kind = WipCanonicalGoalEvaluationKind::Interned { final_revision };
563-
self.canonical_goal_evaluation_kind(kind);
564-
true
565-
} else {
566-
false
567-
}
568-
} else {
569-
true
570-
}
571-
}
572-
573-
fn on_provisional_cache_hit(&mut self) {
574-
self.canonical_goal_evaluation_kind(WipCanonicalGoalEvaluationKind::ProvisionalCacheHit);
575-
}
576-
577-
fn on_cycle_in_stack(&mut self) {
578-
self.canonical_goal_evaluation_kind(WipCanonicalGoalEvaluationKind::CycleInStack);
579-
}
580-
581-
fn finalize_canonical_goal_evaluation(
582-
&mut self,
583-
tcx: I,
584-
) -> Option<I::CanonicalGoalEvaluationStepRef> {
585-
self.as_mut().map(|this| match this {
586-
DebugSolver::CanonicalGoalEvaluation(evaluation) => {
587-
let final_revision = mem::take(&mut evaluation.final_revision).unwrap();
588-
let final_revision =
589-
tcx.intern_canonical_goal_evaluation_step(final_revision.finalize());
590-
let kind = WipCanonicalGoalEvaluationKind::Interned { final_revision };
591-
assert_eq!(evaluation.kind.replace(kind), None);
592-
final_revision
593-
}
594-
_ => unreachable!(),
595-
})
596-
}
597-
}

‎compiler/rustc_next_trait_solver/src/solve/search_graph.rs

+40-19
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1+
use std::convert::Infallible;
12
use std::marker::PhantomData;
23

34
use rustc_type_ir::inherent::*;
4-
use rustc_type_ir::search_graph::{self, CycleKind, UsageKind};
5+
use rustc_type_ir::search_graph::{self, CycleKind};
56
use rustc_type_ir::solve::{CanonicalInput, Certainty, QueryResult};
67
use rustc_type_ir::Interner;
78

8-
use super::inspect::{self, ProofTreeBuilder};
9-
use super::FIXPOINT_STEP_LIMIT;
9+
use super::inspect::ProofTreeBuilder;
10+
use super::{has_no_inference_or_external_constraints, FIXPOINT_STEP_LIMIT};
1011
use crate::delegate::SolverDelegate;
1112

1213
/// This type is never constructed. We only use it to implement `search_graph::Delegate`
@@ -22,9 +23,21 @@ where
2223
{
2324
type Cx = D::Interner;
2425

26+
const ENABLE_PROVISIONAL_CACHE: bool = true;
27+
type ValidationScope = Infallible;
28+
fn enter_validation_scope(
29+
_cx: Self::Cx,
30+
_input: CanonicalInput<I>,
31+
) -> Option<Self::ValidationScope> {
32+
None
33+
}
34+
2535
const FIXPOINT_STEP_LIMIT: usize = FIXPOINT_STEP_LIMIT;
2636

2737
type ProofTreeBuilder = ProofTreeBuilder<D>;
38+
fn inspect_is_noop(inspect: &mut Self::ProofTreeBuilder) -> bool {
39+
inspect.is_noop()
40+
}
2841

2942
fn recursion_limit(cx: I) -> usize {
3043
cx.recursion_limit()
@@ -41,24 +54,16 @@ where
4154
}
4255
}
4356

44-
fn reached_fixpoint(
45-
cx: I,
46-
kind: UsageKind,
57+
fn is_initial_provisional_result(
58+
cx: Self::Cx,
59+
kind: CycleKind,
4760
input: CanonicalInput<I>,
48-
provisional_result: Option<QueryResult<I>>,
4961
result: QueryResult<I>,
5062
) -> bool {
51-
if let Some(r) = provisional_result {
52-
r == result
53-
} else {
54-
match kind {
55-
UsageKind::Single(CycleKind::Coinductive) => {
56-
response_no_constraints(cx, input, Certainty::Yes) == result
57-
}
58-
UsageKind::Single(CycleKind::Inductive) => {
59-
response_no_constraints(cx, input, Certainty::overflow(false)) == result
60-
}
61-
UsageKind::Mixed => false,
63+
match kind {
64+
CycleKind::Coinductive => response_no_constraints(cx, input, Certainty::Yes) == result,
65+
CycleKind::Inductive => {
66+
response_no_constraints(cx, input, Certainty::overflow(false)) == result
6267
}
6368
}
6469
}
@@ -68,14 +73,30 @@ where
6873
inspect: &mut ProofTreeBuilder<D>,
6974
input: CanonicalInput<I>,
7075
) -> QueryResult<I> {
71-
inspect.canonical_goal_evaluation_kind(inspect::WipCanonicalGoalEvaluationKind::Overflow);
76+
inspect.canonical_goal_evaluation_overflow();
7277
response_no_constraints(cx, input, Certainty::overflow(true))
7378
}
7479

7580
fn on_fixpoint_overflow(cx: I, input: CanonicalInput<I>) -> QueryResult<I> {
7681
response_no_constraints(cx, input, Certainty::overflow(false))
7782
}
7883

84+
fn is_ambiguous_result(result: QueryResult<I>) -> bool {
85+
result.is_ok_and(|response| {
86+
has_no_inference_or_external_constraints(response)
87+
&& matches!(response.value.certainty, Certainty::Maybe(_))
88+
})
89+
}
90+
91+
fn propagate_ambiguity(
92+
cx: I,
93+
for_input: CanonicalInput<I>,
94+
from_result: QueryResult<I>,
95+
) -> QueryResult<I> {
96+
let certainty = from_result.unwrap().value.certainty;
97+
response_no_constraints(cx, for_input, certainty)
98+
}
99+
79100
fn step_is_coinductive(cx: I, input: CanonicalInput<I>) -> bool {
80101
input.value.goal.predicate.is_coinductive(cx)
81102
}

‎compiler/rustc_trait_selection/src/solve/inspect/analyse.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -332,13 +332,9 @@ impl<'a, 'tcx> InspectGoal<'a, 'tcx> {
332332

333333
pub fn candidates(&'a self) -> Vec<InspectCandidate<'a, 'tcx>> {
334334
let mut candidates = vec![];
335-
let last_eval_step = match self.evaluation_kind {
336-
inspect::CanonicalGoalEvaluationKind::Overflow
337-
| inspect::CanonicalGoalEvaluationKind::CycleInStack
338-
| inspect::CanonicalGoalEvaluationKind::ProvisionalCacheHit => {
339-
warn!("unexpected root evaluation: {:?}", self.evaluation_kind);
340-
return vec![];
341-
}
335+
let last_eval_step = match &self.evaluation_kind {
336+
// An annoying edge case in case the recursion limit is 0.
337+
inspect::CanonicalGoalEvaluationKind::Overflow => return vec![],
342338
inspect::CanonicalGoalEvaluationKind::Evaluation { final_revision } => final_revision,
343339
};
344340

‎compiler/rustc_type_ir/src/binder.rs

+8-16
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use derive_where::derive_where;
88
use rustc_macros::{HashStable_NoContext, TyDecodable, TyEncodable};
99
#[cfg(feature = "nightly")]
1010
use rustc_serialize::Decodable;
11-
use tracing::debug;
11+
use tracing::instrument;
1212

1313
use crate::data_structures::SsoHashSet;
1414
use crate::fold::{FallibleTypeFolder, TypeFoldable, TypeFolder, TypeSuperFoldable};
@@ -831,28 +831,20 @@ impl<'a, I: Interner> ArgFolder<'a, I> {
831831
/// As indicated in the diagram, here the same type `&'a i32` is instantiated once, but in the
832832
/// first case we do not increase the De Bruijn index and in the second case we do. The reason
833833
/// is that only in the second case have we passed through a fn binder.
834+
#[instrument(level = "trace", skip(self), fields(binders_passed = self.binders_passed), ret)]
834835
fn shift_vars_through_binders<T: TypeFoldable<I>>(&self, val: T) -> T {
835-
debug!(
836-
"shift_vars(val={:?}, binders_passed={:?}, has_escaping_bound_vars={:?})",
837-
val,
838-
self.binders_passed,
839-
val.has_escaping_bound_vars()
840-
);
841-
842836
if self.binders_passed == 0 || !val.has_escaping_bound_vars() {
843-
return val;
837+
val
838+
} else {
839+
ty::fold::shift_vars(self.cx, val, self.binders_passed)
844840
}
845-
846-
let result = ty::fold::shift_vars(TypeFolder::cx(self), val, self.binders_passed);
847-
debug!("shift_vars: shifted result = {:?}", result);
848-
849-
result
850841
}
851842

852843
fn shift_region_through_binders(&self, region: I::Region) -> I::Region {
853844
if self.binders_passed == 0 || !region.has_escaping_bound_vars() {
854-
return region;
845+
region
846+
} else {
847+
ty::fold::shift_region(self.cx, region, self.binders_passed)
855848
}
856-
ty::fold::shift_region(self.cx, region, self.binders_passed)
857849
}
858850
}

‎compiler/rustc_type_ir/src/fold.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
use std::mem;
4949

5050
use rustc_index::{Idx, IndexVec};
51-
use tracing::debug;
51+
use tracing::instrument;
5252

5353
use crate::data_structures::Lrc;
5454
use crate::inherent::*;
@@ -415,15 +415,14 @@ pub fn shift_region<I: Interner>(cx: I, region: I::Region, amount: u32) -> I::Re
415415
}
416416
}
417417

418+
#[instrument(level = "trace", skip(cx), ret)]
418419
pub fn shift_vars<I: Interner, T>(cx: I, value: T, amount: u32) -> T
419420
where
420421
T: TypeFoldable<I>,
421422
{
422-
debug!("shift_vars(value={:?}, amount={})", value, amount);
423-
424423
if amount == 0 || !value.has_escaping_bound_vars() {
425-
return value;
424+
value
425+
} else {
426+
value.fold_with(&mut Shifter::new(cx, amount))
426427
}
427-
428-
value.fold_with(&mut Shifter::new(cx, amount))
429428
}

‎compiler/rustc_type_ir/src/interner.rs

-12
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use crate::inherent::*;
1111
use crate::ir_print::IrPrint;
1212
use crate::lang_items::TraitSolverLangItem;
1313
use crate::relate::Relate;
14-
use crate::solve::inspect::CanonicalGoalEvaluationStep;
1514
use crate::solve::{
1615
CanonicalInput, ExternalConstraintsData, PredefinedOpaquesData, QueryResult, SolverMode,
1716
};
@@ -65,11 +64,6 @@ pub trait Interner:
6564
+ Eq
6665
+ TypeVisitable<Self>
6766
+ SliceLike<Item = Self::LocalDefId>;
68-
type CanonicalGoalEvaluationStepRef: Copy
69-
+ Debug
70-
+ Hash
71-
+ Eq
72-
+ Deref<Target = CanonicalGoalEvaluationStep<Self>>;
7367

7468
type CanonicalVars: Copy
7569
+ Debug
@@ -177,11 +171,6 @@ pub trait Interner:
177171

178172
fn debug_assert_args_compatible(self, def_id: Self::DefId, args: Self::GenericArgs);
179173

180-
fn intern_canonical_goal_evaluation_step(
181-
self,
182-
step: CanonicalGoalEvaluationStep<Self>,
183-
) -> Self::CanonicalGoalEvaluationStepRef;
184-
185174
fn mk_type_list_from_iter<I, T>(self, args: I) -> T::Output
186175
where
187176
I: Iterator<Item = T>,
@@ -390,7 +379,6 @@ impl<T, R, E> CollectAndApply<T, R> for Result<T, E> {
390379
}
391380

392381
impl<I: Interner> search_graph::Cx for I {
393-
type ProofTree = Option<I::CanonicalGoalEvaluationStepRef>;
394382
type Input = CanonicalInput<I>;
395383
type Result = QueryResult<I>;
396384

Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
use derive_where::derive_where;
2-
use rustc_index::IndexVec;
32

4-
use super::{AvailableDepth, Cx, StackDepth, StackEntry};
5-
use crate::data_structures::{HashMap, HashSet};
6-
7-
#[derive_where(Debug, Clone, Copy; X: Cx)]
8-
struct QueryData<X: Cx> {
9-
result: X::Result,
10-
proof_tree: X::ProofTree,
11-
}
3+
use super::{AvailableDepth, Cx, NestedGoals};
4+
use crate::data_structures::HashMap;
125

136
struct Success<X: Cx> {
14-
data: X::Tracked<QueryData<X>>,
157
additional_depth: usize,
8+
nested_goals: NestedGoals<X>,
9+
result: X::Tracked<X::Result>,
10+
}
11+
12+
struct WithOverflow<X: Cx> {
13+
nested_goals: NestedGoals<X>,
14+
result: X::Tracked<X::Result>,
1615
}
1716

1817
/// The cache entry for a given input.
@@ -23,24 +22,15 @@ struct Success<X: Cx> {
2322
#[derive_where(Default; X: Cx)]
2423
struct CacheEntry<X: Cx> {
2524
success: Option<Success<X>>,
26-
/// We have to be careful when caching roots of cycles.
27-
///
28-
/// See the doc comment of `StackEntry::cycle_participants` for more
29-
/// details.
30-
nested_goals: HashSet<X::Input>,
31-
with_overflow: HashMap<usize, X::Tracked<QueryData<X>>>,
25+
with_overflow: HashMap<usize, WithOverflow<X>>,
3226
}
3327

3428
#[derive_where(Debug; X: Cx)]
3529
pub(super) struct CacheData<'a, X: Cx> {
3630
pub(super) result: X::Result,
37-
pub(super) proof_tree: X::ProofTree,
3831
pub(super) additional_depth: usize,
3932
pub(super) encountered_overflow: bool,
40-
// FIXME: This is currently unused, but impacts the design
41-
// by requiring a closure for `Cx::with_global_cache`.
42-
#[allow(dead_code)]
43-
pub(super) nested_goals: &'a HashSet<X::Input>,
33+
pub(super) nested_goals: &'a NestedGoals<X>,
4434
}
4535
#[derive_where(Default; X: Cx)]
4636
pub struct GlobalCache<X: Cx> {
@@ -55,20 +45,21 @@ impl<X: Cx> GlobalCache<X> {
5545
input: X::Input,
5646

5747
result: X::Result,
58-
proof_tree: X::ProofTree,
5948
dep_node: X::DepNodeIndex,
6049

6150
additional_depth: usize,
6251
encountered_overflow: bool,
63-
nested_goals: &HashSet<X::Input>,
52+
nested_goals: NestedGoals<X>,
6453
) {
65-
let data = cx.mk_tracked(QueryData { result, proof_tree }, dep_node);
54+
let result = cx.mk_tracked(result, dep_node);
6655
let entry = self.map.entry(input).or_default();
67-
entry.nested_goals.extend(nested_goals);
6856
if encountered_overflow {
69-
entry.with_overflow.insert(additional_depth, data);
57+
let with_overflow = WithOverflow { nested_goals, result };
58+
let prev = entry.with_overflow.insert(additional_depth, with_overflow);
59+
assert!(prev.is_none());
7060
} else {
71-
entry.success = Some(Success { data, additional_depth });
61+
let prev = entry.success.replace(Success { additional_depth, nested_goals, result });
62+
assert!(prev.is_none());
7263
}
7364
}
7465

@@ -80,36 +71,37 @@ impl<X: Cx> GlobalCache<X> {
8071
&'a self,
8172
cx: X,
8273
input: X::Input,
83-
stack: &IndexVec<StackDepth, StackEntry<X>>,
8474
available_depth: AvailableDepth,
75+
mut candidate_is_applicable: impl FnMut(&NestedGoals<X>) -> bool,
8576
) -> Option<CacheData<'a, X>> {
8677
let entry = self.map.get(&input)?;
87-
if stack.iter().any(|e| entry.nested_goals.contains(&e.input)) {
88-
return None;
89-
}
90-
91-
if let Some(ref success) = entry.success {
92-
if available_depth.cache_entry_is_applicable(success.additional_depth) {
93-
let QueryData { result, proof_tree } = cx.get_tracked(&success.data);
78+
if let Some(Success { additional_depth, ref nested_goals, ref result }) = entry.success {
79+
if available_depth.cache_entry_is_applicable(additional_depth)
80+
&& candidate_is_applicable(nested_goals)
81+
{
9482
return Some(CacheData {
95-
result,
96-
proof_tree,
97-
additional_depth: success.additional_depth,
83+
result: cx.get_tracked(&result),
84+
additional_depth,
9885
encountered_overflow: false,
99-
nested_goals: &entry.nested_goals,
86+
nested_goals,
10087
});
10188
}
10289
}
10390

104-
entry.with_overflow.get(&available_depth.0).map(|e| {
105-
let QueryData { result, proof_tree } = cx.get_tracked(e);
106-
CacheData {
107-
result,
108-
proof_tree,
109-
additional_depth: available_depth.0,
110-
encountered_overflow: true,
111-
nested_goals: &entry.nested_goals,
91+
let additional_depth = available_depth.0;
92+
if let Some(WithOverflow { nested_goals, result }) =
93+
entry.with_overflow.get(&additional_depth)
94+
{
95+
if candidate_is_applicable(nested_goals) {
96+
return Some(CacheData {
97+
result: cx.get_tracked(result),
98+
additional_depth,
99+
encountered_overflow: true,
100+
nested_goals,
101+
});
112102
}
113-
})
103+
}
104+
105+
None
114106
}
115107
}

‎compiler/rustc_type_ir/src/search_graph/mod.rs

+618-301
Large diffs are not rendered by default.

‎compiler/rustc_type_ir/src/search_graph/validate.rs

-75
This file was deleted.

‎compiler/rustc_type_ir/src/solve/inspect.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,7 @@ pub struct CanonicalGoalEvaluation<I: Interner> {
6969
#[derive_where(PartialEq, Eq, Hash, Debug; I: Interner)]
7070
pub enum CanonicalGoalEvaluationKind<I: Interner> {
7171
Overflow,
72-
CycleInStack,
73-
ProvisionalCacheHit,
74-
Evaluation { final_revision: I::CanonicalGoalEvaluationStepRef },
72+
Evaluation { final_revision: CanonicalGoalEvaluationStep<I> },
7573
}
7674

7775
#[derive_where(PartialEq, Eq, Hash, Debug; I: Interner)]

‎compiler/rustc_type_ir/src/solve/mod.rs

-8
Original file line numberDiff line numberDiff line change
@@ -340,11 +340,3 @@ impl MaybeCause {
340340
}
341341
}
342342
}
343-
344-
#[derive_where(PartialEq, Eq, Debug; I: Interner)]
345-
pub struct CacheData<I: Interner> {
346-
pub result: QueryResult<I>,
347-
pub proof_tree: Option<I::CanonicalGoalEvaluationStepRef>,
348-
pub additional_depth: usize,
349-
pub encountered_overflow: bool,
350-
}

0 commit comments

Comments
 (0)
Please sign in to comment.