Skip to content

Symbolic execution and search should apply rules correctly #2234

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 51 commits into from
Nov 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
e5f682e
Use LogicT instead of MaybeT
andreiburdusa Oct 27, 2020
2cdc16d
Exit code
andreiburdusa Oct 29, 2020
936683e
Stylish
andreiburdusa Oct 29, 2020
06a86ce
Merge remote-tracking branch 'upstream/master' into strategy-all-ignored
andreiburdusa Oct 29, 2020
9e094cf
Use seqstrict
andreiburdusa Oct 29, 2020
68cab8b
Update two golden files
andreiburdusa Oct 29, 2020
6671c5b
Update a golden file
andreiburdusa Oct 29, 2020
425a4f3
Update golden
andreiburdusa Oct 29, 2020
c9145c1
Kore.Step.transitionRule: do not ignore remainders
ana-pantilie Nov 1, 2020
6a4ea25
Merge remote-tracking branch 'upstream/master' into strategy-all-ignored
ana-pantilie Nov 6, 2020
ff48e9f
Step.transitionRule: add ExecutionState and transitionRuleSearch
ana-pantilie Nov 6, 2020
a4ed1f9
ExecutionState: StartExec + comment out traces
ana-pantilie Nov 9, 2020
788cebe
Step.transitionRule: correctly apply priority groups of rewrites
ana-pantilie Nov 9, 2020
8750219
Step.transitionRule: choose rewrite application procedure from CL str…
ana-pantilie Nov 9, 2020
91bf625
Step.transitionRule: simplifyRemainder
ana-pantilie Nov 9, 2020
5a37a84
Test.Kore.Step: remove outdated tests and fix implementation, will do…
ana-pantilie Nov 10, 2020
2fa54b0
Kore.Step: temporarily factor out transitionSimplify
ana-pantilie Nov 10, 2020
4abca15
Test.Kore.Exec: remove unused definitions and imports
ana-pantilie Nov 10, 2020
c182035
issue-2010: update golden
ana-pantilie Nov 10, 2020
3e25252
issue-1872: update golden
ana-pantilie Nov 10, 2020
ebc1dda
Add integration test issue-2205
ana-pantilie Nov 10, 2020
a2d0aa7
Kore.Exec.search: use new transitionRule
ana-pantilie Nov 10, 2020
c2de367
issue-2095: regenerate golden ?is this right?
ana-pantilie Nov 10, 2020
81a46eb
Kore.Exec.search: minor fix
ana-pantilie Nov 10, 2020
fb8c53c
SMT.Translate.translatePattern: add fallback for translateApplication
ana-pantilie Nov 11, 2020
39ef365
translatePattern: fallback checks if pattern is functional
ana-pantilie Nov 11, 2020
d957204
translatePattern: fallback case only for functional patterns
ana-pantilie Nov 11, 2020
fab5a42
SMT.Translate test cases: constructors, one functional, one arbitrary
ana-pantilie Nov 11, 2020
3dec78a
Merge branch 'master' into add-smt-application-translation-fallback
ana-pantilie Nov 12, 2020
12d78b1
Rule.Combine, Rule.Simplify tests: fix runners
ana-pantilie Nov 12, 2020
45f2078
SMT.Translate tests: remove TODOs
ana-pantilie Nov 12, 2020
a29c504
SMT.Translate tests: revert change
ana-pantilie Nov 12, 2020
3eb2c74
Address review comment: add explanation
ana-pantilie Nov 13, 2020
b5aaf5f
Address review comment: remove smtConstructor from MockSymbols
ana-pantilie Nov 13, 2020
affccf1
SMT.Translate.translateApplication: fixes and address review comment
ana-pantilie Nov 13, 2020
db68774
tests: some of the test data needed functional symbols
ana-pantilie Nov 13, 2020
6c42fd6
Merge remote-tracking branch 'origin/add-smt-application-translation-…
ana-pantilie Nov 13, 2020
ae6a169
issue-2010: revert expected output
ana-pantilie Nov 13, 2020
dafb0da
Test.Kore.Step: run test with SMT
ana-pantilie Nov 13, 2020
eea4cb3
Merge remote-tracking branch 'upstream/master' into strategy-all-ignored
ana-pantilie Nov 16, 2020
618e69c
Clean-up: remove old types
ana-pantilie Nov 16, 2020
85245c4
rename to extractProgramState, add instances
ana-pantilie Nov 17, 2020
45f20c1
Add tests for the symbolic execution strategy
ana-pantilie Nov 17, 2020
65d1645
Clean-up tests
ana-pantilie Nov 17, 2020
cacda76
General clean-up
ana-pantilie Nov 17, 2020
5b2076f
Search should not use --strategy CL option
ana-pantilie Nov 17, 2020
7242833
Review: clean-up strategy CL option
ana-pantilie Nov 18, 2020
6fa9671
Review: address documentation comments
ana-pantilie Nov 18, 2020
37eee35
Review: transitionRule and Prim clean-up
ana-pantilie Nov 18, 2020
11a0d91
Error message for strategy CL option
ana-pantilie Nov 18, 2020
fe36087
Merge branch 'master' into strategy-all-ignored
ttuegel Nov 19, 2020
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
45 changes: 24 additions & 21 deletions kore/app/exec/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import Options.Applicative
, value
)
import qualified Options.Applicative as Options
import qualified Options.Applicative.Help.Pretty as OptPretty
import System.Clock
( Clock (Monotonic)
, TimeSpec
Expand All @@ -82,7 +83,6 @@ import System.IO
, withFile
)

