Skip to content

Commit 9e2401f

Browse files
committed
Emit equation traces in the standard KORE RPC JSON logging format
1 parent d850290 commit 9e2401f

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

kore/src/Kore/Equation/DebugEquation.hs

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ import Kore.Internal.TermLike (
5252
SomeVariableName,
5353
TermLike,
5454
)
55+
import Kore.JsonRpc.Types.Log qualified as KoreRpcLog
5556
import Kore.Rewrite.Axiom.MatcherData (
5657
MatchResult,
5758
)
@@ -270,8 +271,34 @@ instance Entry DebugAttemptEquation where
270271
(srcLoc equation)
271272
oneLineDoc (DebugAttemptEquationResult _ (Left _)) = "equation is not applicable"
272273
oneLineDoc (DebugAttemptEquationResult _ (Right _)) = "equation is applicable"
273-
oneLineJson entry =
274-
JSON.object ["entry" JSON..= Log.entryTypeText (Log.toEntry entry)]
274+
275+
oneLineJson = \case
276+
entry@DebugAttemptEquation{} -> JSON.object ["entry" JSON..= Log.entryTypeText (Log.toEntry entry)]
277+
DebugAttemptEquationResult equation (Right _) ->
278+
JSON.toJSON $
279+
KoreRpcLog.Simplification
280+
{ originalTerm = Nothing
281+
, originalTermIndex = Nothing
282+
, result =
283+
KoreRpcLog.Success
284+
{ rewrittenTerm = Nothing
285+
, substitution = Nothing
286+
, ruleId = fromMaybe "UNKNOWN" (Attribute.getUniqueId . Attribute.uniqueId . attributes $ equation)
287+
}
288+
, origin = KoreRpcLog.KoreRpc
289+
}
290+
DebugAttemptEquationResult equation (Left failureReason) ->
291+
JSON.toJSON $
292+
KoreRpcLog.Simplification
293+
{ originalTerm = Nothing
294+
, originalTermIndex = Nothing
295+
, result =
296+
KoreRpcLog.Failure
297+
{ reason = (Pretty.renderText . Pretty.layoutOneLine) (pretty failureReason)
298+
, _ruleId = Attribute.getUniqueId . Attribute.uniqueId . attributes $ equation
299+
}
300+
, origin = KoreRpcLog.KoreRpc
301+
}
275302

276303
-- | Log the result of attempting to apply an 'Equation'.
277304
debugAttemptEquationResult ::

0 commit comments

Comments
 (0)