Skip to content

Commit 0f31483

Browse files
authored
RPC trace cleanup: remove simplification logs (#3880)
Fixes #3871 Note that removing the simplification log request parameters and the simplification log entries form the response is same, because `pyk` is already modified to not recognize them, see: - the `LogEntry` [type](https://github.com/runtimeverification/k/blob/develop/pyk/src/pyk/kore/rpc.py#L543) - the parameters for [execute](https://github.com/runtimeverification/k/blob/develop/pyk/src/pyk/kore/rpc.py#L1003), [simplify](https://github.com/runtimeverification/k/blob/develop/pyk/src/pyk/kore/rpc.py#L1049) and [implies](https://github.com/runtimeverification/k/blob/develop/pyk/src/pyk/kore/rpc.py#L1030) request But even considering that, we should run `pyk`'s integration tests before merging.
1 parent 4c6a57a commit 0f31483

File tree

8 files changed

+71
-355
lines changed

8 files changed

+71
-355
lines changed

booster/library/Booster/Definition/Ceil.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ computeCeilRule ::
101101
computeCeilRule mllvm def r@RewriteRule.RewriteRule{lhs, requires, rhs, attributes, computedAttributes}
102102
| null computedAttributes.notPreservesDefinednessReasons = pure Nothing
103103
| otherwise = do
104-
(res, _) <- runEquationT (Flag False) def mllvm Nothing mempty $ do
104+
(res, _) <- runEquationT def mllvm Nothing mempty $ do
105105
lhsCeils <- Set.fromList <$> computeCeil lhs
106106
requiresCeils <- Set.fromList <$> concatMapM (computeCeil . coerce) (Set.toList requires)
107107
let subtractLHSAndRequiresCeils = (Set.\\ (lhsCeils `Set.union` requiresCeils)) . Set.fromList

booster/library/Booster/JsonRpc.hs

Lines changed: 14 additions & 199 deletions
Large diffs are not rendered by default.

booster/library/Booster/Pattern/ApplyEquations.hs

Lines changed: 12 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@ module Booster.Pattern.ApplyEquations (
1515
getConfig,
1616
EquationPreference (..),
1717
EquationFailure (..),
18-
EquationTrace (..),
19-
pattern CollectEquationTraces,
20-
pattern NoCollectEquationTraces,
21-
eraseStates,
2218
EquationMetadata (..),
2319
ApplyEquationResult (..),
2420
ApplyEquationFailure (..),
@@ -85,7 +81,7 @@ import Booster.Pattern.Util
8581
import Booster.Prettyprinter (renderDefault, renderOneLineText)
8682
import Booster.SMT.Interface qualified as SMT
8783
import Booster.Syntax.Json.Externalise (externaliseTerm)
88-
import Booster.Util (Bound (..), Flag (..))
84+
import Booster.Util (Bound (..))
8985
import Kore.JsonRpc.Types.Log qualified as KoreRpcLog
9086
import Kore.Util (showHashHex)
9187

@@ -152,18 +148,11 @@ data EquationConfig = EquationConfig
152148
{ definition :: KoreDefinition
153149
, llvmApi :: Maybe LLVM.API
154150
, smtSolver :: Maybe SMT.SMTContext
155-
, doTracing :: Flag "CollectEquationTraces"
156151
, maxRecursion :: Bound "Recursion"
157152
, maxIterations :: Bound "Iterations"
158153
, logger :: Logger LogMessage
159154
}
160155

161-
pattern CollectEquationTraces :: Flag "CollectEquationTraces"
162-
pattern CollectEquationTraces = Flag True
163-
164-
pattern NoCollectEquationTraces :: Flag "CollectEquationTraces"
165-
pattern NoCollectEquationTraces = Flag False
166-
167156
data EquationState = EquationState
168157
{ termStack :: Seq Term
169158
, recursionStack :: [Term]
@@ -197,15 +186,6 @@ data EquationTrace term
197186
| EquationNotApplied term EquationMetadata ApplyEquationFailure
198187
deriving stock (Eq, Show)
199188

200-
{- | For the given equation trace, construct a new one,
201-
removing the heavy-weight information (the states),
202-
but keeping the meta-data (rule labels).
203-
-}
204-
eraseStates :: EquationTrace Term -> EquationTrace ()
205-
eraseStates = \case
206-
EquationApplied _ metadata _ -> EquationApplied () metadata ()
207-
EquationNotApplied _ metadata failureInfo -> EquationNotApplied () metadata failureInfo
208-
209189
instance Pretty (EquationTrace Term) where
210190
pretty (EquationApplied subjectTerm metadata rewritten) =
211191
vsep
@@ -415,14 +395,13 @@ data EquationPreference = PreferFunctions | PreferSimplifications
415395

416396
runEquationT ::
417397
LoggerMIO io =>
418-
Flag "CollectEquationTraces" ->
419398
KoreDefinition ->
420399
Maybe LLVM.API ->
421400
Maybe SMT.SMTContext ->
422401
SimplifierCache ->
423402
EquationT io a ->
424403
io (Either EquationFailure a, SimplifierCache)
425-
runEquationT doTracing definition llvmApi smtSolver sCache (EquationT m) = do
404+
runEquationT definition llvmApi smtSolver sCache (EquationT m) = do
426405
globalEquationOptions <- liftIO GlobalState.readGlobalEquationOptions
427406
logger <- getLogger
428407
(res, endState) <-
@@ -434,7 +413,6 @@ runEquationT doTracing definition llvmApi smtSolver sCache (EquationT m) = do
434413
{ definition
435414
, llvmApi
436415
, smtSolver
437-
, doTracing
438416
, maxIterations = globalEquationOptions.maxIterations
439417
, maxRecursion = globalEquationOptions.maxRecursion
440418
, logger
@@ -537,15 +515,14 @@ llvmSimplify term = do
537515
evaluateTerm ::
538516
LoggerMIO io =>
539517
MonadLoggerIO io =>
540-
Flag "CollectEquationTraces" ->
541518
Direction ->
542519
KoreDefinition ->
543520
Maybe LLVM.API ->
544521
Maybe SMT.SMTContext ->
545522
Term ->
546523
io (Either EquationFailure Term, SimplifierCache)
547-
evaluateTerm doTracing direction def llvmApi smtSolver =
548-
runEquationT doTracing def llvmApi smtSolver mempty
524+
evaluateTerm direction def llvmApi smtSolver =
525+
runEquationT def llvmApi smtSolver mempty
549526
. evaluateTerm' direction
550527

551528
-- version for internal nested evaluation
@@ -562,15 +539,14 @@ evaluateTerm' direction = iterateEquations direction PreferFunctions
562539
evaluatePattern ::
563540
LoggerMIO io =>
564541
MonadLoggerIO io =>
565-
Flag "CollectEquationTraces" ->
566542
KoreDefinition ->
567543
Maybe LLVM.API ->
568544
Maybe SMT.SMTContext ->
569545
SimplifierCache ->
570546
Pattern ->
571547
io (Either EquationFailure Pattern, SimplifierCache)
572-
evaluatePattern doTracing def mLlvmLibrary smtSolver cache =
573-
runEquationT doTracing def mLlvmLibrary smtSolver cache . evaluatePattern'
548+
evaluatePattern def mLlvmLibrary smtSolver cache =
549+
runEquationT def mLlvmLibrary smtSolver cache . evaluatePattern'
574550

575551
-- version for internal nested evaluation
576552
evaluatePattern' ::
@@ -600,15 +576,14 @@ simplifyAssumedPredicate p = do
600576
evaluateConstraints ::
601577
LoggerMIO io =>
602578
MonadLoggerIO io =>
603-
Flag "CollectEquationTraces" ->
604579
KoreDefinition ->
605580
Maybe LLVM.API ->
606581
Maybe SMT.SMTContext ->
607582
SimplifierCache ->
608583
Set Predicate ->
609584
io (Either EquationFailure (Set Predicate), SimplifierCache)
610-
evaluateConstraints doTracing def mLlvmLibrary smtSolver cache =
611-
runEquationT doTracing def mLlvmLibrary smtSolver cache . evaluateConstraints'
585+
evaluateConstraints def mLlvmLibrary smtSolver cache =
586+
runEquationT def mLlvmLibrary smtSolver cache . evaluateConstraints'
612587

613588
evaluateConstraints' ::
614589
LoggerMIO io =>
@@ -1084,28 +1059,26 @@ applyEquation term rule = withRuleContext rule $ fmap (either Failure Success) $
10841059
simplifyConstraint ::
10851060
LoggerMIO io =>
10861061
MonadLoggerIO io =>
1087-
Flag "CollectEquationTraces" ->
10881062
KoreDefinition ->
10891063
Maybe LLVM.API ->
10901064
Maybe SMT.SMTContext ->
10911065
SimplifierCache ->
10921066
Predicate ->
10931067
io (Either EquationFailure Predicate, SimplifierCache)
1094-
simplifyConstraint doTracing def mbApi mbSMT cache (Predicate p) = do
1095-
runEquationT doTracing def mbApi mbSMT cache $ (coerce <$>) . simplifyConstraint' True $ p
1068+
simplifyConstraint def mbApi mbSMT cache (Predicate p) = do
1069+
runEquationT def mbApi mbSMT cache $ (coerce <$>) . simplifyConstraint' True $ p
10961070

10971071
simplifyConstraints ::
10981072
LoggerMIO io =>
10991073
MonadLoggerIO io =>
1100-
Flag "CollectEquationTraces" ->
11011074
KoreDefinition ->
11021075
Maybe LLVM.API ->
11031076
Maybe SMT.SMTContext ->
11041077
SimplifierCache ->
11051078
[Predicate] ->
11061079
io (Either EquationFailure [Predicate], SimplifierCache)
1107-
simplifyConstraints doTracing def mbApi mbSMT cache ps =
1108-
runEquationT doTracing def mbApi mbSMT cache $
1080+
simplifyConstraints def mbApi mbSMT cache ps =
1081+
runEquationT def mbApi mbSMT cache $
11091082
concatMap splitAndBools
11101083
<$> mapM ((coerce <$>) . simplifyConstraint' True . coerce) ps
11111084

booster/library/Booster/Pattern/Rewrite.hs

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,10 @@ import Booster.Log (
5757
)
5858
import Booster.Pattern.ApplyEquations (
5959
EquationFailure (..),
60-
EquationTrace,
6160
SimplifierCache,
6261
evaluatePattern,
6362
simplifyConstraint,
6463
)
65-
import Booster.Pattern.ApplyEquations qualified as ApplyEquations
6664
import Booster.Pattern.Base
6765
import Booster.Pattern.Bool
6866
import Booster.Pattern.Index (TermIndex (..), kCellTermIndex)
@@ -97,9 +95,6 @@ instance MonadLoggerIO io => LoggerMIO (RewriteT io) where
9795
getLogger = RewriteT $ asks logger
9896
withLogger modL (RewriteT m) = RewriteT $ withReaderT (\cfg@RewriteConfig{logger} -> cfg{logger = modL logger}) m
9997

100-
castDoTracingFlag :: Flag "CollectRewriteTraces" -> Flag "CollectEquationTraces"
101-
castDoTracingFlag = coerce
102-
10398
pattern CollectRewriteTraces :: Flag "CollectRewriteTraces"
10499
pattern CollectRewriteTraces = Flag True
105100

@@ -439,11 +434,11 @@ applyRule pat@Pattern{ceilConditions} rule = withRuleContext rule $ runRewriteRu
439434
Predicate ->
440435
RewriteRuleAppT (RewriteT io) (Maybe a)
441436
checkConstraint onUnclear onBottom p = do
442-
RewriteConfig{definition, llvmApi, smtSolver, doTracing} <- lift $ RewriteT ask
437+
RewriteConfig{definition, llvmApi, smtSolver} <- lift $ RewriteT ask
443438
oldCache <- lift . RewriteT . lift $ get
444439
(simplified, cache) <-
445440
withContext "constraint" $
446-
simplifyConstraint (castDoTracingFlag doTracing) definition llvmApi smtSolver oldCache p
441+
simplifyConstraint definition llvmApi smtSolver oldCache p
447442
-- update cache
448443
lift . RewriteT . lift . modify $ const cache
449444
-- TODO should we keep the traces? Or only on success?
@@ -547,11 +542,7 @@ data RewriteTrace pat
547542
| -- | attempted rewrite failed
548543
RewriteStepFailed (RewriteFailed "Rewrite")
549544
| -- | Applied simplification to the pattern
550-
RewriteSimplified [EquationTrace (TracePayload pat)] (Maybe EquationFailure)
551-
552-
type family TracePayload pat where
553-
TracePayload Pattern = Term
554-
TracePayload () = ()
545+
RewriteSimplified (Maybe EquationFailure)
555546

556547
{- | For the given rewrite trace, construct a new one,
557548
removing the heavy-weight information (the states),
@@ -562,8 +553,7 @@ eraseStates = \case
562553
RewriteSingleStep rule_label mUniqueId _preState _postState -> RewriteSingleStep rule_label mUniqueId () ()
563554
RewriteBranchingStep _state branchMetadata -> RewriteBranchingStep () branchMetadata
564555
RewriteStepFailed failureInfo -> RewriteStepFailed failureInfo
565-
RewriteSimplified equationTraces mbEquationFailure ->
566-
RewriteSimplified (map ApplyEquations.eraseStates equationTraces) mbEquationFailure
556+
RewriteSimplified mbEquationFailure -> RewriteSimplified mbEquationFailure
567557

568558
instance Pretty (RewriteTrace Pattern) where
569559
pretty = \case
@@ -741,25 +731,25 @@ performRewrite doTracing def mLlvmLibrary mSolver mbMaxDepth cutLabels terminalL
741731
st <- get
742732
let cache = st.simplifierCache
743733
smt = st.smtSolver
744-
evaluatePattern (castDoTracingFlag doTracing) def mLlvmLibrary smt cache p >>= \(res, newCache) -> do
734+
evaluatePattern def mLlvmLibrary smt cache p >>= \(res, newCache) -> do
745735
updateCache newCache
746736
case res of
747737
Right newPattern -> do
748-
emitRewriteTrace $ RewriteSimplified [] Nothing
738+
emitRewriteTrace $ RewriteSimplified Nothing
749739
pure $ Just newPattern
750740
Left r@(SideConditionFalse _p) -> do
751741
logSimplify "A side condition was found to be false, pruning"
752-
emitRewriteTrace $ RewriteSimplified [] (Just r)
742+
emitRewriteTrace $ RewriteSimplified (Just r)
753743
pure Nothing
754744
Left r@UndefinedTerm{} -> do
755745
logSimplify "Term is undefined, pruning"
756-
emitRewriteTrace $ RewriteSimplified [] (Just r)
746+
emitRewriteTrace $ RewriteSimplified (Just r)
757747
pure Nothing
758748
Left r@(TooManyIterations n _start _result) -> do
759749
logSimplify $
760750
"Unable to simplify in " <> Text.pack (show n) <> " iterations, returning original"
761751
-- warning has been printed inside ApplyEquation.evaluatePattern
762-
emitRewriteTrace $ RewriteSimplified [] (Just r)
752+
emitRewriteTrace $ RewriteSimplified (Just r)
763753
-- NB start/result in this error are terms and might come
764754
-- from simplifying one of the constraints. Therefore, the
765755
-- original pattern must be returned.
@@ -773,11 +763,11 @@ performRewrite doTracing def mLlvmLibrary mSolver mbMaxDepth cutLabels terminalL
773763
<> prettyText l
774764
<> ": \n"
775765
<> Text.unlines (map (prettyText . fst) termDiffs)
776-
emitRewriteTrace $ RewriteSimplified [] (Just r)
766+
emitRewriteTrace $ RewriteSimplified (Just r)
777767
pure $ Just p
778768
Left other -> do
779769
logError $ "Simplification error during rewrite: " <> (Text.pack . constructorName $ other)
780-
emitRewriteTrace $ RewriteSimplified [] (Just other)
770+
emitRewriteTrace $ RewriteSimplified (Just other)
781771
pure $ Just p
782772

783773
-- Results may change when simplification prunes a false side

booster/tools/booster/Proxy.hs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,7 @@ respondEither cfg@ProxyConfig{statsVar, boosterState} booster kore req = case re
9090
| otherwise ->
9191
let logSettings =
9292
LogSettings
93-
{ logSuccessfulSimplifications = execReq.logSuccessfulSimplifications
94-
, logFailedSimplifications = execReq.logFailedSimplifications
95-
, logSuccessfulRewrites = execReq.logSuccessfulRewrites
93+
{ logSuccessfulRewrites = execReq.logSuccessfulRewrites
9694
, logFailedRewrites = execReq.logFailedRewrites
9795
, logFallbacks = execReq.logFallbacks
9896
, logTiming = execReq.logTiming
@@ -550,8 +548,6 @@ respondEither cfg@ProxyConfig{statsVar, boosterState} booster kore req = case re
550548
SimplifyRequest
551549
{ state = execStateToKoreJson state
552550
, _module = mbModule
553-
, logSuccessfulSimplifications = Nothing
554-
, logFailedSimplifications = Nothing
555551
, logTiming
556552
}
557553

@@ -612,9 +608,7 @@ respondEither cfg@ProxyConfig{statsVar, boosterState} booster kore req = case re
612608
}
613609

614610
data LogSettings = LogSettings
615-
{ logSuccessfulSimplifications :: Maybe Bool
616-
, logFailedSimplifications :: Maybe Bool
617-
, logSuccessfulRewrites :: Maybe Bool
611+
{ logSuccessfulRewrites :: Maybe Bool
618612
, logFailedRewrites :: Maybe Bool
619613
, logFallbacks :: Maybe Bool
620614
, logTiming :: Maybe Bool

booster/unit-tests/Test/Booster/Pattern/ApplyEquations.hs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ test_evaluateFunction =
9898
unsafePerformIO
9999
. runNoLoggingT
100100
. (fst <$>)
101-
. evaluateTerm NoCollectEquationTraces direction funDef Nothing Nothing
101+
. evaluateTerm direction funDef Nothing Nothing
102102

103103
isTooManyIterations (Left (TooManyIterations _n _ _)) = pure ()
104104
isTooManyIterations (Left err) = assertFailure $ "Unexpected error " <> show err
@@ -129,7 +129,7 @@ test_simplify =
129129
unsafePerformIO
130130
. runNoLoggingT
131131
. (fst <$>)
132-
. evaluateTerm NoCollectEquationTraces direction simplDef Nothing Nothing
132+
. evaluateTerm direction simplDef Nothing Nothing
133133
a = var "A" someSort
134134

135135
test_simplifyPattern :: TestTree
@@ -159,7 +159,7 @@ test_simplifyPattern =
159159
unsafePerformIO
160160
. runNoLoggingT
161161
. (fst <$>)
162-
. evaluatePattern NoCollectEquationTraces simplDef Nothing Nothing mempty
162+
. evaluatePattern simplDef Nothing Nothing mempty
163163
a = var "A" someSort
164164

165165
test_simplifyConstraint :: TestTree
@@ -229,7 +229,7 @@ test_simplifyConstraint =
229229
unsafePerformIO
230230
. runNoLoggingT
231231
. (fst <$>)
232-
. simplifyConstraint NoCollectEquationTraces testDefinition Nothing Nothing mempty
232+
. simplifyConstraint testDefinition Nothing Nothing mempty
233233

234234
test_errors :: TestTree
235235
test_errors =
@@ -242,7 +242,7 @@ test_errors =
242242
loopTerms =
243243
[f $ app con1 [a], f $ app con2 [a], f $ app con3 [a, a], f $ app con1 [a]]
244244
isLoop loopTerms . unsafePerformIO . runNoLoggingT $
245-
fst <$> evaluateTerm NoCollectEquationTraces TopDown loopDef Nothing Nothing subj
245+
fst <$> evaluateTerm TopDown loopDef Nothing Nothing subj
246246
]
247247
where
248248
isLoop ts (Left (EquationLoop ts')) = ts @?= ts'

kore-rpc-types/src/Kore/JsonRpc/Types.hs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ data ExecuteRequest = ExecuteRequest
3939
, assumeStateDefined :: !(Maybe Bool)
4040
, logSuccessfulRewrites :: !(Maybe Bool)
4141
, logFailedRewrites :: !(Maybe Bool)
42-
, logSuccessfulSimplifications :: !(Maybe Bool)
43-
, logFailedSimplifications :: !(Maybe Bool)
4442
, logFallbacks :: !(Maybe Bool)
4543
, logTiming :: !(Maybe Bool)
4644
}
@@ -54,8 +52,6 @@ data ImpliesRequest = ImpliesRequest
5452
, consequent :: !KoreJson
5553
, _module :: !(Maybe Text)
5654
, assumeDefined :: !(Maybe Bool)
57-
, logSuccessfulSimplifications :: !(Maybe Bool)
58-
, logFailedSimplifications :: !(Maybe Bool)
5955
, logTiming :: !(Maybe Bool)
6056
}
6157
deriving stock (Generic, Show, Eq)
@@ -66,8 +62,6 @@ data ImpliesRequest = ImpliesRequest
6662
data SimplifyRequest = SimplifyRequest
6763
{ state :: KoreJson
6864
, _module :: !(Maybe Text)
69-
, logSuccessfulSimplifications :: !(Maybe Bool)
70-
, logFailedSimplifications :: !(Maybe Bool)
7165
, logTiming :: !(Maybe Bool)
7266
}
7367
deriving stock (Generic, Show, Eq)

0 commit comments

Comments
 (0)