import qualified Data.Limit as Limit
import Kore.Attribute.Symbol as Attribute
import Kore.BugReport
import Kore.Exec
Expand Down Expand Up @@ -148,9 +148,6 @@ import Kore.Reachability
import qualified Kore.Reachability.Claim as Claim
import Kore.Rewriting.RewritingVariable
import Kore.Step
import Kore.Step.RulePattern
( RewriteRule
)
import Kore.Step.Search
( SearchType (..)
)
Expand Down Expand Up @@ -268,9 +265,6 @@ applyKoreSearchOptions Nothing koreExecOpts = koreExecOpts
applyKoreSearchOptions koreSearchOptions@(Just koreSearchOpts) koreExecOpts =
koreExecOpts
{ koreSearchOptions
, strategy =
-- Search relies on exploring the entire space of states.
("all", priorityAllStrategy)
, depthLimit = min depthLimit searchTypeDepthLimit
}
where
Expand All @@ -293,7 +287,7 @@ data KoreExecOptions = KoreExecOptions
-- ^ The name of the main module in the definition
, breadthLimit :: !(Limit Natural)
, depthLimit :: !(Limit Natural)
, strategy :: !(String, [RewriteRule RewritingVariableName] -> Strategy (Prim (RewriteRule RewritingVariableName)))
, strategy :: !ExecutionMode
, koreSolverOptions :: !KoreSolverOptions
, koreLogOptions :: !KoreLogOptions
, koreSearchOptions :: !(Maybe KoreSearchOptions)
Expand Down Expand Up @@ -346,17 +340,12 @@ parseKoreExecOptions startTime =
parseBreadthLimit = Limit <$> breadth <|> pure Unlimited
parseDepthLimit = Limit <$> depth <|> pure Unlimited
parseStrategy =
option (readSum "strategy" strategies)
option parseExecutionMode
( metavar "STRATEGY"
<> long "strategy"
<> value ("all", priorityAllStrategy)
<> value All
<> help "Select rewrites using STRATEGY."
)
where
strategies =
[ ("any", priorityAnyStrategy)
, ("all", priorityAllStrategy)
]

breadth =
option auto
Expand Down Expand Up @@ -384,6 +373,20 @@ parseKoreExecOptions startTime =
, long "rts-statistics"
, help "Write runtime statistics to FILENAME in JSON format."
]
parseExecutionMode = do
val <- str
case val :: String of
"all" -> return All
"any" -> return Any
_ ->
readerError
$ show
$ OptPretty.hsep
[ "Unknown option"
, OptPretty.squotes (OptPretty.text val)
<> OptPretty.dot
, "Known options are 'all' and 'any'."
]

