@@ -26,6 +26,16 @@ pub(crate) struct RecursiveContext<I: Interner> {
26
26
caching_enabled : bool ,
27
27
}
28
28
29
+ trait Context < I : Interner > {
30
+ fn instantiate_binders_universally ( & mut self , interner : & I , arg : & Binders < Goal < I > > ) -> Goal < I > ;
31
+
32
+ fn instantiate_binders_existentially (
33
+ & mut self ,
34
+ interner : & I ,
35
+ arg : & Binders < Goal < I > > ,
36
+ ) -> Goal < I > ;
37
+ }
38
+
29
39
/// A Solver is the basic context in which you can propose goals for a given
30
40
/// program. **All questions posed to the solver are in canonical, closed form,
31
41
/// so that each question is answered with effectively a "clean slate"**. This
@@ -341,10 +351,10 @@ impl<'me, I: Interner> Solver<'me, I> {
341
351
minimums : & mut Minimums ,
342
352
) -> ( Fallible < Solution < I > > , ClausePriority ) {
343
353
debug_heading ! ( "solve_via_simplification({:?})" , canonical_goal) ;
344
- let ( mut fulfill, subst, goal ) = Fulfill :: new ( self , canonical_goal) ;
345
- if let Err ( e ) = fulfill . push_goal ( & goal . environment , goal . goal ) {
346
- return ( Err ( e) , ClausePriority :: High ) ;
347
- }
354
+ let ( fulfill, subst) = match Fulfill :: new_with_simplification ( self , canonical_goal) {
355
+ Ok ( r ) => r ,
356
+ Err ( e ) => return ( Err ( e) , ClausePriority :: High ) ,
357
+ } ;
348
358
( fulfill. solve ( subst, minimums) , ClausePriority :: High )
349
359
}
350
360
@@ -369,52 +379,34 @@ impl<'me, I: Interner> Solver<'me, I> {
369
379
return ( Ok ( Solution :: Ambig ( Guidance :: Unknown ) ) , ClausePriority :: High ) ;
370
380
}
371
381
372
- match program_clause. data ( self . program . interner ( ) ) {
373
- ProgramClauseData :: Implies ( implication) => {
374
- let res = self . solve_via_implication (
375
- canonical_goal,
376
- & Binders :: new (
377
- VariableKinds :: from ( self . program . interner ( ) , vec ! [ ] ) ,
378
- implication. clone ( ) ,
379
- ) ,
380
- minimums,
381
- ) ;
382
- if let ( Ok ( solution) , priority) = res {
383
- debug ! ( "ok: solution={:?} prio={:?}" , solution, priority) ;
384
- cur_solution = Some ( match cur_solution {
385
- None => ( solution, priority) ,
386
- Some ( ( cur, cur_priority) ) => combine_with_priorities (
387
- self . program . interner ( ) ,
388
- & canonical_goal. canonical . value . goal ,
389
- cur,
390
- cur_priority,
391
- solution,
392
- priority,
393
- ) ,
394
- } ) ;
395
- } else {
396
- debug ! ( "error" ) ;
397
- }
398
- }
382
+ let res = match program_clause. data ( self . program . interner ( ) ) {
383
+ ProgramClauseData :: Implies ( implication) => self . solve_via_implication (
384
+ canonical_goal,
385
+ & Binders :: new (
386
+ VariableKinds :: from ( self . program . interner ( ) , vec ! [ ] ) ,
387
+ implication. clone ( ) ,
388
+ ) ,
389
+ minimums,
390
+ ) ,
399
391
ProgramClauseData :: ForAll ( implication) => {
400
- let res = self . solve_via_implication ( canonical_goal, implication, minimums) ;
401
- if let ( Ok ( solution) , priority) = res {
402
- debug ! ( "ok: solution={:?} prio={:?}" , solution, priority) ;
403
- cur_solution = Some ( match cur_solution {
404
- None => ( solution, priority) ,
405
- Some ( ( cur, cur_priority) ) => combine_with_priorities (
406
- self . program . interner ( ) ,
407
- & canonical_goal. canonical . value . goal ,
408
- cur,
409
- cur_priority,
410
- solution,
411
- priority,
412
- ) ,
413
- } ) ;
414
- } else {
415
- debug ! ( "error" ) ;
416
- }
392
+ self . solve_via_implication ( canonical_goal, implication, minimums)
417
393
}
394
+ } ;
395
+ if let ( Ok ( solution) , priority) = res {
396
+ debug ! ( "ok: solution={:?} prio={:?}" , solution, priority) ;
397
+ cur_solution = Some ( match cur_solution {
398
+ None => ( solution, priority) ,
399
+ Some ( ( cur, cur_priority) ) => combine_with_priorities (
400
+ self . program . interner ( ) ,
401
+ & canonical_goal. canonical . value . goal ,
402
+ cur,
403
+ cur_priority,
404
+ solution,
405
+ priority,
406
+ ) ,
407
+ } ) ;
408
+ } else {
409
+ debug ! ( "error" ) ;
418
410
}
419
411
}
420
412
cur_solution. map_or ( ( Err ( NoSolution ) , ClausePriority :: High ) , |( s, p) | ( Ok ( s) , p) )
@@ -434,28 +426,11 @@ impl<'me, I: Interner> Solver<'me, I> {
434
426
canonical_goal,
435
427
clause
436
428
) ;
437
- let interner = self . program . interner ( ) ;
438
- let ( mut fulfill, subst, goal) = Fulfill :: new ( self , canonical_goal) ;
439
- let ProgramClauseImplication {
440
- consequence,
441
- conditions,
442
- priority : _,
443
- } = fulfill. instantiate_binders_existentially ( clause) ;
444
-
445
- debug ! ( "the subst is {:?}" , subst) ;
446
-
447
- if let Err ( e) = fulfill. unify ( & goal. environment , & goal. goal , & consequence) {
448
- return ( Err ( e) , ClausePriority :: High ) ;
449
- }
450
-
451
- // if so, toss in all of its premises
452
- for condition in conditions. as_slice ( interner) {
453
- if let Err ( e) = fulfill. push_goal ( & goal. environment , condition. clone ( ) ) {
454
- return ( Err ( e) , ClausePriority :: High ) ;
455
- }
456
- }
429
+ let ( fulfill, subst) = match Fulfill :: new_with_clause ( self , canonical_goal, clause) {
430
+ Ok ( r) => r,
431
+ Err ( e) => return ( Err ( e) , ClausePriority :: High ) ,
432
+ } ;
457
433
458
- // and then try to solve
459
434
(
460
435
fulfill. solve ( subst, minimums) ,
461
436
clause. skip_binders ( ) . priority ,
0 commit comments