@@ -24,6 +24,7 @@ import Control.Monad.Logger (
24
24
runNoLoggingT ,
25
25
)
26
26
import Control.Monad.Logger qualified as Logger
27
+ import Data.ByteString qualified as BS
27
28
import Data.Conduit.Network (serverSettings )
28
29
import Data.IORef (writeIORef )
29
30
import Data.InternedText (globalInternedTextCache )
@@ -33,7 +34,7 @@ import Data.Map qualified as Map
33
34
import Data.Maybe (fromMaybe , isJust , mapMaybe )
34
35
import Data.Set qualified as Set
35
36
import Data.Text qualified as Text
36
- import Data.Text.Encoding qualified as Text (decodeUtf8 )
37
+ import Data.Text.Encoding qualified as Text (decodeUtf8 , encodeUtf8 )
37
38
import Options.Applicative
38
39
import System.Clock (
39
40
Clock (.. ),
@@ -69,8 +70,9 @@ import Kore.JsonRpc.Types (API, HaltReason (..), ReqOrRes (Req, Res))
69
70
import Kore.JsonRpc.Types.Depth (Depth (.. ))
70
71
import Kore.Log (
71
72
ExeName (.. ),
72
- KoreLogType (LogSomeAction ),
73
+ KoreLogType (.. ),
73
74
LogAction (LogAction ),
75
+ LogSomeActionData (.. ),
74
76
TimestampsSwitch (TimestampsDisable ),
75
77
defaultKoreLogOptions ,
76
78
swappableLogger ,
@@ -112,6 +114,7 @@ main = do
112
114
, boosterSMT
113
115
, fallbackReasons
114
116
, simplifyAtEnd
117
+ , simplifyBeforeFallback
115
118
}
116
119
} = options
117
120
(logLevel, customLevels) = adjustLogLevels logLevels
@@ -123,8 +126,9 @@ main = do
123
126
koreSolverOptions = translateSMTOpts smtOptions
124
127
125
128
Booster. withLogFile simplificationLogFile $ \ mLogFileHandle -> do
126
- let logLevelToHandle = \ case
127
- Logger. LevelOther " SimplifyJson" -> fromMaybe IO. stderr mLogFileHandle
129
+ let simplificationLogHandle = fromMaybe IO. stderr mLogFileHandle
130
+ logLevelToHandle = \ case
131
+ Logger. LevelOther " SimplifyJson" -> simplificationLogHandle
128
132
_ -> IO. stderr
129
133
130
134
Booster. runHandleLoggingT logLevelToHandle . Logger. filterLogger levelFilter $ do
@@ -140,7 +144,16 @@ main = do
140
144
141
145
monadLogger <- askLoggerIO
142
146
143
- liftIO $ void $ withBugReport (ExeName " kore-rpc-booster" ) BugReportOnError $ \ reportDirectory -> withMDLib llvmLibraryFile $ \ mdl -> do
147
+ koreLogEntriesAsJsonSelector <-
148
+ case Map. lookup (Logger. LevelOther " SimplifyJson" ) logLevelToKoreLogEntryMap of
149
+ Nothing -> do
150
+ Logger. logWarnNS
151
+ " proxy"
152
+ " Could not find out which Kore log entries correspond to the SimplifyJson level"
153
+ pure (const False )
154
+ Just es -> pure (`elem` es)
155
+
156
+ liftIO $ void $ withBugReport (ExeName " kore-rpc-booster" ) BugReportOnError $ \ _reportDirectory -> withMDLib llvmLibraryFile $ \ mdl -> do
144
157
let coLogLevel = fromMaybe Log. Info $ toSeverity logLevel
145
158
koreLogOptions =
146
159
(defaultKoreLogOptions (ExeName " " ) startTime)
@@ -149,11 +162,29 @@ main = do
149
162
, Log. timestampsSwitch = TimestampsDisable
150
163
, Log. debugSolverOptions =
151
164
Log. DebugSolverOptions . fmap (<> " .kore" ) $ smtOptions >>= (. transcript)
152
- , Log. logType = LogSomeAction $ LogAction $ \ txt -> liftIO $ monadLogger defaultLoc " kore" logLevel $ toLogStr txt
165
+ , Log. logType =
166
+ LogSomeAction $
167
+ LogSomeActionData
168
+ { entrySelector = koreLogEntriesAsJsonSelector
169
+ , standardLogAction =
170
+ (LogAction $ \ txt -> liftIO $ monadLogger defaultLoc " kore" logLevel $ toLogStr txt)
171
+ , jsonLogAction =
172
+ ( LogAction $ \ txt ->
173
+ let bytes =
174
+ Text. encodeUtf8 $
175
+ if simplificationLogHandle == IO. stderr
176
+ then " [SimplifyJson] " <> txt <> " \n "
177
+ else txt <> " \n "
178
+ in liftIO $ do
179
+ BS. hPutStr simplificationLogHandle bytes
180
+ IO. hFlush simplificationLogHandle
181
+ )
182
+ }
183
+ , Log. logFormat = Log. Standard
153
184
}
154
185
srvSettings = serverSettings port " *"
155
186
156
- withLogger reportDirectory koreLogOptions $ \ actualLogAction -> do
187
+ withLogger koreLogOptions $ \ actualLogAction -> do
157
188
mLlvmLibrary <- maybe (pure Nothing ) (fmap Just . mkAPI) mdl
158
189
definitionsWithCeilSummaries <-
159
190
liftIO $
@@ -220,6 +251,7 @@ main = do
220
251
, boosterState
221
252
, fallbackReasons
222
253
, simplifyAtEnd
254
+ , simplifyBeforeFallback
223
255
, customLogLevels = customLevels
224
256
}
225
257
server =
@@ -259,16 +291,22 @@ toSeverity LevelOther{} = Nothing
259
291
260
292
koreExtraLogs :: Map. Map LogLevel Log. EntryTypes
261
293
koreExtraLogs =
262
- Map. map (Set. fromList . mapMaybe (`Map.lookup` Log. textToType Log. registry)) $
263
- Map. fromList
264
- [ (LevelOther " SimplifyKore" , [" DebugAttemptEquation" , " DebugApplyEquation" ])
265
- ,
266
- ( LevelOther " RewriteKore"
267
- , [" DebugAttemptedRewriteRules" , " DebugAppliedLabeledRewriteRule" , " DebugAppliedRewriteRules" ]
268
- )
269
- , (LevelOther " SimplifySuccess" , [" DebugApplyEquation" ])
270
- , (LevelOther " RewriteSuccess" , [" DebugAppliedRewriteRules" ])
271
- ]
294
+ Map. map
295
+ (Set. fromList . mapMaybe (`Map.lookup` Log. textToType Log. registry))
296
+ logLevelToKoreLogEntryMap
297
+
298
+ logLevelToKoreLogEntryMap :: Map. Map LogLevel [Text. Text ]
299
+ logLevelToKoreLogEntryMap =
300
+ Map. fromList
301
+ [ (LevelOther " SimplifyKore" , [" DebugAttemptEquation" , " DebugApplyEquation" ])
302
+ , (LevelOther " SimplifyJson" , [" DebugAttemptEquation" ])
303
+ ,
304
+ ( LevelOther " RewriteKore"
305
+ , [" DebugAttemptedRewriteRules" , " DebugAppliedLabeledRewriteRule" , " DebugAppliedRewriteRules" ]
306
+ )
307
+ , (LevelOther " SimplifySuccess" , [" DebugApplyEquation" ])
308
+ , (LevelOther " RewriteSuccess" , [" DebugAppliedRewriteRules" ])
309
+ ]
272
310
273
311
data CLProxyOptions = CLProxyOptions
274
312
{ clOptions :: CLOptions
@@ -286,6 +324,8 @@ data ProxyOptions = ProxyOptions
286
324
-- ^ halt reasons to re-execute (fallback) to double-check the result
287
325
, simplifyAtEnd :: Bool
288
326
-- ^ whether to run a post-exec simplification
327
+ , simplifyBeforeFallback :: Bool
328
+ -- ^ whether to run a simplification before fall-back execute requests
289
329
}
290
330
291
331
parserInfoModifiers :: InfoMod options
@@ -334,6 +374,12 @@ clProxyOptionsParser =
334
374
( long " no-post-exec-simplify"
335
375
<> help " disable post-exec simplification"
336
376
)
377
+ <*> flag
378
+ True
379
+ False
380
+ ( long " no-fallback-simplify"
381
+ <> help " disable simplification before fallback requests"
382
+ )
337
383
338
384
reasonReader :: String -> Either String HaltReason
339
385
reasonReader = \ case
@@ -368,7 +414,8 @@ translateSMTOpts = \case
368
414
translateSExpr (SMT. Atom (SMT. SMTId x)) = KoreSMT. Atom (Text. decodeUtf8 x)
369
415
translateSExpr (SMT. List ss) = KoreSMT. List $ map translateSExpr ss
370
416
371
- mkKoreServer :: Log. LoggerEnv IO -> CLOptions -> KoreSolverOptions -> IO KoreServer
417
+ mkKoreServer ::
418
+ Log. LoggerEnv IO -> CLOptions -> KoreSolverOptions -> IO KoreServer
372
419
mkKoreServer loggerEnv@ Log. LoggerEnv {logAction} CLOptions {definitionFile, mainModuleName} koreSolverOptions =
373
420
flip Log. runLoggerT logAction $ do
374
421
sd@ GlobalMain. SerializedDefinition {internedTextCache} <-
0 commit comments