-- | modifiers for the Command line parser description
parserInfoModifiers :: InfoMod options
Expand Down Expand Up @@ -462,7 +465,7 @@ koreExecSh
<$> maybeLimit Nothing Just breadthLimit
, (\limit -> unwords ["--depth", show limit])
<$> maybeLimit Nothing Just depthLimit
, pure $ unwords ["--strategy", fst strategy]
, pure $ unwords ["--strategy", unparseExecutionMode strategy]
, rtsStatistics $>
unwords ["--rts-statistics", defaultRtsStatisticsFilePath]
]
Expand All @@ -472,6 +475,8 @@ koreExecSh
, maybe mempty unparseKoreProveOptions koreProveOptions
, maybe mempty unparseKoreMergeOptions koreMergeOptions
]
unparseExecutionMode All = "all"
unparseExecutionMode Any = "any"

defaultDefinitionFilePath :: KoreExecOptions -> FilePath
defaultDefinitionFilePath KoreExecOptions { koreProveOptions }
Expand Down Expand Up @@ -615,14 +620,13 @@ koreSearch execOptions searchOptions = do
initial <- loadPattern mainModule patternFileName
final <-
execute execOptions mainModule
$ search breadthLimit mainModule strategy' initial target config
$ search depthLimit breadthLimit mainModule initial target config
lift $ renderResult execOptions (unparse final)
return ExitSuccess
where
KoreSearchOptions { bound, searchType } = searchOptions
config = Search.Config { bound, searchType }
KoreExecOptions { breadthLimit, depthLimit, strategy } = execOptions
strategy' = Limit.replicate depthLimit . snd strategy
KoreExecOptions { breadthLimit, depthLimit } = execOptions

koreRun :: KoreExecOptions -> Main ExitCode
koreRun execOptions = do
Expand All @@ -634,12 +638,11 @@ koreRun execOptions = do
initial <- loadPattern mainModule patternFileName
(exitCode, final) <-
execute execOptions mainModule
$ exec breadthLimit mainModule strategy' initial
$ exec depthLimit breadthLimit mainModule strategy initial
lift $ renderResult execOptions (unparse final)
return exitCode
where
KoreExecOptions { breadthLimit, depthLimit, strategy } = execOptions
strategy' = Limit.replicate depthLimit . snd strategy

