Skip to content

Commit a1927d6

Browse files
committed
proof tree cleanup 3/n
1 parent e172773 commit a1927d6

File tree

5 files changed

+18
-72
lines changed

5 files changed

+18
-72
lines changed

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

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@ where
3636
struct WipGoalEvaluation<I: Interner> {
3737
pub uncanonicalized_goal: Goal<I, I::Predicate>,
3838
pub orig_values: Vec<I::GenericArg>,
39-
pub encountered_overflow: bool,
40-
/// After we finished evaluating this is moved into `kind`.
41-
pub final_revision: Option<WipEvaluationStep<I>>,
39+
pub final_revision: Option<inspect::Probe<I>>,
4240
pub result: Option<QueryResult<I>>,
4341
}
4442

@@ -133,7 +131,6 @@ impl<D: SolverDelegate<Interner = I>, I: Interner> GoalEvaluationBuilder<D> {
133131
state: Some(Box::new(WipGoalEvaluation {
134132
uncanonicalized_goal,
135133
orig_values: orig_values.to_vec(),
136-
encountered_overflow: false,
137134
final_revision: None,
138135
result: None,
139136
})),
@@ -158,23 +155,11 @@ impl<D: SolverDelegate<Interner = I>, I: Interner> GoalEvaluationBuilder<D> {
158155
inspect::GoalEvaluation {
159156
uncanonicalized_goal: this.uncanonicalized_goal,
160157
orig_values: this.orig_values,
161-
kind: if this.encountered_overflow {
162-
assert!(this.final_revision.is_none());
163-
inspect::GoalEvaluationKind::Overflow
164-
} else {
165-
let final_revision = this.final_revision.unwrap().finalize();
166-
inspect::GoalEvaluationKind::Evaluation { final_revision }
167-
},
158+
final_revision: this.final_revision.unwrap(),
168159
result: this.result.unwrap(),
169160
}
170161
}
171162

172-
pub(crate) fn canonical_goal_evaluation_overflow(&mut self) {
173-
if let Some(this) = self.as_mut() {
174-
this.encountered_overflow = true;
175-
}
176-
}
177-
178163
pub(crate) fn new_goal_evaluation_step(
179164
&mut self,
180165
var_values: ty::CanonicalVarValues<I>,
@@ -200,7 +185,7 @@ impl<D: SolverDelegate<Interner = I>, I: Interner> GoalEvaluationBuilder<D> {
200185

201186
pub(crate) fn goal_evaluation_step(&mut self, goal_evaluation_step: EvaluationStepBuilder<D>) {
202187
if let Some(this) = self.as_mut() {
203-
this.final_revision = Some(*goal_evaluation_step.state.unwrap());
188+
this.final_revision = Some(goal_evaluation_step.state.unwrap().finalize());
204189
}
205190
}
206191

compiler/rustc_next_trait_solver/src/solve/search_graph.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,7 @@ where
8181
Self::initial_provisional_result(cx, kind, input) == result
8282
}
8383

84-
fn on_stack_overflow(
85-
cx: I,
86-
input: CanonicalInput<I>,
87-
inspect: &mut GoalEvaluationBuilder<D>,
88-
) -> QueryResult<I> {
89-
inspect.canonical_goal_evaluation_overflow();
84+
fn on_stack_overflow(cx: I, input: CanonicalInput<I>) -> QueryResult<I> {
9085
response_no_constraints(cx, input, Certainty::overflow(true))
9186
}
9287

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

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pub struct InspectGoal<'a, 'tcx> {
3737
orig_values: Vec<ty::GenericArg<'tcx>>,
3838
goal: Goal<'tcx, ty::Predicate<'tcx>>,
3939
result: Result<Certainty, NoSolution>,
40-
evaluation_kind: inspect::GoalEvaluationKind<TyCtxt<'tcx>>,
40+
final_revision: inspect::Probe<TyCtxt<'tcx>>,
4141
normalizes_to_term_hack: Option<NormalizesToTermHack<'tcx>>,
4242
source: GoalSource,
4343
}
@@ -391,15 +391,8 @@ impl<'a, 'tcx> InspectGoal<'a, 'tcx> {
391391

392392
pub fn candidates(&'a self) -> Vec<InspectCandidate<'a, 'tcx>> {
393393
let mut candidates = vec![];
394-
let last_eval_step = match &self.evaluation_kind {
395-
// An annoying edge case in case the recursion limit is 0.
396-
inspect::GoalEvaluationKind::Overflow => return vec![],
397-
inspect::GoalEvaluationKind::Evaluation { final_revision } => final_revision,
398-
};
399-
400394
let mut nested_goals = vec![];
401-
self.candidates_recur(&mut candidates, &mut nested_goals, &last_eval_step);
402-
395+
self.candidates_recur(&mut candidates, &mut nested_goals, &self.final_revision);
403396
candidates
404397
}
405398

@@ -426,7 +419,8 @@ impl<'a, 'tcx> InspectGoal<'a, 'tcx> {
426419
) -> Self {
427420
let infcx = <&SolverDelegate<'tcx>>::from(infcx);
428421

429-
let inspect::GoalEvaluation { uncanonicalized_goal, orig_values, kind, result } = root;
422+
let inspect::GoalEvaluation { uncanonicalized_goal, orig_values, final_revision, result } =
423+
root;
430424
// If there's a normalizes-to goal, AND the evaluation result with the result of
431425
// constraining the normalizes-to RHS and computing the nested goals.
432426
let result = result.and_then(|ok| {
@@ -441,7 +435,7 @@ impl<'a, 'tcx> InspectGoal<'a, 'tcx> {
441435
orig_values,
442436
goal: eager_resolve_vars(infcx, uncanonicalized_goal),
443437
result,
444-
evaluation_kind: kind,
438+
final_revision,
445439
normalizes_to_term_hack: term_hack_and_nested_certainty.map(|(n, _)| n),
446440
source,
447441
}

compiler/rustc_type_ir/src/search_graph/mod.rs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,7 @@ pub trait Delegate: Sized {
9292
input: <Self::Cx as Cx>::Input,
9393
result: <Self::Cx as Cx>::Result,
9494
) -> bool;
95-
fn on_stack_overflow(
96-
cx: Self::Cx,
97-
input: <Self::Cx as Cx>::Input,
98-
inspect: &mut Self::ProofTreeBuilder,
99-
) -> <Self::Cx as Cx>::Result;
95+
fn on_stack_overflow(cx: Self::Cx, input: <Self::Cx as Cx>::Input) -> <Self::Cx as Cx>::Result;
10096
fn on_fixpoint_overflow(
10197
cx: Self::Cx,
10298
input: <Self::Cx as Cx>::Input,
@@ -718,7 +714,7 @@ impl<D: Delegate<Cx = X>, X: Cx> SearchGraph<D> {
718714
let Some(available_depth) =
719715
AvailableDepth::allowed_depth_for_nested::<D>(self.root_depth, &self.stack)
720716
else {
721-
return self.handle_overflow(cx, input, inspect);
717+
return self.handle_overflow(cx, input);
722718
};
723719

724720
// We check the provisional cache before checking the global cache. This simplifies
@@ -833,12 +829,7 @@ impl<D: Delegate<Cx = X>, X: Cx> SearchGraph<D> {
833829
result
834830
}
835831

836-
fn handle_overflow(
837-
&mut self,
838-
cx: X,
839-
input: X::Input,
840-
inspect: &mut D::ProofTreeBuilder,
841-
) -> X::Result {
832+
fn handle_overflow(&mut self, cx: X, input: X::Input) -> X::Result {
842833
if let Some(last) = self.stack.last_mut() {
843834
last.encountered_overflow = true;
844835
// If computing a goal `B` depends on another goal `A` and
@@ -853,7 +844,7 @@ impl<D: Delegate<Cx = X>, X: Cx> SearchGraph<D> {
853844
}
854845

855846
debug!("encountered stack overflow");
856-
D::on_stack_overflow(cx, input, inspect)
847+
D::on_stack_overflow(cx, input)
857848
}
858849

859850
/// When reevaluating a goal with a changed provisional result, all provisional cache entry

compiler/rustc_type_ir/src/solve/inspect.rs

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -45,41 +45,26 @@ pub type CanonicalState<I, T> = Canonical<I, State<I, T>>;
4545
/// for the `CanonicalVarValues` of the canonicalized goal.
4646
/// We use this to map any [CanonicalState] from the local `InferCtxt`
4747
/// of the solver query to the `InferCtxt` of the caller.
48-
#[derive_where(PartialEq, Hash; I: Interner)]
48+
#[derive_where(PartialEq, Eq, Hash; I: Interner)]
4949
pub struct GoalEvaluation<I: Interner> {
5050
pub uncanonicalized_goal: Goal<I, I::Predicate>,
5151
pub orig_values: Vec<I::GenericArg>,
52-
pub kind: GoalEvaluationKind<I>,
52+
pub final_revision: Probe<I>,
5353
pub result: QueryResult<I>,
5454
}
5555

56-
impl<I: Interner> Eq for GoalEvaluation<I> {}
57-
58-
#[derive_where(PartialEq, Hash, Debug; I: Interner)]
59-
pub enum GoalEvaluationKind<I: Interner> {
60-
Overflow,
61-
Evaluation {
62-
/// This is always `ProbeKind::Root`.
63-
final_revision: Probe<I>,
64-
},
65-
}
66-
67-
impl<I: Interner> Eq for GoalEvaluationKind<I> {}
68-
6956
/// A self-contained computation during trait solving. This either
7057
/// corresponds to a `EvalCtxt::probe(_X)` call or the root evaluation
7158
/// of a goal.
72-
#[derive_where(PartialEq, Hash, Debug; I: Interner)]
59+
#[derive_where(PartialEq, Eq, Hash, Debug; I: Interner)]
7360
pub struct Probe<I: Interner> {
7461
/// What happened inside of this probe in chronological order.
7562
pub steps: Vec<ProbeStep<I>>,
7663
pub kind: ProbeKind<I>,
7764
pub final_state: CanonicalState<I, ()>,
7865
}
7966

80-
impl<I: Interner> Eq for Probe<I> {}
81-
82-
#[derive_where(PartialEq, Hash, Debug; I: Interner)]
67+
#[derive_where(PartialEq, Eq, Hash, Debug; I: Interner)]
8368
pub enum ProbeStep<I: Interner> {
8469
/// We added a goal to the `EvalCtxt` which will get proven
8570
/// the next time `EvalCtxt::try_evaluate_added_goals` is called.
@@ -98,12 +83,10 @@ pub enum ProbeStep<I: Interner> {
9883
MakeCanonicalResponse { shallow_certainty: Certainty },
9984
}
10085

101-
impl<I: Interner> Eq for ProbeStep<I> {}
102-
10386
/// What kind of probe we're in. In case the probe represents a candidate, or
10487
/// the final result of the current goal - via [ProbeKind::Root] - we also
10588
/// store the [QueryResult].
106-
#[derive_where(Clone, Copy, PartialEq, Hash, Debug; I: Interner)]
89+
#[derive_where(Clone, Copy, PartialEq, Eq, Hash, Debug; I: Interner)]
10790
#[derive(TypeVisitable_Generic, TypeFoldable_Generic)]
10891
pub enum ProbeKind<I: Interner> {
10992
/// The root inference context while proving a goal.
@@ -128,5 +111,3 @@ pub enum ProbeKind<I: Interner> {
128111
/// Checking that a rigid alias is well-formed.
129112
RigidAlias { result: QueryResult<I> },
130113
}
131-
132-
impl<I: Interner> Eq for ProbeKind<I> {}

0 commit comments

Comments
 (0)