@@ -28,7 +28,6 @@ module Booster.Pattern.ApplyEquations (
28
28
evaluateConstraints ,
29
29
) where
30
30
31
- import Control.Applicative (Alternative (.. ))
32
31
import Control.Monad
33
32
import Control.Monad.Extra (fromMaybeM , whenJust )
34
33
import Control.Monad.IO.Class (MonadIO (.. ))
@@ -45,7 +44,6 @@ import Control.Monad.Trans.Except
45
44
import Control.Monad.Trans.Reader (ReaderT (.. ), ask , asks , withReaderT )
46
45
import Control.Monad.Trans.State
47
46
import Data.Aeson (object , (.=) )
48
- import Data.Aeson.Text (encodeToLazyText )
49
47
import Data.Bifunctor (bimap )
50
48
import Data.ByteString.Char8 qualified as BS
51
49
import Data.Coerce (coerce )
@@ -62,7 +60,6 @@ import Data.Set qualified as Set
62
60
import Data.Text (Text , pack )
63
61
import Data.Text qualified as Text
64
62
import Data.Text.Encoding qualified as Text
65
- import Data.Text.Lazy qualified as Text (toStrict )
66
63
import GHC.TypeLits (KnownSymbol )
67
64
import Prettyprinter
68
65
@@ -82,7 +79,6 @@ import Booster.Prettyprinter (renderDefault, renderOneLineText)
82
79
import Booster.SMT.Interface qualified as SMT
83
80
import Booster.Syntax.Json.Externalise (externaliseTerm )
84
81
import Booster.Util (Bound (.. ))
85
- import Kore.JsonRpc.Types.Log qualified as KoreRpcLog
86
82
import Kore.Util (showHashHex )
87
83
88
84
newtype EquationT io a
@@ -254,52 +250,6 @@ isMatchFailure _ = False
254
250
isSuccess EquationApplied {} = True
255
251
isSuccess _ = False
256
252
257
- {- | Attempt to get an equation's unique id, falling back to it's label or eventually to UNKNOWN.
258
- The fallbacks are useful in case of cached equation applications or the ones done via LLVM,
259
- as neither of these categories have unique IDs.
260
- -}
261
- equationRuleIdWithFallbacks :: EquationMetadata -> Text
262
- equationRuleIdWithFallbacks metadata =
263
- fromMaybe " UNKNOWN" (fmap getUniqueId metadata. ruleId <|> metadata. label)
264
-
265
- equationTraceToLogEntry :: EquationTrace Term -> KoreRpcLog. LogEntry
266
- equationTraceToLogEntry = \ case
267
- EquationApplied _subjectTerm metadata _rewritten ->
268
- KoreRpcLog. Simplification
269
- { originalTerm
270
- , originalTermIndex
271
- , origin
272
- , result =
273
- KoreRpcLog. Success Nothing Nothing _ruleId
274
- }
275
- where
276
- originalTerm = Nothing
277
- originalTermIndex = Nothing
278
- origin = KoreRpcLog. Booster
279
- _ruleId = equationRuleIdWithFallbacks metadata
280
- EquationNotApplied _subjectTerm metadata failure ->
281
- KoreRpcLog. Simplification
282
- { originalTerm
283
- , originalTermIndex
284
- , origin
285
- , result = KoreRpcLog. Failure (failureDescription failure) (Just _ruleId)
286
- }
287
- where
288
- originalTerm = Nothing
289
- originalTermIndex = Nothing
290
- origin = KoreRpcLog. Booster
291
- _ruleId = equationRuleIdWithFallbacks metadata
292
-
293
- failureDescription :: ApplyEquationFailure -> Text. Text
294
- failureDescription = \ case
295
- FailedMatch {} -> " Failed match"
296
- IndeterminateMatch -> " IndeterminateMatch"
297
- IndeterminateCondition {} -> " IndeterminateCondition"
298
- ConditionFalse {} -> " ConditionFalse"
299
- EnsuresFalse {} -> " EnsuresFalse"
300
- RuleNotPreservingDefinedness -> " RuleNotPreservingDefinedness"
301
- MatchConstraintViolated {} -> " MatchConstraintViolated"
302
-
303
253
startState :: SimplifierCache -> EquationState
304
254
startState cache =
305
255
EquationState
@@ -426,9 +376,7 @@ iterateEquations ::
426
376
Term ->
427
377
EquationT io Term
428
378
iterateEquations direction preference startTerm = do
429
- result <- pushRecursion startTerm >>= checkCounter >> go startTerm <* popRecursion
430
- when (startTerm /= result) $ withContext " success" $ withTermContext result $ pure ()
431
- pure result
379
+ pushRecursion startTerm >>= checkCounter >> go startTerm <* popRecursion
432
380
where
433
381
checkCounter counter = do
434
382
config <- getConfig
@@ -832,13 +780,15 @@ applyEquations theory handler term = do
832
780
processEquations [] =
833
781
pure term -- nothing to do, term stays the same
834
782
processEquations (eq : rest) = do
835
- res <- applyEquation term eq
783
+ res <- withRuleContext eq $ applyEquation term eq
836
784
emitEquationTrace term eq. attributes. location eq. attributes. ruleLabel eq. attributes. uniqueId res
837
785
handler
838
- (\ t -> setChanged >> pure t)
786
+ ( \ t -> setChanged >> (withContext (LogContext eq) $ withContext " success" $ withTermContext t $ pure t)
787
+ )
839
788
(processEquations rest)
840
- ( withContext " abort" $
841
- logMessage (" Aborting simplification/function evaluation" :: Text ) >> pure term
789
+ ( withContext (LogContext eq) $
790
+ withContext " abort" $
791
+ logMessage (" Aborting simplification/function evaluation" :: Text ) >> pure term
842
792
)
843
793
res
844
794
@@ -861,9 +811,6 @@ emitEquationTrace t loc lbl uid res = do
861
811
Failure failure -> EquationNotApplied t (EquationMetadata loc lbl uid) failure
862
812
prettyItem = pack . renderDefault . pretty $ newTraceItem
863
813
logOther (LevelOther " Simplify" ) prettyItem
864
- logOther
865
- (LevelOther " SimplifyJson" )
866
- (Text. toStrict . encodeToLazyText $ equationTraceToLogEntry newTraceItem)
867
814
case res of
868
815
Success {} -> logOther (LevelOther " SimplifySuccess" ) prettyItem
869
816
_ -> pure ()
@@ -875,7 +822,7 @@ applyEquation ::
875
822
Term ->
876
823
RewriteRule tag ->
877
824
EquationT io ApplyEquationResult
878
- applyEquation term rule = withRuleContext rule $ fmap (either Failure Success ) $ runExceptT $ do
825
+ applyEquation term rule = fmap (either Failure Success ) $ runExceptT $ do
879
826
-- ensured by internalisation: no existentials in equations
880
827
unless (null rule. existentials) $ do
881
828
withContext " abort" $
0 commit comments