Skip to content

Always output fully-simplified states #2303

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Dec 9, 2020
Merged
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
28 changes: 21 additions & 7 deletions kore/src/Kore/Step.hs
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,27 @@ retractRemaining _ = Nothing
-}
executionStrategy :: Stream (Strategy Prim)
executionStrategy =
(Strategy.sequence . fmap Strategy.apply)
[ Begin
, Simplify
, Rewrite
]
& Stream.iterate id
step1 Stream.:> Stream.iterate id stepN
where
step1 =
(Strategy.sequence . fmap Strategy.apply)
[ Begin
, Simplify
, Rewrite
, Simplify
]
stepN =
(Strategy.sequence . fmap Strategy.apply)
[ Begin
, Rewrite
, Simplify
]

{- | The sequence of transitions under the specified depth limit.

See also: 'executionStrategy'

-}
limitedExecutionStrategy :: Limit Natural -> [Strategy Prim]
limitedExecutionStrategy depthLimit =
Limit.takeWithin depthLimit (toList executionStrategy)
Expand All @@ -119,7 +133,7 @@ data Prim
= Begin
| Simplify
| Rewrite
deriving (Show)
deriving (Eq, Show)

{- The two modes of symbolic execution. Each mode determines the way
rewrite rules are applied during a rewrite step.
Expand Down
49 changes: 49 additions & 0 deletions kore/test/Test/Kore/Step.hs
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
module Test.Kore.Step
( test_stepStrategy
, test_executionStrategy
) where

import Prelude.Kore

import Hedgehog
( Gen
)
import qualified Hedgehog
import qualified Hedgehog.Gen
import qualified Hedgehog.Range
import Test.Tasty
import Test.Tasty.Hedgehog

import qualified Control.Exception as Exception
import qualified Control.Lens as Lens
Expand Down Expand Up @@ -298,6 +306,47 @@ test_stepStrategy =
Right _ ->
assertFailure "Expected exception LimitExceeded"

test_executionStrategy :: [TestTree]
test_executionStrategy =
[ testProperty "every step contains Rewrite" $ Hedgehog.property $ do
strategies <- Hedgehog.forAll genStrategies
for_ strategies $ \strategy -> do
Hedgehog.annotateShow strategy
Hedgehog.assert (hasRewrite strategy)

, testProperty "Simplify is the last sub-step" $ Hedgehog.property $ do
strategies <- Hedgehog.forAll genStrategies
let strategy = last strategies
Hedgehog.annotateShow strategy
Hedgehog.assert (isLastSimplify strategy)
]
where
genStrategies :: Gen [Strategy Prim]
genStrategies = do
let range = Hedgehog.Gen.integral (Hedgehog.Range.linear 1 16)
depthLimit <- Limit <$> range
pure (limitedExecutionStrategy depthLimit)

hasRewrite :: Strategy Prim -> Bool
hasRewrite = \case
Strategy.Seq s1 s2 -> hasRewrite s1 || hasRewrite s2
Strategy.And s1 s2 -> hasRewrite s1 || hasRewrite s2
Strategy.Or s1 s2 -> hasRewrite s1 || hasRewrite s2
Strategy.Apply p -> p == Rewrite
Strategy.Stuck -> False
Strategy.Continue -> False

isLastSimplify :: Strategy Prim -> Bool
isLastSimplify = \case
Strategy.Seq s Strategy.Continue -> isLastSimplify s
Strategy.Seq s Strategy.Stuck -> isLastSimplify s
Strategy.Seq _ s -> isLastSimplify s
Strategy.And s1 s2 -> isLastSimplify s1 && isLastSimplify s2
Strategy.Or s1 s2 -> isLastSimplify s1 && isLastSimplify s2
Strategy.Apply p -> p == Simplify
Strategy.Stuck -> False
Strategy.Continue -> False

simpleRewrite
:: TermLike VariableName
-> TermLike VariableName
Expand Down