Skip to content

Commit c5f3aef

Browse files
ttuegelrv-jenkins
andauthored
Replace ListT and BranchT with LogicT (#1806)
* Replace ListT and BranchT with LogicT * Logic: Linting * termEqualsAnd: Omit lowerLogicT * TermLikeSimplifier: Use any MonadLogic * simplifyConditionalTerm: Generalize from LogicT * Logic: Add missing module header * Keep names observeAll and observeAllT consistent Co-authored-by: rv-jenkins <[email protected]>
1 parent 1407e08 commit c5f3aef

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+321
-831
lines changed

kore/package.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ dependencies:
6767
- haskeline >=0.7
6868
- integer-gmp >=1.0
6969
- lens >=4.17
70+
- logict >=0.7
7071
- megaparsec >= 7.0.4
7172
- memory >=0.14
7273
- mmorph >=1.1

kore/src/Branch.hs

Lines changed: 0 additions & 165 deletions
This file was deleted.

kore/src/Kore/Builtin/AssociativeCommutative.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ import Data.Reflection
5858
)
5959
import qualified Data.Reflection as Reflection
6060

61-
import Branch
6261
import qualified Kore.Attribute.Pattern.Simplified as Attribute
6362
( Simplified
6463
)
@@ -119,6 +118,7 @@ import Kore.Unparser
119118
, unparseToString
120119
)
121120
import qualified Kore.Unparser as Unparser
121+
import Logic
122122
import Pretty
123123
( Doc
124124
)
@@ -978,7 +978,7 @@ unifyEqualsNormalizedAc
978978

979979
simplify :: TermLike variable -> unifier (Pattern variable)
980980
simplify term =
981-
alternate $ simplifyConditionalTerm SideCondition.topTODO term
981+
lowerLogicT $ simplifyConditionalTerm SideCondition.topTODO term
982982

983983
simplifyPair
984984
:: (TermLike variable, Domain.Value normalized (TermLike variable))
@@ -1017,7 +1017,7 @@ unifyEqualsNormalizedAc
10171017
where
10181018
simplifyTermLike :: TermLike variable -> unifier (Pattern variable)
10191019
simplifyTermLike term =
1020-
alternate $ simplifyConditionalTerm SideCondition.topTODO term
1020+
lowerLogicT $ simplifyConditionalTerm SideCondition.topTODO term
10211021

10221022
buildResultFromUnifiers
10231023
:: forall normalized unifier variable

kore/src/Kore/Builtin/KEqual.hs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ import Data.Text
4646
( Text
4747
)
4848

49-
import qualified Branch
5049
import Kore.Attribute.Hook
5150
( Hook (..)
5251
)
@@ -78,6 +77,7 @@ import Kore.Unification.Unify as Unify
7877
import Kore.Unification.Unify
7978
( MonadUnify
8079
)
80+
import qualified Logic
8181

8282
verifiers :: Builtin.Verifiers
8383
verifiers =
@@ -302,13 +302,11 @@ unifyIfThenElse unifyChildren a b =
302302
let branchCondition = takeCondition True condition
303303
Pattern.andCondition solution branchCondition
304304
& simplifyCondition SideCondition.top
305-
& Branch.gather
306-
& (>>= Unify.scatter)
305+
& Logic.lowerLogicT
307306
takeBranch2 IfThenElse { condition, branch2 } = do
308307
solution <- unifyChildren branch2 termLike2
309308
let branchCondition = takeCondition False condition
310309
Pattern.andCondition solution branchCondition
311310
& simplifyCondition SideCondition.top
312-
& Branch.gather
313-
& (>>= Unify.scatter)
311+
& Logic.lowerLogicT
314312
worker _ _ = empty

kore/src/Kore/Equation/Application.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ checkRequires sideCondition predicate requires =
292292
-- Collect the simplified results. If they are \bottom, then \and(predicate,
293293
-- requires) is valid; otherwise, the required pre-conditions are not met
294294
-- and the rule will not be applied.
295-
& (OrCondition.gather >=> assertBottom)
295+
& (OrCondition.observeAllT >=> assertBottom)
296296
where
297297
simplifyCondition = Simplifier.simplifyCondition sideCondition'
298298

kore/src/Kore/Internal/MultiOr.hs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ module Kore.Internal.MultiOr
2121
, flattenGeneric
2222
, fullCrossProduct
2323
, gather
24+
, observeAllT
2425
, make
2526
, merge
2627
, mergeAll
@@ -44,14 +45,15 @@ import GHC.Exts
4445
)
4546
import qualified GHC.Generics as GHC
4647

