Skip to content

Commit 3a6ce74

Browse files
committed
move to nested module
1 parent 9af7122 commit 3a6ce74

File tree

2 files changed

+134
-130
lines changed

2 files changed

+134
-130
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
use super::{CanonicalInput, Certainty, Goal, NoSolution, QueryInput, QueryResult};
22
use crate::{traits::IsNormalizesToHack, ty};
3+
use format::ProofTreeFormatter;
34
use std::fmt::{Debug, Write};
45

6+
mod format;
7+
58
#[derive(Eq, PartialEq, Debug, Hash, HashStable)]
69
pub enum CacheHit {
710
Provisional,
@@ -74,133 +77,3 @@ impl Debug for GoalCandidate<'_> {
7477
ProofTreeFormatter { f, on_newline: true }.format_candidate(self)
7578
}
7679
}
77-
78-
struct ProofTreeFormatter<'a, 'b> {
79-
f: &'a mut (dyn Write + 'b),
80-
on_newline: bool,
81-
}
82-
83-
impl Write for ProofTreeFormatter<'_, '_> {
84-
fn write_str(&mut self, s: &str) -> std::fmt::Result {
85-
for line in s.split_inclusive("\n") {
86-
if self.on_newline {
87-
self.f.write_str(" ")?;
88-
}
89-
self.on_newline = line.ends_with("\n");
90-
self.f.write_str(line)?;
91-
}
92-
93-
Ok(())
94-
}
95-
}
96-
97-
impl ProofTreeFormatter<'_, '_> {
98-
fn nested(&mut self) -> ProofTreeFormatter<'_, '_> {
99-
ProofTreeFormatter { f: self, on_newline: true }
100-
}
101-
102-
fn format_goal_evaluation(&mut self, goal: &GoalEvaluation<'_>) -> std::fmt::Result {
103-
let f = &mut *self.f;
104-
105-
let goal_text = match goal.is_normalizes_to_hack {
106-
IsNormalizesToHack::Yes => "NORMALIZES-TO HACK GOAL",
107-
IsNormalizesToHack::No => "GOAL",
108-
};
109-
110-
writeln!(f, "{}: {:?}", goal_text, goal.uncanonicalized_goal,)?;
111-
writeln!(f, "CANONICALIZED: {:?}", goal.canonicalized_goal)?;
112-
113-
match &goal.kind {
114-
GoalEvaluationKind::CacheHit(CacheHit::Global) => {
115-
writeln!(f, "GLOBAL CACHE HIT: {:?}", goal.result)
116-
}
117-
GoalEvaluationKind::CacheHit(CacheHit::Provisional) => {
118-
writeln!(f, "PROVISIONAL CACHE HIT: {:?}", goal.result)
119-
}
120-
GoalEvaluationKind::Uncached { revisions } => {
121-
for (n, step) in revisions.iter().enumerate() {
122-
let f = &mut *self.f;
123-
writeln!(f, "REVISION {n}: {:?}", step.result)?;
124-
let mut f = self.nested();
125-
f.format_evaluation_step(step)?;
126-
}
127-
128-
let f = &mut *self.f;
129-
writeln!(f, "RESULT: {:?}", goal.result)
130-
}
131-
}?;
132-
133-
if goal.returned_goals.len() > 0 {
134-
let f = &mut *self.f;
135-
writeln!(f, "NESTED GOALS ADDED TO CALLER: [")?;
136-
let mut f = self.nested();
137-
for goal in goal.returned_goals.iter() {
138-
writeln!(f, "ADDED GOAL: {:?},", goal)?;
139-
}
140-
writeln!(self.f, "]")?;
141-
}
142-
143-
Ok(())
144-
}
145-
146-
fn format_evaluation_step(
147-
&mut self,
148-
evaluation_step: &GoalEvaluationStep<'_>,
149-
) -> std::fmt::Result {
150-
let f = &mut *self.f;
151-
writeln!(f, "INSTANTIATED: {:?}", evaluation_step.instantiated_goal)?;
152-
153-
for candidate in &evaluation_step.candidates {
154-
let mut f = self.nested();
155-
f.format_candidate(candidate)?;
156-
}
157-
for nested_goal_evaluation in &evaluation_step.nested_goal_evaluations {
158-
let mut f = self.nested();
159-
f.format_nested_goal_evaluation(nested_goal_evaluation)?;
160-
}
161-
162-
Ok(())
163-
}
164-
165-
fn format_candidate(&mut self, candidate: &GoalCandidate<'_>) -> std::fmt::Result {
166-
let f = &mut *self.f;
167-
168-
match &candidate.kind {
169-
CandidateKind::NormalizedSelfTyAssembly => {
170-
writeln!(f, "NORMALIZING SELF TY FOR ASSEMBLY:")
171-
}
172-
CandidateKind::Candidate { name, result } => {
173-
writeln!(f, "CANDIDATE {}: {:?}", name, result)
174-
}
175-
}?;
176-
177-
let mut f = self.nested();
178-
for candidate in &candidate.candidates {
179-
f.format_candidate(candidate)?;
180-
}
181-
for nested_evaluations in &candidate.nested_goal_evaluations {
182-
f.format_nested_goal_evaluation(nested_evaluations)?;
183-
}
184-
185-
Ok(())
186-
}
187-
188-
fn format_nested_goal_evaluation(
189-
&mut self,
190-
nested_goal_evaluation: &AddedGoalsEvaluation<'_>,
191-
) -> std::fmt::Result {
192-
let f = &mut *self.f;
193-
writeln!(f, "TRY_EVALUATE_ADDED_GOALS: {:?}", nested_goal_evaluation.result)?;
194-
195-
for (n, revision) in nested_goal_evaluation.evaluations.iter().enumerate() {
196-
let f = &mut *self.f;
197-
writeln!(f, "REVISION {n}")?;
198-
let mut f = self.nested();
199-
for goal_evaluation in revision {
200-
f.format_goal_evaluation(goal_evaluation)?;
201-
}
202-
}
203-
204-
Ok(())
205-
}
206-
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
use super::*;
2+
3+
pub(super) struct ProofTreeFormatter<'a, 'b> {
4+
pub(super) f: &'a mut (dyn Write + 'b),
5+
pub(super) on_newline: bool,
6+
}
7+
8+
impl Write for ProofTreeFormatter<'_, '_> {
9+
fn write_str(&mut self, s: &str) -> std::fmt::Result {
10+
for line in s.split_inclusive("\n") {
11+
if self.on_newline {
12+
self.f.write_str(" ")?;
13+
}
14+
self.on_newline = line.ends_with("\n");
15+
self.f.write_str(line)?;
16+
}
17+
18+
Ok(())
19+
}
20+
}
21+
22+
impl ProofTreeFormatter<'_, '_> {
23+
fn nested(&mut self) -> ProofTreeFormatter<'_, '_> {
24+
ProofTreeFormatter { f: self, on_newline: true }
25+
}
26+
27+
pub(super) fn format_goal_evaluation(&mut self, goal: &GoalEvaluation<'_>) -> std::fmt::Result {
28+
let f = &mut *self.f;
29+
30+
let goal_text = match goal.is_normalizes_to_hack {
31+
IsNormalizesToHack::Yes => "NORMALIZES-TO HACK GOAL",
32+
IsNormalizesToHack::No => "GOAL",
33+
};
34+
35+
writeln!(f, "{}: {:?}", goal_text, goal.uncanonicalized_goal,)?;
36+
writeln!(f, "CANONICALIZED: {:?}", goal.canonicalized_goal)?;
37+
38+
match &goal.kind {
39+
GoalEvaluationKind::CacheHit(CacheHit::Global) => {
40+
writeln!(f, "GLOBAL CACHE HIT: {:?}", goal.result)
41+
}
42+
GoalEvaluationKind::CacheHit(CacheHit::Provisional) => {
43+
writeln!(f, "PROVISIONAL CACHE HIT: {:?}", goal.result)
44+
}
45+
GoalEvaluationKind::Uncached { revisions } => {
46+
for (n, step) in revisions.iter().enumerate() {
47+
let f = &mut *self.f;
48+
writeln!(f, "REVISION {n}: {:?}", step.result)?;
49+
let mut f = self.nested();
50+
f.format_evaluation_step(step)?;
51+
}
52+
53+
let f = &mut *self.f;
54+
writeln!(f, "RESULT: {:?}", goal.result)
55+
}
56+
}?;
57+
58+
if goal.returned_goals.len() > 0 {
59+
let f = &mut *self.f;
60+
writeln!(f, "NESTED GOALS ADDED TO CALLER: [")?;
61+
let mut f = self.nested();
62+
for goal in goal.returned_goals.iter() {
63+
writeln!(f, "ADDED GOAL: {:?},", goal)?;
64+
}
65+
writeln!(self.f, "]")?;
66+
}
67+
68+
Ok(())
69+
}
70+
71+
pub(super) fn format_evaluation_step(
72+
&mut self,
73+
evaluation_step: &GoalEvaluationStep<'_>,
74+
) -> std::fmt::Result {
75+
let f = &mut *self.f;
76+
writeln!(f, "INSTANTIATED: {:?}", evaluation_step.instantiated_goal)?;
77+
78+
for candidate in &evaluation_step.candidates {
79+
let mut f = self.nested();
80+
f.format_candidate(candidate)?;
81+
}
82+
for nested_goal_evaluation in &evaluation_step.nested_goal_evaluations {
83+
let mut f = self.nested();
84+
f.format_nested_goal_evaluation(nested_goal_evaluation)?;
85+
}
86+
87+
Ok(())
88+
}
89+
90+
pub(super) fn format_candidate(&mut self, candidate: &GoalCandidate<'_>) -> std::fmt::Result {
91+
let f = &mut *self.f;
92+
93+
match &candidate.kind {
94+
CandidateKind::NormalizedSelfTyAssembly => {
95+
writeln!(f, "NORMALIZING SELF TY FOR ASSEMBLY:")
96+
}
97+
CandidateKind::Candidate { name, result } => {
98+
writeln!(f, "CANDIDATE {}: {:?}", name, result)
99+
}
100+
}?;
101+
102+
let mut f = self.nested();
103+
for candidate in &candidate.candidates {
104+
f.format_candidate(candidate)?;
105+
}
106+
for nested_evaluations in &candidate.nested_goal_evaluations {
107+
f.format_nested_goal_evaluation(nested_evaluations)?;
108+
}
109+
110+
Ok(())
111+
}
112+
113+
pub(super) fn format_nested_goal_evaluation(
114+
&mut self,
115+
nested_goal_evaluation: &AddedGoalsEvaluation<'_>,
116+
) -> std::fmt::Result {
117+
let f = &mut *self.f;
118+
writeln!(f, "TRY_EVALUATE_ADDED_GOALS: {:?}", nested_goal_evaluation.result)?;
119+
120+
for (n, revision) in nested_goal_evaluation.evaluations.iter().enumerate() {
121+
let f = &mut *self.f;
122+
writeln!(f, "REVISION {n}")?;
123+
let mut f = self.nested();
124+
for goal_evaluation in revision {
125+
f.format_goal_evaluation(goal_evaluation)?;
126+
}
127+
}
128+
129+
Ok(())
130+
}
131+
}

0 commit comments

Comments
 (0)