@@ -439,7 +439,11 @@ evaluateTerm' ::
439439evaluateTerm' direction = iterateEquations direction PreferFunctions
440440
441441{- | Simplify a Pattern, processing its constraints independently.
442- Returns either the first failure or the new pattern if no failure was encountered
442+
443+ Before evaluating the term of the pattern,
444+ the constraints of the pattern are checked for consistency with an SMT solver.
445+
446+ Returns either the first failure or the new pattern if no failure was encountered.
443447-}
444448evaluatePattern ::
445449 LoggerMIO io =>
@@ -458,13 +462,28 @@ evaluatePattern' ::
458462 Pattern ->
459463 EquationT io Pattern
460464evaluatePattern' pat@ Pattern {term, ceilConditions} = withPatternContext pat $ do
461- newTerm <- withTermContext term $ evaluateTerm' BottomUp term `catch_` keepTopLevelResults
462- -- after evaluating the term, evaluate all (existing and
463- -- newly-acquired) constraints, once
464- traverse_ simplifyAssumedPredicate . predicates =<< getState
465- -- this may yield additional new constraints, left unevaluated
466- evaluatedConstraints <- predicates <$> getState
467- pure Pattern {constraints = evaluatedConstraints, term = newTerm, ceilConditions}
465+ solver <- (. smtSolver) <$> getConfig
466+ -- check initial constraints for consistency, reporting an error if they are Bottom
467+ SMT. isSat solver pat. constraints >>= \ case
468+ Right False -> do
469+ let collapseAndBools :: Set Predicate -> Predicate
470+ collapseAndBools = undefined
471+ -- the constraints are unsatisfiable, which means that the patten is Bottom
472+ throw . SideConditionFalse . collapseAndBools $ pat. constraints
473+ Left unknwon@ SMT. SMTSolverUnknown {} -> do
474+ -- unlikely case of an Unknown response to a consistency check.
475+ -- What to do here? fail hard for now.
476+ liftIO $ Exception. throw unknwon
477+ Left other -> liftIO $ Exception. throw other -- fail hard on other SMT errors
478+ Right True -> do
479+ -- constrains are consistent, continue
480+ newTerm <- withTermContext term $ evaluateTerm' BottomUp term `catch_` keepTopLevelResults
481+ -- after evaluating the term, evaluate all (existing and
482+ -- newly-acquired) constraints, once
483+ traverse_ simplifyAssumedPredicate . predicates =<< getState
484+ -- this may yield additional new constraints, left unevaluated
485+ evaluatedConstraints <- predicates <$> getState
486+ pure Pattern {constraints = evaluatedConstraints, term = newTerm, ceilConditions}
468487 where
469488 -- when TooManyIterations exception occurred while evaluating the top-level term,
470489 -- i.e. not in a recursive evaluation of a side-condition,
0 commit comments