Skip to content

Commit d04ebc0

Browse files
committed
Log the combined rewrite rule remainder
Add negative info to DebugAppliedRewriteRules log entry Debug remainder Debug remainders more Make kore-rpc-booster aware of DebugRewriteRulesRemainder Revert "Debug remainders more" This reverts commit 0c56365. Revert "Debug remainder" This reverts commit cab0016. Add json log for DebugRewriteRulesRemainder Add default implementation of oneLineContextJson Add entry type to json of DebugRewriteRulesRemainder Ask forDebugEvaluateCondition Fix typo Accept rule count in DebugRewriteRulesRemainder
1 parent 974ab83 commit d04ebc0

File tree

7 files changed

+119
-2
lines changed

7 files changed

+119
-2
lines changed

booster/tools/booster/Server.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,7 @@ logLevelToKoreLogEntryMap =
394394
)
395395
, (LevelOther "SimplifySuccess", ["DebugTerm"])
396396
, (LevelOther "RewriteSuccess", ["DebugAppliedRewriteRules", "DebugTerm"])
397+
, (LevelOther "Unconditional", ["DebugRewriteRulesRemainder", "DebugEvaluateCondition"])
397398
]
398399

399400
data CLProxyOptions = CLProxyOptions

kore/kore.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,7 @@ library
352352
Kore.Log.DebugRewriteTrace
353353
Kore.Log.DebugSolver
354354
Kore.Log.DebugSubstitutionSimplifier
355+
Kore.Log.DebugRewriteRulesRemainder
355356
Kore.Log.DebugTransition
356357
Kore.Log.DebugUnification
357358
Kore.Log.DebugUnifyBottom

