@@ -24,7 +24,6 @@ import Control.Monad.Logger.CallStack qualified as Log
24
24
import Control.Monad.Trans.Except (catchE , except , runExcept , runExceptT , throwE , withExceptT )
25
25
import Crypto.Hash (SHA256 (.. ), hashWith )
26
26
import Data.Bifunctor (second )
27
- import Data.Coerce (coerce )
28
27
import Data.Foldable
29
28
import Data.List (singleton )
30
29
import Data.Map.Strict (Map )
@@ -135,8 +134,6 @@ respond stateVar =
135
134
(fromMaybe False )
136
135
[ req. logSuccessfulRewrites
137
136
, req. logFailedRewrites
138
- , req. logSuccessfulSimplifications
139
- , req. logFailedSimplifications
140
137
, req. logFallbacks
141
138
]
142
139
-- apply the given substitution before doing anything else
@@ -224,31 +221,11 @@ respond stateVar =
224
221
start <- liftIO $ getTime Monotonic
225
222
let internalised =
226
223
runExcept $ internaliseTermOrPredicate DisallowAlias CheckSubsorts Nothing def req. state. term
227
- let mkEquationTraces
228
- | coerce doTracing =
229
- Just
230
- . mapMaybe
231
- ( mkLogEquationTrace
232
- ( fromMaybe False req. logSuccessfulSimplifications
233
- , fromMaybe False req. logFailedSimplifications
234
- )
235
- )
236
- | otherwise =
237
- const Nothing
238
- mkTraces duration traceData
224
+ let mkTraces duration
239
225
| Just True <- req. logTiming =
240
- Just $
241
- [ProcessingTime (Just Booster ) duration]
242
- <> fromMaybe [] (mkEquationTraces traceData)
226
+ Just [ProcessingTime (Just Booster ) duration]
243
227
| otherwise =
244
- mkEquationTraces traceData
245
- doTracing =
246
- Flag $
247
- any
248
- (fromMaybe False )
249
- [ req. logSuccessfulSimplifications
250
- , req. logFailedSimplifications
251
- ]
228
+ Nothing
252
229
253
230
solver <- traverse (SMT. initSolver def) mSMTOptions
254
231
@@ -287,10 +264,10 @@ respond stateVar =
287
264
result = case catMaybes (mbPredicate : mbSubstitution : map Just unsupported) of
288
265
[] -> term
289
266
ps -> KoreJson. KJAnd tSort $ term : ps
290
- pure $ Right (addHeader result, [] )
267
+ pure $ Right (addHeader result)
291
268
(Left ApplyEquations. SideConditionFalse {}, _) -> do
292
269
let tSort = externaliseSort $ sortOfPattern pat
293
- pure $ Right (addHeader $ KoreJson. KJBottom tSort, [] )
270
+ pure $ Right (addHeader $ KoreJson. KJBottom tSort)
294
271
(Left (ApplyEquations. EquationLoop _terms), _) ->
295
272
pure . Left . RpcError. backendError $ RpcError. Aborted " equation loop detected"
296
273
(Left other, _) ->
@@ -300,7 +277,7 @@ respond stateVar =
300
277
| null ps. boolPredicates && null ps. ceilPredicates && null ps. substitution && null ps. unsupported ->
301
278
pure $
302
279
Right
303
- (addHeader $ Syntax. KJTop (fromMaybe (error " not a predicate" ) $ sortOfJson req. state. term), [] )
280
+ (addHeader $ Syntax. KJTop (fromMaybe (error " not a predicate" ) $ sortOfJson req. state. term))
304
281
| otherwise -> do
305
282
Log. logInfoNS " booster" " Simplifying predicates"
306
283
unless (null ps. unsupported) $ do
@@ -329,18 +306,18 @@ respond stateVar =
329
306
<> map (uncurry $ externaliseSubstitution predicateSort) (Map. toList ps. substitution)
330
307
<> ps. unsupported
331
308
332
- pure $ Right (addHeader $ Syntax. KJAnd predicateSort result, [] )
309
+ pure $ Right (addHeader $ Syntax. KJAnd predicateSort result)
333
310
(Left something, _) ->
334
311
pure . Left . RpcError. backendError $ RpcError. Aborted $ renderText $ pretty something
335
312
whenJust solver SMT. closeSolver
336
313
stop <- liftIO $ getTime Monotonic
337
314
338
315
let duration =
339
316
fromIntegral (toNanoSecs (diffTimeSpec stop start)) / 1e9
340
- mkSimplifyResponse state traceData =
317
+ mkSimplifyResponse state =
341
318
RpcTypes. Simplify
342
- RpcTypes. SimplifyResult {state, logs = mkTraces duration traceData }
343
- pure $ second ( uncurry mkSimplifyResponse) ( fmap (second ( map ApplyEquations. eraseStates)) result)
319
+ RpcTypes. SimplifyResult {state, logs = mkTraces duration}
320
+ pure $ second mkSimplifyResponse result
344
321
RpcTypes. GetModel req -> withModule req. _module $ \ case
345
322
(_, _, Nothing ) -> do
346
323
Log. logErrorNS " booster" " get-model request, not supported without SMT solver"
@@ -727,7 +704,6 @@ execResponse mbDuration req (d, traces, rr) originalSubstitution unsupported = c
727
704
let abortRewriteLog =
728
705
mkLogRewriteTrace
729
706
(logSuccessfulRewrites, logFailedRewrites)
730
- (logSuccessfulSimplifications, logFailedSimplifications)
731
707
(RewriteStepFailed failure)
732
708
in logs <|> abortRewriteLog
733
709
, state = toExecState p originalSubstitution unsupported Nothing
@@ -738,8 +714,6 @@ execResponse mbDuration req (d, traces, rr) originalSubstitution unsupported = c
738
714
where
739
715
logSuccessfulRewrites = fromMaybe False req. logSuccessfulRewrites
740
716
logFailedRewrites = fromMaybe False req. logFailedRewrites
741
- logSuccessfulSimplifications = fromMaybe False req. logSuccessfulSimplifications
742
- logFailedSimplifications = fromMaybe False req. logFailedSimplifications
743
717
depth = RpcTypes. Depth d
744
718
745
719
logs =
@@ -748,7 +722,6 @@ execResponse mbDuration req (d, traces, rr) originalSubstitution unsupported = c
748
722
fmap
749
723
( mkLogRewriteTrace
750
724
(logSuccessfulRewrites, logFailedRewrites)
751
- (logSuccessfulSimplifications, logFailedSimplifications)
752
725
)
753
726
traces
754
727
timingLog =
@@ -777,105 +750,12 @@ toExecState pat sub unsupported muid =
777
750
| null unsupported = id
778
751
| otherwise = maybe (Just allUnsupported) (Just . Syntax. KJAnd termSort . (: unsupported))
779
752
780
- mkLogEquationTrace :: (Bool , Bool ) -> ApplyEquations. EquationTrace () -> Maybe LogEntry
781
- mkLogEquationTrace
782
- (logSuccessfulSimplifications, logFailedSimplifications) = \ case
783
- ApplyEquations. EquationApplied _subjectTerm metadata _rewritten ->
784
- if logSuccessfulSimplifications
785
- then
786
- Just $
787
- Simplification
788
- { originalTerm
789
- , originalTermIndex
790
- , origin
791
- , result =
792
- Success
793
- { rewrittenTerm = Nothing
794
- , substitution = Nothing
795
- , ruleId = fromMaybe " UNKNOWN" _ruleId
796
- }
797
- }
798
- else Nothing
799
- where
800
- originalTerm = Nothing
801
- originalTermIndex = Nothing
802
- origin = Booster
803
- _ruleId = fmap getUniqueId metadata. ruleId
804
- ApplyEquations. EquationNotApplied _subjectTerm metadata result ->
805
- case result of
806
- ApplyEquations. FailedMatch {}
807
- | logFailedSimplifications ->
808
- Just $
809
- Simplification
810
- { originalTerm
811
- , originalTermIndex
812
- , origin
813
- , result = Failure {reason = " Failed match" , _ruleId}
814
- }
815
- ApplyEquations. IndeterminateMatch
816
- | logFailedSimplifications ->
817
- Just $
818
- Simplification
819
- { originalTerm
820
- , originalTermIndex
821
- , origin
822
- , result = Failure {reason = " Indeterminate match" , _ruleId}
823
- }
824
- ApplyEquations. IndeterminateCondition {}
825
- | logFailedSimplifications ->
826
- Just $
827
- Simplification
828
- { originalTerm
829
- , originalTermIndex
830
- , origin
831
- , result = Failure {reason = " Indeterminate side-condition" , _ruleId}
832
- }
833
- ApplyEquations. ConditionFalse {}
834
- | logFailedSimplifications ->
835
- Just $
836
- Simplification
837
- { originalTerm
838
- , originalTermIndex
839
- , origin
840
- , result = Failure {reason = " Side-condition is false" , _ruleId}
841
- }
842
- ApplyEquations. RuleNotPreservingDefinedness
843
- | logFailedSimplifications ->
844
- Just $
845
- Simplification
846
- { originalTerm
847
- , originalTermIndex
848
- , origin
849
- , result = Failure {reason = " The equation does not preserve definedness" , _ruleId}
850
- }
851
- ApplyEquations. MatchConstraintViolated _ varName
852
- | logFailedSimplifications ->
853
- Just $
854
- Simplification
855
- { originalTerm
856
- , originalTermIndex
857
- , origin
858
- , result =
859
- Failure
860
- { reason = " Symbolic/concrete constraint violated for variable: " <> Text. decodeUtf8 varName
861
- , _ruleId
862
- }
863
- }
864
- _ -> Nothing
865
- where
866
- originalTerm = Nothing
867
- originalTermIndex = Nothing
868
- origin = Booster
869
- _ruleId = fmap getUniqueId metadata. ruleId
870
-
871
753
mkLogRewriteTrace ::
872
- (Bool , Bool ) ->
873
754
(Bool , Bool ) ->
874
755
RewriteTrace () ->
875
756
Maybe [LogEntry ]
876
757
mkLogRewriteTrace
877
- (logSuccessfulRewrites, logFailedRewrites)
878
- equationLogOpts@ (logSuccessfulSimplifications, logFailedSimplifications) =
758
+ (logSuccessfulRewrites, logFailedRewrites) =
879
759
\ case
880
760
RewriteSingleStep _ uid _ _res
881
761
| logSuccessfulRewrites ->
@@ -926,68 +806,5 @@ mkLogRewriteTrace
926
806
}
927
807
, origin = Booster
928
808
}
929
- RewriteSimplified equationTraces Nothing
930
- | logSuccessfulSimplifications || logFailedSimplifications ->
931
- mapM (mkLogEquationTrace equationLogOpts) equationTraces
932
- | otherwise -> Just []
933
- RewriteSimplified equationTraces (Just failure)
934
- | logFailedSimplifications -> do
935
- let final = singleton $ case failure of
936
- ApplyEquations. IndexIsNone trm ->
937
- Simplification
938
- { originalTerm = Just $ execStateToKoreJson $ toExecState (Pattern. Pattern_ trm) mempty mempty Nothing
939
- , originalTermIndex = Nothing
940
- , origin = Booster
941
- , result = Failure {reason = " No index found for term" , _ruleId = Nothing }
942
- }
943
- ApplyEquations. TooManyIterations i _ _ ->
944
- Simplification
945
- { originalTerm = Nothing
946
- , originalTermIndex = Nothing
947
- , origin = Booster
948
- , result = Failure {reason = " Reached iteration depth limit " <> pack (show i), _ruleId = Nothing }
949
- }
950
- ApplyEquations. EquationLoop _ ->
951
- Simplification
952
- { originalTerm = Nothing
953
- , originalTermIndex = Nothing
954
- , origin = Booster
955
- , result = Failure {reason = " Loop detected" , _ruleId = Nothing }
956
- }
957
- ApplyEquations. TooManyRecursions stk ->
958
- Simplification
959
- { originalTerm = Nothing
960
- , originalTermIndex = Nothing
961
- , origin = Booster
962
- , result =
963
- Failure
964
- { reason =
965
- " Reached recursion limit of "
966
- <> pack (show $ length stk)
967
- , _ruleId = Nothing
968
- }
969
- }
970
- ApplyEquations. InternalError err ->
971
- Simplification
972
- { originalTerm = Nothing
973
- , originalTermIndex = Nothing
974
- , origin = Booster
975
- , result = Failure {reason = " Internal error: " <> err, _ruleId = Nothing }
976
- }
977
- ApplyEquations. SideConditionFalse _predicate ->
978
- Simplification
979
- { originalTerm = Nothing
980
- , originalTermIndex = Nothing
981
- , origin = Booster
982
- , result = Failure {reason = " Side conditions false" , _ruleId = Nothing }
983
- }
984
- ApplyEquations. UndefinedTerm _t _err ->
985
- Simplification
986
- { originalTerm = Nothing
987
- , originalTermIndex = Nothing
988
- , origin = Booster
989
- , result = Failure {reason = " Undefined term found" , _ruleId = Nothing }
990
- }
991
- (<> final) <$> mapM (mkLogEquationTrace equationLogOpts) equationTraces
992
- | otherwise -> Just []
809
+ RewriteSimplified {} -> Just []
993
810
_ -> Nothing
0 commit comments