Skip to content

Commit 6ae3e32

Browse files
authored
Symbolic execution and search should apply rules correctly (#2234)
1 parent 97edcf4 commit 6ae3e32

File tree

12 files changed

+9932
-1777
lines changed

12 files changed

+9932
-1777
lines changed

kore/app/exec/Main.hs

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ import Options.Applicative
5656
, value
5757
)
5858
import qualified Options.Applicative as Options
59+
import qualified Options.Applicative.Help.Pretty as OptPretty
5960
import System.Clock
6061
( Clock (Monotonic)
6162
, TimeSpec
@@ -82,7 +83,6 @@ import System.IO
8283
, withFile
8384
)
8485

85-
import qualified Data.Limit as Limit
8686
import Kore.Attribute.Symbol as Attribute
8787
import Kore.BugReport
8888
import Kore.Exec
@@ -148,9 +148,6 @@ import Kore.Reachability
148148
import qualified Kore.Reachability.Claim as Claim
149149
import Kore.Rewriting.RewritingVariable
150150
import Kore.Step
151-
import Kore.Step.RulePattern
152-
( RewriteRule
153-
)
154151
import Kore.Step.Search
155152
( SearchType (..)
156153
)
@@ -268,9 +265,6 @@ applyKoreSearchOptions Nothing koreExecOpts = koreExecOpts
268265
applyKoreSearchOptions koreSearchOptions@(Just koreSearchOpts) koreExecOpts =
269266
koreExecOpts
270267
{ koreSearchOptions
271-
, strategy =
272-
-- Search relies on exploring the entire space of states.
273-
("all", priorityAllStrategy)
274268
, depthLimit = min depthLimit searchTypeDepthLimit
275269
}
276270
where
@@ -293,7 +287,7 @@ data KoreExecOptions = KoreExecOptions
293287
-- ^ The name of the main module in the definition
294288
, breadthLimit :: !(Limit Natural)
295289
, depthLimit :: !(Limit Natural)
296-
, strategy :: !(String, [RewriteRule RewritingVariableName] -> Strategy (Prim (RewriteRule RewritingVariableName)))
290+
, strategy :: !ExecutionMode
297291
, koreSolverOptions :: !KoreSolverOptions
298292
, koreLogOptions :: !KoreLogOptions
299293
, koreSearchOptions :: !(Maybe KoreSearchOptions)
@@ -346,17 +340,12 @@ parseKoreExecOptions startTime =
346340
parseBreadthLimit = Limit <$> breadth <|> pure Unlimited
347341
parseDepthLimit = Limit <$> depth <|> pure Unlimited
348342
parseStrategy =
349-
option (readSum "strategy" strategies)
343+
option parseExecutionMode
350344
( metavar "STRATEGY"
351345
<> long "strategy"
352-
<> value ("all", priorityAllStrategy)
346+
<> value All
353347
<> help "Select rewrites using STRATEGY."
354348
)
355-
where
356-
strategies =
357-
[ ("any", priorityAnyStrategy)
358-
, ("all", priorityAllStrategy)
359-
]
360349

361350
breadth =
362351
option auto
@@ -384,6 +373,20 @@ parseKoreExecOptions startTime =
384373
, long "rts-statistics"
385374
, help "Write runtime statistics to FILENAME in JSON format."
386375
]
376+
parseExecutionMode = do
377+
val <- str
378+
case val :: String of
379+
"all" -> return All
380+
"any" -> return Any
381+
_ ->
382+
readerError
383+
$ show
384+
$ OptPretty.hsep
385+
[ "Unknown option"
386+
, OptPretty.squotes (OptPretty.text val)
387+
<> OptPretty.dot
388+
, "Known options are 'all' and 'any'."
389+
]
387390

388391
-- | modifiers for the Command line parser description
389392
parserInfoModifiers :: InfoMod options
@@ -462,7 +465,7 @@ koreExecSh
462465
<$> maybeLimit Nothing Just breadthLimit
463466
, (\limit -> unwords ["--depth", show limit])
464467
<$> maybeLimit Nothing Just depthLimit
465-
, pure $ unwords ["--strategy", fst strategy]
468+
, pure $ unwords ["--strategy", unparseExecutionMode strategy]
466469
, rtsStatistics $>
467470
unwords ["--rts-statistics", defaultRtsStatisticsFilePath]
468471
]
@@ -472,6 +475,8 @@ koreExecSh
472475
, maybe mempty unparseKoreProveOptions koreProveOptions
473476
, maybe mempty unparseKoreMergeOptions koreMergeOptions
474477
]
478+
unparseExecutionMode All = "all"
479+
unparseExecutionMode Any = "any"
475480