47-
import Branch
48-
( BranchT
49-
)
50-
import qualified Branch as BranchT
5148
import Kore.Debug
5249
import Kore.TopBottom
5350
( TopBottom (..)
5451
)
52+
import Logic
53+
( LogicT
54+
, MonadLogic
55+
)
56+
import qualified Logic
5557

5658
{-| 'MultiOr' is a Matching logic or of its children
5759
@@ -348,7 +350,8 @@ crossProductGeneric
348350
crossProductGeneric joiner (MultiOr first) (MultiOr second) =
349351
MultiOr $ joiner <$> first <*> second
350352

351-
gather
352-
:: (Ord a, TopBottom a, Monad m)
353-
=> BranchT m a -> m (MultiOr a)
354-
gather branched = make <$> BranchT.gather branched
353+
gather :: (Ord a, TopBottom a, MonadLogic m) => m a -> m (MultiOr a)
354+
gather act = make <$> Logic.gather act
355+
356+
observeAllT :: (Ord a, TopBottom a, Monad m) => LogicT m a -> m (MultiOr a)
357+
observeAllT act = make <$> Logic.observeAllT act

kore/src/Kore/Internal/OrCondition.hs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ module Kore.Internal.OrCondition
1010
, fromConditions
1111
, fromCondition
1212
, fromPredicate
13-
, gather
13+
, MultiOr.gather
14+
, MultiOr.observeAllT
1415
, bottom
1516
, top
1617
, isFalse
@@ -22,9 +23,6 @@ import Prelude.Kore
2223

2324
import qualified Data.Foldable as Foldable
2425

25-
import Branch
26-
( BranchT
27-
)
2826
import Kore.Internal.Condition
2927
( Condition
3028
)
@@ -47,7 +45,6 @@ import Kore.TopBottom
4745
( TopBottom (..)
4846
)
4947

50-
5148
{-| The disjunction of 'Condition'.
5249
-}
5350
type OrCondition variable = MultiOr (Condition variable)
@@ -113,8 +110,3 @@ toPredicate
113110
=> MultiOr (Predicate variable) -> Predicate variable
114111
toPredicate multiOr =
115112
Predicate.makeMultipleOrPredicate (MultiOr.extractPatterns multiOr)
116-
117-
gather
118-
:: (InternalVariable variable, Monad m)
119-
=> BranchT m (Condition variable) -> m (OrCondition variable)
120-
gather = MultiOr.gather

kore/src/Kore/Internal/OrPattern.hs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ module Kore.Internal.OrPattern
1212
, toPatterns
1313
, fromPattern
1414
, fromTermLike
15-
, gather
1615
, bottom
1716
, isFalse
1817
, isPredicate
@@ -23,15 +22,14 @@ module Kore.Internal.OrPattern
2322
, targetBinder
2423
, MultiOr.flatten
2524
, MultiOr.filterOr
25+
, MultiOr.gather
26+
, MultiOr.observeAllT
2627
) where
2728

2829
import Prelude.Kore
2930

3031
import qualified Data.Foldable as Foldable
3132

32-
import Branch
33-
( BranchT
34-
)
3533
import Kore.Internal.Condition
3634
( Condition
3735
)
@@ -200,11 +198,6 @@ coerceSort sort =
200198
. map (Pattern.coerceSort sort)
201199
. toPatterns
202200

203-
gather
204-
:: (InternalVariable variable, Monad m)
205-
=> BranchT m (Pattern variable) -> m (OrPattern variable)
206-
gather = MultiOr.gather
207-
208201
targetBinder
209202
:: forall variable
210203
. InternalVariable variable

kore/src/Kore/Profiler/Data.hs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ import System.Clock
5757
)
5858

5959
import Control.Monad.Counter
60-
import ListT
61-
( ListT (..)
62-
, mapListT
60+
import Logic
61+
( LogicT
6362
)
63+
import qualified Logic
6464

6565
{- | Monad that can also handle profiling events.
6666
-}
@@ -274,8 +274,8 @@ instance MonadProfiler m => MonadProfiler (ExceptT e m)
274274

275275
instance MonadProfiler m => MonadProfiler (IdentityT m)
276276

277-
instance MonadProfiler m => MonadProfiler (ListT m) where
278-
profile a = mapListT (profile a)
277+
instance MonadProfiler m => MonadProfiler (LogicT m) where
278+
profile a = Logic.mapLogicT (profile a)
279279
{-# INLINE profile #-}
280280

281281
instance MonadProfiler m => MonadProfiler (MaybeT m)

0 commit comments

Comments
 (0)