@@ -364,34 +364,7 @@ impl<'me, I: Interner> Solver<'me, I> {
364
364
where
365
365
C : IntoIterator < Item = ProgramClause < I > > ,
366
366
{
367
- // TODO we don't actually need to keep track of the inputs
368
367
let mut cur_solution = None ;
369
- fn combine_with_priorities < I : Interner > (
370
- a : Solution < I > ,
371
- prio_a : ClausePriority ,
372
- inputs_a : Vec < Parameter < I > > ,
373
- b : Solution < I > ,
374
- prio_b : ClausePriority ,
375
- inputs_b : Vec < Parameter < I > > ,
376
- ) -> ( Solution < I > , ClausePriority , Vec < Parameter < I > > ) {
377
- match ( prio_a, prio_b) {
378
- ( ClausePriority :: High , ClausePriority :: Low ) if inputs_a == inputs_b => {
379
- debug ! (
380
- "preferring solution: {:?} over {:?} because of higher prio" ,
381
- a, b
382
- ) ;
383
- ( a, ClausePriority :: High , inputs_a)
384
- }
385
- ( ClausePriority :: Low , ClausePriority :: High ) if inputs_a == inputs_b => {
386
- debug ! (
387
- "preferring solution: {:?} over {:?} because of higher prio" ,
388
- b, a
389
- ) ;
390
- ( b, ClausePriority :: High , inputs_b)
391
- }
392
- _ => ( a. combine ( b) , prio_a, inputs_a) ,
393
- }
394
- }
395
368
for program_clause in clauses {
396
369
debug_heading ! ( "clause={:?}" , program_clause) ;
397
370
@@ -407,29 +380,15 @@ impl<'me, I: Interner> Solver<'me, I> {
407
380
) ;
408
381
if let ( Ok ( solution) , priority) = res {
409
382
debug ! ( "ok: solution={:?} prio={:?}" , solution, priority) ;
410
- let inputs = if let Some ( subst) = solution. constrained_subst ( ) {
411
- let subst_goal = subst. value . subst . apply (
412
- & canonical_goal. canonical . value . goal ,
413
- self . program . interner ( ) ,
414
- ) ;
415
- debug ! ( "subst_goal = {:?}" , subst_goal) ;
416
- subst_goal. inputs ( self . program . interner ( ) )
417
- } else {
418
- canonical_goal
419
- . canonical
420
- . value
421
- . goal
422
- . inputs ( self . program . interner ( ) )
423
- } ;
424
383
cur_solution = Some ( match cur_solution {
425
- None => ( solution, priority, inputs) ,
426
- Some ( ( cur, cur_priority, cur_inputs) ) => combine_with_priorities (
384
+ None => ( solution, priority) ,
385
+ Some ( ( cur, cur_priority) ) => combine_with_priorities (
386
+ self . program . interner ( ) ,
387
+ canonical_goal,
427
388
cur,
428
389
cur_priority,
429
- cur_inputs,
430
390
solution,
431
391
priority,
432
- inputs,
433
392
) ,
434
393
} ) ;
435
394
} else {
@@ -440,29 +399,15 @@ impl<'me, I: Interner> Solver<'me, I> {
440
399
let res = self . solve_via_implication ( canonical_goal, implication, minimums) ;
441
400
if let ( Ok ( solution) , priority) = res {
442
401
debug ! ( "ok: solution={:?} prio={:?}" , solution, priority) ;
443
- let inputs = if let Some ( subst) = solution. constrained_subst ( ) {
444
- let subst_goal = subst. value . subst . apply (
445
- & canonical_goal. canonical . value . goal ,
446
- self . program . interner ( ) ,
447
- ) ;
448
- debug ! ( "subst_goal = {:?}" , subst_goal) ;
449
- subst_goal. inputs ( self . program . interner ( ) )
450
- } else {
451
- canonical_goal
452
- . canonical
453
- . value
454
- . goal
455
- . inputs ( self . program . interner ( ) )
456
- } ;
457
402
cur_solution = Some ( match cur_solution {
458
- None => ( solution, priority, inputs) ,
459
- Some ( ( cur, cur_priority, cur_inputs) ) => combine_with_priorities (
403
+ None => ( solution, priority) ,
404
+ Some ( ( cur, cur_priority) ) => combine_with_priorities (
405
+ self . program . interner ( ) ,
406
+ canonical_goal,
460
407
cur,
461
408
cur_priority,
462
- cur_inputs,
463
409
solution,
464
410
priority,
465
- inputs,
466
411
) ,
467
412
} ) ;
468
413
} else {
@@ -471,9 +416,7 @@ impl<'me, I: Interner> Solver<'me, I> {
471
416
}
472
417
}
473
418
}
474
- cur_solution. map_or ( ( Err ( NoSolution ) , ClausePriority :: High ) , |( s, p, _) | {
475
- ( Ok ( s) , p)
476
- } )
419
+ cur_solution. map_or ( ( Err ( NoSolution ) , ClausePriority :: High ) , |( s, p) | ( Ok ( s) , p) )
477
420
}
478
421
479
422
/// Modus ponens! That is: try to apply an implication by proving its premises.
@@ -524,6 +467,49 @@ impl<'me, I: Interner> Solver<'me, I> {
524
467
}
525
468
}
526
469
470
+ fn calculate_inputs < I : Interner > (
471
+ interner : & I ,
472
+ canonical_goal : & UCanonical < InEnvironment < DomainGoal < I > > > ,
473
+ solution : & Solution < I > ,
474
+ ) -> Vec < Parameter < I > > {
475
+ if let Some ( subst) = solution. constrained_subst ( ) {
476
+ let subst_goal = subst
477
+ . value
478
+ . subst
479
+ . apply ( & canonical_goal. canonical . value . goal , interner) ;
480
+ subst_goal. inputs ( interner)
481
+ } else {
482
+ canonical_goal. canonical . value . goal . inputs ( interner)
483
+ }
484
+ }
485
+
486
+ fn combine_with_priorities < I : Interner > (
487
+ interner : & I ,
488
+ canonical_goal : & UCanonical < InEnvironment < DomainGoal < I > > > ,
489
+ a : Solution < I > ,
490
+ prio_a : ClausePriority ,
491
+ b : Solution < I > ,
492
+ prio_b : ClausePriority ,
493
+ ) -> ( Solution < I > , ClausePriority ) {
494
+ match ( prio_a, prio_b, a, b) {
495
+ ( ClausePriority :: High , ClausePriority :: Low , higher, lower)
496
+ | ( ClausePriority :: Low , ClausePriority :: High , lower, higher) => {
497
+ let inputs_higher = calculate_inputs ( interner, canonical_goal, & higher) ;
498
+ let inputs_lower = calculate_inputs ( interner, canonical_goal, & lower) ;
499
+ if inputs_higher == inputs_lower {
500
+ debug ! (
501
+ "preferring solution: {:?} over {:?} because of higher prio" ,
502
+ higher, lower
503
+ ) ;
504
+ ( higher, ClausePriority :: High )
505
+ } else {
506
+ ( higher. combine ( lower) , ClausePriority :: High )
507
+ }
508
+ }
509
+ ( _, _, a, b) => ( a. combine ( b) , prio_a) ,
510
+ }
511
+ }
512
+
527
513
impl Minimums {
528
514
fn new ( ) -> Self {
529
515
Minimums {
0 commit comments