Skip to content

Commit e936e5b

Browse files
authored
[3198] fix stopping prover on branches + logging unproven (#3199)
* The rewritten prover was returning a final instead of a stopped state when stopping at branches * Proof depth for unproven claims was not logged at info level as before. This fixes both problems, and adds a unit test for stopping at branches. Fixes #3198
1 parent e0580ec commit e936e5b

File tree

3 files changed

+58
-10
lines changed

3 files changed

+58
-10
lines changed

kore/src/Kore/Exec/GraphTraversal.hs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import Control.Monad (foldM)
1919
import Control.Monad.Trans.State
2020
import Data.Limit
2121
import Data.List.NonEmpty qualified as NE
22+
import Data.Maybe (maybeToList)
2223
import Data.Sequence (Seq (..))
2324
import Data.Sequence qualified as Seq
2425
import GHC.Natural
@@ -227,11 +228,14 @@ graphTraversal
227228
exceedsLimit =
228229
not . withinLimit breadthLimit . fromIntegral . Seq.length
229230

230-
shouldStop :: TransitionResult (TState instr config) -> Bool
231-
shouldStop =
232-
case stopOn of
233-
Leaf -> const False
234-
LeafOrBranching -> isBranch
231+
-- when stopping at branches, turn a 'Branch' result into a 'Stopped'
232+
branchStop :: TransitionResult (TState i c) -> TransitionResult (TState i c)
233+
branchStop result
234+
| isBranch result =
235+
case stopOn of
236+
Leaf -> result
237+
LeafOrBranching -> Stopped (maybeToList $ extractState result)
238+
| otherwise = result
235239

236240
worker ::
237241
Seq (TState instr config) ->
@@ -263,8 +267,8 @@ graphTraversal
263267
Seq (TState instr config) ->
264268
Simplifier (StepResult (TState instr config))
265269
step a q = do
266-
next <- transit a
267-
if (isStuck next || isFinal next || isStopped next || shouldStop next)
270+
next <- branchStop <$> transit a
271+
if (isStuck next || isFinal next || isStopped next)
268272
then pure (Output next q)
269273
else
270274
let abort (LimitExceeded queue) = Abort next queue

kore/src/Kore/Reachability/Prove.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,13 +340,15 @@ proveClaim
340340
limitedStrategyList
341341
(ProofDepth 0, startGoal)
342342

343-
let returnUnprovenClaims n =
343+
let returnUnprovenClaims n unproven = do
344+
mapM_ (infoUnprovenDepth . fst) unproven
344345
pure
345346
. Left
346347
. (,fromIntegral n)
347348
. MultiAnd.make
348349
. map StuckClaim
349350
. mapMaybe (extractUnproven . snd)
351+
$ unproven
350352

351353
case traversalResult of
352354
GraphTraversal.GotStuck n rs ->

kore/test/Test/Kore/Reachability/Prove.hs

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ import Kore.Rewrite.RulePattern (
4646
rulePattern,
4747
)
4848
import Kore.Rewrite.Strategy (
49-
FinalNodeType (Leaf),
49+
FinalNodeType (..),
5050
GraphSearchOrder (..),
5151
)
5252
import Kore.Rewrite.Transition (runTransitionT)
@@ -780,6 +780,7 @@ test_proveClaims =
780780
Unlimited
781781
Unlimited
782782
1
783+
Leaf
783784
axioms
784785
[mkSimpleClaim Mock.a Mock.d]
785786
[]
@@ -795,6 +796,44 @@ test_proveClaims =
795796
in [ mkTest "OnePath" simpleOnePathClaim
796797
, mkTest "AllPath" simpleAllPathClaim
797798
]
799+
, testGroup "returns branch state when stopping at branch points" $
800+
let axioms =
801+
[ simpleAxiom Mock.a Mock.d
802+
, simpleAxiom Mock.d (mkOr Mock.b Mock.c)
803+
]
804+
mkTest name mkSimpleClaim mkSomeClaim =
805+
testCase name $ do
806+
actual <-
807+
Test.Kore.Reachability.Prove.proveClaims
808+
Unlimited
809+
Unlimited
810+
1
811+
LeafOrBranching
812+
axioms
813+
[mkSimpleClaim Mock.a $ mkOr Mock.b Mock.c]
814+
[]
815+
let stuck =
816+
mkSomeClaim
817+
(Pattern.fromTermLike Mock.d)
818+
( OrPattern.fromPatterns $
819+
map
820+
Pattern.fromTermLike
821+
[ Mock.b
822+
, Mock.c
823+
]
824+
)
825+
[]
826+
expect =
827+
ProveClaimsResult
828+
{ stuckClaims = MultiAnd.singleton $ StuckClaim stuck
829+
, provenClaims = MultiAnd.top
830+
, unexplored = 0
831+
}
832+
assertEqual "count" (unexplored expect) (unexplored actual)
833+
assertEqual "claim" (stuckClaims expect) (stuckClaims actual)
834+
in [ mkTest "OnePath" simpleOnePathClaim mkSomeClaimOnePath
835+
, mkTest "AllPath" simpleAllPathClaim mkSomeClaimAllPath
836+
]
798837
]
799838

800839
test_transitionRule :: TestTree
@@ -892,6 +931,7 @@ proveClaims ::
892931
Limit Natural ->
893932
Limit Natural ->
894933
Natural ->
934+
FinalNodeType ->
895935
[Rule SomeClaim] ->
896936
[SomeClaim] ->
897937
[SomeClaim] ->
@@ -900,6 +940,7 @@ proveClaims
900940
breadthLimit
901941
depthLimit
902942
maxCounterexamples
943+
finalNodeType
903944
axioms
904945
claims
905946
alreadyProven =
@@ -909,7 +950,7 @@ proveClaims
909950
breadthLimit
910951
BreadthFirst
911952
maxCounterexamples
912-
Leaf
953+
finalNodeType
913954
(AllClaims claims)
914955
(Axioms axioms)
915956
(AlreadyProven (map unparseToText2 alreadyProven))
@@ -941,6 +982,7 @@ proveClaimsMaxCounterexamples_
941982
breadthLimit
942983
depthLimit
943984
maxCounterexamples
985+
Leaf
944986
axioms
945987
claims
946988
alreadyProven

0 commit comments

Comments
 (0)