1
- use crate :: cache:: Cache ;
2
1
use crate :: search_graph:: DepthFirstNumber ;
3
2
use crate :: search_graph:: SearchGraph ;
4
3
use crate :: solve:: { SolveDatabase , SolveIteration } ;
5
4
use crate :: stack:: { Stack , StackDepth } ;
5
+ use crate :: { cache:: Cache , PrioritizedSolution } ;
6
6
use crate :: { Minimums , UCanonicalGoal } ;
7
7
use chalk_ir:: { interner:: Interner , NoSolution } ;
8
8
use chalk_ir:: { Canonical , ConstrainedSubst , Goal , InEnvironment , UCanonical } ;
@@ -17,12 +17,12 @@ struct RecursiveContext<I: Interner> {
17
17
18
18
/// The "search graph" stores "in-progress results" that are still being
19
19
/// solved.
20
- search_graph : SearchGraph < UCanonicalGoal < I > , Fallible < Solution < I > > > ,
20
+ search_graph : SearchGraph < UCanonicalGoal < I > , PrioritizedSolution < I > > ,
21
21
22
22
/// The "cache" stores results for goals that we have completely solved.
23
23
/// Things are added to the cache when we have completely processed their
24
24
/// result.
25
- cache : Option < Cache < UCanonicalGoal < I > , Fallible < Solution < I > > > > ,
25
+ cache : Option < Cache < UCanonicalGoal < I > , PrioritizedSolution < I > > > ,
26
26
27
27
/// The maximum size for goals.
28
28
max_size : usize ,
@@ -46,7 +46,7 @@ impl<I: Interner> RecursiveSolver<I> {
46
46
pub fn new (
47
47
overflow_depth : usize ,
48
48
max_size : usize ,
49
- cache : Option < Cache < UCanonicalGoal < I > , Fallible < Solution < I > > > > ,
49
+ cache : Option < Cache < UCanonicalGoal < I > , PrioritizedSolution < I > > > ,
50
50
) -> Self {
51
51
Self {
52
52
ctx : Box :: new ( RecursiveContext :: new ( overflow_depth, max_size, cache) ) ,
@@ -84,7 +84,7 @@ impl<I: Interner> RecursiveContext<I> {
84
84
pub fn new (
85
85
overflow_depth : usize ,
86
86
max_size : usize ,
87
- cache : Option < Cache < UCanonicalGoal < I > , Fallible < Solution < I > > > > ,
87
+ cache : Option < Cache < UCanonicalGoal < I > , PrioritizedSolution < I > > > ,
88
88
) -> Self {
89
89
RecursiveContext {
90
90
stack : Stack :: new ( overflow_depth) ,
@@ -149,7 +149,7 @@ impl<'me, I: Interner> Solver<'me, I> {
149
149
// so this function will eventually be constant and the loop terminates.
150
150
loop {
151
151
let minimums = & mut Minimums :: new ( ) ;
152
- let ( current_answer, current_prio ) = self . solve_iteration ( & canonical_goal, minimums) ;
152
+ let current_answer = self . solve_iteration ( & canonical_goal, minimums) ;
153
153
154
154
debug ! (
155
155
"solve_new_subgoal: loop iteration result = {:?} with minimums {:?}" ,
@@ -160,24 +160,22 @@ impl<'me, I: Interner> Solver<'me, I> {
160
160
// None of our subgoals depended on us directly.
161
161
// We can return.
162
162
self . context . search_graph [ dfn] . solution = current_answer;
163
- self . context . search_graph [ dfn] . solution_priority = current_prio;
164
163
return * minimums;
165
164
}
166
165
167
166
// Some of our subgoals depended on us. We need to re-run
168
167
// with the current answer.
169
- if self . context . search_graph [ dfn] . solution == current_answer {
168
+ if self . context . search_graph [ dfn] . solution . solution == current_answer. solution {
170
169
// Reached a fixed point.
171
170
return * minimums;
172
171
}
173
172
174
- let current_answer_is_ambig = match & current_answer {
173
+ let current_answer_is_ambig = match & current_answer. solution {
175
174
Ok ( s) => s. is_ambig ( ) ,
176
175
Err ( _) => false ,
177
176
} ;
178
177
179
178
self . context . search_graph [ dfn] . solution = current_answer;
180
- self . context . search_graph [ dfn] . solution_priority = current_prio;
181
179
182
180
// Subtle: if our current answer is ambiguous, we can just stop, and
183
181
// in fact we *must* -- otherwise, we sometimes fail to reach a
@@ -206,7 +204,7 @@ impl<'me, I: Interner> SolveDatabase<I> for Solver<'me, I> {
206
204
if let Some ( cache) = & self . context . cache {
207
205
if let Some ( value) = cache. get ( & goal) {
208
206
debug ! ( "solve_reduced_goal: cache hit, value={:?}" , value) ;
209
- return value. clone ( ) ;
207
+ return value. solution . clone ( ) ;
210
208
}
211
209
}
212
210
@@ -231,12 +229,11 @@ impl<'me, I: Interner> SolveDatabase<I> for Solver<'me, I> {
231
229
232
230
// Return the solution from the table.
233
231
let previous_solution = self . context . search_graph [ dfn] . solution . clone ( ) ;
234
- let previous_solution_priority = self . context . search_graph [ dfn] . solution_priority ;
235
232
info ! (
236
- "solve_goal: cycle detected, previous solution {:?} with prio {:?} " ,
237
- previous_solution, previous_solution_priority
233
+ "solve_goal: cycle detected, previous solution {:?}" ,
234
+ previous_solution,
238
235
) ;
239
- previous_solution
236
+ previous_solution. solution
240
237
} else {
241
238
// Otherwise, push the goal onto the stack and create a table.
242
239
// The initial result for this table depends on whether the goal is coinductive.
@@ -253,10 +250,11 @@ impl<'me, I: Interner> SolveDatabase<I> for Solver<'me, I> {
253
250
} else {
254
251
Err ( NoSolution )
255
252
} ;
256
- let dfn = self
257
- . context
258
- . search_graph
259
- . insert ( & goal, depth, initial_solution) ;
253
+ let dfn = self . context . search_graph . insert (
254
+ & goal,
255
+ depth,
256
+ PrioritizedSolution :: high ( initial_solution) ,
257
+ ) ;
260
258
let subgoal_minimums = self . solve_new_subgoal ( goal, depth, dfn) ;
261
259
self . context . search_graph [ dfn] . links = subgoal_minimums;
262
260
self . context . search_graph [ dfn] . stack_depth = None ;
@@ -265,7 +263,6 @@ impl<'me, I: Interner> SolveDatabase<I> for Solver<'me, I> {
265
263
266
264
// Read final result from table.
267
265
let result = self . context . search_graph [ dfn] . solution . clone ( ) ;
268
- let priority = self . context . search_graph [ dfn] . solution_priority ;
269
266
270
267
// If processing this subgoal did not involve anything
271
268
// outside of its subtree, then we can promote it to the
@@ -283,8 +280,8 @@ impl<'me, I: Interner> SolveDatabase<I> for Solver<'me, I> {
283
280
}
284
281
}
285
282
286
- info ! ( "solve_goal: solution = {:?} prio {:?} " , result, priority ) ;
287
- result
283
+ info ! ( "solve_goal: solution = {:#?} " , result) ;
284
+ result. solution
288
285
}
289
286
}
290
287
0 commit comments