Skip to content

Commit 3f8cf47

Browse files
committed
inspect: merge [Canonical]GoalEvaluation
1 parent 2a45990 commit 3f8cf47

File tree

4 files changed

+34
-97
lines changed

4 files changed

+34
-97
lines changed

compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -454,21 +454,16 @@ where
454454
let (orig_values, canonical_goal) = self.canonicalize_goal(goal);
455455
let mut goal_evaluation =
456456
self.inspect.new_goal_evaluation(goal, &orig_values, goal_evaluation_kind);
457-
let mut canonical_goal_evaluation =
458-
goal_evaluation.new_canonical_goal_evaluation(canonical_goal);
459-
let canonical_response = self.search_graph.evaluate_goal(
457+
let canonical_result = self.search_graph.evaluate_goal(
460458
self.cx(),
461459
canonical_goal,
462460
self.step_kind_for_source(source),
463-
&mut canonical_goal_evaluation,
461+
&mut goal_evaluation,
464462
);
465-
canonical_goal_evaluation.query_result(canonical_response);
466-
goal_evaluation.canonical_goal_evaluation(canonical_goal_evaluation);
467-
let response = match canonical_response {
468-
Err(e) => {
469-
self.inspect.goal_evaluation(goal_evaluation);
470-
return Err(e);
471-
}
463+
goal_evaluation.query_result(canonical_result);
464+
self.inspect.goal_evaluation(goal_evaluation);
465+
let response = match canonical_result {
466+
Err(e) => return Err(e),
472467
Ok(response) => response,
473468
};
474469

@@ -477,7 +472,6 @@ where
477472

478473
let (normalization_nested_goals, certainty) =
479474
self.instantiate_and_apply_query_response(goal.param_env, &orig_values, response);
480-
self.inspect.goal_evaluation(goal_evaluation);
481475

482476
// FIXME: We previously had an assert here that checked that recomputing
483477
// a goal after applying its constraints did not change its response.

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

Lines changed: 19 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ use rustc_type_ir::{self as ty, Interner};
1313
use crate::delegate::SolverDelegate;
1414
use crate::solve::eval_ctxt::canonical;
1515
use crate::solve::{
16-
CanonicalInput, Certainty, GenerateProofTree, Goal, GoalEvaluationKind, GoalSource,
17-
QueryResult, inspect,
16+
Certainty, GenerateProofTree, Goal, GoalEvaluationKind, GoalSource, QueryResult, inspect,
1817
};
1918

2019
/// The core data structure when building proof trees.
@@ -54,7 +53,6 @@ where
5453
enum DebugSolver<I: Interner> {
5554
Root,
5655
GoalEvaluation(WipGoalEvaluation<I>),
57-
CanonicalGoalEvaluation(WipCanonicalGoalEvaluation<I>),
5856
CanonicalGoalEvaluationStep(WipCanonicalGoalEvaluationStep<I>),
5957
}
6058

@@ -64,12 +62,6 @@ impl<I: Interner> From<WipGoalEvaluation<I>> for DebugSolver<I> {
6462
}
6563
}
6664

67-
impl<I: Interner> From<WipCanonicalGoalEvaluation<I>> for DebugSolver<I> {
68-
fn from(g: WipCanonicalGoalEvaluation<I>) -> DebugSolver<I> {
69-
DebugSolver::CanonicalGoalEvaluation(g)
70-
}
71-
}
72-
7365
impl<I: Interner> From<WipCanonicalGoalEvaluationStep<I>> for DebugSolver<I> {
7466
fn from(g: WipCanonicalGoalEvaluationStep<I>) -> DebugSolver<I> {
7567
DebugSolver::CanonicalGoalEvaluationStep(g)
@@ -80,39 +72,24 @@ impl<I: Interner> From<WipCanonicalGoalEvaluationStep<I>> for DebugSolver<I> {
8072
struct WipGoalEvaluation<I: Interner> {
8173
pub uncanonicalized_goal: Goal<I, I::Predicate>,
8274
pub orig_values: Vec<I::GenericArg>,
83-
pub evaluation: Option<WipCanonicalGoalEvaluation<I>>,
75+
pub encountered_overflow: bool,
76+
/// Only used for uncached goals. After we finished evaluating
77+
/// the goal, this is interned and moved into `kind`.
78+
pub final_revision: Option<WipCanonicalGoalEvaluationStep<I>>,
79+
pub result: Option<QueryResult<I>>,
8480
}
8581

8682
impl<I: Interner> WipGoalEvaluation<I> {
8783
fn finalize(self) -> inspect::GoalEvaluation<I> {
8884
inspect::GoalEvaluation {
8985
uncanonicalized_goal: self.uncanonicalized_goal,
9086
orig_values: self.orig_values,
91-
evaluation: self.evaluation.unwrap().finalize(),
92-
}
93-
}
94-
}
95-
96-
#[derive_where(PartialEq, Eq, Debug; I: Interner)]
97-
struct WipCanonicalGoalEvaluation<I: Interner> {
98-
goal: CanonicalInput<I>,
99-
encountered_overflow: bool,
100-
/// Only used for uncached goals. After we finished evaluating
101-
/// the goal, this is interned and moved into `kind`.
102-
final_revision: Option<WipCanonicalGoalEvaluationStep<I>>,
103-
result: Option<QueryResult<I>>,
104-
}
105-
106-
impl<I: Interner> WipCanonicalGoalEvaluation<I> {
107-
fn finalize(self) -> inspect::CanonicalGoalEvaluation<I> {
108-
inspect::CanonicalGoalEvaluation {
109-
goal: self.goal,
11087
kind: if self.encountered_overflow {
11188
assert!(self.final_revision.is_none());
112-
inspect::CanonicalGoalEvaluationKind::Overflow
89+
inspect::GoalEvaluationKind::Overflow
11390
} else {
11491
let final_revision = self.final_revision.unwrap().finalize();
115-
inspect::CanonicalGoalEvaluationKind::Evaluation { final_revision }
92+
inspect::GoalEvaluationKind::Evaluation { final_revision }
11693
},
11794
result: self.result.unwrap(),
11895
}
@@ -256,55 +233,27 @@ impl<D: SolverDelegate<Interner = I>, I: Interner> ProofTreeBuilder<D> {
256233

257234
pub(in crate::solve) fn new_goal_evaluation(
258235
&mut self,
259-
goal: Goal<I, I::Predicate>,
236+
uncanonicalized_goal: Goal<I, I::Predicate>,
260237
orig_values: &[I::GenericArg],
261238
kind: GoalEvaluationKind,
262239
) -> ProofTreeBuilder<D> {
263240
self.opt_nested(|| match kind {
264241
GoalEvaluationKind::Root => Some(WipGoalEvaluation {
265-
uncanonicalized_goal: goal,
242+
uncanonicalized_goal,
266243
orig_values: orig_values.to_vec(),
267-
evaluation: None,
244+
encountered_overflow: false,
245+
final_revision: None,
246+
result: None,
268247
}),
269248
GoalEvaluationKind::Nested => None,
270249
})
271250
}
272251

273-
pub(crate) fn new_canonical_goal_evaluation(
274-
&mut self,
275-
goal: CanonicalInput<I>,
276-
) -> ProofTreeBuilder<D> {
277-
self.nested(|| WipCanonicalGoalEvaluation {
278-
goal,
279-
encountered_overflow: false,
280-
final_revision: None,
281-
result: None,
282-
})
283-
}
284-
285-
pub(crate) fn canonical_goal_evaluation(
286-
&mut self,
287-
canonical_goal_evaluation: ProofTreeBuilder<D>,
288-
) {
289-
if let Some(this) = self.as_mut() {
290-
match (this, *canonical_goal_evaluation.state.unwrap()) {
291-
(
292-
DebugSolver::GoalEvaluation(goal_evaluation),
293-
DebugSolver::CanonicalGoalEvaluation(canonical_goal_evaluation),
294-
) => {
295-
let prev = goal_evaluation.evaluation.replace(canonical_goal_evaluation);
296-
assert_eq!(prev, None);
297-
}
298-
_ => unreachable!(),
299-
}
300-
}
301-
}
302-
303252
pub(crate) fn canonical_goal_evaluation_overflow(&mut self) {
304253
if let Some(this) = self.as_mut() {
305254
match this {
306-
DebugSolver::CanonicalGoalEvaluation(canonical_goal_evaluation) => {
307-
canonical_goal_evaluation.encountered_overflow = true;
255+
DebugSolver::GoalEvaluation(goal_evaluation) => {
256+
goal_evaluation.encountered_overflow = true;
308257
}
309258
_ => unreachable!(),
310259
};
@@ -343,10 +292,10 @@ impl<D: SolverDelegate<Interner = I>, I: Interner> ProofTreeBuilder<D> {
343292
if let Some(this) = self.as_mut() {
344293
match (this, *goal_evaluation_step.state.unwrap()) {
345294
(
346-
DebugSolver::CanonicalGoalEvaluation(canonical_goal_evaluations),
295+
DebugSolver::GoalEvaluation(goal_evaluation),
347296
DebugSolver::CanonicalGoalEvaluationStep(goal_evaluation_step),
348297
) => {
349-
canonical_goal_evaluations.final_revision = Some(goal_evaluation_step);
298+
goal_evaluation.final_revision = Some(goal_evaluation_step);
350299
}
351300
_ => unreachable!(),
352301
}
@@ -489,8 +438,8 @@ impl<D: SolverDelegate<Interner = I>, I: Interner> ProofTreeBuilder<D> {
489438
pub(crate) fn query_result(&mut self, result: QueryResult<I>) {
490439
if let Some(this) = self.as_mut() {
491440
match this {
492-
DebugSolver::CanonicalGoalEvaluation(canonical_goal_evaluation) => {
493-
assert_eq!(canonical_goal_evaluation.result.replace(result), None);
441+
DebugSolver::GoalEvaluation(goal_evaluation) => {
442+
assert_eq!(goal_evaluation.result.replace(result), None);
494443
}
495444
DebugSolver::CanonicalGoalEvaluationStep(evaluation_step) => {
496445
assert_eq!(

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

Lines changed: 6 additions & 6 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::CanonicalGoalEvaluationKind<TyCtxt<'tcx>>,
40+
evaluation_kind: inspect::GoalEvaluationKind<TyCtxt<'tcx>>,
4141
normalizes_to_term_hack: Option<NormalizesToTermHack<'tcx>>,
4242
source: GoalSource,
4343
}
@@ -396,8 +396,8 @@ impl<'a, 'tcx> InspectGoal<'a, 'tcx> {
396396
let mut candidates = vec![];
397397
let last_eval_step = match &self.evaluation_kind {
398398
// An annoying edge case in case the recursion limit is 0.
399-
inspect::CanonicalGoalEvaluationKind::Overflow => return vec![],
400-
inspect::CanonicalGoalEvaluationKind::Evaluation { final_revision } => final_revision,
399+
inspect::GoalEvaluationKind::Overflow => return vec![],
400+
inspect::GoalEvaluationKind::Evaluation { final_revision } => final_revision,
401401
};
402402

403403
let mut nested_goals = vec![];
@@ -429,10 +429,10 @@ impl<'a, 'tcx> InspectGoal<'a, 'tcx> {
429429
) -> Self {
430430
let infcx = <&SolverDelegate<'tcx>>::from(infcx);
431431

432-
let inspect::GoalEvaluation { uncanonicalized_goal, orig_values, evaluation } = root;
432+
let inspect::GoalEvaluation { uncanonicalized_goal, orig_values, kind, result } = root;
433433
// If there's a normalizes-to goal, AND the evaluation result with the result of
434434
// constraining the normalizes-to RHS and computing the nested goals.
435-
let result = evaluation.result.and_then(|ok| {
435+
let result = result.and_then(|ok| {
436436
let nested_goals_certainty =
437437
term_hack_and_nested_certainty.map_or(Ok(Certainty::Yes), |(_, c)| c)?;
438438
Ok(ok.value.certainty.and(nested_goals_certainty))
@@ -444,7 +444,7 @@ impl<'a, 'tcx> InspectGoal<'a, 'tcx> {
444444
orig_values,
445445
goal: eager_resolve_vars(infcx, uncanonicalized_goal),
446446
result,
447-
evaluation_kind: evaluation.kind,
447+
evaluation_kind: kind,
448448
normalizes_to_term_hack: term_hack_and_nested_certainty.map(|(n, _)| n),
449449
source,
450450
}

compiler/rustc_type_ir/src/solve/inspect.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use std::hash::Hash;
2323
use derive_where::derive_where;
2424
use rustc_type_ir_macros::{TypeFoldable_Generic, TypeVisitable_Generic};
2525

26-
use crate::solve::{CandidateSource, CanonicalInput, Certainty, Goal, GoalSource, QueryResult};
26+
use crate::solve::{CandidateSource, Certainty, Goal, GoalSource, QueryResult};
2727
use crate::{Canonical, CanonicalVarValues, Interner};
2828

2929
/// Some `data` together with information about how they relate to the input
@@ -54,18 +54,12 @@ pub type CanonicalState<I, T> = Canonical<I, State<I, T>>;
5454
pub struct GoalEvaluation<I: Interner> {
5555
pub uncanonicalized_goal: Goal<I, I::Predicate>,
5656
pub orig_values: Vec<I::GenericArg>,
57-
pub evaluation: CanonicalGoalEvaluation<I>,
58-
}
59-
60-
#[derive_where(PartialEq, Eq, Hash, Debug; I: Interner)]
61-
pub struct CanonicalGoalEvaluation<I: Interner> {
62-
pub goal: CanonicalInput<I>,
63-
pub kind: CanonicalGoalEvaluationKind<I>,
57+
pub kind: GoalEvaluationKind<I>,
6458
pub result: QueryResult<I>,
6559
}
6660

6761
#[derive_where(PartialEq, Eq, Hash, Debug; I: Interner)]
68-
pub enum CanonicalGoalEvaluationKind<I: Interner> {
62+
pub enum GoalEvaluationKind<I: Interner> {
6963
Overflow,
7064
Evaluation {
7165
/// This is always `ProbeKind::Root`.

0 commit comments

Comments
 (0)