1
Fork 0

inspect nits

This commit is contained in:
lcnr 2023-06-20 12:40:18 +02:00
parent f7472aa69e
commit e4b171a198

View file

@ -20,6 +20,7 @@ pub struct WipGoalEvaluation<'tcx> {
pub result: Option<QueryResult<'tcx>>, pub result: Option<QueryResult<'tcx>>,
} }
impl<'tcx> WipGoalEvaluation<'tcx> { impl<'tcx> WipGoalEvaluation<'tcx> {
pub fn finalize(self) -> inspect::GoalEvaluation<'tcx> { pub fn finalize(self) -> inspect::GoalEvaluation<'tcx> {
inspect::GoalEvaluation { inspect::GoalEvaluation {
@ -47,6 +48,7 @@ pub struct WipAddedGoalsEvaluation<'tcx> {
pub evaluations: Vec<Vec<WipGoalEvaluation<'tcx>>>, pub evaluations: Vec<Vec<WipGoalEvaluation<'tcx>>>,
pub result: Option<Result<Certainty, NoSolution>>, pub result: Option<Result<Certainty, NoSolution>>,
} }
impl<'tcx> WipAddedGoalsEvaluation<'tcx> { impl<'tcx> WipAddedGoalsEvaluation<'tcx> {
pub fn finalize(self) -> inspect::AddedGoalsEvaluation<'tcx> { pub fn finalize(self) -> inspect::AddedGoalsEvaluation<'tcx> {
inspect::AddedGoalsEvaluation { inspect::AddedGoalsEvaluation {
@ -71,6 +73,7 @@ pub struct WipGoalEvaluationStep<'tcx> {
pub result: Option<QueryResult<'tcx>>, pub result: Option<QueryResult<'tcx>>,
} }
impl<'tcx> WipGoalEvaluationStep<'tcx> { impl<'tcx> WipGoalEvaluationStep<'tcx> {
pub fn finalize(self) -> inspect::GoalEvaluationStep<'tcx> { pub fn finalize(self) -> inspect::GoalEvaluationStep<'tcx> {
inspect::GoalEvaluationStep { inspect::GoalEvaluationStep {
@ -92,6 +95,7 @@ pub struct WipGoalCandidate<'tcx> {
pub candidates: Vec<WipGoalCandidate<'tcx>>, pub candidates: Vec<WipGoalCandidate<'tcx>>,
pub kind: Option<CandidateKind<'tcx>>, pub kind: Option<CandidateKind<'tcx>>,
} }
impl<'tcx> WipGoalCandidate<'tcx> { impl<'tcx> WipGoalCandidate<'tcx> {
pub fn finalize(self) -> inspect::GoalCandidate<'tcx> { pub fn finalize(self) -> inspect::GoalCandidate<'tcx> {
inspect::GoalCandidate { inspect::GoalCandidate {
@ -115,10 +119,45 @@ pub enum DebugSolver<'tcx> {
GoalCandidate(WipGoalCandidate<'tcx>), GoalCandidate(WipGoalCandidate<'tcx>),
} }
pub struct ProofTreeBuilder<'tcx>(Option<Box<DebugSolver<'tcx>>>); impl<'tcx> From<WipGoalEvaluation<'tcx>> for DebugSolver<'tcx> {
fn from(g: WipGoalEvaluation<'tcx>) -> DebugSolver<'tcx> {
DebugSolver::GoalEvaluation(g)
}
}
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)
}
}
impl<'tcx> From<WipGoalCandidate<'tcx>> for DebugSolver<'tcx> {
fn from(g: WipGoalCandidate<'tcx>) -> DebugSolver<'tcx> {
DebugSolver::GoalCandidate(g)
}
}
pub struct ProofTreeBuilder<'tcx> {
state: Option<Box<DebugSolver<'tcx>>>,
}
impl<'tcx> ProofTreeBuilder<'tcx> { impl<'tcx> ProofTreeBuilder<'tcx> {
fn new(state: impl Into<DebugSolver<'tcx>>) -> ProofTreeBuilder<'tcx> {
ProofTreeBuilder { state: Some(Box::new(state.into())) }
}
fn as_mut(&mut self) -> Option<&mut DebugSolver<'tcx>> {
self.state.as_mut().map(|boxed| &mut **boxed)
}
pub fn finalize(self) -> Option<inspect::GoalEvaluation<'tcx>> { pub fn finalize(self) -> Option<inspect::GoalEvaluation<'tcx>> {
match *(self.0?) { match *(self.state?) {
DebugSolver::GoalEvaluation(wip_goal_evaluation) => { DebugSolver::GoalEvaluation(wip_goal_evaluation) => {
Some(wip_goal_evaluation.finalize()) Some(wip_goal_evaluation.finalize())
} }
@ -127,15 +166,15 @@ impl<'tcx> ProofTreeBuilder<'tcx> {
} }
pub fn new_root() -> ProofTreeBuilder<'tcx> { pub fn new_root() -> ProofTreeBuilder<'tcx> {
Self(Some(Box::new(DebugSolver::Root))) ProofTreeBuilder::new(DebugSolver::Root)
} }
pub fn new_noop() -> ProofTreeBuilder<'tcx> { pub fn new_noop() -> ProofTreeBuilder<'tcx> {
Self(None) ProofTreeBuilder { state: None }
} }
pub fn is_noop(&self) -> bool { pub fn is_noop(&self) -> bool {
self.0.is_none() self.state.is_none()
} }
pub fn new_goal_evaluation( pub fn new_goal_evaluation(
@ -143,11 +182,11 @@ impl<'tcx> ProofTreeBuilder<'tcx> {
goal: Goal<'tcx, ty::Predicate<'tcx>>, goal: Goal<'tcx, ty::Predicate<'tcx>>,
is_normalizes_to_hack: IsNormalizesToHack, is_normalizes_to_hack: IsNormalizesToHack,
) -> ProofTreeBuilder<'tcx> { ) -> ProofTreeBuilder<'tcx> {
if self.0.is_none() { if self.state.is_none() {
return ProofTreeBuilder(None); return ProofTreeBuilder { state: None };
} }
Self(Some(Box::new(DebugSolver::GoalEvaluation(WipGoalEvaluation { ProofTreeBuilder::new(WipGoalEvaluation {
uncanonicalized_goal: goal, uncanonicalized_goal: goal,
canonicalized_goal: None, canonicalized_goal: None,
evaluation_steps: vec![], evaluation_steps: vec![],
@ -155,41 +194,33 @@ impl<'tcx> ProofTreeBuilder<'tcx> {
cache_hit: None, cache_hit: None,
returned_goals: vec![], returned_goals: vec![],
result: None, result: None,
})))) })
} }
pub fn canonicalized_goal(&mut self, canonical_goal: CanonicalInput<'tcx>) { pub fn canonicalized_goal(&mut self, canonical_goal: CanonicalInput<'tcx>) {
let this = match self.0.as_mut() { if let Some(this) = self.as_mut() {
None => return,
Some(this) => &mut **this,
};
match this { match this {
DebugSolver::GoalEvaluation(goal_evaluation) => { DebugSolver::GoalEvaluation(goal_evaluation) => {
assert!(goal_evaluation.canonicalized_goal.is_none()); assert_eq!(goal_evaluation.canonicalized_goal.replace(canonical_goal), None);
goal_evaluation.canonicalized_goal = Some(canonical_goal)
} }
_ => unreachable!(), _ => unreachable!(),
} }
} }
}
pub fn cache_hit(&mut self, cache_hit: CacheHit) { pub fn cache_hit(&mut self, cache_hit: CacheHit) {
let this = match self.0.as_mut() { if let Some(this) = self.as_mut() {
None => return,
Some(this) => &mut **this,
};
match this { match this {
DebugSolver::GoalEvaluation(goal_evaluation) => { DebugSolver::GoalEvaluation(goal_evaluation) => {
goal_evaluation.cache_hit = Some(cache_hit) assert_eq!(goal_evaluation.cache_hit.replace(cache_hit), None);
} }
_ => unreachable!(), _ => unreachable!(),
}; };
} }
pub fn returned_goals(&mut self, goals: &[Goal<'tcx, ty::Predicate<'tcx>>]) { }
let this = match self.0.as_mut() {
None => return,
Some(this) => &mut **this,
};
pub fn returned_goals(&mut self, goals: &[Goal<'tcx, ty::Predicate<'tcx>>]) {
if let Some(this) = self.as_mut() {
match this { match this {
DebugSolver::GoalEvaluation(evaluation) => { DebugSolver::GoalEvaluation(evaluation) => {
assert!(evaluation.returned_goals.is_empty()); assert!(evaluation.returned_goals.is_empty());
@ -198,82 +229,74 @@ impl<'tcx> ProofTreeBuilder<'tcx> {
_ => unreachable!(), _ => unreachable!(),
} }
} }
}
pub fn goal_evaluation(&mut self, goal_evaluation: ProofTreeBuilder<'tcx>) { pub fn goal_evaluation(&mut self, goal_evaluation: ProofTreeBuilder<'tcx>) {
let this = match self.0.as_mut() { if let Some(this) = self.as_mut() {
None => return, match (this, *goal_evaluation.state.unwrap()) {
Some(this) => &mut **this,
};
match (this, *goal_evaluation.0.unwrap()) {
( (
DebugSolver::AddedGoalsEvaluation(WipAddedGoalsEvaluation { evaluations, .. }), DebugSolver::AddedGoalsEvaluation(WipAddedGoalsEvaluation {
evaluations, ..
}),
DebugSolver::GoalEvaluation(goal_evaluation), DebugSolver::GoalEvaluation(goal_evaluation),
) => evaluations.last_mut().unwrap().push(goal_evaluation), ) => evaluations.last_mut().unwrap().push(goal_evaluation),
(this @ DebugSolver::Root, goal_evaluation) => *this = goal_evaluation, (this @ DebugSolver::Root, goal_evaluation) => *this = goal_evaluation,
_ => unreachable!(), _ => unreachable!(),
} }
} }
}
pub fn new_goal_evaluation_step( pub fn new_goal_evaluation_step(
&mut self, &mut self,
instantiated_goal: QueryInput<'tcx, ty::Predicate<'tcx>>, instantiated_goal: QueryInput<'tcx, ty::Predicate<'tcx>>,
) -> ProofTreeBuilder<'tcx> { ) -> ProofTreeBuilder<'tcx> {
if self.0.is_none() { if self.state.is_none() {
return Self(None); return ProofTreeBuilder { state: None };
} }
Self(Some(Box::new(DebugSolver::GoalEvaluationStep(WipGoalEvaluationStep { ProofTreeBuilder::new(WipGoalEvaluationStep {
instantiated_goal, instantiated_goal,
nested_goal_evaluations: vec![], nested_goal_evaluations: vec![],
candidates: vec![], candidates: vec![],
result: None, result: None,
})))) })
} }
pub fn goal_evaluation_step(&mut self, goal_eval_step: ProofTreeBuilder<'tcx>) { pub fn goal_evaluation_step(&mut self, goal_eval_step: ProofTreeBuilder<'tcx>) {
let this = match self.0.as_mut() { if let Some(this) = self.as_mut() {
None => return, match (this, *goal_eval_step.state.unwrap()) {
Some(this) => &mut **this,
};
match (this, *goal_eval_step.0.unwrap()) {
(DebugSolver::GoalEvaluation(goal_eval), DebugSolver::GoalEvaluationStep(step)) => { (DebugSolver::GoalEvaluation(goal_eval), DebugSolver::GoalEvaluationStep(step)) => {
goal_eval.evaluation_steps.push(step); goal_eval.evaluation_steps.push(step);
} }
_ => unreachable!(), _ => unreachable!(),
} }
} }
pub fn new_goal_candidate(&mut self) -> ProofTreeBuilder<'tcx> {
if self.0.is_none() {
return Self(None);
} }
Self(Some(Box::new(DebugSolver::GoalCandidate(WipGoalCandidate { pub fn new_goal_candidate(&mut self) -> ProofTreeBuilder<'tcx> {
if self.state.is_none() {
return ProofTreeBuilder { state: None };
}
ProofTreeBuilder::new(WipGoalCandidate {
nested_goal_evaluations: vec![], nested_goal_evaluations: vec![],
candidates: vec![], candidates: vec![],
kind: None, kind: None,
})))) })
} }
pub fn candidate_kind(&mut self, kind: CandidateKind<'tcx>) {
let this = match self.0.as_mut() {
None => return,
Some(this) => &mut **this,
};
pub fn candidate_kind(&mut self, candidate_kind: CandidateKind<'tcx>) {
if let Some(this) = self.as_mut() {
match this { match this {
DebugSolver::GoalCandidate(WipGoalCandidate { kind: old_kind @ None, .. }) => { DebugSolver::GoalCandidate(this) => {
*old_kind = Some(kind) assert_eq!(this.kind.replace(candidate_kind), None)
} }
_ => unreachable!(), _ => unreachable!(),
} }
} }
pub fn goal_candidate(&mut self, candidate: ProofTreeBuilder<'tcx>) { }
let this = match self.0.as_mut() {
None => return,
Some(this) => &mut **this,
};
match (this, *candidate.0.unwrap()) { pub fn goal_candidate(&mut self, candidate: ProofTreeBuilder<'tcx>) {
if let Some(this) = self.as_mut() {
match (this, *candidate.state.unwrap()) {
( (
DebugSolver::GoalCandidate(WipGoalCandidate { candidates, .. }) DebugSolver::GoalCandidate(WipGoalCandidate { candidates, .. })
| DebugSolver::GoalEvaluationStep(WipGoalEvaluationStep { candidates, .. }), | DebugSolver::GoalEvaluationStep(WipGoalEvaluationStep { candidates, .. }),
@ -282,23 +305,18 @@ impl<'tcx> ProofTreeBuilder<'tcx> {
_ => unreachable!(), _ => unreachable!(),
} }
} }
}
pub fn new_evaluate_added_goals(&mut self) -> ProofTreeBuilder<'tcx> { pub fn new_evaluate_added_goals(&mut self) -> ProofTreeBuilder<'tcx> {
if self.0.is_none() { if self.state.is_none() {
return Self(None); return ProofTreeBuilder { state: None };
} }
Self(Some(Box::new(DebugSolver::AddedGoalsEvaluation(WipAddedGoalsEvaluation { ProofTreeBuilder::new(WipAddedGoalsEvaluation { evaluations: vec![], result: None })
evaluations: vec![],
result: None,
}))))
} }
pub fn evaluate_added_goals_loop_start(&mut self) { pub fn evaluate_added_goals_loop_start(&mut self) {
let this = match self.0.as_mut() { if let Some(this) = self.as_mut() {
None => return,
Some(this) => &mut **this,
};
match this { match this {
DebugSolver::AddedGoalsEvaluation(this) => { DebugSolver::AddedGoalsEvaluation(this) => {
this.evaluations.push(vec![]); this.evaluations.push(vec![]);
@ -306,56 +324,49 @@ impl<'tcx> ProofTreeBuilder<'tcx> {
_ => unreachable!(), _ => unreachable!(),
} }
} }
pub fn eval_added_goals_result(&mut self, result: Result<Certainty, NoSolution>) { }
let this = match self.0.as_mut() {
None => return,
Some(this) => &mut **this,
};
pub fn eval_added_goals_result(&mut self, result: Result<Certainty, NoSolution>) {
if let Some(this) = self.as_mut() {
match this { match this {
DebugSolver::AddedGoalsEvaluation(this) => { DebugSolver::AddedGoalsEvaluation(this) => {
assert!(this.result.is_none()); assert_eq!(this.result.replace(result), None);
this.result = Some(result);
} }
_ => unreachable!(), _ => unreachable!(),
} }
} }
pub fn added_goals_evaluation(&mut self, goals_evaluation: ProofTreeBuilder<'tcx>) { }
let this = match self.0.as_mut() {
None => return,
Some(this) => &mut **this,
};
match (this, *goals_evaluation.0.unwrap()) { pub fn added_goals_evaluation(&mut self, goals_evaluation: ProofTreeBuilder<'tcx>) {
if let Some(this) = self.as_mut() {
match (this, *goals_evaluation.state.unwrap()) {
( (
DebugSolver::GoalEvaluationStep(WipGoalEvaluationStep { DebugSolver::GoalEvaluationStep(WipGoalEvaluationStep {
nested_goal_evaluations, nested_goal_evaluations,
.. ..
}) })
| DebugSolver::GoalCandidate(WipGoalCandidate { nested_goal_evaluations, .. }), | DebugSolver::GoalCandidate(WipGoalCandidate {
nested_goal_evaluations, ..
}),
DebugSolver::AddedGoalsEvaluation(added_goals_evaluation), DebugSolver::AddedGoalsEvaluation(added_goals_evaluation),
) => nested_goal_evaluations.push(added_goals_evaluation), ) => nested_goal_evaluations.push(added_goals_evaluation),
_ => unreachable!(), _ => unreachable!(),
} }
} }
}
pub fn query_result(&mut self, result: QueryResult<'tcx>) { pub fn query_result(&mut self, result: QueryResult<'tcx>) {
let this = match self.0.as_mut() { if let Some(this) = self.as_mut() {
None => return,
Some(this) => &mut **this,
};
match this { match this {
DebugSolver::GoalEvaluation(goal_evaluation) => { DebugSolver::GoalEvaluation(goal_evaluation) => {
assert!(goal_evaluation.result.is_none()); assert_eq!(goal_evaluation.result.replace(result), None);
goal_evaluation.result = Some(result); }
DebugSolver::GoalEvaluationStep(evaluation_step) => {
assert_eq!(evaluation_step.result.replace(result), None);
} }
DebugSolver::Root DebugSolver::Root
| DebugSolver::AddedGoalsEvaluation(_) | DebugSolver::AddedGoalsEvaluation(_)
| DebugSolver::GoalCandidate(_) => unreachable!(), | DebugSolver::GoalCandidate(_) => unreachable!(),
DebugSolver::GoalEvaluationStep(evaluation_step) => {
assert!(evaluation_step.result.is_none());
evaluation_step.result = Some(result);
} }
} }
} }