Skip to content

Commit 3888160

Browse files
authored
Use entire goal in proof strategy (#1936)
* Breadth limit: handle for prove * Strategy.Verification: replace Pattern with OrPattern * Remove redundant constraints * Remove unused import * Fix tests * Remove unused imports * Add unit tests * Add integration tests * Clean-up * Address review comments * Regenerate golden file * Strategies.Verification: replace (Pattern Variable) with ReachabilityRule in CommonProofState * kore-repl: keep entire goal in execution graph * Strategies.Verification: remove redundant function * Repl: use stored goal instead of generating claims * Clean-up * Clean-up * Repl: add dest (destination) command * Clean-up * Address review comment * Address review comments * Revert + fix * Verification.verifyClaimStep: remove target argument
1 parent e0d6539 commit 3888160

File tree

9 files changed

+162
-170
lines changed

9 files changed

+162
-170
lines changed

kore/src/Kore/Repl.hs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -251,19 +251,18 @@ runRepl
251251
firstClaimExecutionGraph = emptyExecutionGraph firstClaim
252252

253253
stepper0
254-
:: ReachabilityRule
255-
-> [ReachabilityRule]
254+
:: [ReachabilityRule]
256255
-> [Axiom]
257256
-> ExecutionGraph Axiom
258257
-> ReplNode
259258
-> m (ExecutionGraph Axiom)
260-
stepper0 claim claims axioms graph rnode = do
259+
stepper0 claims axioms graph rnode = do
261260
let node = unReplNode rnode
262261
if Graph.outdeg (Strategy.graph graph) node == 0
263262
then
264263
catchEverything graph
265264
$ catchInterruptWithDefault graph
266-
$ verifyClaimStep claim claims axioms graph node
265+
$ verifyClaimStep claims axioms graph node
267266
else pure graph
268267

269268
catchInterruptWithDefault :: a -> m a -> m a

kore/src/Kore/Repl/Data.hs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,8 @@ data ReplCommand
229229
-- ^ Select a different node in the graph.
230230
| ShowConfig !(Maybe ReplNode)
231231
-- ^ Show the configuration from the current node.
232+
| ShowDest !(Maybe ReplNode)
233+
-- ^ Show the destination from the current node.
232234
| OmitCell !(Maybe String)
233235
-- ^ Adds or removes cell to omit list, or shows current omit list.
234236
| ShowLeafs
@@ -334,6 +336,8 @@ helpText =
334336
\select <n> select node id 'n' from the graph\n\
335337
\config [n] shows the config for node 'n'\
336338
\ (defaults to current node)\n\
339+
\dest [n] shows the destination for node 'n'\
340+
\ (defaults to current node)\n\
337341
\omit [cell] adds or removes cell to omit list\
338342
\ (defaults to showing the omit\
339343
\ list)\n\
@@ -493,13 +497,12 @@ data ReplState = ReplState
493497
-- | Configuration environment for the repl.
494498
data Config m = Config
495499
{ stepper
496-
:: Claim
497-
-> [Claim]
500+
:: [Claim]
498501
-> [Axiom]
499502
-> ExecutionGraph Axiom
500503
-> ReplNode
501504
-> m (ExecutionGraph Axiom)
502-
-- ^ Stepper function, it is a partially applied 'verifyClaimStep'
505+
-- ^ Stepper function
503506
, unifier
504507
:: SideCondition VariableName
505508
-> TermLike VariableName

kore/src/Kore/Repl/Interpreter.hs

Lines changed: 52 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ import Kore.Step.RulePattern
178178
( ReachabilityRule (..)
179179
, RulePattern (..)
180180
, ToRulePattern (..)
181+
, rhsToPattern
181182
)
182183
import Kore.Step.Simplification.Data
183184
( MonadSimplify
@@ -186,12 +187,12 @@ import qualified Kore.Step.Strategy as Strategy
186187
import Kore.Strategies.Goal
187188
import Kore.Strategies.ProofState
188189
( ProofStateTransformer (ProofStateTransformer)
190+
, extractUnproven
189191
, proofState
190192
)
191193
import qualified Kore.Strategies.ProofState as ProofState.DoNotUse
192194
import Kore.Strategies.Verification
193195
( CommonProofState
194-
, commonProofStateTransformer
195196
)
196197
import Kore.Syntax.Application
197198
import qualified Kore.Syntax.Id as Id
@@ -248,6 +249,7 @@ replInterpreter0 printAux printKore replCmd = do
248249
ProveStepsF n -> proveStepsF n $> Continue
249250
SelectNode i -> selectNode i $> Continue
250251
ShowConfig mc -> showConfig mc $> Continue
252+
ShowDest mc -> showDest mc $> Continue
251253
OmitCell c -> omitCell c $> Continue
252254
ShowLeafs -> showLeafs $> Continue
253255
ShowRule mc -> showRule mc $> Continue
@@ -521,14 +523,37 @@ showConfig
521523
=> Maybe ReplNode
522524
-- ^ 'Nothing' for current node, or @Just n@ for a specific node identifier
523525
-> ReplM m ()
524-
showConfig configNode = do
525-
maybeConfig <- getConfigAt configNode
526-
case maybeConfig of
526+
showConfig =
527+
showProofStateComponent "Config" getConfiguration
528+
529+
-- | Shows destination at node 'n', or current node if 'Nothing' is passed.
530+
showDest
531+
:: Monad m
532+
=> Maybe ReplNode
533+
-- ^ 'Nothing' for current node, or @Just n@ for a specific node identifier
534+
-> ReplM m ()
535+
showDest =
536+
showProofStateComponent "Destination" (rhsToPattern . getDestination)
537+
538+
showProofStateComponent
539+
:: Monad m
540+
=> String
541+
-- ^ component name
542+
-> (ReachabilityRule -> Pattern VariableName)
543+
-> Maybe ReplNode
544+
-> ReplM m ()
545+
showProofStateComponent name transformer maybeNode = do
546+
maybeProofState <- getProofStateAt maybeNode
547+
case maybeProofState of
527548
Nothing -> putStrLn' "Invalid node!"
528549
Just (ReplNode node, config) -> do
529550
omit <- Lens.use (field @"omit")
530-
putStrLn' $ "Config at node " <> show node <> " is:"
531-
tell $ unparseStrategy omit config
551+
putStrLn' $ name <> " at node " <> show node <> " is:"
552+
unparseProofStateComponent
553+
transformer
554+
omit
555+
config
556+
& tell
532557

533558
-- | Shows current omit list if passed 'Nothing'. Adds/removes from the list
534559
-- depending on whether the string already exists in the list or not.
@@ -846,7 +871,7 @@ tryAxiomClaimWorker mode ref = do
846871
-> ReplM m ()
847872
showUnificationFailure axiomOrClaim' node = do
848873
let first = extractLeftPattern axiomOrClaim'
849-
maybeSecond <- getConfigAt (Just node)
874+
maybeSecond <- getProofStateAt (Just node)
850875
case maybeSecond of
851876
Nothing -> putStrLn' "Unexpected error getting current config."
852877
Just (_, second) ->
@@ -858,7 +883,7 @@ tryAxiomClaimWorker mode ref = do
858883
, goalRewrittenTransformer = patternUnifier
859884
, goalStuckTransformer = patternUnifier
860885
}
861-
second
886+
(getConfiguration <$> second)
862887
where
863888
patternUnifier :: Pattern VariableName -> ReplM m ()
864889
patternUnifier
@@ -964,30 +989,25 @@ savePartialProof
964989
-> FilePath
965990
-> ReplM m ()
966991
savePartialProof maybeNatural file = do
967-
currentClaim <- Lens.use (field @"claim")
968992
currentIndex <- Lens.use (field @"claimIndex")
969993
claims <- Lens.use (field @"claims")
970994
Config { mainModuleName } <- ask
971-
maybeConfig <- getConfigAt maybeNode
972-
case maybeConfig of
995+
maybeConfig <- getProofStateAt maybeNode
996+
case (fmap . fmap) extractUnproven maybeConfig of
973997
Nothing -> putStrLn' "Invalid node!"
974-
Just (currentNode, currentProofState) -> do
975-
let config = unwrapConfig currentProofState
976-
newClaim = createClaim currentClaim config
977-
newTrustedClaims =
998+
Just (_, Nothing) -> putStrLn' "Goal is proven."
999+
Just (currentNode, Just currentGoal) -> do
1000+
let newTrustedClaims =
9781001
makeTrusted
9791002
<$> removeIfRoot currentNode currentIndex claims
9801003
newDefinition =
9811004
createNewDefinition
9821005
mainModuleName
9831006
(makeModuleName file)
984-
$ newClaim : newTrustedClaims
1007+
$ currentGoal : newTrustedClaims
9851008
saveUnparsedDefinitionToFile (unparse newDefinition)
9861009
putStrLn' "Done."
9871010
where
988-
unwrapConfig :: CommonProofState -> Pattern VariableName
989-
unwrapConfig = proofState commonProofStateTransformer
990-
9911011
saveUnparsedDefinitionToFile
9921012
:: Pretty.Doc ann
9931013
-> ReplM m ()
@@ -1203,26 +1223,30 @@ showRewriteRule rule =
12031223
<> makeAuxReplOutput (show . Pretty.pretty . from @_ @SourceLocation $ rule)
12041224

12051225
-- | Unparses a strategy node, using an omit list to hide specified children.
1206-
unparseStrategy
1207-
:: Set String
1226+
unparseProofStateComponent
1227+
:: (ReachabilityRule -> Pattern VariableName)
1228+
-> Set String
12081229
-- ^ omit list
12091230
-> CommonProofState
12101231
-- ^ pattern
12111232
-> ReplOutput
1212-
unparseStrategy omitList =
1233+
unparseProofStateComponent transformation omitList =
12131234
proofState ProofStateTransformer
1214-
{ goalTransformer = makeKoreReplOutput . unparseToString . fmap hide
1215-
, goalRemainderTransformer = \pat ->
1235+
{ goalTransformer =
1236+
makeKoreReplOutput . unparseComponent
1237+
, goalRemainderTransformer = \goal ->
12161238
makeAuxReplOutput "Stuck: \n"
1217-
<> makeKoreReplOutput (unparseToString $ fmap hide pat)
1239+
<> makeKoreReplOutput (unparseComponent goal)
12181240
, goalRewrittenTransformer =
1219-
makeKoreReplOutput . unparseToString . fmap hide
1220-
, goalStuckTransformer = \pat ->
1241+
makeKoreReplOutput . unparseComponent
1242+
, goalStuckTransformer = \goal ->
12211243
makeAuxReplOutput "Stuck: \n"
1222-
<> makeKoreReplOutput (unparseToString $ fmap hide pat)
1244+
<> makeKoreReplOutput (unparseComponent goal)
12231245
, provenValue = makeAuxReplOutput "Reached bottom"
12241246
}
12251247
where
1248+
unparseComponent =
1249+
unparseToString . fmap hide . transformation
12261250
hide :: TermLike VariableName -> TermLike VariableName
12271251
hide =
12281252
Recursive.unfold $ \termLike ->

kore/src/Kore/Repl/Parser.hs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ nonRecursiveCommand =
105105
, proveSteps
106106
, selectNode
107107
, showConfig
108+
, showDest
108109
, omitCell
109110
, showLeafs
110111
, showRule
@@ -188,6 +189,11 @@ showConfig = do
188189
dec <- literal "config" *> maybeDecimal
189190
return $ ShowConfig (fmap ReplNode dec)
190191

192+
showDest :: Parser ReplCommand
193+
showDest = do
194+
dec <- literal "dest" *> maybeDecimal
195+
return $ ShowDest (fmap ReplNode dec)
196+
191197
omitCell :: Parser ReplCommand
192198
omitCell = OmitCell <$$> literal "omit" *> maybeWord
193199

0 commit comments

Comments
 (0)