2023-06-20 12:19:40 +02:00
|
|
|
use rustc_middle::traits::query::NoSolution;
|
2023-09-11 11:34:57 +02:00
|
|
|
use rustc_middle::traits::solve::inspect::{self, CacheHit, ProbeKind};
|
2023-06-20 12:19:40 +02:00
|
|
|
use rustc_middle::traits::solve::{
|
|
|
|
CanonicalInput, Certainty, Goal, IsNormalizesToHack, QueryInput, QueryResult,
|
2023-06-08 19:10:07 +01:00
|
|
|
};
|
2023-07-04 10:01:54 +01:00
|
|
|
use rustc_middle::ty::{self, TyCtxt};
|
2023-07-04 14:56:05 +01:00
|
|
|
use rustc_session::config::DumpSolverProofTree;
|
2023-06-08 19:10:07 +01:00
|
|
|
|
2023-07-04 14:56:05 +01:00
|
|
|
use super::eval_ctxt::UseGlobalCache;
|
2023-07-04 10:01:54 +01:00
|
|
|
use super::GenerateProofTree;
|
2023-06-09 01:11:58 +01:00
|
|
|
|
2023-09-11 11:34:57 +02:00
|
|
|
#[derive(Eq, PartialEq, Debug)]
|
2023-06-08 23:24:01 +01:00
|
|
|
pub struct WipGoalEvaluation<'tcx> {
|
|
|
|
pub uncanonicalized_goal: Goal<'tcx, ty::Predicate<'tcx>>,
|
2023-08-14 11:29:42 +02:00
|
|
|
pub evaluation: Option<WipCanonicalGoalEvaluation<'tcx>>,
|
2023-06-08 23:58:34 +01:00
|
|
|
pub is_normalizes_to_hack: IsNormalizesToHack,
|
|
|
|
pub returned_goals: Vec<Goal<'tcx, ty::Predicate<'tcx>>>,
|
2023-06-08 23:24:01 +01:00
|
|
|
}
|
2023-06-20 12:40:18 +02:00
|
|
|
|
2023-06-08 23:24:01 +01:00
|
|
|
impl<'tcx> WipGoalEvaluation<'tcx> {
|
|
|
|
pub fn finalize(self) -> inspect::GoalEvaluation<'tcx> {
|
|
|
|
inspect::GoalEvaluation {
|
|
|
|
uncanonicalized_goal: self.uncanonicalized_goal,
|
2023-08-14 11:29:42 +02:00
|
|
|
evaluation: self.evaluation.unwrap().finalize(),
|
|
|
|
is_normalizes_to_hack: self.is_normalizes_to_hack,
|
|
|
|
returned_goals: self.returned_goals,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-11 15:48:04 +02:00
|
|
|
#[derive(Eq, PartialEq, Debug)]
|
|
|
|
pub enum WipGoalEvaluationKind {
|
|
|
|
Overflow,
|
|
|
|
CacheHit(CacheHit),
|
|
|
|
}
|
|
|
|
|
2023-09-11 11:34:57 +02:00
|
|
|
#[derive(Eq, PartialEq, Debug)]
|
2023-08-14 11:29:42 +02:00
|
|
|
pub struct WipCanonicalGoalEvaluation<'tcx> {
|
|
|
|
pub goal: CanonicalInput<'tcx>,
|
2023-09-11 15:48:04 +02:00
|
|
|
pub kind: Option<WipGoalEvaluationKind>,
|
|
|
|
pub revisions: Vec<WipGoalEvaluationStep<'tcx>>,
|
2023-08-14 11:29:42 +02:00
|
|
|
pub result: Option<QueryResult<'tcx>>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'tcx> WipCanonicalGoalEvaluation<'tcx> {
|
|
|
|
pub fn finalize(self) -> inspect::CanonicalGoalEvaluation<'tcx> {
|
2023-09-11 15:48:04 +02:00
|
|
|
let kind = match self.kind {
|
|
|
|
Some(WipGoalEvaluationKind::Overflow) => inspect::GoalEvaluationKind::Overflow,
|
|
|
|
Some(WipGoalEvaluationKind::CacheHit(hit)) => {
|
|
|
|
inspect::GoalEvaluationKind::CacheHit(hit)
|
2023-08-14 11:29:42 +02:00
|
|
|
}
|
2023-09-11 15:48:04 +02:00
|
|
|
None => inspect::GoalEvaluationKind::Uncached {
|
|
|
|
revisions: self
|
|
|
|
.revisions
|
|
|
|
.into_iter()
|
|
|
|
.map(WipGoalEvaluationStep::finalize)
|
|
|
|
.collect(),
|
|
|
|
},
|
2023-08-14 11:29:42 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
inspect::CanonicalGoalEvaluation { goal: self.goal, kind, result: self.result.unwrap() }
|
2023-06-08 23:24:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-11 11:34:57 +02:00
|
|
|
#[derive(Eq, PartialEq, Debug)]
|
2023-06-08 23:24:01 +01:00
|
|
|
pub struct WipAddedGoalsEvaluation<'tcx> {
|
|
|
|
pub evaluations: Vec<Vec<WipGoalEvaluation<'tcx>>>,
|
|
|
|
pub result: Option<Result<Certainty, NoSolution>>,
|
|
|
|
}
|
2023-06-20 12:40:18 +02:00
|
|
|
|
2023-06-08 23:24:01 +01:00
|
|
|
impl<'tcx> WipAddedGoalsEvaluation<'tcx> {
|
|
|
|
pub fn finalize(self) -> inspect::AddedGoalsEvaluation<'tcx> {
|
|
|
|
inspect::AddedGoalsEvaluation {
|
|
|
|
evaluations: self
|
|
|
|
.evaluations
|
|
|
|
.into_iter()
|
|
|
|
.map(|evaluations| {
|
|
|
|
evaluations.into_iter().map(WipGoalEvaluation::finalize).collect()
|
|
|
|
})
|
|
|
|
.collect(),
|
|
|
|
result: self.result.unwrap(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-11 11:34:57 +02:00
|
|
|
#[derive(Eq, PartialEq, Debug)]
|
2023-06-08 23:24:01 +01:00
|
|
|
pub struct WipGoalEvaluationStep<'tcx> {
|
|
|
|
pub instantiated_goal: QueryInput<'tcx, ty::Predicate<'tcx>>,
|
|
|
|
|
2023-09-14 09:58:29 +02:00
|
|
|
pub evaluation: WipProbe<'tcx>,
|
2023-06-08 23:24:01 +01:00
|
|
|
}
|
2023-06-20 12:40:18 +02:00
|
|
|
|
2023-06-08 23:24:01 +01:00
|
|
|
impl<'tcx> WipGoalEvaluationStep<'tcx> {
|
|
|
|
pub fn finalize(self) -> inspect::GoalEvaluationStep<'tcx> {
|
2023-09-11 15:48:04 +02:00
|
|
|
let evaluation = self.evaluation.finalize();
|
|
|
|
match evaluation.kind {
|
|
|
|
ProbeKind::Root { .. } => (),
|
|
|
|
_ => unreachable!("unexpected root evaluation: {evaluation:?}"),
|
2023-06-08 23:24:01 +01:00
|
|
|
}
|
2023-09-11 15:48:04 +02:00
|
|
|
inspect::GoalEvaluationStep { instantiated_goal: self.instantiated_goal, evaluation }
|
2023-06-08 23:24:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-11 11:34:57 +02:00
|
|
|
#[derive(Eq, PartialEq, Debug)]
|
2023-09-14 09:58:29 +02:00
|
|
|
pub struct WipProbe<'tcx> {
|
2023-08-14 11:29:42 +02:00
|
|
|
pub added_goals_evaluations: Vec<WipAddedGoalsEvaluation<'tcx>>,
|
2023-09-14 09:58:29 +02:00
|
|
|
pub nested_probes: Vec<WipProbe<'tcx>>,
|
2023-09-11 11:34:57 +02:00
|
|
|
pub kind: Option<ProbeKind<'tcx>>,
|
2023-06-08 23:24:01 +01:00
|
|
|
}
|
2023-06-20 12:40:18 +02:00
|
|
|
|
2023-09-14 09:58:29 +02:00
|
|
|
impl<'tcx> WipProbe<'tcx> {
|
|
|
|
pub fn finalize(self) -> inspect::Probe<'tcx> {
|
|
|
|
inspect::Probe {
|
2023-08-14 11:29:42 +02:00
|
|
|
added_goals_evaluations: self
|
|
|
|
.added_goals_evaluations
|
2023-06-08 23:24:01 +01:00
|
|
|
.into_iter()
|
|
|
|
.map(WipAddedGoalsEvaluation::finalize)
|
|
|
|
.collect(),
|
2023-09-14 09:58:29 +02:00
|
|
|
nested_probes: self.nested_probes.into_iter().map(WipProbe::finalize).collect(),
|
2023-06-08 23:24:01 +01:00
|
|
|
kind: self.kind.unwrap(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-08 19:10:07 +01:00
|
|
|
#[derive(Debug)]
|
|
|
|
pub enum DebugSolver<'tcx> {
|
|
|
|
Root,
|
2023-06-08 23:24:01 +01:00
|
|
|
GoalEvaluation(WipGoalEvaluation<'tcx>),
|
2023-08-14 11:29:42 +02:00
|
|
|
CanonicalGoalEvaluation(WipCanonicalGoalEvaluation<'tcx>),
|
2023-06-08 23:24:01 +01:00
|
|
|
AddedGoalsEvaluation(WipAddedGoalsEvaluation<'tcx>),
|
|
|
|
GoalEvaluationStep(WipGoalEvaluationStep<'tcx>),
|
2023-09-14 09:58:29 +02:00
|
|
|
Probe(WipProbe<'tcx>),
|
2023-06-08 19:10:07 +01:00
|
|
|
}
|
|
|
|
|
2023-06-20 12:40:18 +02:00
|
|
|
impl<'tcx> From<WipGoalEvaluation<'tcx>> for DebugSolver<'tcx> {
|
|
|
|
fn from(g: WipGoalEvaluation<'tcx>) -> DebugSolver<'tcx> {
|
|
|
|
DebugSolver::GoalEvaluation(g)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-14 11:29:42 +02:00
|
|
|
impl<'tcx> From<WipCanonicalGoalEvaluation<'tcx>> for DebugSolver<'tcx> {
|
|
|
|
fn from(g: WipCanonicalGoalEvaluation<'tcx>) -> DebugSolver<'tcx> {
|
|
|
|
DebugSolver::CanonicalGoalEvaluation(g)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-20 12:40:18 +02:00
|
|
|
impl<'tcx> From<WipAddedGoalsEvaluation<'tcx>> for DebugSolver<'tcx> {
|
|
|
|
fn from(g: WipAddedGoalsEvaluation<'tcx>) -> DebugSolver<'tcx> {
|
|
|
|
DebugSolver::AddedGoalsEvaluation(g)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'tcx> From<WipGoalEvaluationStep<'tcx>> for DebugSolver<'tcx> {
|
|
|
|
fn from(g: WipGoalEvaluationStep<'tcx>) -> DebugSolver<'tcx> {
|
|
|
|
DebugSolver::GoalEvaluationStep(g)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-14 09:58:29 +02:00
|
|
|
impl<'tcx> From<WipProbe<'tcx>> for DebugSolver<'tcx> {
|
|
|
|
fn from(p: WipProbe<'tcx>) -> DebugSolver<'tcx> {
|
|
|
|
DebugSolver::Probe(p)
|
2023-06-20 12:40:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct ProofTreeBuilder<'tcx> {
|
2023-07-04 14:56:05 +01:00
|
|
|
state: Option<Box<BuilderData<'tcx>>>,
|
|
|
|
}
|
|
|
|
|
|
|
|
struct BuilderData<'tcx> {
|
|
|
|
tree: DebugSolver<'tcx>,
|
|
|
|
use_global_cache: UseGlobalCache,
|
2023-06-20 12:40:18 +02:00
|
|
|
}
|
|
|
|
|
2023-06-08 19:58:04 +01:00
|
|
|
impl<'tcx> ProofTreeBuilder<'tcx> {
|
2023-07-03 21:00:10 +01:00
|
|
|
fn new(
|
|
|
|
state: impl Into<DebugSolver<'tcx>>,
|
2023-07-04 14:56:05 +01:00
|
|
|
use_global_cache: UseGlobalCache,
|
2023-07-03 21:00:10 +01:00
|
|
|
) -> ProofTreeBuilder<'tcx> {
|
2023-07-04 14:56:05 +01:00
|
|
|
ProofTreeBuilder {
|
|
|
|
state: Some(Box::new(BuilderData { tree: state.into(), use_global_cache })),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-14 11:48:40 +02:00
|
|
|
fn nested<T: Into<DebugSolver<'tcx>>>(&self, state: impl FnOnce() -> T) -> Self {
|
2023-07-04 14:56:05 +01:00
|
|
|
match &self.state {
|
|
|
|
Some(prev_state) => Self {
|
|
|
|
state: Some(Box::new(BuilderData {
|
2023-08-14 11:48:40 +02:00
|
|
|
tree: state().into(),
|
2023-07-04 14:56:05 +01:00
|
|
|
use_global_cache: prev_state.use_global_cache,
|
|
|
|
})),
|
|
|
|
},
|
|
|
|
None => Self { state: None },
|
|
|
|
}
|
2023-06-20 12:40:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fn as_mut(&mut self) -> Option<&mut DebugSolver<'tcx>> {
|
2023-07-04 14:56:05 +01:00
|
|
|
self.state.as_mut().map(|boxed| &mut boxed.tree)
|
2023-06-20 12:40:18 +02:00
|
|
|
}
|
|
|
|
|
2023-06-08 23:24:01 +01:00
|
|
|
pub fn finalize(self) -> Option<inspect::GoalEvaluation<'tcx>> {
|
2023-07-04 14:56:05 +01:00
|
|
|
match self.state?.tree {
|
2023-06-08 23:24:01 +01:00
|
|
|
DebugSolver::GoalEvaluation(wip_goal_evaluation) => {
|
|
|
|
Some(wip_goal_evaluation.finalize())
|
|
|
|
}
|
2023-06-08 23:58:34 +01:00
|
|
|
root => unreachable!("unexpected proof tree builder root node: {:?}", root),
|
2023-06-08 23:24:01 +01:00
|
|
|
}
|
2023-06-08 19:10:07 +01:00
|
|
|
}
|
|
|
|
|
2023-07-04 14:56:05 +01:00
|
|
|
pub fn use_global_cache(&self) -> bool {
|
|
|
|
self.state
|
|
|
|
.as_ref()
|
|
|
|
.map(|state| matches!(state.use_global_cache, UseGlobalCache::Yes))
|
|
|
|
.unwrap_or(true)
|
2023-07-03 21:00:10 +01:00
|
|
|
}
|
|
|
|
|
2023-07-04 10:01:54 +01:00
|
|
|
pub fn new_maybe_root(
|
|
|
|
tcx: TyCtxt<'tcx>,
|
|
|
|
generate_proof_tree: GenerateProofTree,
|
|
|
|
) -> ProofTreeBuilder<'tcx> {
|
|
|
|
match generate_proof_tree {
|
2023-07-10 15:17:01 +02:00
|
|
|
GenerateProofTree::Never => ProofTreeBuilder::new_noop(),
|
|
|
|
GenerateProofTree::IfEnabled => {
|
|
|
|
let opts = &tcx.sess.opts.unstable_opts;
|
|
|
|
match opts.dump_solver_proof_tree {
|
|
|
|
DumpSolverProofTree::Always => {
|
|
|
|
let use_cache = opts.dump_solver_proof_tree_use_cache.unwrap_or(true);
|
|
|
|
ProofTreeBuilder::new_root(UseGlobalCache::from_bool(use_cache))
|
|
|
|
}
|
|
|
|
// `OnError` is handled by reevaluating goals in error
|
|
|
|
// reporting with `GenerateProofTree::Yes`.
|
|
|
|
DumpSolverProofTree::OnError | DumpSolverProofTree::Never => {
|
|
|
|
ProofTreeBuilder::new_noop()
|
|
|
|
}
|
|
|
|
}
|
2023-07-04 10:01:54 +01:00
|
|
|
}
|
2023-07-10 15:17:01 +02:00
|
|
|
GenerateProofTree::Yes(use_cache) => ProofTreeBuilder::new_root(use_cache),
|
2023-07-04 10:01:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-04 14:56:05 +01:00
|
|
|
pub fn new_root(use_global_cache: UseGlobalCache) -> ProofTreeBuilder<'tcx> {
|
|
|
|
ProofTreeBuilder::new(DebugSolver::Root, use_global_cache)
|
2023-06-08 19:10:07 +01:00
|
|
|
}
|
|
|
|
|
2023-06-08 19:58:04 +01:00
|
|
|
pub fn new_noop() -> ProofTreeBuilder<'tcx> {
|
2023-07-04 14:56:05 +01:00
|
|
|
ProofTreeBuilder { state: None }
|
2023-06-08 19:10:07 +01:00
|
|
|
}
|
|
|
|
|
2023-06-08 23:24:01 +01:00
|
|
|
pub fn is_noop(&self) -> bool {
|
2023-06-20 12:40:18 +02:00
|
|
|
self.state.is_none()
|
2023-06-08 23:24:01 +01:00
|
|
|
}
|
|
|
|
|
2023-06-08 19:58:04 +01:00
|
|
|
pub fn new_goal_evaluation(
|
2023-06-08 19:10:07 +01:00
|
|
|
&mut self,
|
|
|
|
goal: Goal<'tcx, ty::Predicate<'tcx>>,
|
2023-06-08 23:58:34 +01:00
|
|
|
is_normalizes_to_hack: IsNormalizesToHack,
|
2023-06-08 19:58:04 +01:00
|
|
|
) -> ProofTreeBuilder<'tcx> {
|
2023-08-14 11:48:40 +02:00
|
|
|
self.nested(|| WipGoalEvaluation {
|
2023-07-04 14:56:05 +01:00
|
|
|
uncanonicalized_goal: goal,
|
2023-08-14 11:29:42 +02:00
|
|
|
evaluation: None,
|
2023-07-04 14:56:05 +01:00
|
|
|
is_normalizes_to_hack,
|
|
|
|
returned_goals: vec![],
|
2023-08-14 11:29:42 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn new_canonical_goal_evaluation(
|
|
|
|
&mut self,
|
|
|
|
goal: CanonicalInput<'tcx>,
|
|
|
|
) -> ProofTreeBuilder<'tcx> {
|
2023-08-14 11:48:40 +02:00
|
|
|
self.nested(|| WipCanonicalGoalEvaluation {
|
2023-08-14 11:29:42 +02:00
|
|
|
goal,
|
2023-09-11 15:48:04 +02:00
|
|
|
kind: None,
|
|
|
|
revisions: vec![],
|
2023-07-04 14:56:05 +01:00
|
|
|
result: None,
|
|
|
|
})
|
2023-06-08 19:10:07 +01:00
|
|
|
}
|
2023-06-20 12:40:18 +02:00
|
|
|
|
2023-08-14 11:29:42 +02:00
|
|
|
pub fn canonical_goal_evaluation(&mut self, canonical_goal_evaluation: ProofTreeBuilder<'tcx>) {
|
2023-06-20 12:40:18 +02:00
|
|
|
if let Some(this) = self.as_mut() {
|
2023-08-14 11:29:42 +02:00
|
|
|
match (this, canonical_goal_evaluation.state.unwrap().tree) {
|
|
|
|
(
|
|
|
|
DebugSolver::GoalEvaluation(goal_evaluation),
|
|
|
|
DebugSolver::CanonicalGoalEvaluation(canonical_goal_evaluation),
|
|
|
|
) => goal_evaluation.evaluation = Some(canonical_goal_evaluation),
|
2023-06-20 12:40:18 +02:00
|
|
|
_ => unreachable!(),
|
2023-06-08 19:10:07 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-06-20 12:40:18 +02:00
|
|
|
|
2023-09-11 15:48:04 +02:00
|
|
|
pub fn goal_evaluation_kind(&mut self, kind: WipGoalEvaluationKind) {
|
2023-06-20 12:40:18 +02:00
|
|
|
if let Some(this) = self.as_mut() {
|
|
|
|
match this {
|
2023-08-14 11:29:42 +02:00
|
|
|
DebugSolver::CanonicalGoalEvaluation(canonical_goal_evaluation) => {
|
2023-09-11 15:48:04 +02:00
|
|
|
assert_eq!(canonical_goal_evaluation.kind.replace(kind), None);
|
2023-06-20 12:40:18 +02:00
|
|
|
}
|
|
|
|
_ => unreachable!(),
|
|
|
|
};
|
|
|
|
}
|
2023-06-08 19:10:07 +01:00
|
|
|
}
|
2023-06-20 12:40:18 +02:00
|
|
|
|
2023-06-08 23:58:34 +01:00
|
|
|
pub fn returned_goals(&mut self, goals: &[Goal<'tcx, ty::Predicate<'tcx>>]) {
|
2023-06-20 12:40:18 +02:00
|
|
|
if let Some(this) = self.as_mut() {
|
|
|
|
match this {
|
|
|
|
DebugSolver::GoalEvaluation(evaluation) => {
|
|
|
|
assert!(evaluation.returned_goals.is_empty());
|
|
|
|
evaluation.returned_goals.extend(goals);
|
|
|
|
}
|
|
|
|
_ => unreachable!(),
|
2023-06-08 23:58:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-06-08 19:58:04 +01:00
|
|
|
pub fn goal_evaluation(&mut self, goal_evaluation: ProofTreeBuilder<'tcx>) {
|
2023-06-20 12:40:18 +02:00
|
|
|
if let Some(this) = self.as_mut() {
|
2023-07-04 14:56:05 +01:00
|
|
|
match (this, goal_evaluation.state.unwrap().tree) {
|
2023-06-20 12:40:18 +02:00
|
|
|
(
|
|
|
|
DebugSolver::AddedGoalsEvaluation(WipAddedGoalsEvaluation {
|
|
|
|
evaluations, ..
|
|
|
|
}),
|
|
|
|
DebugSolver::GoalEvaluation(goal_evaluation),
|
|
|
|
) => evaluations.last_mut().unwrap().push(goal_evaluation),
|
|
|
|
(this @ DebugSolver::Root, goal_evaluation) => *this = goal_evaluation,
|
|
|
|
_ => unreachable!(),
|
|
|
|
}
|
2023-06-08 19:10:07 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-08 19:58:04 +01:00
|
|
|
pub fn new_goal_evaluation_step(
|
2023-06-08 19:10:07 +01:00
|
|
|
&mut self,
|
|
|
|
instantiated_goal: QueryInput<'tcx, ty::Predicate<'tcx>>,
|
2023-06-08 19:58:04 +01:00
|
|
|
) -> ProofTreeBuilder<'tcx> {
|
2023-08-14 11:48:40 +02:00
|
|
|
self.nested(|| WipGoalEvaluationStep {
|
2023-07-04 14:56:05 +01:00
|
|
|
instantiated_goal,
|
2023-09-14 09:58:29 +02:00
|
|
|
evaluation: WipProbe {
|
2023-09-11 15:48:04 +02:00
|
|
|
added_goals_evaluations: vec![],
|
2023-09-14 09:58:29 +02:00
|
|
|
nested_probes: vec![],
|
2023-09-11 15:48:04 +02:00
|
|
|
kind: None,
|
|
|
|
},
|
2023-07-04 14:56:05 +01:00
|
|
|
})
|
2023-06-08 19:10:07 +01:00
|
|
|
}
|
2023-08-14 11:29:42 +02:00
|
|
|
pub fn goal_evaluation_step(&mut self, goal_evaluation_step: ProofTreeBuilder<'tcx>) {
|
2023-06-20 12:40:18 +02:00
|
|
|
if let Some(this) = self.as_mut() {
|
2023-08-14 11:29:42 +02:00
|
|
|
match (this, goal_evaluation_step.state.unwrap().tree) {
|
|
|
|
(
|
|
|
|
DebugSolver::CanonicalGoalEvaluation(canonical_goal_evaluations),
|
|
|
|
DebugSolver::GoalEvaluationStep(goal_evaluation_step),
|
|
|
|
) => {
|
2023-09-11 15:48:04 +02:00
|
|
|
canonical_goal_evaluations.revisions.push(goal_evaluation_step);
|
2023-06-20 12:40:18 +02:00
|
|
|
}
|
|
|
|
_ => unreachable!(),
|
2023-06-08 19:10:07 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-14 09:58:29 +02:00
|
|
|
pub fn new_probe(&mut self) -> ProofTreeBuilder<'tcx> {
|
|
|
|
self.nested(|| WipProbe {
|
2023-08-14 11:29:42 +02:00
|
|
|
added_goals_evaluations: vec![],
|
2023-09-14 09:58:29 +02:00
|
|
|
nested_probes: vec![],
|
2023-07-04 14:56:05 +01:00
|
|
|
kind: None,
|
|
|
|
})
|
2023-06-08 19:10:07 +01:00
|
|
|
}
|
2023-06-20 12:40:18 +02:00
|
|
|
|
2023-09-11 11:34:57 +02:00
|
|
|
pub fn probe_kind(&mut self, probe_kind: ProbeKind<'tcx>) {
|
2023-06-20 12:40:18 +02:00
|
|
|
if let Some(this) = self.as_mut() {
|
|
|
|
match this {
|
2023-09-14 09:58:29 +02:00
|
|
|
DebugSolver::Probe(this) => {
|
2023-09-11 11:34:57 +02:00
|
|
|
assert_eq!(this.kind.replace(probe_kind), None)
|
2023-06-20 12:40:18 +02:00
|
|
|
}
|
|
|
|
_ => unreachable!(),
|
2023-06-08 19:10:07 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-06-20 12:40:18 +02:00
|
|
|
|
2023-09-14 09:58:29 +02:00
|
|
|
pub fn finish_probe(&mut self, probe: ProofTreeBuilder<'tcx>) {
|
2023-06-20 12:40:18 +02:00
|
|
|
if let Some(this) = self.as_mut() {
|
2023-09-14 09:58:29 +02:00
|
|
|
match (this, probe.state.unwrap().tree) {
|
2023-06-20 12:40:18 +02:00
|
|
|
(
|
2023-09-14 09:58:29 +02:00
|
|
|
DebugSolver::Probe(WipProbe { nested_probes, .. })
|
2023-09-11 15:48:04 +02:00
|
|
|
| DebugSolver::GoalEvaluationStep(WipGoalEvaluationStep {
|
2023-09-14 09:58:29 +02:00
|
|
|
evaluation: WipProbe { nested_probes, .. },
|
2023-09-11 15:48:04 +02:00
|
|
|
..
|
|
|
|
}),
|
2023-09-14 09:58:29 +02:00
|
|
|
DebugSolver::Probe(probe),
|
|
|
|
) => nested_probes.push(probe),
|
2023-06-20 12:40:18 +02:00
|
|
|
_ => unreachable!(),
|
|
|
|
}
|
2023-06-08 19:10:07 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-08 19:58:04 +01:00
|
|
|
pub fn new_evaluate_added_goals(&mut self) -> ProofTreeBuilder<'tcx> {
|
2023-08-14 11:48:40 +02:00
|
|
|
self.nested(|| WipAddedGoalsEvaluation { evaluations: vec![], result: None })
|
2023-06-08 19:10:07 +01:00
|
|
|
}
|
2023-06-20 12:40:18 +02:00
|
|
|
|
2023-06-08 19:58:04 +01:00
|
|
|
pub fn evaluate_added_goals_loop_start(&mut self) {
|
2023-06-20 12:40:18 +02:00
|
|
|
if let Some(this) = self.as_mut() {
|
|
|
|
match this {
|
|
|
|
DebugSolver::AddedGoalsEvaluation(this) => {
|
|
|
|
this.evaluations.push(vec![]);
|
|
|
|
}
|
|
|
|
_ => unreachable!(),
|
2023-06-08 19:10:07 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-06-20 12:40:18 +02:00
|
|
|
|
2023-06-08 19:58:04 +01:00
|
|
|
pub fn eval_added_goals_result(&mut self, result: Result<Certainty, NoSolution>) {
|
2023-06-20 12:40:18 +02:00
|
|
|
if let Some(this) = self.as_mut() {
|
|
|
|
match this {
|
|
|
|
DebugSolver::AddedGoalsEvaluation(this) => {
|
|
|
|
assert_eq!(this.result.replace(result), None);
|
|
|
|
}
|
|
|
|
_ => unreachable!(),
|
2023-06-08 19:10:07 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-06-20 12:40:18 +02:00
|
|
|
|
2023-08-14 11:29:42 +02:00
|
|
|
pub fn added_goals_evaluation(&mut self, added_goals_evaluation: ProofTreeBuilder<'tcx>) {
|
2023-06-20 12:40:18 +02:00
|
|
|
if let Some(this) = self.as_mut() {
|
2023-08-14 11:29:42 +02:00
|
|
|
match (this, added_goals_evaluation.state.unwrap().tree) {
|
2023-06-20 12:40:18 +02:00
|
|
|
(
|
|
|
|
DebugSolver::GoalEvaluationStep(WipGoalEvaluationStep {
|
2023-09-14 09:58:29 +02:00
|
|
|
evaluation: WipProbe { added_goals_evaluations, .. },
|
2023-06-20 12:40:18 +02:00
|
|
|
..
|
|
|
|
})
|
2023-09-14 09:58:29 +02:00
|
|
|
| DebugSolver::Probe(WipProbe { added_goals_evaluations, .. }),
|
2023-06-20 12:40:18 +02:00
|
|
|
DebugSolver::AddedGoalsEvaluation(added_goals_evaluation),
|
2023-08-14 11:29:42 +02:00
|
|
|
) => added_goals_evaluations.push(added_goals_evaluation),
|
2023-06-20 12:40:18 +02:00
|
|
|
_ => unreachable!(),
|
|
|
|
}
|
2023-06-08 19:10:07 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-08 19:58:04 +01:00
|
|
|
pub fn query_result(&mut self, result: QueryResult<'tcx>) {
|
2023-06-20 12:40:18 +02:00
|
|
|
if let Some(this) = self.as_mut() {
|
|
|
|
match this {
|
2023-08-14 11:29:42 +02:00
|
|
|
DebugSolver::CanonicalGoalEvaluation(canonical_goal_evaluation) => {
|
|
|
|
assert_eq!(canonical_goal_evaluation.result.replace(result), None);
|
2023-06-20 12:40:18 +02:00
|
|
|
}
|
|
|
|
DebugSolver::GoalEvaluationStep(evaluation_step) => {
|
2023-09-11 15:48:04 +02:00
|
|
|
assert_eq!(
|
|
|
|
evaluation_step.evaluation.kind.replace(ProbeKind::Root { result }),
|
|
|
|
None
|
|
|
|
);
|
2023-06-20 12:40:18 +02:00
|
|
|
}
|
2023-08-14 11:29:42 +02:00
|
|
|
_ => unreachable!(),
|
2023-06-08 19:10:07 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|