Skip to content

Commit abf1477

Browse files
Emit a warning when kore-exec exceeds the depth limit (#2461)
* New log entry * Emit Warning * Format with stylish-haskell * Update kore.cabal Use `hpack -f kore` to regenerate kore.cabal * Fix merge conflicts * Add test for WarnDepthLimitExceeded Test the warning emitted by exec when the depth limit is exceeded by using a new MonadLog instance, called TestLog, that saves log entries in its state * Fix unrelated test name * Format with stylish-haskell * Materialize Nix expressions Co-authored-by: andreiburdusa <[email protected]> Co-authored-by: rv-jenkins <[email protected]>
1 parent 964e64e commit abf1477

File tree

7 files changed

+127
-3
lines changed

7 files changed

+127
-3
lines changed

kore/kore.cabal

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ cabal-version: 2.2
44
--
55
-- see: https://github.com/sol/hpack
66
--
7-
-- hash: 2efec6a0024031e0d72609be302ec5298405ab977cfd1fac26ad002a0327ef18
7+
-- hash: 07e8077838828e32133511c3586cca1bb5973f27bc8cc2240aecfe790484d785
88

99
name: kore
1010
version: 0.41.0.0
@@ -224,6 +224,7 @@ library
224224
Kore.Log.Registry
225225
Kore.Log.SQLite
226226
Kore.Log.WarnBoundedModelChecker
227+
Kore.Log.WarnDepthLimitExceeded
227228
Kore.Log.WarnFunctionWithoutEvaluators
228229
Kore.Log.WarnIfLowProductivity
229230
Kore.Log.WarnRetrySolverQuery

kore/src/Kore/Exec.hs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ import Kore.Log.InfoExecDepth
109109
import Kore.Log.KoreLogOptions
110110
( KoreLogOptions (..)
111111
)
112+
import Kore.Log.WarnDepthLimitExceeded
113+
( warnDepthLimitExceeded
114+
)
112115
import Kore.Log.WarnTrivialClaim
113116
import qualified Kore.ModelChecker.Bounded as Bounded
114117
import Kore.Reachability
@@ -254,7 +257,7 @@ exec
254257
& lift
255258
Strategy.leavesM
256259
updateQueue
257-
(Strategy.unfoldTransition transit)
260+
(unfoldTransition transit)
258261
( limitedExecutionStrategy depthLimit
259262
, (ExecDepth 0, Start initialConfig)
260263
)
@@ -284,6 +287,9 @@ exec
284287
-- are internalized.
285288
metadataTools = MetadataTools.build verifiedModule
286289
initialSort = termLikeSort initialTerm
290+
unfoldTransition transit (instrs, config) = do
291+
when (null instrs) $ forM_ depthLimit warnDepthLimitExceeded
292+
Strategy.unfoldTransition transit (instrs, config)
287293

288294
{- | Modify a 'TransitionRule' to track the depth of the execution graph.
289295
-}

kore/src/Kore/Log/Registry.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ import Kore.Log.InfoReachability
113113
import Kore.Log.WarnBoundedModelChecker
114114
( WarnBoundedModelChecker
115115
)
116+
import Kore.Log.WarnDepthLimitExceeded
117+
( WarnDepthLimitExceeded
118+
)
116119
import Kore.Log.WarnFunctionWithoutEvaluators
117120
( WarnFunctionWithoutEvaluators
118121
)
@@ -181,6 +184,7 @@ entryHelpDocsErr, entryHelpDocsNoErr :: [Pretty.Doc ()]
181184
, mk $ Proxy @WarnFunctionWithoutEvaluators
182185
, mk $ Proxy @WarnSymbolSMTRepresentation
183186
, mk $ Proxy @WarnStuckClaimState
187+
, mk $ Proxy @WarnDepthLimitExceeded
184188
, mk $ Proxy @WarnBoundedModelChecker
185189
, mk $ Proxy @WarnIfLowProductivity
186190
, mk $ Proxy @WarnTrivialClaim
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{- |
2+
Copyright : (c) Runtime Verification, 2019
3+
License : NCSA
4+
5+
-}
6+
7+
module Kore.Log.WarnDepthLimitExceeded
8+
( WarnDepthLimitExceeded (..)
9+
, warnDepthLimitExceeded
10+
) where
11+
12+
import Prelude.Kore
13+
14+
import Debug
15+
import Log
16+
import Numeric.Natural
17+
( Natural
18+
)
19+
import Pretty
20+
( Pretty
21+
, pretty
22+
)
23+
import qualified Pretty
24+
25+
newtype WarnDepthLimitExceeded =
26+
WarnDepthLimitExceeded { limitExceeded :: Natural }
27+
deriving (Show, Eq)
28+
29+
instance Debug WarnDepthLimitExceeded where
30+
debugPrec w = \_ -> Pretty.pretty . show $ w
31+
32+
instance Diff WarnDepthLimitExceeded where
33+
diffPrec = diffPrecEq
34+
instance Pretty WarnDepthLimitExceeded where
35+
pretty (WarnDepthLimitExceeded n) =
36+
Pretty.hsep
37+
[ "The depth limit", pretty n, "was exceeded."]
38+
39+
instance Entry WarnDepthLimitExceeded where
40+
entrySeverity _ = Warning
41+
helpDoc _ = "warn when depth limit is exceeded"
42+
43+
warnDepthLimitExceeded :: MonadLog log => Natural -> log ()
44+
warnDepthLimitExceeded = logEntry . WarnDepthLimitExceeded

kore/test/Test/Kore/Exec.hs

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,23 @@ module Test.Kore.Exec
44
, test_searchPriority
55
, test_searchExceedingBreadthLimit
66
, test_execGetExitCode
7+
, test_execDepthLimitExceeded
78
) where
89