koreProve :: KoreExecOptions -> KoreProveOptions -> Main ExitCode
koreProve execOptions proveOptions = do
Expand Down
63 changes: 35 additions & 28 deletions kore/src/Kore/Exec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,6 @@ import Kore.IndexedModule.Resolvers
( resolveInternalSymbol
)
import qualified Kore.Internal.Condition as Condition
import Kore.Internal.MultiOr
( make
)
import qualified Kore.Internal.MultiOr as MultiOr
import qualified Kore.Internal.OrPattern as OrPattern
import Kore.Internal.Pattern
Expand Down Expand Up @@ -160,7 +157,6 @@ import Kore.Step.Search
import qualified Kore.Step.Search as Search
import Kore.Step.Simplification.Data
( MonadProf
, SimplifierT
, evalSimplifier
)
import qualified Kore.Step.Simplification.Data as Simplifier
Expand Down Expand Up @@ -213,14 +209,14 @@ exec
, MonadProf smt
)
=> Limit Natural
-> Limit Natural
-> VerifiedModule StepperAttributes
-- ^ The main module
-> ([Rewrite] -> [Strategy (Prim Rewrite)])
-- ^ The strategy to use for execution; see examples in "Kore.Step.Step"
-> ExecutionMode
-> TermLike VariableName
-- ^ The input pattern
-> smt (ExitCode, TermLike VariableName)
exec breadthLimit verifiedModule strategy initialTerm =
exec depthLimit breadthLimit verifiedModule strategy initialTerm =
evalSimplifier verifiedModule' $ do
initialized <- initializeAndSimplify verifiedModule
let Initialized { rewriteRules } = initialized
Expand All @@ -237,9 +233,10 @@ exec breadthLimit verifiedModule strategy initialTerm =
. Strategy.applyBreadthLimit
breadthLimit
dropStrategy
rewriteGroups = groupRewritesByPriority rewriteRules
transit instr config =
Strategy.transitionRule
(transitionRule & trackExecDepth)
(transitionRule rewriteGroups strategy & trackExecDepth)
instr
config
& runTransitionT
Expand All @@ -248,24 +245,21 @@ exec breadthLimit verifiedModule strategy initialTerm =
Strategy.leavesM
updateQueue
(Strategy.unfoldTransition transit)
( strategy rewriteRules
, (ExecDepth 0, mkRewritingPattern initialConfig)
( limitedExecutionStrategy depthLimit
, (ExecDepth 0, Start (mkRewritingPattern initialConfig))
)
let (depths, finalConfigs) = unzip finals
infoExecDepth (maximum depths)
let finalConfigs' = make $ getRewritingPattern <$> finalConfigs
let finalConfigs' =
MultiOr.make
$ getRewritingPattern
. extractProgramState
<$> finalConfigs
exitCode <- getExitCode verifiedModule finalConfigs'
let finalTerm = forceSort initialSort $ OrPattern.toTermLike finalConfigs'
return (exitCode, finalTerm)
where
dropStrategy = snd
getFinalConfigsOf
:: LogicT
(SimplifierT smt)
( [Strategy (Prim (RewriteRule RewritingVariableName))]
, (ExecDepth, Pattern RewritingVariableName)
)
-> SimplifierT smt [(ExecDepth, Pattern RewritingVariableName)]
getFinalConfigsOf act = observeAllT $ fmap snd act
verifiedModule' =
IndexedModule.mapPatterns
Expand All @@ -290,8 +284,8 @@ trackExecDepth transit prim (execDepth, execState) = do
where
didRewrite _ = isRewrite prim

isRewrite Simplify = False
isRewrite (Rewrite _) = True
isRewrite Rewrite = True
isRewrite _ = False

-- | Project the value of the exit cell, if it is present.
getExitCode
Expand Down Expand Up @@ -341,18 +335,17 @@ search
, MonadProf smt
)
=> Limit Natural
-> Limit Natural
-> VerifiedModule StepperAttributes
-- ^ The main module
-> ([Rewrite] -> [Strategy (Prim Rewrite)])
-- ^ The strategy to use for execution; see examples in "Kore.Step.Step"
-> TermLike VariableName
-- ^ The input pattern
-> Pattern VariableName
-- ^ The pattern to match during execution
-> Search.Config
-- ^ The bound on the number of search matches and the search type
-> smt (TermLike VariableName)
search breadthLimit verifiedModule strategy termLike searchPattern searchConfig
search depthLimit breadthLimit verifiedModule termLike searchPattern searchConfig
=
evalSimplifier verifiedModule $ do
initialized <- initializeAndSimplify verifiedModule
Expand All @@ -365,15 +358,30 @@ search breadthLimit verifiedModule strategy termLike searchPattern searchConfig
case toList simplifiedPatterns of
[] -> Pattern.bottomOf (termLikeSort termLike)
(config : _) -> config
rewriteGroups =
groupRewritesByPriority rewriteRules
runStrategy' =
runStrategy breadthLimit transitionRule (strategy rewriteRules)
executionGraph <- runStrategy' (mkRewritingPattern initialPattern)
runStrategy
breadthLimit
-- search relies on exploring
-- the entire space of states.
(transitionRule rewriteGroups All)
(limitedExecutionStrategy depthLimit)
executionGraph <-
runStrategy' (Start $ mkRewritingPattern initialPattern)
let
match target config = Search.matchWith target config
match target config1 config2 =
Search.matchWith
target
config1
(extractProgramState config2)
solutionsLists <-
searchGraph
searchConfig
(match SideCondition.topTODO (mkRewritingPattern searchPattern))
(match
SideCondition.topTODO
(mkRewritingPattern searchPattern)
)
executionGraph
let
solutions = concatMap toList solutionsLists
Expand All @@ -387,7 +395,6 @@ search breadthLimit verifiedModule strategy termLike searchPattern searchConfig
where
patternSort = termLikeSort termLike


-- | Proving a spec given as a module containing rules to be proven
prove
:: forall smt
Expand Down
Loading