@@ -3,11 +3,10 @@ use crate::logic::RootSearchFail;
3
3
use crate :: table:: AnswerIndex ;
4
4
use crate :: tables:: Tables ;
5
5
use crate :: { TableIndex , TimeStamp } ;
6
- use std:: fmt:: Display ;
7
6
8
7
use chalk_ir:: debug;
9
8
use chalk_ir:: interner:: Interner ;
10
- use chalk_ir:: { Canonical , ConstrainedSubst , Goal , InEnvironment , Substitution , UCanonical } ;
9
+ use chalk_ir:: { Goal , InEnvironment , Substitution , UCanonical } ;
11
10
12
11
pub struct Forest < I : Interner , C : Context < I > > {
13
12
pub ( crate ) tables : Tables < I > ,
@@ -39,7 +38,7 @@ impl<I: Interner, C: Context<I>> Forest<I, C> {
39
38
/// iterator. Each time you invoke `next`, it will do the work to
40
39
/// extract one more answer. These answers are cached in between
41
40
/// invocations. Invoking `next` fewer times is preferable =)
42
- fn iter_answers < ' f > (
41
+ pub fn iter_answers < ' f > (
43
42
& ' f mut self ,
44
43
context : & ' f impl ContextOps < I , C > ,
45
44
goal : & UCanonical < InEnvironment < Goal < I > > > ,
@@ -54,89 +53,6 @@ impl<I: Interner, C: Context<I>> Forest<I, C> {
54
53
_context : std:: marker:: PhantomData :: < C > ,
55
54
}
56
55
}
57
-
58
- /// Solves a given goal, producing the solution. This will do only
59
- /// as much work towards `goal` as it has to (and that works is
60
- /// cached for future attempts).
61
- pub fn solve (
62
- & mut self ,
63
- context : & impl ContextOps < I , C > ,
64
- goal : & UCanonical < InEnvironment < Goal < I > > > ,
65
- should_continue : impl Fn ( ) -> bool ,
66
- ) -> Option < C :: Solution > {
67
- context. make_solution ( & goal, self . iter_answers ( context, goal) , should_continue)
68
- }
69
-
70
- /// Solves a given goal, producing the solution. This will do only
71
- /// as much work towards `goal` as it has to (and that works is
72
- /// cached for future attempts). Calls provided function `f` to
73
- /// iterate over multiple solutions until the function return `false`.
74
- pub fn solve_multiple (
75
- & mut self ,
76
- context : & impl ContextOps < I , C > ,
77
- goal : & UCanonical < InEnvironment < Goal < I > > > ,
78
- mut f : impl FnMut ( SubstitutionResult < Canonical < ConstrainedSubst < I > > > , bool ) -> bool ,
79
- ) -> bool {
80
- let mut answers = self . iter_answers ( context, goal) ;
81
- loop {
82
- let subst = match answers. next_answer ( || true ) {
83
- AnswerResult :: Answer ( answer) => {
84
- if !answer. ambiguous {
85
- SubstitutionResult :: Definite ( answer. subst )
86
- } else {
87
- if context. is_trivial_constrained_substitution ( & answer. subst ) {
88
- SubstitutionResult :: Floundered
89
- } else {
90
- SubstitutionResult :: Ambiguous ( answer. subst )
91
- }
92
- }
93
- }
94
- AnswerResult :: Floundered => SubstitutionResult :: Floundered ,
95
- AnswerResult :: NoMoreSolutions => {
96
- return true ;
97
- }
98
- AnswerResult :: QuantumExceeded => continue ,
99
- } ;
100
-
101
- if !f ( subst, !answers. peek_answer ( || true ) . is_no_more_solutions ( ) ) {
102
- return false ;
103
- }
104
- }
105
- }
106
- }
107
-
108
- #[ derive( Debug ) ]
109
- pub enum SubstitutionResult < S > {
110
- Definite ( S ) ,
111
- Ambiguous ( S ) ,
112
- Floundered ,
113
- }
114
-
115
- impl < S > SubstitutionResult < S > {
116
- pub fn as_ref ( & self ) -> SubstitutionResult < & S > {
117
- match self {
118
- SubstitutionResult :: Definite ( subst) => SubstitutionResult :: Definite ( subst) ,
119
- SubstitutionResult :: Ambiguous ( subst) => SubstitutionResult :: Ambiguous ( subst) ,
120
- SubstitutionResult :: Floundered => SubstitutionResult :: Floundered ,
121
- }
122
- }
123
- pub fn map < U , F : FnOnce ( S ) -> U > ( self , f : F ) -> SubstitutionResult < U > {
124
- match self {
125
- SubstitutionResult :: Definite ( subst) => SubstitutionResult :: Definite ( f ( subst) ) ,
126
- SubstitutionResult :: Ambiguous ( subst) => SubstitutionResult :: Ambiguous ( f ( subst) ) ,
127
- SubstitutionResult :: Floundered => SubstitutionResult :: Floundered ,
128
- }
129
- }
130
- }
131
-
132
- impl < S : Display > Display for SubstitutionResult < S > {
133
- fn fmt ( & self , fmt : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
134
- match self {
135
- SubstitutionResult :: Definite ( subst) => write ! ( fmt, "{}" , subst) ,
136
- SubstitutionResult :: Ambiguous ( subst) => write ! ( fmt, "Ambiguous({})" , subst) ,
137
- SubstitutionResult :: Floundered => write ! ( fmt, "Floundered" ) ,
138
- }
139
- }
140
56
}
141
57
142
58
struct ForestSolver < ' me , I : Interner , C : Context < I > , CO : ContextOps < I , C > > {
0 commit comments