Skip to content

Commit e8e32c3

Browse files
committed
inspect: merge [Canonical]GoalEvaluation
1 parent 5132e6c commit e8e32c3

File tree

4 files changed

+33
-97
lines changed

4 files changed

+33
-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
@@ -453,21 +453,16 @@ where
453453
let (orig_values, canonical_goal) = self.canonicalize_goal(goal);
454454
let mut goal_evaluation =
455455
self.inspect.new_goal_evaluation(goal, &orig_values, goal_evaluation_kind);
456-
let mut canonical_goal_evaluation =
457-
goal_evaluation.new_canonical_goal_evaluation(canonical_goal);
458-
let canonical_response = self.search_graph.evaluate_goal(
456+
let canonical_result = self.search_graph.evaluate_goal(
459457
self.cx(),
460458
canonical_goal,
461459
self.step_kind_for_source(source),
462-
&mut canonical_goal_evaluation,
460+
&mut goal_evaluation,
463461
);
464-
canonical_goal_evaluation.query_result(canonical_response);
465-
goal_evaluation.canonical_goal_evaluation(canonical_goal_evaluation);
466-
let response = match canonical_response {
467-
Err(e) => {
468-
self.inspect.goal_evaluation(goal_evaluation);
469-
return Err(e);
470-
}
462+
goal_evaluation.query_result(canonical_result);
463+
self.inspect.goal_evaluation(goal_evaluation);
464+
let response = match canonical_result {
465+
Err(e) => return Err(e),
471466
Ok(response) => response,
472467
};
473468

@@ -476,7 +471,6 @@ where
476471

477472
let (normalization_nested_goals, certainty) =
478473
self.instantiate_and_apply_query_response(goal.param_env, &orig_values, response);
479-
self.inspect.goal_evaluation(goal_evaluation);
480474

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

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

Lines changed: 18 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,23 @@ 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+
/// After we finished evaluating this is moved into `kind`.
77+
pub final_revision: Option<WipCanonicalGoalEvaluationStep<I>>,
78+
pub result: Option<QueryResult<I>>,
8479
}
8580

8681
impl<I: Interner> WipGoalEvaluation<I> {
8782
fn finalize(self) -> inspect::GoalEvaluation<I> {
8883
inspect::GoalEvaluation {
8984
uncanonicalized_goal: self.uncanonicalized_goal,
9085
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,
11086
kind: if self.encountered_overflow {
11187
assert!(self.final_revision.is_none());
112-
inspect::CanonicalGoalEvaluationKind::Overflow
88+
inspect::GoalEvaluationKind::Overflow
11389
} else {
11490
let final_revision = self.final_revision.unwrap().finalize();
115-
inspect::CanonicalGoalEvaluationKind::Evaluation { final_revision }
91+
inspect::GoalEvaluationKind::Evaluation { final_revision }
11692
},
11793
result: self.result.unwrap(),
11894
}
@@ -256,55 +232,27 @@ impl<D: SolverDelegate<Interner = I>, I: Interner> ProofTreeBuilder<D> {
256232

257233
pub(in crate::solve) fn new_goal_evaluation(
258234
&mut self,
259-
goal: Goal<I, I::Predicate>,
235+
uncanonicalized_goal: Goal<I, I::Predicate>,
260236
orig_values: &[I::GenericArg],
261237
kind: GoalEvaluationKind,
262238
) -> ProofTreeBuilder<D> {
263239
self.opt_nested(|| match kind {
264240
GoalEvaluationKind::Root => Some(WipGoalEvaluation {
265-
uncanonicalized_goal: goal,
241+
uncanonicalized_goal,
266242
orig_values: orig_values.to_vec(),
267-
evaluation: None,
243+
encountered_overflow: false,
244+
final_revision: None,
245+
result: None,
268246
}),
269247
GoalEvaluationKind::Nested => None,
270248
})
271249
}
272250

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-
303251
pub(crate) fn canonical_goal_evaluation_overflow(&mut self) {
304252
if let Some(this) = self.as_mut() {
305253
match this {
306-
DebugSolver::CanonicalGoalEvaluation(canonical_goal_evaluation) => {
307-
canonical_goal_evaluation.encountered_overflow = true;
254+
DebugSolver::GoalEvaluation(goal_evaluation) => {
255+
goal_evaluation.encountered_overflow = true;
308256
}
309257
_ => unreachable!(),
310258
};
@@ -343,10 +291,10 @@ impl<D: SolverDelegate<Interner = I>, I: Interner> ProofTreeBuilder<D> {
343291
if let Some(this) = self.as_mut() {
344292
match (this, *goal_evaluation_step.state.unwrap()) {
345293
(
346-
DebugSolver::CanonicalGoalEvaluation(canonical_goal_evaluations),
294+
DebugSolver::GoalEvaluation(goal_evaluation),
347295
DebugSolver::CanonicalGoalEvaluationStep(goal_evaluation_step),
348296
) => {
349-
canonical_goal_evaluations.final_revision = Some(goal_evaluation_step);
297+
goal_evaluation.final_revision = Some(goal_evaluation_step);
350298
}
351299
_ => unreachable!(),
352300
}
@@ -489,8 +437,8 @@ impl<D: SolverDelegate<Interner = I>, I: Interner> ProofTreeBuilder<D> {
489437
pub(crate) fn query_result(&mut self, result: QueryResult<I>) {
490438
if let Some(this) = self.as_mut() {
491439
match this {
492-
DebugSolver::CanonicalGoalEvaluation(canonical_goal_evaluation) => {
493-
assert_eq!(canonical_goal_evaluation.result.replace(result), None);
440+
DebugSolver::GoalEvaluation(goal_evaluation) => {
441+
assert_eq!(goal_evaluation.result.replace(result), None);
494442
}
495443
DebugSolver::CanonicalGoalEvaluationStep(evaluation_step) => {
496444
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)