@@ -455,21 +455,42 @@ evaluatePattern ::
455
455
Pattern ->
456
456
io (Either EquationFailure Pattern , SimplifierCache )
457
457
evaluatePattern def mLlvmLibrary smtSolver cache pat =
458
- runEquationT def mLlvmLibrary smtSolver cache pat. constraints . evaluatePattern' $ pat
458
+ runEquationT
459
+ def
460
+ mLlvmLibrary
461
+ smtSolver
462
+ cache
463
+ -- interpret substitution as additional known constraints
464
+ (pat. constraints <> (Set. fromList . asEquations $ pat. substitution))
465
+ . evaluatePattern'
466
+ $ pat
459
467
460
468
-- version for internal nested evaluation
461
469
evaluatePattern' ::
462
470
LoggerMIO io =>
463
471
Pattern ->
464
472
EquationT io Pattern
465
- evaluatePattern' pat@ Pattern {term, ceilConditions, substitution } = withPatternContext pat $ do
473
+ evaluatePattern' pat@ Pattern {term, ceilConditions} = withPatternContext pat $ do
466
474
newTerm <- withTermContext term $ evaluateTerm' BottomUp term `catch_` keepTopLevelResults
467
475
-- after evaluating the term, evaluate all (existing and
468
476
-- newly-acquired) constraints, once
469
477
traverse_ simplifyAssumedPredicate . predicates =<< getState
470
478
-- this may yield additional new constraints, left unevaluated
471
479
evaluatedConstraints <- predicates <$> getState
472
- pure Pattern {constraints = evaluatedConstraints, term = newTerm, ceilConditions, substitution}
480
+ -- The interface-level evaluatePattern puts pat.substitution together with pat.constraints
481
+ -- into the simplifier state as known truth. Here the substitution will bubble-up as part of
482
+ -- evaluatedConstraints. To avoid duplicating constraints (i.e. having equivalent entities
483
+ -- in pat.predicate and pat.substitution), we discard the old substitution here
484
+ -- and extract a possible simplified one from evaluatedConstraints.
485
+ let (simplifiedSubsitution, simplifiedConstraints) = partitionPredicates (Set. toList evaluatedConstraints)
486
+
487
+ pure
488
+ Pattern
489
+ { constraints = Set. fromList simplifiedConstraints
490
+ , term = newTerm
491
+ , ceilConditions
492
+ , substitution = simplifiedSubsitution
493
+ }
473
494
where
474
495
-- when TooManyIterations exception occurred while evaluating the top-level term,
475
496
-- i.e. not in a recursive evaluation of a side-condition,
0 commit comments