910
import Prelude.Kore
1011

1112
import Test.Tasty
1213

1314
import Control.Exception as Exception
15+
import Control.Monad.Catch
16+
( MonadCatch
17+
, MonadMask
18+
, MonadThrow
19+
)
20+
import Control.Monad.State.Strict
21+
( StateT (..)
22+
)
23+
import qualified Control.Monad.State.Strict as State
1424
import Data.Default
1525
( def
1626
)
@@ -27,6 +37,7 @@ import System.Exit
2737
( ExitCode (..)
2838
)
2939

40+
import qualified Data.Bifunctor as Bifunctor
3041
import Data.Limit
3142
( Limit (..)
3243
)
@@ -51,6 +62,7 @@ import Kore.Internal.Predicate
5162
)
5263
import Kore.Internal.TermLike
5364
import qualified Kore.Internal.TermLike as TermLike
65+
import Kore.Log.WarnDepthLimitExceeded
5466
import Kore.Step
5567
( ExecutionMode (..)
5668
)
@@ -69,6 +81,9 @@ import Kore.Step.Search
6981
( SearchType (..)
7082
)
7183
import qualified Kore.Step.Search as Search
84+
import Kore.Step.Simplification.Data
85+
( MonadProf
86+
)
7287
import Kore.Step.Strategy
7388
( LimitExceeded (..)
7489
)
@@ -78,6 +93,12 @@ import Kore.Syntax.Definition hiding
7893
)
7994
import qualified Kore.Syntax.Definition as Syntax
8095
import qualified Kore.Verified as Verified
96+
import Log
97+
( Entry (..)
98+
, MonadLog (..)
99+
, SomeEntry
100+
)
101+
import qualified SMT
81102

82103
import Test.Kore
83104
import qualified Test.Kore.IndexedModule.MockMetadataTools as Mock
@@ -123,6 +144,53 @@ test_execPriority = testCase "execPriority" $ actual >>= assertEqual "" expected
123144
inputPattern = applyToNoArgs mySort "a"
124145
expected = (ExitSuccess, applyToNoArgs mySort "d")
125146

147+
newtype TestLog a = TestLog ( StateT [SomeEntry] SMT.NoSMT a )
148+
deriving newtype (Functor, Applicative, Monad)
149+
deriving newtype (State.MonadState [SomeEntry], MonadIO, SMT.MonadSMT)
150+
deriving newtype (MonadThrow, MonadCatch, MonadMask, MonadProf)
151+
152+
instance MonadLog TestLog where
153+
logEntry entry = State.modify (toEntry entry :)
154+
logWhile entry (TestLog state) =
155+
TestLog $ State.mapStateT addEntry state
156+
where
157+
addEntry :: SMT.NoSMT (a, [SomeEntry]) -> SMT.NoSMT (a, [SomeEntry])
158+
addEntry = fmap $ Bifunctor.second (toEntry entry :)
159+
160+
runTestLog :: TestLog a -> IO [SomeEntry]
161+
runTestLog (TestLog state) = runNoSMT $ State.execStateT state []
162+
163+
test_execDepthLimitExceeded :: TestTree
164+
test_execDepthLimitExceeded = testCase "exec exceeds depth limit"
165+
$ do
166+
entries <- actual
167+
let actualDepthWarnings =
168+
catMaybes $ fromEntry @WarnDepthLimitExceeded <$> entries
169+
expectedWarning = WarnDepthLimitExceeded 1
170+
assertEqual "" [expectedWarning] actualDepthWarnings
171+
where
172+
actual =
173+
exec
174+
(Limit 1)
175+
Unlimited
176+
verifiedModule
177+
Any
178+
inputPattern
179+
& runTestLog
180+
verifiedModule = verifiedMyModule Module
181+
{ moduleName = ModuleName "MY-MODULE"
182+
, moduleSentences =
183+
[ asSentence mySortDecl
184+
, asSentence $ constructorDecl "a"
185+
, asSentence $ constructorDecl "b"
186+
, functionalAxiom "a"
187+
, functionalAxiom "b"
188+
, simpleRewriteAxiom "a" "b"
189+
]
190+
, moduleAttributes = Attributes []
191+
}
192+
inputPattern = applyToNoArgs mySort "a"
193+
126194
test_exec :: TestTree
127195
test_exec = testCase "exec" $ actual >>= assertEqual "" expected
128196
where

kore/test/Test/Kore/Step/Simplification/Overloading.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ test_unifyOverloading =
210210
(Mock.sortInjectionSubSubToTop Mock.aSubSubsort)
211211
)
212212
)
213-
, narrows "qqdirect overload vs. variable, left side; var direct"
213+
, narrows "direct overload vs. variable, left side; var direct"
214214
( Mock.topOverload (Mock.sortInjectionOtherToTop Mock.aOtherSort)
215215
, Mock.sortInjectionSubToTop (mkElemVar Mock.xConfigSubSort)
216216
)

nix/kore.nix.d/kore.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@
283283
"Kore/Log/Registry"
284284
"Kore/Log/SQLite"
285285
"Kore/Log/WarnBoundedModelChecker"
286+
"Kore/Log/WarnDepthLimitExceeded"
286287
"Kore/Log/WarnFunctionWithoutEvaluators"
287288
"Kore/Log/WarnIfLowProductivity"
288289
"Kore/Log/WarnRetrySolverQuery"

0 commit comments

Comments
 (0)