476481
defaultDefinitionFilePath :: KoreExecOptions -> FilePath
477482
defaultDefinitionFilePath KoreExecOptions { koreProveOptions }
@@ -615,14 +620,13 @@ koreSearch execOptions searchOptions = do
615620
initial <- loadPattern mainModule patternFileName
616621
final <-
617622
execute execOptions mainModule
618-
$ search breadthLimit mainModule strategy' initial target config
623+
$ search depthLimit breadthLimit mainModule initial target config
619624
lift $ renderResult execOptions (unparse final)
620625
return ExitSuccess
621626
where
622627
KoreSearchOptions { bound, searchType } = searchOptions
623628
config = Search.Config { bound, searchType }
624-
KoreExecOptions { breadthLimit, depthLimit, strategy } = execOptions
625-
strategy' = Limit.replicate depthLimit . snd strategy
629+
KoreExecOptions { breadthLimit, depthLimit } = execOptions
626630

627631
koreRun :: KoreExecOptions -> Main ExitCode
628632
koreRun execOptions = do
@@ -634,12 +638,11 @@ koreRun execOptions = do
634638
initial <- loadPattern mainModule patternFileName
635639
(exitCode, final) <-
636640
execute execOptions mainModule
637-
$ exec breadthLimit mainModule strategy' initial
641+
$ exec depthLimit breadthLimit mainModule strategy initial
638642
lift $ renderResult execOptions (unparse final)
639643
return exitCode
640644
where
641645
KoreExecOptions { breadthLimit, depthLimit, strategy } = execOptions
642-
strategy' = Limit.replicate depthLimit . snd strategy
643646

644647
koreProve :: KoreExecOptions -> KoreProveOptions -> Main ExitCode
645648
koreProve execOptions proveOptions = do

