about summary refs log tree commit diff
path: root/compiler/rustc_middle
diff options
context:
space:
mode:
authorlcnr <rust@lcnr.de>2023-08-14 11:29:42 +0200
committerlcnr <rust@lcnr.de>2023-09-11 11:51:32 +0200
commitfc452e2ed3a173dfbfc28fce8bca08170da53111 (patch)
tree5e586bea7eadb1ee22fe5efad8750ec095460e86 /compiler/rustc_middle
parent7d1e416d3234bdfed6443dc2e4301f2d6f063525 (diff)
downloadrust-fc452e2ed3a173dfbfc28fce8bca08170da53111.tar.gz
rust-fc452e2ed3a173dfbfc28fce8bca08170da53111.zip
split GoalEvaluation and CanonicalGoalEvaluation
the unnormalized goal is in the callers inference context, while
anything inside of the `CanonicalGoalEvaluation` is inside of
a new one.
Diffstat (limited to 'compiler/rustc_middle')
-rw-r--r--compiler/rustc_middle/src/traits/solve/inspect.rs28
-rw-r--r--compiler/rustc_middle/src/traits/solve/inspect/format.rs65
2 files changed, 43 insertions, 50 deletions
diff --git a/compiler/rustc_middle/src/traits/solve/inspect.rs b/compiler/rustc_middle/src/traits/solve/inspect.rs
index 4e2af3816ac..dc51ded1b80 100644
--- a/compiler/rustc_middle/src/traits/solve/inspect.rs
+++ b/compiler/rustc_middle/src/traits/solve/inspect.rs
@@ -16,12 +16,15 @@ pub enum CacheHit {
 #[derive(Eq, PartialEq, Hash, HashStable)]
 pub struct GoalEvaluation<'tcx> {
     pub uncanonicalized_goal: Goal<'tcx, ty::Predicate<'tcx>>,
-    pub canonicalized_goal: CanonicalInput<'tcx>,
-
-    pub kind: GoalEvaluationKind<'tcx>,
     pub is_normalizes_to_hack: IsNormalizesToHack,
+    pub evaluation: CanonicalGoalEvaluation<'tcx>,
     pub returned_goals: Vec<Goal<'tcx, ty::Predicate<'tcx>>>,
+}
 
+#[derive(Eq, PartialEq, Hash, HashStable)]
+pub struct CanonicalGoalEvaluation<'tcx> {
+    pub goal: CanonicalInput<'tcx>,
+    pub kind: GoalEvaluationKind<'tcx>,
     pub result: QueryResult<'tcx>,
 }
 
@@ -41,30 +44,20 @@ pub struct AddedGoalsEvaluation<'tcx> {
     pub evaluations: Vec<Vec<GoalEvaluation<'tcx>>>,
     pub result: Result<Certainty, NoSolution>,
 }
-impl Debug for AddedGoalsEvaluation<'_> {
-    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
-        ProofTreeFormatter::new(f).format_nested_goal_evaluation(self)
-    }
-}
 
 #[derive(Eq, PartialEq, Hash, HashStable)]
 pub struct GoalEvaluationStep<'tcx> {
     pub instantiated_goal: QueryInput<'tcx, ty::Predicate<'tcx>>,
 
-    pub nested_goal_evaluations: Vec<AddedGoalsEvaluation<'tcx>>,
+    pub added_goals_evaluations: Vec<AddedGoalsEvaluation<'tcx>>,
     pub candidates: Vec<GoalCandidate<'tcx>>,
 
     pub result: QueryResult<'tcx>,
 }
-impl Debug for GoalEvaluationStep<'_> {
-    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
-        ProofTreeFormatter::new(f).format_evaluation_step(self)
-    }
-}
 
 #[derive(Eq, PartialEq, Hash, HashStable)]
 pub struct GoalCandidate<'tcx> {
-    pub nested_goal_evaluations: Vec<AddedGoalsEvaluation<'tcx>>,
+    pub added_goals_evaluations: Vec<AddedGoalsEvaluation<'tcx>>,
     pub candidates: Vec<GoalCandidate<'tcx>>,
     pub kind: CandidateKind<'tcx>,
 }
@@ -83,8 +76,3 @@ pub enum CandidateKind<'tcx> {
     /// the source type upholds all of the target type's object bounds.
     UpcastProbe,
 }
-impl Debug for GoalCandidate<'_> {
-    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
-        ProofTreeFormatter::new(f).format_candidate(self)
-    }
-}
diff --git a/compiler/rustc_middle/src/traits/solve/inspect/format.rs b/compiler/rustc_middle/src/traits/solve/inspect/format.rs
index 8759fecb05a..a9f2b76baf9 100644
--- a/compiler/rustc_middle/src/traits/solve/inspect/format.rs
+++ b/compiler/rustc_middle/src/traits/solve/inspect/format.rs
@@ -39,44 +39,49 @@ impl<'a, 'b> ProofTreeFormatter<'a, 'b> {
         func(&mut ProofTreeFormatter { f: &mut Indentor { f: self.f, on_newline: true } })
     }
 
