Skip to content

Commit

Permalink
Format with fourmolu
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions committed Aug 19, 2024
1 parent 18e89bb commit 64eec65
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 21 deletions.
6 changes: 3 additions & 3 deletions booster/library/Booster/SMT/Interface.hs
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,6 @@ closureOver atoms exprs = loop mempty exprs atoms
loop acc exprs' currentAtoms =
let (addedExprs, rest) = Set.partition (Set.null . Set.intersection currentAtoms . smtVars) exprs'
newAtoms = Set.unions $ Set.map smtVars addedExprs
in if Set.null addedExprs
then acc
else loop (acc <> addedExprs) rest newAtoms
in if Set.null addedExprs
then acc
else loop (acc <> addedExprs) rest newAtoms
17 changes: 11 additions & 6 deletions kore/src/Kore/Rewrite/SMT/Evaluator.hs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,11 @@ evalPredicate onUnknown predicate sideConditionM = case predicate of
Nothing ->
decidePredicate onUnknown SideCondition.top [] predicate
Just sideCondition ->
decidePredicate onUnknown sideCondition (Predicate.getMultiAndPredicate $ from @_ @(Predicate _) sideCondition) predicate
decidePredicate
onUnknown
sideCondition
(Predicate.getMultiAndPredicate $ from @_ @(Predicate _) sideCondition)
predicate

{- | Attempt to evaluate the 'Conditional' argument with an optional side
condition using an external SMT solver.
Expand Down Expand Up @@ -193,11 +197,12 @@ decidePredicate onUnknown sideCondition sideConditionPredicates predicate =
query = onErrorUnknown $ SMT.withSolver . evalTranslator $ do
tools <- Simplifier.askMetadataTools
Morph.hoist SMT.liftSMT $ do
sideConditionPredicates' <- concatMap SMT.splitAnd <$>
traverse
(translatePredicate sideCondition tools)
sideConditionPredicates
predicate' <- SMT.splitAnd <$> translatePredicate sideCondition tools predicate
sideConditionPredicates' <-
concatMap SMT.splitAnd
<$> traverse
(translatePredicate sideCondition tools)
sideConditionPredicates
predicate' <- SMT.splitAnd <$> translatePredicate sideCondition tools predicate
let predicates' = SMT.transitiveClosure (Set.fromList predicate') $ Set.fromList sideConditionPredicates'
-- when (Set.fromList predicate' /= predicates') $ liftIO $ do
-- putStrLn $ "predicate: " <> show (Set.fromList predicate')
Expand Down
26 changes: 14 additions & 12 deletions kore/src/SMT/Utils.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module SMT.Utils (module SMT.Utils) where

import Data.Set (Set)
import Data.Set qualified as Set
import Data.Text (Text, isPrefixOf, isSuffixOf)
Expand All @@ -8,21 +9,22 @@ import SMT qualified

splitAnd :: SMT.SExpr -> [SMT.SExpr]
splitAnd = \case
SMT.List (SMT.Atom "and": xs) -> concatMap splitAnd xs
other -> [other]
SMT.List (SMT.Atom "and" : xs) -> concatMap splitAnd xs
other -> [other]

varAtoms :: SMT.SExpr -> Set Text
varAtoms = \case
SMT.Atom a
| "<" `isPrefixOf` a && ">" `isSuffixOf` a -> Set.singleton a
| otherwise -> mempty
SMT.List xs -> mconcat $ map varAtoms xs
_ -> mempty
SMT.Atom a
| "<" `isPrefixOf` a && ">" `isSuffixOf` a -> Set.singleton a
| otherwise -> mempty
SMT.List xs -> mconcat $ map varAtoms xs
_ -> mempty

transitiveClosure :: Set SMT.SExpr -> Set SMT.SExpr -> Set SMT.SExpr
transitiveClosure :: Set SMT.SExpr -> Set SMT.SExpr -> Set SMT.SExpr
transitiveClosure cl' rest' = loop (Set.unions (Set.map varAtoms cl')) cl' rest'
where
loop clVars cl rest =
let (nonCommon, common) = Set.partition (null . Set.intersection clVars . varAtoms) rest in
if null common then cl else
loop (clVars <> Set.unions (Set.map varAtoms common)) (cl <> common) nonCommon
loop clVars cl rest =
let (nonCommon, common) = Set.partition (null . Set.intersection clVars . varAtoms) rest
in if null common
then cl
else loop (clVars <> Set.unions (Set.map varAtoms common)) (cl <> common) nonCommon

0 comments on commit 64eec65

Please sign in to comment.