Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions kore/src/Kore/Exec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,10 @@ exec
<$> finalConfigs
exitCode <- getExitCode verifiedModule finalConfigs'
let finalTerm =
forceSort initialSort $
OrPattern.toTermLike
(MultiOr.map getRewritingPattern finalConfigs')
OrPattern.toTermLike
initialSort
(MultiOr.map getRewritingPattern finalConfigs')
& forceSort initialSort
return (exitCode, finalTerm)
where
dropStrategy = snd
Expand Down
10 changes: 10 additions & 0 deletions kore/src/Kore/Internal/MultiOr.hs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ import GHC.Exts (
)
import qualified GHC.Generics as GHC
import qualified Generics.SOP as SOP
import Kore.Attribute.Pattern.FreeVariables (
HasFreeVariables (..),
)
import Kore.Debug
import Kore.Internal.MultiAnd (
MultiAnd,
Expand Down Expand Up @@ -111,6 +114,13 @@ instance (Ord child, TopBottom child) => From [child] (MultiOr child) where
instance From (MultiOr child) [child] where
from = getMultiOr

instance
(Ord variable, HasFreeVariables child variable) =>
HasFreeVariables (MultiOr child) variable
where
freeVariables = foldMap freeVariables . getMultiOr
{-# INLINE freeVariables #-}

bottom :: MultiOr term
bottom = MultiOr []

Expand Down
12 changes: 7 additions & 5 deletions kore/src/Kore/Internal/OrPattern.hs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ import Kore.Internal.TermLike (
InternalVariable,
Sort,
TermLike,
mkBottom_,
mkBottom,
mkOr,
)
import Kore.Syntax.Variable
Expand Down Expand Up @@ -164,11 +164,12 @@ isTrue = isTop
toPattern ::
forall variable.
InternalVariable variable =>
Sort ->
OrPattern variable ->
Pattern variable
toPattern multiOr =
toPattern sort multiOr =
case toList multiOr of
[] -> Pattern.bottom
[] -> Pattern.bottomOf sort
[patt] -> patt
patts -> foldr1 mergeWithOr patts
where
Expand Down Expand Up @@ -201,11 +202,12 @@ isPredicate = all Pattern.isPredicate
-- | Transforms a 'Pattern' into a 'TermLike'.
toTermLike ::
InternalVariable variable =>
Sort ->
OrPattern variable ->
TermLike variable
toTermLike multiOr =
toTermLike sort multiOr =
case toList multiOr of
[] -> mkBottom_
[] -> mkBottom sort
[patt] -> Pattern.toTermLike patt
patts -> foldr1 mkOr (Pattern.toTermLike <$> patts)

Expand Down
13 changes: 0 additions & 13 deletions kore/src/Kore/Internal/Pattern.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ module Kore.Internal.Pattern (
fromCondition_,
fromTermAndPredicate,
fromPredicateSorted,
bottom,
bottomOf,
isBottom,
isTop,
Expand Down Expand Up @@ -81,7 +80,6 @@ import Kore.Internal.TermLike (
TermLike,
mkAnd,
mkBottom,
mkBottom_,
mkTop,
mkTop_,
termLikeSort,
Expand Down Expand Up @@ -239,17 +237,6 @@ toTermLike Conditional{term, predicate, substitution} =
predicateTermLike = Predicate.fromPredicate sort predicate'
sort = termLikeSort pattern'

{- |'bottom' is an expanded pattern that has a bottom condition and that
should become Bottom when transformed to a ML pattern.
-}
bottom :: InternalVariable variable => Pattern variable
bottom =
Conditional
{ term = mkBottom_
, predicate = Predicate.makeFalsePredicate
, substitution = mempty
}

{- | An 'Pattern' where the 'term' is 'Bottom' of the given 'Sort'.

The 'predicate' is set to 'makeFalsePredicate'.
Expand Down
14 changes: 0 additions & 14 deletions kore/src/Kore/Internal/TermLike.hs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ module Kore.Internal.TermLike (
mkSignedness,

-- * Predicate constructors
mkBottom_,
mkCeil_,
mkEquals_,
mkFloor_,
Expand Down Expand Up @@ -975,19 +974,6 @@ mkBottom ::
mkBottom bottomSort =
updateCallStack $ synthesize (BottomF Bottom{bottomSort})

{- | Construct a 'Bottom' pattern in 'predicateSort'.

This should not be used outside "Kore.Internal.Predicate"; please use
'mkBottom' instead.

See also: 'mkBottom'
-}
mkBottom_ ::
HasCallStack =>
InternalVariable variable =>
TermLike variable
mkBottom_ = updateCallStack $ mkBottom predicateSort

{- | Construct a 'Ceil' pattern in the given sort.

See also: 'mkCeil_'
Expand Down
13 changes: 6 additions & 7 deletions kore/src/Kore/Step/ClaimPattern.hs
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,15 @@ instance Pretty ClaimPattern where
, "existentials:"
, Pretty.indent 4 (Pretty.list $ unparse <$> existentials)
, "right:"
, Pretty.indent 4 (unparse $ OrPattern.toTermLike right)
, Pretty.indent 4 (unparse $ OrPattern.toTermLike sort right)
]
where
ClaimPattern
{ left
, right
, existentials
} = claimPattern'
sort = TermLike.termLikeSort (Pattern.term left)

instance TopBottom ClaimPattern where
isTop _ = False
Expand All @@ -141,13 +142,11 @@ freeVariablesRight ::
ClaimPattern ->
FreeVariables RewritingVariableName
freeVariablesRight claimPattern'@(ClaimPattern _ _ _ _) =
freeVariables
( TermLike.mkExistsN
existentials
(OrPattern.toTermLike right)
)
freeVariables right
& FreeVariables.bindVariables boundVariables
where
ClaimPattern{right, existentials} = claimPattern'
boundVariables = inject @(SomeVariable _) <$> existentials

freeVariablesLeft ::
ClaimPattern ->
Expand Down Expand Up @@ -214,7 +213,7 @@ claimPatternToTerm modality representation@(ClaimPattern _ _ _ _) =
& Pattern.toTermLike
& getRewritingTerm
rightPattern =
TermLike.mkExistsN existentials (OrPattern.toTermLike right)
TermLike.mkExistsN existentials (OrPattern.toTermLike sort right)
& getRewritingTerm

substituteRight ::
Expand Down
13 changes: 6 additions & 7 deletions kore/src/Kore/Step/Implication.hs
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,15 @@ instance Pretty (Implication modality) where
, "existentials:"
, Pretty.indent 4 (Pretty.list $ unparse <$> existentials)
, "right:"
, Pretty.indent 4 (unparse $ OrPattern.toTermLike right)
, Pretty.indent 4 (unparse $ OrPattern.toTermLike sort right)
]
where
Implication
{ left
, right
, existentials
} = implication'
sort = TermLike.termLikeSort (Pattern.term left)

instance TopBottom (Implication modality) where
isTop _ = False
Expand All @@ -143,13 +144,11 @@ freeVariablesRight ::
Implication modality ->
FreeVariables RewritingVariableName
freeVariablesRight implication'@(Implication _ _ _ _ _) =
freeVariables
( TermLike.mkExistsN
existentials
(OrPattern.toTermLike right)
)
freeVariables right
& FreeVariables.bindVariables boundVariables
where
Implication{right, existentials} = implication'
boundVariables = inject @(SomeVariable _) <$> existentials

freeVariablesLeft ::
Implication modality ->
Expand Down Expand Up @@ -217,7 +216,7 @@ implicationToTerm representation@(Implication _ _ _ _ _) =
& Predicate.fromPredicate sort
& getRewritingTerm
rightPattern =
TermLike.mkExistsN existentials (OrPattern.toTermLike right)
TermLike.mkExistsN existentials (OrPattern.toTermLike sort right)
& getRewritingTerm

substituteRight ::
Expand Down
11 changes: 8 additions & 3 deletions kore/src/Kore/Step/Simplification/Equals.hs
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,16 @@ simplify ::
SideCondition RewritingVariableName ->
Equals Sort (OrPattern RewritingVariableName) ->
simplifier (OrPattern RewritingVariableName)
simplify sideCondition Equals{equalsFirst = first, equalsSecond = second} =
simplify sideCondition equals =
simplifyEvaluated sideCondition first' second'
where
(first', second') =
minMaxBy (on compareForEquals OrPattern.toTermLike) first second
Equals
{ equalsOperandSort
, equalsFirst = first
, equalsSecond = second
} = equals
comparison = on compareForEquals (OrPattern.toTermLike equalsOperandSort)
(first', second') = minMaxBy comparison first second

{- TODO (virgil): Preserve pattern sorts under simplification.

Expand Down
15 changes: 8 additions & 7 deletions kore/src/Kore/Step/Simplification/Next.hs
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,15 @@ Right now this does not do any actual simplification.
simplify ::
Next Sort (OrPattern RewritingVariableName) ->
OrPattern RewritingVariableName
simplify Next{nextChild = child} = simplifyEvaluated child
simplify Next{nextChild = child, nextSort = sort} = simplifyEvaluated sort child

simplifyEvaluated ::
Sort ->
OrPattern RewritingVariableName ->
OrPattern RewritingVariableName
simplifyEvaluated simplified =
OrPattern.fromTermLike $
TermLike.markSimplified $
mkNext $
Pattern.toTermLike $
OrPattern.toPattern simplified
simplifyEvaluated sort simplified =
OrPattern.toPattern sort simplified
& Pattern.toTermLike
& mkNext
& TermLike.markSimplified
& OrPattern.fromTermLike
20 changes: 11 additions & 9 deletions kore/src/Kore/Step/Simplification/Rewrites.hs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ simplify
Rewrites
{ rewritesFirst = first
, rewritesSecond = second
, rewritesSort = sort
} =
simplifyEvaluatedRewrites first second
simplifyEvaluatedRewrites sort first second

{- TODO (virgil): Preserve pattern sorts under simplification.

Expand All @@ -55,21 +56,22 @@ will make it even more useful to carry around.

-}
simplifyEvaluatedRewrites ::
Sort ->
OrPattern RewritingVariableName ->
OrPattern RewritingVariableName ->
OrPattern RewritingVariableName
simplifyEvaluatedRewrites first second =
simplifyEvaluatedRewrites sort first second =
makeEvaluateRewrites
(OrPattern.toPattern first)
(OrPattern.toPattern second)
(OrPattern.toPattern sort first)
(OrPattern.toPattern sort second)

makeEvaluateRewrites ::
Pattern RewritingVariableName ->
Pattern RewritingVariableName ->
OrPattern RewritingVariableName
makeEvaluateRewrites first second =
OrPattern.fromTermLike $
TermLike.markSimplified $
mkRewrites
(Pattern.toTermLike first)
(Pattern.toTermLike second)
mkRewrites
(Pattern.toTermLike first)
(Pattern.toTermLike second)
& TermLike.markSimplified
& OrPattern.fromTermLike
3 changes: 2 additions & 1 deletion kore/test/Test/Kore/Step/Simplification/Pattern.hs
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,9 @@ test_Pattern_simplify_equalityterm =
)
]
first = Mock.cf
sort = termLikeSort first
second =
OrPattern.toTermLike
OrPattern.toTermLike sort
. OrPattern.fromPatterns
$ [ Conditional
{ term = Mock.cg
Expand Down