-    pub(super) fn format_goal_evaluation(&mut self, goal: &GoalEvaluation<'_>) -> std::fmt::Result {
-        let goal_text = match goal.is_normalizes_to_hack {
+    pub(super) fn format_goal_evaluation(&mut self, eval: &GoalEvaluation<'_>) -> std::fmt::Result {
+        let goal_text = match eval.is_normalizes_to_hack {
             IsNormalizesToHack::Yes => "NORMALIZES-TO HACK GOAL",
             IsNormalizesToHack::No => "GOAL",
         };
+        writeln!(self.f, "{}: {:?}", goal_text, eval.uncanonicalized_goal)?;
+        self.nested(|this| this.format_canonical_goal_evaluation(&eval.evaluation))?;
+        if eval.returned_goals.len() > 0 {
+            writeln!(self.f, "NESTED GOALS ADDED TO CALLER: [")?;
+            self.nested(|this| {
+                for goal in eval.returned_goals.iter() {
+                    writeln!(this.f, "ADDED GOAL: {goal:?},")?;
+                }
+                Ok(())
+            })?;
 
-        writeln!(self.f, "{}: {:?}", goal_text, goal.uncanonicalized_goal)?;
-        writeln!(self.f, "CANONICALIZED: {:?}", goal.canonicalized_goal)?;
+            writeln!(self.f, "]")
+        } else {
+            Ok(())
+        }
+    }
+
+    pub(super) fn format_canonical_goal_evaluation(
+        &mut self,
+        eval: &CanonicalGoalEvaluation<'_>,
+    ) -> std::fmt::Result {
+        writeln!(self.f, "GOAL: {:?}", eval.goal)?;
 
-        match &goal.kind {
+        match &eval.kind {
             GoalEvaluationKind::CacheHit(CacheHit::Global) => {
-                writeln!(self.f, "GLOBAL CACHE HIT: {:?}", goal.result)
+                writeln!(self.f, "GLOBAL CACHE HIT: {:?}", eval.result)
             }
             GoalEvaluationKind::CacheHit(CacheHit::Provisional) => {
-                writeln!(self.f, "PROVISIONAL CACHE HIT: {:?}", goal.result)
+                writeln!(self.f, "PROVISIONAL CACHE HIT: {:?}", eval.result)
             }
             GoalEvaluationKind::Uncached { revisions } => {
                 for (n, step) in revisions.iter().enumerate() {
                     writeln!(self.f, "REVISION {n}: {:?}", step.result)?;
                     self.nested(|this| this.format_evaluation_step(step))?;
                 }
-                writeln!(self.f, "RESULT: {:?}", goal.result)
+                writeln!(self.f, "RESULT: {:?}", eval.result)
             }
-        }?;
-
-        if goal.returned_goals.len() > 0 {
-            writeln!(self.f, "NESTED GOALS ADDED TO CALLER: [")?;
-            self.nested(|this| {
-                for goal in goal.returned_goals.iter() {
-                    writeln!(this.f, "ADDED GOAL: {goal:?},")?;
-                }
-                Ok(())
-            })?;
-
-            writeln!(self.f, "]")?;
         }
-
-        Ok(())
     }
 
     pub(super) fn format_evaluation_step(
@@ -88,8 +93,8 @@ impl<'a, 'b> ProofTreeFormatter<'a, 'b> {
         for candidate in &evaluation_step.candidates {
             self.nested(|this| this.format_candidate(candidate))?;
         }
-        for nested in &evaluation_step.nested_goal_evaluations {
-            self.nested(|this| this.format_nested_goal_evaluation(nested))?;
+        for nested in &evaluation_step.added_goals_evaluations {
+            self.nested(|this| this.format_added_goals_evaluation(nested))?;
         }
 
         Ok(())
@@ -115,20 +120,20 @@ impl<'a, 'b> ProofTreeFormatter<'a, 'b> {
             for candidate in &candidate.candidates {
                 this.format_candidate(candidate)?;
             }
-            for nested in &candidate.nested_goal_evaluations {
-                this.format_nested_goal_evaluation(nested)?;
+            for nested in &candidate.added_goals_evaluations {
+                this.format_added_goals_evaluation(nested)?;
             }
             Ok(())
         })
     }
 
-    pub(super) fn format_nested_goal_evaluation(
+    pub(super) fn format_added_goals_evaluation(
         &mut self,
-        nested_goal_evaluation: &AddedGoalsEvaluation<'_>,
+        added_goals_evaluation: &AddedGoalsEvaluation<'_>,
     ) -> std::fmt::Result {
-        writeln!(self.f, "TRY_EVALUATE_ADDED_GOALS: {:?}", nested_goal_evaluation.result)?;
+        writeln!(self.f, "TRY_EVALUATE_ADDED_GOALS: {:?}", added_goals_evaluation.result)?;
 
-        for (n, revision) in nested_goal_evaluation.evaluations.iter().enumerate() {
+        for (n, revision) in added_goals_evaluation.evaluations.iter().enumerate() {
             writeln!(self.f, "REVISION {n}")?;
             self.nested(|this| {
                 for goal_evaluation in revision {