Skip to content

Commit cfca64b

Browse files
ana-pantiliegithub-actionsdopamane
authored
Add limited loop to Condition simplifier (#2915)
* Add limited loop in Condition simplifier * Format with fourmolu * Remove undefined from SubstitutionSimplifier * Format with fourmolu * Add warning for unsimplified Condition * Format with fourmolu * Remove commented out traces * Materialize Nix expressions * Add integration test * Review: use foldM instead of explicit loop Co-authored-by: David Cox <[email protected]> * Format with fourmolu Co-authored-by: github-actions <[email protected]> Co-authored-by: David Cox <[email protected]>
1 parent 8ce8fe6 commit cfca64b

File tree

11 files changed

+114
-11
lines changed

11 files changed

+114
-11
lines changed

kore/kore.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ library
358358
Kore.Log.WarnStuckClaimState
359359
Kore.Log.WarnSymbolSMTRepresentation
360360
Kore.Log.WarnTrivialClaim
361-
Kore.Log.WarnUnsimplifiedPredicate
361+
Kore.Log.WarnUnsimplified
362362
Kore.ModelChecker.Bounded
363363
Kore.ModelChecker.Simplification
364364
Kore.ModelChecker.Step

kore/src/Kore/Log/Registry.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,8 @@ import Kore.Log.WarnSymbolSMTRepresentation (
139139
import Kore.Log.WarnTrivialClaim (
140140
WarnTrivialClaim,
141141
)
142-
import Kore.Log.WarnUnsimplifiedPredicate (
142+
import Kore.Log.WarnUnsimplified (
143+
WarnUnsimplifiedCondition,
143144
WarnUnsimplifiedPredicate,
144145
)
145146
import Log (
@@ -220,6 +221,7 @@ entryHelpDocsErr, entryHelpDocsNoErr :: [Pretty.Doc ()]
220221
, mk $ Proxy @DebugBeginClaim
221222
, mk $ Proxy @DebugProven
222223
, mk $ Proxy @WarnUnsimplifiedPredicate
224+
, mk $ Proxy @WarnUnsimplifiedCondition
223225
]
224226
,
225227
[ mk $ Proxy @ErrorBottomTotalFunction

kore/src/Kore/Log/WarnUnsimplifiedPredicate.hs renamed to kore/src/Kore/Log/WarnUnsimplified.hs

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,20 @@
22
Copyright : (c) Runtime Verification, 2021
33
License : BSD-3-Clause
44
-}
5-
module Kore.Log.WarnUnsimplifiedPredicate (
5+
module Kore.Log.WarnUnsimplified (
66
WarnUnsimplifiedPredicate (..),
77
warnUnsimplifiedPredicate,
8+
WarnUnsimplifiedCondition (..),
9+
warnUnsimplifiedCondition,
810
) where
911

12+
import Kore.Internal.Condition (
13+
Condition,
14+
)
15+
import Kore.Internal.Conditional (
16+
Conditional,
17+
)
18+
import qualified Kore.Internal.Conditional as Conditional
1019
import Kore.Internal.MultiAnd (
1120
MultiAnd,
1221
)
@@ -31,6 +40,13 @@ data WarnUnsimplifiedPredicate = WarnUnsimplifiedPredicate
3140
}
3241
deriving stock (Show)
3342

43+
data WarnUnsimplifiedCondition = WarnUnsimplifiedCondition
44+
{ limit :: !Int
45+
, original :: !(Condition RewritingVariableName)
46+
, output :: !(Condition RewritingVariableName)
47+
}
48+
deriving stock (Show)
49+
3450
instance Pretty WarnUnsimplifiedPredicate where
3551
pretty WarnUnsimplifiedPredicate{original, output, limit} =
3652
Pretty.vsep
@@ -49,11 +65,34 @@ instance Pretty WarnUnsimplifiedPredicate where
4965
, (Pretty.indent 4) (Pretty.pretty output)
5066
]
5167

68+
instance Pretty WarnUnsimplifiedCondition where
69+
pretty WarnUnsimplifiedCondition{original, output, limit} =
70+
Pretty.vsep
71+
[ Pretty.hsep
72+
[ "Condition not simplified after"
73+
, Pretty.pretty limit
74+
, "rounds."
75+
]
76+
, "Original condition:"
77+
, (Pretty.indent 4) (Pretty.pretty original)
78+
, Pretty.hsep
79+
[ "Output after"
80+
, Pretty.pretty limit
81+
, "rounds:"
82+
]
83+
, (Pretty.indent 4) (Pretty.pretty output)
84+
]
85+
5286
instance Entry WarnUnsimplifiedPredicate where
5387
entrySeverity _ = Warning
5488
oneLineDoc WarnUnsimplifiedPredicate{limit} = Pretty.pretty limit
5589
helpDoc _ = "warn when a predicate is not simplified"
5690

91+
instance Entry WarnUnsimplifiedCondition where
92+
entrySeverity _ = Warning
93+
oneLineDoc WarnUnsimplifiedCondition{limit} = Pretty.pretty limit
94+
helpDoc _ = "warn when a condition is not simplified"
95+
5796
warnUnsimplifiedPredicate ::
5897
MonadLog log =>
5998
Int ->
@@ -62,3 +101,15 @@ warnUnsimplifiedPredicate ::
62101
log ()
63102
warnUnsimplifiedPredicate limit original output =
64103
logEntry WarnUnsimplifiedPredicate{limit, original, output}
104+
105+
warnUnsimplifiedCondition ::
106+
MonadLog log =>
107+
Int ->
108+
Conditional RewritingVariableName any ->
109+
Conditional RewritingVariableName any ->
110+
log ()
111+
warnUnsimplifiedCondition
112+
limit
113+
(Conditional.withoutTerm -> original)
114+
(Conditional.withoutTerm -> output) =
115+
logEntry WarnUnsimplifiedCondition{limit, original, output}

kore/src/Kore/Simplify/Condition.hs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ import Kore.Internal.Substitution (
4141
Assignment,
4242
)
4343
import qualified Kore.Internal.Substitution as Substitution
44+
import Kore.Log.WarnUnsimplified (
45+
warnUnsimplifiedCondition,
46+
)
4447
import Kore.Rewrite.RewritingVariable (
4548
RewritingVariableName,
4649
)
@@ -78,9 +81,24 @@ simplify ::
7881
SideCondition RewritingVariableName ->
7982
Conditional RewritingVariableName any ->
8083
LogicT simplifier (Conditional RewritingVariableName any)
81-
simplify SubstitutionSimplifier{simplifySubstitution} sideCondition =
82-
normalize >=> worker
84+
simplify SubstitutionSimplifier{simplifySubstitution} sideCondition original = do
85+
normOriginal <- normalize original
86+
(isFullySimplified, result) <- foldM simplifyingCondition (False, normOriginal) [1 .. limit]
87+
unless isFullySimplified $ warnUnsimplifiedCondition limit original result
88+
return result
8389
where
90+
limit :: Int
91+
limit = 4
92+
93+
simplifyingCondition ::
94+
(Bool, Conditional RewritingVariableName any) ->
95+
Int ->
96+
LogicT simplifier (Bool, Conditional RewritingVariableName any)
97+
simplifyingCondition result@(True, _) _ = return result
98+
simplifyingCondition (_, input) _ = do
99+
output <- worker input
100+
return (fullySimplified output, extract output)
101+
84102
worker Conditional{term, predicate, substitution} = do
85103
let substitution' = Substitution.toMap substitution
86104
predicate' = substitute substitution' predicate
@@ -100,9 +118,7 @@ simplify SubstitutionSimplifier{simplifySubstitution} sideCondition =
100118
(field @"predicate")
101119
simplifyConjunctions
102120
normalized{term}
103-
if fullySimplified simplifiedPattern
104-
then return (extract simplifiedPattern)
105-
else worker (extract simplifiedPattern)
121+
return simplifiedPattern
106122

107123
simplifyPredicate predicate =
108124
Predicate.simplify sideCondition predicate & lift

kore/src/Kore/Simplify/Pattern.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@ makeEvaluate sideCondition =
129129

130130
worker pattern' =
131131
OrPattern.observeAllT $ do
132-
withSimplifiedCondition <- simplifyCondition sideCondition pattern'
132+
withSimplifiedCondition <-
133+
simplifyCondition sideCondition pattern'
133134
let (term, simplifiedCondition) =
134135
Conditional.splitTerm withSimplifiedCondition
135136
term' = substitute (toMap $ substitution simplifiedCondition) term

kore/src/Kore/Simplify/Predicate.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ import Kore.Internal.TermLike (
5353
termLikeSort,
5454
)
5555
import qualified Kore.Internal.TermLike as TermLike
56-
import Kore.Log.WarnUnsimplifiedPredicate (
56+
import Kore.Log.WarnUnsimplified (
5757
warnUnsimplifiedPredicate,
5858
)
5959
import Kore.Rewrite.RewritingVariable (

nix/kore.nix.d/kore.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@
279279
"Kore/Log/WarnStuckClaimState"
280280
"Kore/Log/WarnSymbolSMTRepresentation"
281281
"Kore/Log/WarnTrivialClaim"
282-
"Kore/Log/WarnUnsimplifiedPredicate"
282+
"Kore/Log/WarnUnsimplified"
283283
"Kore/ModelChecker/Bounded"
284284
"Kore/ModelChecker/Simplification"
285285
"Kore/ModelChecker/Step"

test/kprove-hangs/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
DEF = test
2+
include $(CURDIR)/../include.mk

test/kprove-hangs/test-spec.k

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module VERIFICATION
2+
imports TEST
3+
4+
endmodule
5+
6+
module TEST-SPEC
7+
imports VERIFICATION
8+
9+
claim <k> (a ~> _ => .) ... </k>
10+
11+
endmodule
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#Ceil ( _0 ~> _DotVar1 ~> . )
2+
#And
3+
#Not ( {
4+
_DotVar1
5+
#Equals
6+
a ~> _0 ~> _DotVar1 ~> .
7+
} )
8+
#And
9+
<k>
10+
a ~> _0 ~> _DotVar1 ~> .
11+
</k>

0 commit comments

Comments
 (0)