kore/src/Kore/Log/DebugAppliedRewriteRules.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ instance Entry DebugAppliedRewriteRules where
6767
| null appliedRewriteRules = True
6868
| otherwise = False
6969
oneLineDoc DebugAppliedRewriteRules{appliedRewriteRules}
70-
| null appliedRewriteRules = mempty
70+
| null appliedRewriteRules =
71+
"failed to apply " <> pretty (length appliedRewriteRules) <> " rewrite rules"
7172
| otherwise =
7273
"applied " <> pretty (length appliedRewriteRules) <> " rewrite rules"
7374
oneLineJson DebugAppliedRewriteRules{appliedRewriteRules}
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
{-# LANGUAGE RecordWildCards #-}
2+
{-# LANGUAGE NoStrict #-}
3+
{-# LANGUAGE NoStrictData #-}
4+
5+
{- |
6+
Copyright : (c) Runtime Verification, 2020-2021
7+
License : BSD-3-Clause
8+
-}
9+
module Kore.Log.DebugRewriteRulesRemainder (
10+
DebugRewriteRulesRemainder (..),
11+
debugRewriteRulesRemainder,
12+
) where
13+
14+
import Data.Aeson (Value (Array), object, toJSON, (.=))
15+
import Data.Text qualified as Text
16+
import Data.Vector (fromList)
17+
import Kore.Internal.Conditional qualified as Conditional
18+
import Kore.Internal.Pattern (
19+
Pattern,
20+
)
21+
import Kore.Internal.Predicate (
22+
Predicate,
23+
)
24+
import Kore.Internal.Predicate qualified as Predicate
25+
import Kore.Internal.TermLike qualified as TermLike
26+
import Kore.Internal.Variable (
27+
VariableName,
28+
toVariableName,
29+
)
30+
import Kore.Rewrite.RewritingVariable
31+
import Kore.Syntax.Json qualified as PatternJson
32+
import Kore.Unparser
33+
import Kore.Util (showHashHex)
34+
import Log
35+
import Prelude.Kore
36+
import Pretty (
37+
Pretty (..),
38+
)
39+
import Pretty qualified
40+
41+
data DebugRewriteRulesRemainder = DebugRewriteRulesRemainder
42+
{ configuration :: !(Pattern VariableName)
43+
, rulesCount :: !Int
44+
, remainder :: !(Predicate RewritingVariableName)
45+
}
46+
deriving stock (Show)
47+
48+
instance Pretty DebugRewriteRulesRemainder where
49+
pretty DebugRewriteRulesRemainder{..} =
50+
Pretty.vsep
51+
[ (Pretty.hsep . catMaybes)
52+
[ Just "The rules"
53+
, Just "produced a remainder"
54+
, Just . pretty $ remainder
55+
]
56+
, "On configuration:"
57+
, Pretty.indent 2 . unparse $ configuration
58+
]
59+
60+
instance Entry DebugRewriteRulesRemainder where
61+
entrySeverity _ = Debug
62+
helpDoc _ = "log rewrite rules remainder"
63+
64+
oneLineContextJson
65+
entry@DebugRewriteRulesRemainder{configuration, rulesCount} =
66+
Array $
67+
fromList
68+
[ object ["entry" .= entryTypeText (toEntry entry)]
69+
, object
70+
[ "term" .= showHashHex (hash configuration)
71+
]
72+
, object
73+
[ "rules-count" .= Text.pack (show rulesCount)
74+
]
75+
]
76+
77+
oneLineDoc entry@(DebugRewriteRulesRemainder{rulesCount, remainder}) =
78+
let context = map Pretty.brackets (pretty <$> oneLineContextDoc entry <> ["detail"])
79+
logMsg =
80+
( Pretty.hsep . concat $
81+
[ ["After applying ", pretty rulesCount, " rewrite rules"]
82+
, ["there is a remainder condition: ", Pretty.group . pretty $ remainder]
83+
]
84+
)
85+
in mconcat context <> logMsg
86+
87+
oneLineJson DebugRewriteRulesRemainder{remainder} =
88+
toJSON
89+
. PatternJson.fromPredicate sortBool
90+
. Predicate.mapVariables (pure toVariableName)
91+
$ remainder
92+
93+
sortBool :: TermLike.Sort
94+
sortBool =
95+
(TermLike.SortActualSort $ TermLike.SortActual (TermLike.Id "SortBool" TermLike.AstLocationNone) [])
96+
97+
debugRewriteRulesRemainder ::
98+
MonadLog log =>
99+
Pattern RewritingVariableName ->
100+
Int ->
101+
Predicate RewritingVariableName ->
102+
log ()
103+
debugRewriteRulesRemainder pat rulesCount remainder =
104+
logEntry DebugRewriteRulesRemainder{..}
105+
where
106+
configuration = mapConditionalVariables TermLike.mapVariables pat
107+
mapConditionalVariables mapTermVariables =
108+
Conditional.mapVariables mapTermVariables (pure toVariableName)

kore/src/Kore/Log/Registry.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ import Kore.Log.DebugProven (
6363
import Kore.Log.DebugRetrySolverQuery (
6464
DebugRetrySolverQuery,
6565
)
66+
import Kore.Log.DebugRewriteRulesRemainder (
67+
DebugRewriteRulesRemainder,
68+
)
6669
import Kore.Log.DebugRewriteTrace (
6770
DebugFinalPatterns,
6871
DebugInitialClaim,
@@ -229,6 +232,7 @@ entryHelpDocsErr, entryHelpDocsNoErr :: [Pretty.Doc ()]
229232
, mk $ Proxy @DebugTransition
230233
, mk $ Proxy @DebugAppliedRewriteRules
231234
, mk $ Proxy @DebugAppliedLabeledRewriteRule
235+
, mk $ Proxy @DebugRewriteRulesRemainder
232236
, mk $ Proxy @DebugAttemptedRewriteRules
233237
, mk $ Proxy @DebugSubstitutionSimplifier
234238
, mk $ Proxy @WarnFunctionWithoutEvaluators

kore/src/Kore/Rewrite/RewriteStep.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import Kore.Log.DebugAppliedRewriteRules (
4343
debugAppliedRewriteRules,
4444
)
4545
import Kore.Log.DebugCreatedSubstitution (debugCreatedSubstitution)
46+
import Kore.Log.DebugRewriteRulesRemainder (debugRewriteRulesRemainder)
4647
import Kore.Log.DebugRewriteTrace (
4748
debugRewriteTrace,
4849
)
@@ -305,6 +306,7 @@ finalizeRulesParallel
305306
& fmap fold
306307
let unifications = MultiOr.make (Conditional.withoutTerm <$> unifiedRules)
307308
remainderPredicate = Remainder.remainder' unifications
309+
debugRewriteRulesRemainder initial (length unifiedRules) remainderPredicate
308310
-- evaluate the remainder predicate to make sure it is actually satisfiable
309311
SMT.evalPredicate
310312
(ErrorDecidePredicateUnknown $srcLoc Nothing)

kore/src/Log/Entry.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class (Show entry, Typeable entry) => Entry entry where
6666

6767
oneLineContextJson :: entry -> JSON.Value
6868
default oneLineContextJson :: entry -> JSON.Value
69-
oneLineContextJson _ = JSON.Array mempty
69+
oneLineContextJson entry = JSON.object ["entry" JSON..= entryTypeText (toEntry entry)]
7070

7171
oneLineContextDoc :: entry -> [Text]
7272
default oneLineContextDoc :: entry -> [Text]

0 commit comments

Comments
 (0)