kore/src/Kore/Exec.hs

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,6 @@ import Kore.IndexedModule.Resolvers
8181
( resolveInternalSymbol
8282
)
8383
import qualified Kore.Internal.Condition as Condition
84-
import Kore.Internal.MultiOr
85-
( make
86-
)
8784
import qualified Kore.Internal.MultiOr as MultiOr
8885
import qualified Kore.Internal.OrPattern as OrPattern
8986
import Kore.Internal.Pattern
@@ -160,7 +157,6 @@ import Kore.Step.Search
160157
import qualified Kore.Step.Search as Search
161158
import Kore.Step.Simplification.Data
162159
( MonadProf
163-
, SimplifierT
164160
, evalSimplifier
165161
)
166162
import qualified Kore.Step.Simplification.Data as Simplifier
@@ -213,14 +209,14 @@ exec
213209
, MonadProf smt
214210
)
215211
=> Limit Natural
212+
-> Limit Natural
216213
-> VerifiedModule StepperAttributes
217214
-- ^ The main module
218-
-> ([Rewrite] -> [Strategy (Prim Rewrite)])
219-
-- ^ The strategy to use for execution; see examples in "Kore.Step.Step"
215+
-> ExecutionMode
220216
-> TermLike VariableName
221217
-- ^ The input pattern
222218
-> smt (ExitCode, TermLike VariableName)
223-
exec breadthLimit verifiedModule strategy initialTerm =
219+
exec depthLimit breadthLimit verifiedModule strategy initialTerm =
224220
evalSimplifier verifiedModule' $ do
225221
initialized <- initializeAndSimplify verifiedModule
226222
let Initialized { rewriteRules } = initialized
@@ -237,9 +233,10 @@ exec breadthLimit verifiedModule strategy initialTerm =
237233
. Strategy.applyBreadthLimit
238234
breadthLimit
239235
dropStrategy
236+
rewriteGroups = groupRewritesByPriority rewriteRules
240237
transit instr config =
241238
Strategy.transitionRule
242-
(transitionRule & trackExecDepth)
239+
(transitionRule rewriteGroups strategy & trackExecDepth)
243240
instr
244241
config
245242
& runTransitionT
@@ -248,24 +245,21 @@ exec breadthLimit verifiedModule strategy initialTerm =
248245
Strategy.leavesM
249246
updateQueue
250247
(Strategy.unfoldTransition transit)
251-
( strategy rewriteRules
252-
, (ExecDepth 0, mkRewritingPattern initialConfig)
248+
( limitedExecutionStrategy depthLimit
249+
, (ExecDepth 0, Start (mkRewritingPattern initialConfig))
253250
)
254251
let (depths, finalConfigs) = unzip finals
255252
infoExecDepth (maximum depths)
256-
let finalConfigs' = make $ getRewritingPattern <$> finalConfigs
253+
let finalConfigs' =
254+
MultiOr.make
255+
$ getRewritingPattern
256+
. extractProgramState
257+
<$> finalConfigs
257258
exitCode <- getExitCode verifiedModule finalConfigs'
258259
let finalTerm = forceSort initialSort $ OrPattern.toTermLike finalConfigs'
259260
return (exitCode, finalTerm)
260261
where
261262
dropStrategy = snd
262-
getFinalConfigsOf
263-
:: LogicT
264-
(SimplifierT smt)
265-
( [Strategy (Prim (RewriteRule RewritingVariableName))]
266-
, (ExecDepth, Pattern RewritingVariableName)
267-
)
268-
-> SimplifierT smt [(ExecDepth, Pattern RewritingVariableName)]
269263
getFinalConfigsOf act = observeAllT $ fmap snd act
270264
verifiedModule' =
271265
IndexedModule.mapPatterns
@@ -290,8 +284,8 @@ trackExecDepth transit prim (execDepth, execState) = do
290284
where
291285
didRewrite _ = isRewrite prim
292286

293-
isRewrite Simplify = False
294-
isRewrite (Rewrite _) = True
287+
isRewrite Rewrite = True
288+
isRewrite _ = False
295289

296290
-- | Project the value of the exit cell, if it is present.
297291
getExitCode
@@ -341,18 +335,17 @@ search
341335
, MonadProf smt
342336
)
343337
=> Limit Natural
338+
-> Limit Natural
344339
-> VerifiedModule StepperAttributes
345340
-- ^ The main module
346-
-> ([Rewrite] -> [Strategy (Prim Rewrite)])
347-
-- ^ The strategy to use for execution; see examples in "Kore.Step.Step"
348341
-> TermLike VariableName
349342
-- ^ The input pattern
350343
-> Pattern VariableName
351344
-- ^ The pattern to match during execution
352345
-> Search.Config
353346
-- ^ The bound on the number of search matches and the search type
354347
-> smt (TermLike VariableName)
355-
search breadthLimit verifiedModule strategy termLike searchPattern searchConfig
348+
search depthLimit breadthLimit verifiedModule termLike searchPattern searchConfig
356349
=
357350
evalSimplifier verifiedModule $ do
358351
initialized <- initializeAndSimplify verifiedModule
@@ -365,15 +358,30 @@ search breadthLimit verifiedModule strategy termLike searchPattern searchConfig
365358
case toList simplifiedPatterns of
366359
[] -> Pattern.bottomOf (termLikeSort termLike)
367360
(config : _) -> config
361+
rewriteGroups =
362+
groupRewritesByPriority rewriteRules
368363
runStrategy' =
369-
runStrategy breadthLimit transitionRule (strategy rewriteRules)
370-
executionGraph <- runStrategy' (mkRewritingPattern initialPattern)
364+
runStrategy
365+
breadthLimit
366+
-- search relies on exploring
367+
-- the entire space of states.
368+
(transitionRule rewriteGroups All)
369+
(limitedExecutionStrategy depthLimit)
370+
executionGraph <-
371+
runStrategy' (Start $ mkRewritingPattern initialPattern)
371372
let
372-
match target config = Search.matchWith target config
373+
match target config1 config2 =
374+
Search.matchWith
375+
target
376+
config1
377+
(extractProgramState config2)
373378
solutionsLists <-
374379
searchGraph
375380
searchConfig
376-
(match SideCondition.topTODO (mkRewritingPattern searchPattern))
381+
(match
382+
SideCondition.topTODO
383+
(mkRewritingPattern searchPattern)
384+
)
377385
executionGraph
378386
let
379387
solutions = concatMap toList solutionsLists
@@ -387,7 +395,6 @@ search breadthLimit verifiedModule strategy termLike searchPattern searchConfig
387395
where
388396
patternSort = termLikeSort termLike
389397

390-
391398
-- | Proving a spec given as a module containing rules to be proven
392399
prove
393400
:: forall smt

0 commit comments

Comments
 (0)