@@ -21,7 +21,6 @@ import Control.Exception qualified as Exception
21
21
import Control.Monad
22
22
import Control.Monad.Extra (whenJust )
23
23
import Control.Monad.IO.Class
24
- import Control.Monad.Logger.CallStack qualified as Log
25
24
import Control.Monad.Trans.Except (catchE , except , runExcept , runExceptT , throwE , withExceptT )
26
25
import Crypto.Hash (SHA256 (.. ), hashWith )
27
26
import Data.Bifunctor (second )
@@ -96,7 +95,6 @@ import Kore.Syntax.Json.Types qualified as Syntax
96
95
respond ::
97
96
forall m .
98
97
LoggerMIO m =>
99
- Log. MonadLoggerIO m =>
100
98
MVar ServerState ->
101
99
Respond (RpcTypes. API 'RpcTypes.Req ) m (RpcTypes. API 'RpcTypes.Res )
102
100
respond stateVar =
@@ -123,10 +121,6 @@ respond stateVar =
123
121
unless (null unsupported) $ do
124
122
withKorePatternContext (KoreJson. KJAnd (externaliseSort $ sortOfPattern pat) unsupported) $
125
123
logMessage (" ignoring unsupported predicate parts" :: Text )
126
- Log. logWarnNS
127
- " booster"
128
- " Execute: ignoring unsupported predicate parts"
129
-
130
124
let cutPoints = fromMaybe [] req. cutPointRules
131
125
terminals = fromMaybe [] req. terminalRules
132
126
mbDepth = fmap RpcTypes. getNat req. maxDepth
@@ -235,10 +229,6 @@ respond stateVar =
235
229
Left patternErrors -> do
236
230
forM_ patternErrors $ \ patternError ->
237
231
void $ Booster.Log. withContext " internalise" $ logPatternError patternError
238
- Log. logOtherNS
239
- " booster"
240
- (Log. LevelOther " ErrorDetails" )
241
- (prettyPattern req. state. term)
242
232
pure $
243
233
Left $
244
234
RpcError. backendError $
@@ -249,9 +239,6 @@ respond stateVar =
249
239
unless (null unsupported) $ do
250
240
withKorePatternContext (KoreJson. KJAnd (externaliseSort $ sortOfPattern pat) unsupported) $ do
251
241
logMessage (" ignoring unsupported predicate parts" :: Text )
252
- Log. logWarnNS
253
- " booster"
254
- " Simplify: ignoring unsupported predicate parts"
255
242
-- apply the given substitution before doing anything else
256
243
let substPat =
257
244
Pattern
@@ -284,9 +271,6 @@ respond stateVar =
284
271
unless (null ps. unsupported) $ do
285
272
withKorePatternContext (KoreJson. KJAnd (externaliseSort $ SortApp " SortBool" [] ) ps. unsupported) $ do
286
273
logMessage (" ignoring unsupported predicate parts" :: Text )
287
- Log. logWarnNS
288
- " booster"
289
- " Simplify: ignoring unsupported predicate parts"
290
274
-- apply the given substitution before doing anything else
291
275
let predicates = map (substituteInPredicate ps. substitution) $ Set. toList ps. boolPredicates
292
276
withContext " constraint" $
@@ -321,7 +305,8 @@ respond stateVar =
321
305
pure $ second mkSimplifyResponse result
322
306
RpcTypes. GetModel req -> withModule req. _module $ \ case
323
307
(_, _, Nothing ) -> do
324
- Log. logErrorNS " booster" " get-model request, not supported without SMT solver"
308
+ withContext " get-model" $
309
+ logMessage' (" get-model request, not supported without SMT solver" :: Text )
325
310
pure $ Left RpcError. notImplemented
326
311
(def, _, Just smtOptions) -> do
327
312
let internalised =
@@ -330,64 +315,48 @@ respond stateVar =
330
315
case internalised of
331
316
Left patternErrors -> do
332
317
forM_ patternErrors $ \ patternError ->
333
- Log. logErrorNS " booster" $
334
- " Error internalising cterm: " <> pack (show patternError)
335
- Log. logOtherNS
336
- " booster"
337
- (Log. LevelOther " ErrorDetails" )
338
- (prettyPattern req. state. term)
318
+ void $ Booster.Log. withContext " internalise" $ logPatternError patternError
339
319
pure $
340
320
Left $
341
321
RpcError. backendError $
342
322
RpcError. CouldNotVerifyPattern $
343
323
map patternErrorToRpcError patternErrors
344
324
-- various predicates obtained
345
325
Right things -> do
346
- Log. logInfoNS " booster" " get-model request"
347
326
-- term and predicates were sent. Only work on predicates
348
327
(boolPs, suppliedSubst) <-
349
328
case things of
350
329
TermAndPredicates pat substitution unsupported -> do
351
- Log. logWarnNS
352
- " booster"
353
- " get-model ignores supplied terms and only checks predicates"
354
- Log. logOtherNS
355
- " booster"
356
- (Log. LevelOther " ErrorDetails" )
357
- (renderText $ pretty pat. term)
330
+ withContext " get-model" $
331
+ logMessage' (" ignoring supplied terms and only checking predicates" :: Text )
332
+
358
333
unless (null unsupported) $ do
359
- Log. logWarnNS
360
- " booster"
361
- " get-model: ignoring unsupported predicates"
362
- Log. logOtherNS
363
- " booster"
364
- (Log. LevelOther " ErrorDetails" )
365
- (Text. unlines $ map prettyPattern unsupported)
334
+ withContext " get-model" $ do
335
+ logMessage' (" ignoring unsupported predicates" :: Text )
336
+ withContext " detail" $
337
+ logMessage (Text. unwords $ map prettyPattern unsupported)
366
338
pure (Set. toList pat. constraints, substitution)
367
339
Predicates ps -> do
368
340
unless (null ps. ceilPredicates && null ps. unsupported) $ do
369
- Log. logWarnNS
370
- " booster"
371
- " get-model: ignoring supplied ceils and unsupported predicates"
372
- Log. logOtherNS
373
- " booster"
374
- (Log. LevelOther " ErrorDetails" )
375
- ( Text. unlines $
376
- map
377
- (renderText . (" #Ceil:" <> ) . pretty)
378
- (Set. toList ps. ceilPredicates)
379
- <> map prettyPattern ps. unsupported
380
- )
341
+ withContext " get-model" $ do
342
+ logMessage' (" ignoring supplied ceils and unsupported predicates" :: Text )
343
+ withContext " detail" $
344
+ logMessage
345
+ ( Text. unlines $
346
+ map
347
+ (renderText . (" #Ceil:" <> ) . pretty)
348
+ (Set. toList ps. ceilPredicates)
349
+ <> map prettyPattern ps. unsupported
350
+ )
381
351
pure (Set. toList ps. boolPredicates, ps. substitution)
382
352
383
353
smtResult <-
384
354
if null boolPs && Map. null suppliedSubst
385
355
then do
386
356
-- as per spec, no predicate, no answer
387
- Log. logOtherNS
388
- " booster"
389
- (Log. LevelOther " SMT" )
390
- " No predicates or substitutions given, returning Unknown"
357
+ withContext " get-model" $
358
+ withContext " smt" $
359
+ logMessage (" No predicates or substitutions given, returning Unknown" :: Text )
391
360
pure $ Left SMT. Unknown
392
361
else do
393
362
solver <- SMT. initSolver def smtOptions
@@ -396,8 +365,10 @@ respond stateVar =
396
365
case result of
397
366
Left err -> liftIO $ Exception. throw err -- fail hard on SMT errors
398
367
Right response -> pure response
399
- Log. logOtherNS " booster" (Log. LevelOther " SMT" ) $
400
- " SMT result: " <> pack (either show ((" Subst: " <> ) . show . Map. size) smtResult)
368
+ withContext " get-model" $
369
+ withContext " smt" $
370
+ logMessage $
371
+ " SMT result: " <> pack (either show ((" Subst: " <> ) . show . Map. size) smtResult)
401
372
pure . Right . RpcTypes. GetModel $ case smtResult of
402
373
Left SMT. Unsat ->
403
374
RpcTypes. GetModelResult
@@ -449,15 +420,15 @@ respond stateVar =
449
420
450
421
case (internalised req. antecedent. term, internalised req. consequent. term) of
451
422
(Left patternError, _) -> do
452
- Log. logDebug $ " Error internalising antecedent " <> Text. pack ( show patternError)
423
+ void $ Booster.Log. withContext " internalise " $ logPatternError patternError
453
424
pure $
454
425
Left $
455
426
RpcError. backendError $
456
427
RpcError. CouldNotVerifyPattern
457
428
[ patternErrorToRpcError patternError
458
429
]
459
430
(_, Left patternError) -> do
460
- Log. logDebug $ " Error internalising consequent " <> Text. pack ( show patternError)
431
+ void $ Booster.Log. withContext " internalise " $ logPatternError patternError
461
432
pure $
462
433
Left $
463
434
RpcError. backendError $
@@ -466,19 +437,16 @@ respond stateVar =
466
437
]
467
438
(Right (patL, substitutionL, unsupportedL), Right (patR, substitutionR, unsupportedR)) -> do
468
439
unless (null unsupportedL && null unsupportedR) $ do
469
- Log. logWarnNS
470
- " booster"
471
- " Implies: aborting due to unsupported predicate parts"
440
+ logMessage'
441
+ (" aborting due to unsupported predicate parts" :: Text )
472
442
unless (null unsupportedL) $
473
- Log. logOtherNS
474
- " booster"
475
- (Log. LevelOther " ErrorDetails" )
476
- (Text. unlines $ map prettyPattern unsupportedL)
443
+ withContext " detail" $
444
+ logMessage
445
+ (Text. unwords $ map prettyPattern unsupportedL)
477
446
unless (null unsupportedR) $
478
- Log. logOtherNS
479
- " booster"
480
- (Log. LevelOther " ErrorDetails" )
481
- (Text. unlines $ map prettyPattern unsupportedR)
447
+ withContext " detail" $
448
+ logMessage
449
+ (Text. unwords $ map prettyPattern unsupportedR)
482
450
let
483
451
-- apply the given substitution before doing anything else
484
452
substPatL =
@@ -574,16 +542,13 @@ handleSmtError = JsonRpcHandler $ \case
574
542
SMT. GeneralSMTError err -> runtimeError " problem" err
575
543
SMT. SMTTranslationError err -> runtimeError " translation" err
576
544
SMT. SMTSolverUnknown reason premises preds -> do
577
- Log. logErrorNS " booster" (" SMT returned `Unknown' with reason " <> reason)
578
-
579
545
let bool = externaliseSort Pattern. SortBool -- predicates are terms of sort Bool
580
546
externalise = Syntax. KJAnd bool . map (externalisePredicate bool) . Set. toList
581
547
allPreds = addHeader $ Syntax. KJAnd bool [externalise premises, externalise preds]
582
548
pure $ RpcError. backendError $ RpcError. SmtSolverError $ RpcError. ErrorWithTerm reason allPreds
583
549
where
584
550
runtimeError prefix err = do
585
551
let msg = " SMT " <> prefix <> " : " <> err
586
- Log. logErrorNS " booster" msg
587
552
pure $ RpcError. runtimeError msg
588
553
589
554
data ServerState = ServerState
0 commit comments