@@ -20,7 +20,6 @@ import Control.Concurrent (MVar, putMVar, readMVar, takeMVar)
20
20
import Control.Monad
21
21
import Control.Monad.Extra (whenJust )
22
22
import Control.Monad.IO.Class
23
- import Control.Monad.Logger.CallStack (MonadLoggerIO )
24
23
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 )
@@ -45,12 +44,9 @@ import Booster.Definition.Attributes.Base (UniqueId, getUniqueId, uniqueId)
45
44
import Booster.Definition.Base (KoreDefinition (.. ))
46
45
import Booster.Definition.Base qualified as Definition (RewriteRule (.. ))
47
46
import Booster.LLVM as LLVM (API )
47
+ import Booster.Log
48
48
import Booster.Pattern.ApplyEquations qualified as ApplyEquations
49
- import Booster.Pattern.Base (
50
- Pattern (.. ),
51
- Term ,
52
- Variable ,
53
- )
49
+ import Booster.Pattern.Base (Pattern (.. ), Sort (SortApp ), Term , Variable )
54
50
import Booster.Pattern.Base qualified as Pattern
55
51
import Booster.Pattern.Rewrite (
56
52
RewriteFailed (.. ),
@@ -69,6 +65,7 @@ import Booster.Syntax.Json.Internalise (
69
65
TermOrPredicates (.. ),
70
66
internalisePattern ,
71
67
internaliseTermOrPredicate ,
68
+ logPatternError ,
72
69
patternErrorToRpcError ,
73
70
pattern CheckSubsorts ,
74
71
pattern DisallowAlias ,
@@ -88,7 +85,7 @@ import Kore.Syntax.Json.Types qualified as Syntax
88
85
89
86
respond ::
90
87
forall m .
91
- MonadLoggerIO m =>
88
+ LoggerMIO m =>
92
89
MVar ServerState ->
93
90
Respond (RpcTypes. API 'RpcTypes.Req ) m (RpcTypes. API 'RpcTypes.Res )
94
91
respond stateVar =
@@ -97,14 +94,14 @@ respond stateVar =
97
94
| isJust req. stepTimeout -> pure $ Left $ RpcError. unsupportedOption (" step-timeout" :: String )
98
95
| isJust req. movingAverageStepTimeout ->
99
96
pure $ Left $ RpcError. unsupportedOption (" moving-average-step-timeout" :: String )
100
- RpcTypes. Execute req -> withContext req. _module $ \ (def, mLlvmLibrary, mSMTOptions) -> do
97
+ RpcTypes. Execute req -> withModule req. _module $ \ (def, mLlvmLibrary, mSMTOptions) -> Booster.Log. withContext " execute " $ do
101
98
start <- liftIO $ getTime Monotonic
102
99
-- internalise given constrained term
103
100
let internalised = runExcept $ internalisePattern DisallowAlias CheckSubsorts Nothing def req. state. term
104
101
105
102
case internalised of
106
103
Left patternError -> do
107
- Log. logDebug $ " Error internalising cterm " <> Text. pack ( show patternError)
104
+ void $ Booster.Log. withContext " internalise " $ logPatternError patternError
108
105
pure $
109
106
Left $
110
107
RpcError. backendError $
@@ -113,13 +110,12 @@ respond stateVar =
113
110
]
114
111
Right (pat, substitution, unsupported) -> do
115
112
unless (null unsupported) $ do
113
+ withKorePatternContext (KoreJson. KJAnd (externaliseSort $ sortOfPattern pat) unsupported) $
114
+ logMessage (" ignoring unsupported predicate parts" :: Text )
116
115
Log. logWarnNS
117
116
" booster"
118
117
" Execute: ignoring unsupported predicate parts"
119
- Log. logOtherNS
120
- " booster"
121
- (Log. LevelOther " ErrorDetails" )
122
- (Text. unlines $ map prettyPattern unsupported)
118
+
123
119
let cutPoints = fromMaybe [] req. cutPointRules
124
120
terminals = fromMaybe [] req. terminalRules
125
121
mbDepth = fmap RpcTypes. getNat req. maxDepth
@@ -153,7 +149,7 @@ respond stateVar =
153
149
fromIntegral (toNanoSecs (diffTimeSpec stop start)) / 1e9
154
150
else Nothing
155
151
pure $ execResponse duration req result substitution unsupported
156
- RpcTypes. AddModule RpcTypes. AddModuleRequest {_module, nameAsId = nameAsId'} -> runExceptT $ do
152
+ RpcTypes. AddModule RpcTypes. AddModuleRequest {_module, nameAsId = nameAsId'} -> Booster.Log. withContext " add-module " $ runExceptT $ do
157
153
-- block other request executions while modifying the server state
158
154
state <- liftIO $ takeMVar stateVar
159
155
let nameAsId = fromMaybe False nameAsId'
@@ -211,10 +207,10 @@ respond stateVar =
211
207
(if nameAsId then Map. insert (getId newModule. name) _module else id ) $
212
208
Map. insert moduleHash _module state. addedModules
213
209
}
214
- Log. logInfo $
210
+ Booster. Log.logMessage $
215
211
" Added a new module. Now in scope: " <> Text. intercalate " , " (Map. keys newDefinitions)
216
212
pure $ RpcTypes. AddModule $ RpcTypes. AddModuleResult moduleHash
217
- RpcTypes. Simplify req -> withContext req. _module $ \ (def, mLlvmLibrary, mSMTOptions) -> do
213
+ RpcTypes. Simplify req -> withModule req. _module $ \ (def, mLlvmLibrary, mSMTOptions) -> Booster.Log. withContext " simplify " $ do
218
214
start <- liftIO $ getTime Monotonic
219
215
let internalised =
220
216
runExcept $ internaliseTermOrPredicate DisallowAlias CheckSubsorts Nothing def req. state. term
@@ -249,8 +245,7 @@ respond stateVar =
249
245
result <- case internalised of
250
246
Left patternErrors -> do
251
247
forM_ patternErrors $ \ patternError ->
252
- Log. logErrorNS " booster" $
253
- " Error internalising cterm: " <> pack (show patternError)
248
+ void $ Booster.Log. withContext " internalise" $ logPatternError patternError
254
249
Log. logOtherNS
255
250
" booster"
256
251
(Log. LevelOther " ErrorDetails" )
@@ -262,15 +257,12 @@ respond stateVar =
262
257
map patternErrorToRpcError patternErrors
263
258
-- term and predicate (pattern)
264
259
Right (TermAndPredicates pat substitution unsupported) -> do
265
- Log. logInfoNS " booster" " Simplifying a pattern"
266
260
unless (null unsupported) $ do
261
+ withKorePatternContext (KoreJson. KJAnd (externaliseSort $ sortOfPattern pat) unsupported) $ do
262
+ logMessage (" ignoring unsupported predicate parts" :: Text )
267
263
Log. logWarnNS
268
264
" booster"
269
- " Simplify: ignoring unsupported predicates in input"
270
- Log. logOtherNS
271
- " booster"
272
- (Log. LevelOther " ErrorDetails" )
273
- (Text. unlines $ map prettyPattern unsupported)
265
+ " Simplify: ignoring unsupported predicate parts"
274
266
-- apply the given substitution before doing anything else
275
267
let substPat =
276
268
Pattern
@@ -302,36 +294,35 @@ respond stateVar =
302
294
| otherwise -> do
303
295
Log. logInfoNS " booster" " Simplifying predicates"
304
296
unless (null ps. unsupported) $ do
305
- Log. logWarnNS
306
- " booster"
307
- " Simplify: ignoring unsupported predicates in input"
308
- Log. logOtherNS
309
- " booster"
310
- (Log. LevelOther " ErrorDetails" )
311
- (Text. unlines $ map prettyPattern ps. unsupported)
312
- Log. logOtherNS " booster" (Log. LevelOther " Simplify" ) $ renderText (pretty ps)
297
+ withKorePatternContext (KoreJson. KJAnd (externaliseSort $ SortApp " SortBool" [] ) ps. unsupported) $ do
298
+ logMessage (" ignoring unsupported predicate parts" :: Text )
299
+ Log. logWarnNS
300
+ " booster"
301
+ " Simplify: ignoring unsupported predicate parts"
302
+ -- apply the given substitution before doing anything else
313
303
let predicates = map (substituteInPredicate ps. substitution) $ Set. toList ps. boolPredicates
314
- ApplyEquations. simplifyConstraints
315
- doTracing
316
- def
317
- mLlvmLibrary
318
- solver
319
- mempty
320
- predicates
321
- >>= \ case
322
- (Right newPreds, _) -> do
323
- let predicateSort =
324
- fromMaybe (error " not a predicate" ) $
325
- sortOfJson req. state. term
326
- result =
327
- map (externalisePredicate predicateSort) newPreds
328
- <> map (externaliseCeil predicateSort) (Set. toList ps. ceilPredicates)
329
- <> map (uncurry $ externaliseSubstitution predicateSort) (Map. toList ps. substitution)
330
- <> ps. unsupported
304
+ withContext " constraint" $
305
+ ApplyEquations. simplifyConstraints
306
+ doTracing
307
+ def
308
+ mLlvmLibrary
309
+ solver
310
+ mempty
311
+ predicates
312
+ >>= \ case
313
+ (Right newPreds, _) -> do
314
+ let predicateSort =
315
+ fromMaybe (error " not a predicate" ) $
316
+ sortOfJson req. state. term
317
+ result =
318
+ map (externalisePredicate predicateSort) newPreds
319
+ <> map (externaliseCeil predicateSort) (Set. toList ps. ceilPredicates)
320
+ <> map (uncurry $ externaliseSubstitution predicateSort) (Map. toList ps. substitution)
321
+ <> ps. unsupported
331
322
332
- pure $ Right (addHeader $ Syntax. KJAnd predicateSort result, [] )
333
- (Left something, _) ->
334
- pure . Left . RpcError. backendError $ RpcError. Aborted $ renderText $ pretty something
323
+ pure $ Right (addHeader $ Syntax. KJAnd predicateSort result, [] )
324
+ (Left something, _) ->
325
+ pure . Left . RpcError. backendError $ RpcError. Aborted $ renderText $ pretty something
335
326
whenJust solver SMT. closeSolver
336
327
stop <- liftIO $ getTime Monotonic
337
328
@@ -341,7 +332,7 @@ respond stateVar =
341
332
RpcTypes. Simplify
342
333
RpcTypes. SimplifyResult {state, logs = mkTraces duration traceData}
343
334
pure $ second (uncurry mkSimplifyResponse) (fmap (second (map ApplyEquations. eraseStates)) result)
344
- RpcTypes. GetModel req -> withContext req. _module $ \ case
335
+ RpcTypes. GetModel req -> withModule req. _module $ \ case
345
336
(_, _, Nothing ) -> do
346
337
Log. logErrorNS " booster" " get-model request, not supported without SMT solver"
347
338
pure $ Left RpcError. notImplemented
@@ -470,13 +461,13 @@ respond stateVar =
470
461
-- using "Method does not exist" error code
471
462
_ -> pure $ Left RpcError. notImplemented
472
463
where
473
- withContext ::
464
+ withModule ::
474
465
Maybe Text ->
475
466
( (KoreDefinition , Maybe LLVM. API , Maybe SMT. SMTOptions ) ->
476
467
m (Either ErrorObj (RpcTypes. API 'RpcTypes.Res ))
477
468
) ->
478
469
m (Either ErrorObj (RpcTypes. API 'RpcTypes.Res ))
479
- withContext mbMainModule action = do
470
+ withModule mbMainModule action = do
480
471
state <- liftIO $ readMVar stateVar
481
472
let mainName = fromMaybe state. defaultMain mbMainModule
482
473
case Map. lookup mainName state. definitions of
@@ -806,11 +797,6 @@ mkLogRewriteTrace
806
797
{ reason = " Uncertain about definedness of rule because of: " <> pack (show undefReasons)
807
798
, _ruleId = fmap getUniqueId (uniqueId $ Definition. attributes r)
808
799
}
809
- IsNotMatch r _ _ ->
810
- Failure
811
- { reason = " Produced a non-match"
812
- , _ruleId = fmap getUniqueId (uniqueId $ Definition. attributes r)
813
- }
814
800
RewriteSortError r _ _ ->
815
801
Failure
816
802
{ reason = " Sort error while unifying"
0 commit comments