-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR allows logging Kore's rewrite rule remainders in full. Example log message with `'kore>remainder'`: ``` [kore][execute][remainder][detail] After applying 1 rewrite rules there is a satisfiable remainder condition: \not{_}(\not{_}(\equals{SortInt{}, _}(ConfigVarCONTRACT'Unds'ID:SortInt{}, Lbl'UndsAnd-'Int'Unds'{}(\dv{SortInt{}}("1461501637330902918203684832716283019655932542975"), Lbllookup{}(ConfigVarCONTRACT'Unds'STORAGE:SortMap{}, \dv{SortInt{}}("1")))))) ``` and in json: ``` {"context":["kore","execute","remainder",{"term":"39a4b3d"},{"rules-count":"1"}],"message":{"format":"KORE","version":1,"term":{"tag":"Not","sort":{"tag":"SortApp","name":"SortBool","args":[]},"arg":{"tag":"Not","sort":{"tag":"SortApp","name":"SortBool","args":[]},"arg":{"tag":"Equals","argSort":{"tag":"SortApp","name":"SortInt","args":[]},"sort":{"tag":"SortApp","name":"SortBool","args":[]},"first":{"tag":"EVar","name":"VarCONTRACT'Unds'ID","sort":{"tag":"SortApp","name":"SortInt","args":[]}},"second":{"tag":"App","name":"Lbl'UndsAnd-'Int'Unds'","sorts":[],"args":[{"tag":"DV","sort":{"tag":"SortApp","name":"SortInt","args":[]},"value":"1461501637330902918203684832716283019655932542975"},{"tag":"App","name":"Lbllookup","sorts":[],"args":[{"tag":"EVar","name":"VarCONTRACT'Unds'STORAGE","sort":{"tag":"SortApp","name":"SortMap","args":[]}},{"tag":"DV","sort":{"tag":"SortApp","name":"SortInt","args":[]},"value":"1"}]}]}}}}}} ```
- Loading branch information
Showing
7 changed files
with
133 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
{-# LANGUAGE RecordWildCards #-} | ||
{-# LANGUAGE NoStrict #-} | ||
{-# LANGUAGE NoStrictData #-} | ||
|
||
{- | | ||
Copyright : (c) Runtime Verification, 2020-2021 | ||
License : BSD-3-Clause | ||
-} | ||
module Kore.Log.DebugRewriteRulesRemainder ( | ||
DebugRewriteRulesRemainder (..), | ||
debugRewriteRulesRemainder, | ||
) where | ||
|
||
import Data.Aeson (Value (Array), object, toJSON, (.=)) | ||
import Data.Text qualified as Text | ||
import Data.Vector (fromList) | ||
import Kore.Internal.Conditional qualified as Conditional | ||
import Kore.Internal.Pattern ( | ||
Pattern, | ||
) | ||
import Kore.Internal.Predicate ( | ||
Predicate, | ||
) | ||
import Kore.Internal.Predicate qualified as Predicate | ||
import Kore.Internal.TermLike qualified as TermLike | ||
import Kore.Internal.Variable ( | ||
VariableName, | ||
toVariableName, | ||
) | ||
import Kore.Rewrite.RewritingVariable | ||
import Kore.Syntax.Json qualified as PatternJson | ||
import Kore.Unparser | ||
import Kore.Util (showHashHex) | ||
import Log | ||
import Prelude.Kore | ||
import Pretty ( | ||
Pretty (..), | ||
) | ||
import Pretty qualified | ||
|
||
{- This log entry will be emitted if, after unifying with rewrite rules, | ||
there is a satisfiable remainder condition -} | ||
data DebugRewriteRulesRemainder = DebugRewriteRulesRemainder | ||
{ configuration :: !(Pattern VariableName) | ||
-- ^ the state the rules unified with | ||
, rulesCount :: !Int | ||
-- ^ how many rules were unified | ||
, remainder :: !(Predicate RewritingVariableName) | ||
-- ^ the condition not covered by the rules | ||
} | ||
deriving stock (Show) | ||
|
||
instance Pretty DebugRewriteRulesRemainder where | ||
pretty DebugRewriteRulesRemainder{..} = | ||
Pretty.vsep | ||
[ (Pretty.hsep . catMaybes) | ||
[ Just "The rules" | ||
, Just "produced a remainder" | ||
, Just . pretty $ remainder | ||
] | ||
, "On configuration:" | ||
, Pretty.indent 2 . unparse $ configuration | ||
] | ||
|
||
instance Entry DebugRewriteRulesRemainder where | ||
entrySeverity _ = Debug | ||
helpDoc _ = "log rewrite rules remainder" | ||
|
||
oneLineContextDoc | ||
DebugRewriteRulesRemainder{} = [remainderContextName] | ||
|
||
oneLineContextJson | ||
DebugRewriteRulesRemainder{configuration, rulesCount} = | ||
Array $ | ||
fromList | ||
[ toJSON remainderContextName | ||
, object | ||
[ "term" .= showHashHex (hash configuration) | ||
] | ||
, object | ||
[ "rules-count" .= Text.pack (show rulesCount) | ||
] | ||
] | ||
|
||
oneLineDoc (DebugRewriteRulesRemainder{rulesCount, remainder}) = | ||
let context = [Pretty.brackets "detail"] | ||
logMsg = | ||
( Pretty.hsep | ||
[ "After applying " | ||
, pretty rulesCount | ||
, " rewrite rules" | ||
, "there is a satisfiable remainder condition: " | ||
, Pretty.group . pretty $ remainder | ||
] | ||
) | ||
in mconcat context <> logMsg | ||
|
||
oneLineJson DebugRewriteRulesRemainder{remainder} = | ||
toJSON | ||
. PatternJson.fromPredicate sortBool | ||
. Predicate.mapVariables (pure toVariableName) | ||
$ remainder | ||
|
||
remainderContextName :: Text.Text | ||
remainderContextName = "remainder" | ||
|
||
sortBool :: TermLike.Sort | ||
sortBool = | ||
(TermLike.SortActualSort $ TermLike.SortActual (TermLike.Id "SortBool" TermLike.AstLocationNone) []) | ||
|
||
debugRewriteRulesRemainder :: | ||
MonadLog log => | ||
Pattern RewritingVariableName -> | ||
Int -> | ||
Predicate RewritingVariableName -> | ||
log () | ||
debugRewriteRulesRemainder pat rulesCount remainder = | ||
logEntry DebugRewriteRulesRemainder{..} | ||
where | ||
configuration = mapConditionalVariables TermLike.mapVariables pat | ||
mapConditionalVariables mapTermVariables = | ||
Conditional.mapVariables mapTermVariables (pure toVariableName) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters