Skip to content

Commit 5b4947b

Browse files
committed
Merge remote-tracking branch 'origin/master' into 3813-map-update-hook-and-hook-refactoring
2 parents ae6353d + c391d6b commit 5b4947b

File tree

64 files changed

+33908
-11880
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+33908
-11880
lines changed

.github/workflows/test.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,6 @@ jobs:
201201
cabal-nix-${{ runner.os }}-ghc-${{ env.ghc_version }}-${{ hashFiles('cabal.project') }}
202202
cabal-nix-${{ runner.os }}-ghc-${{ env.ghc_version }}
203203
204-
- name: Run unit tests
205-
if: ${{ steps.changes.outputs.booster == 'true' || steps.changes.outputs.kore == 'true' || steps.changes.outputs.project == 'true' }}
206-
run: GC_DONT_GC=1 nix develop .#cabal --command bash -c "cabal update && cabal build all && cabal test --enable-tests --test-show-details=direct kore-test unit-tests"
207-
208204
- name: Run booster integration tests
209205
if: ${{ (steps.changes.outputs.booster == 'true' || steps.changes.outputs.kore_rpc_types == 'true' || steps.changes.outputs.project == 'true') }}
210206
run: |

booster/test/rpc-integration/test-log-simplify-json/simplify-log.txt.golden

Lines changed: 33498 additions & 9856 deletions
Large diffs are not rendered by default.

booster/tools/booster/Proxy.hs

Lines changed: 8 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import Data.Bifunctor (second)
2525
import Data.Either (partitionEithers)
2626
import Data.List.NonEmpty qualified as NonEmpty
2727
import Data.Map qualified as Map
28-
import Data.Maybe (catMaybes, fromJust, fromMaybe, isJust, isNothing, mapMaybe)
28+
import Data.Maybe (catMaybes, fromMaybe, isJust, isNothing, mapMaybe)
2929
import Data.Text (Text)
3030
import Data.Text qualified as Text
3131
import Data.Text.Lazy (toStrict)
@@ -42,7 +42,6 @@ import Kore.Internal.TermLike (TermLike, VariableName)
4242
import Kore.JsonRpc qualified as Kore (ServerState)
4343
import Kore.JsonRpc.Types
4444
import Kore.JsonRpc.Types qualified as ExecuteRequest (ExecuteRequest (..))
45-
import Kore.JsonRpc.Types qualified as ImpliesRequest (ImpliesRequest (..))
4645
import Kore.JsonRpc.Types qualified as SimplifyRequest (SimplifyRequest (..))
4746
import Kore.JsonRpc.Types.Log qualified as RPCLog
4847
import Kore.Log qualified
@@ -69,6 +68,7 @@ data ProxyConfig = ProxyConfig
6968
, boosterState :: MVar.MVar Booster.ServerState
7069
, fallbackReasons :: [HaltReason]
7170
, simplifyAtEnd :: Bool
71+
, simplifyBeforeFallback :: Bool
7272
, customLogLevels :: ![Log.LogLevel]
7373
}
7474

@@ -105,26 +105,7 @@ respondEither cfg@ProxyConfig{statsVar, boosterState} booster kore req = case re
105105
Map.lookup m bState.definitions
106106
handleExecute logSettings def start execReq
107107
Implies impliesReq -> do
108-
koreResult <-
109-
loggedKore
110-
ImpliesM
111-
( Implies
112-
impliesReq
113-
{ ImpliesRequest.logSuccessfulSimplifications =
114-
Just $ Log.LevelOther "SimplifyJson" `elem` cfg.customLogLevels
115-
}
116-
)
117-
case koreResult of
118-
Right (Implies koreRes) -> do
119-
-- Kore may have produced simplification logs during rewriting. If so,
120-
-- output them Kore at "SimplifyJson" level. Erase terms from the traces.
121-
when (isJust koreRes.logs) $ do
122-
outputLogsAtLevel (Log.LevelOther "SimplifyJson")
123-
. map RPCLog.logEntryEraseTerms
124-
. fromJust
125-
$ koreRes.logs
126-
_ -> pure ()
127-
pure koreResult
108+
loggedKore ImpliesM (Implies impliesReq)
128109
Simplify simplifyReq ->
129110
liftIO (getTime Monotonic) >>= handleSimplify simplifyReq . Just
130111
AddModule _ -> do
@@ -175,8 +156,6 @@ respondEither cfg@ProxyConfig{statsVar, boosterState} booster kore req = case re
175156
Simplify
176157
simplifyReq
177158
{ SimplifyRequest.state = boosterRes.state
178-
, SimplifyRequest.logSuccessfulSimplifications =
179-
Just $ Log.LevelOther "SimplifyJson" `elem` cfg.customLogLevels
180159
}
181160
(koreResult, koreTime) <- Stats.timed $ kore koreReq
182161
case koreResult of
@@ -194,13 +173,6 @@ respondEither cfg@ProxyConfig{statsVar, boosterState} booster kore req = case re
194173
diffBy def boosterRes.state.term koreRes.state.term
195174
in Text.pack ("Kore simplification: Diff (< before - > after)\n" <> diff)
196175
stop <- liftIO $ getTime Monotonic
197-
-- output simplification traces returned by Kore at "SimplifyJson" level, effectively
198-
-- appending them to Booster's traces. Erase terms from the traces.
199-
when (isJust koreRes.logs) $ do
200-
outputLogsAtLevel (Log.LevelOther "SimplifyJson")
201-
. map RPCLog.logEntryEraseTerms
202-
. fromJust
203-
$ koreRes.logs
204176
let timing
205177
| Just start <- mbStart
206178
, fromMaybe False simplifyReq.logTiming =
@@ -289,7 +261,7 @@ respondEither cfg@ProxyConfig{statsVar, boosterState} booster kore req = case re
289261
other -> other
290262

291263
postProcessLogs :: [RPCLog.LogEntry] -> [RPCLog.LogEntry]
292-
postProcessLogs !logs = map RPCLog.logEntryEraseTerms . filter (not . isSimplificationLogEntry) $ logs
264+
postProcessLogs !logs = map RPCLog.logEntryEraseTerms logs
293265

294266
executionLoop ::
295267
LogSettings ->
@@ -353,7 +325,10 @@ respondEither cfg@ProxyConfig{statsVar, boosterState} booster kore req = case re
353325
"Booster " <> show boosterResult.reason <> " at " <> show boosterResult.depth
354326
-- simplify Booster's state with Kore's simplifier
355327
Log.logInfoNS "proxy" . Text.pack $ "Simplifying booster state and falling back to Kore "
356-
simplifyResult <- simplifyExecuteState logSettings r._module def boosterResult.state
328+
simplifyResult <-
329+
if cfg.simplifyBeforeFallback
330+
then simplifyExecuteState logSettings r._module def boosterResult.state
331+
else pure $ Right (boosterResult.state, Nothing)
357332
case simplifyResult of
358333
Left logsOnly -> do
359334
-- state was simplified to \bottom, return vacuous
@@ -369,8 +344,6 @@ respondEither cfg@ProxyConfig{statsVar, boosterState} booster kore req = case re
369344
{ state = execStateToKoreJson simplifiedBoosterState
370345
, maxDepth = Just $ Depth 1
371346
, assumeStateDefined = Just True
372-
, ExecuteRequest.logSuccessfulSimplifications =
373-
Just $ Log.LevelOther "SimplifyJson" `elem` cfg.customLogLevels
374347
}
375348
)
376349
when (isJust statsVar) $ do
@@ -416,16 +389,6 @@ respondEither cfg@ProxyConfig{statsVar, boosterState} booster kore req = case re
416389
Log.logOtherNS "proxy" (Log.LevelOther "Aborts") $
417390
"kore confirms result " <> Text.pack (show bRes)
418391

419-
-- Kore may have produced simplification logs during rewriting. If so,
420-
-- output them Kore at "SimplifyJson" level, effectively
421-
-- appending them to Booster's traces. Erase terms from the traces.
422-
when (isJust koreResult.logs) $ do
423-
outputLogsAtLevel (Log.LevelOther "SimplifyJson")
424-
. map RPCLog.logEntryEraseTerms
425-
. filter isSimplificationLogEntry
426-
. fromJust
427-
$ koreResult.logs
428-
429392
case koreResult.reason of
430393
DepthBound -> do
431394
-- if we made one step, add the number of
@@ -644,15 +607,6 @@ combineLogs logSources
644607
| all isNothing logSources = Nothing
645608
| otherwise = Just $ concat $ catMaybes logSources
646609

647-
-- | Log a list of RPCLog items at a certain level
648-
outputLogsAtLevel :: Log.MonadLogger m => Log.LogLevel -> [RPCLog.LogEntry] -> m ()
649-
outputLogsAtLevel level = mapM_ (Log.logOtherNS "proxy" level . RPCLog.encodeLogEntryText)
650-
651-
isSimplificationLogEntry :: RPCLog.LogEntry -> Bool
652-
isSimplificationLogEntry = \case
653-
RPCLog.Simplification{} -> True
654-
_ -> False
655-
656610
makeVacuous :: Maybe [RPCLog.LogEntry] -> ExecuteResult -> ExecuteResult
657611
makeVacuous newLogs execState =
658612
execState

booster/tools/booster/Server.hs

Lines changed: 65 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import Control.Monad.Logger (
2424
runNoLoggingT,
2525
)
2626
import Control.Monad.Logger qualified as Logger
27+
import Data.ByteString qualified as BS
2728
import Data.Conduit.Network (serverSettings)
2829
import Data.IORef (writeIORef)
2930
import Data.InternedText (globalInternedTextCache)
@@ -33,7 +34,7 @@ import Data.Map qualified as Map
3334
import Data.Maybe (fromMaybe, isJust, mapMaybe)
3435
import Data.Set qualified as Set
3536
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)
3738
import Options.Applicative
3839
import System.Clock (
3940
Clock (..),
@@ -69,8 +70,9 @@ import Kore.JsonRpc.Types (API, HaltReason (..), ReqOrRes (Req, Res))
6970
import Kore.JsonRpc.Types.Depth (Depth (..))
7071
import Kore.Log (
7172
ExeName (..),
72-
KoreLogType (LogSomeAction),
73+
KoreLogType (..),
7374
LogAction (LogAction),
75+
LogSomeActionData (..),
7476
TimestampsSwitch (TimestampsDisable),
7577
defaultKoreLogOptions,
7678
swappableLogger,
@@ -112,6 +114,7 @@ main = do
112114
, boosterSMT
113115
, fallbackReasons
114116
, simplifyAtEnd
117+
, simplifyBeforeFallback
115118
}
116119
} = options
117120
(logLevel, customLevels) = adjustLogLevels logLevels
@@ -123,8 +126,9 @@ main = do
123126
koreSolverOptions = translateSMTOpts smtOptions
124127

125128
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
128132
_ -> IO.stderr
129133

130134
Booster.runHandleLoggingT logLevelToHandle . Logger.filterLogger levelFilter $ do
@@ -140,7 +144,16 @@ main = do
140144

141145
monadLogger <- askLoggerIO
142146

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
144157
let coLogLevel = fromMaybe Log.Info $ toSeverity logLevel
145158
koreLogOptions =
146159
(defaultKoreLogOptions (ExeName "") startTime)
@@ -149,11 +162,29 @@ main = do
149162
, Log.timestampsSwitch = TimestampsDisable
150163
, Log.debugSolverOptions =
151164
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
153184
}
154185
srvSettings = serverSettings port "*"
155186

156-
withLogger reportDirectory koreLogOptions $ \actualLogAction -> do
187+
withLogger koreLogOptions $ \actualLogAction -> do
157188
mLlvmLibrary <- maybe (pure Nothing) (fmap Just . mkAPI) mdl
158189
definitionsWithCeilSummaries <-
159190
liftIO $
@@ -220,6 +251,7 @@ main = do
220251
, boosterState
221252
, fallbackReasons
222253
, simplifyAtEnd
254+
, simplifyBeforeFallback
223255
, customLogLevels = customLevels
224256
}
225257
server =
@@ -259,16 +291,22 @@ toSeverity LevelOther{} = Nothing
259291

260292
koreExtraLogs :: Map.Map LogLevel Log.EntryTypes
261293
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+
]
272310

273311
data CLProxyOptions = CLProxyOptions
274312
{ clOptions :: CLOptions
@@ -286,6 +324,8 @@ data ProxyOptions = ProxyOptions
286324
-- ^ halt reasons to re-execute (fallback) to double-check the result
287325
, simplifyAtEnd :: Bool
288326
-- ^ whether to run a post-exec simplification
327+
, simplifyBeforeFallback :: Bool
328+
-- ^ whether to run a simplification before fall-back execute requests
289329
}
290330

291331
parserInfoModifiers :: InfoMod options
@@ -334,6 +374,12 @@ clProxyOptionsParser =
334374
( long "no-post-exec-simplify"
335375
<> help "disable post-exec simplification"
336376
)
377+
<*> flag
378+
True
379+
False
380+
( long "no-fallback-simplify"
381+
<> help "disable simplification before fallback requests"
382+
)
337383

338384
reasonReader :: String -> Either String HaltReason
339385
reasonReader = \case
@@ -368,7 +414,8 @@ translateSMTOpts = \case
368414
translateSExpr (SMT.Atom (SMT.SMTId x)) = KoreSMT.Atom (Text.decodeUtf8 x)
369415
translateSExpr (SMT.List ss) = KoreSMT.List $ map translateSExpr ss
370416

371-
mkKoreServer :: Log.LoggerEnv IO -> CLOptions -> KoreSolverOptions -> IO KoreServer
417+
mkKoreServer ::
418+
Log.LoggerEnv IO -> CLOptions -> KoreSolverOptions -> IO KoreServer
372419
mkKoreServer loggerEnv@Log.LoggerEnv{logAction} CLOptions{definitionFile, mainModuleName} koreSolverOptions =
373420
flip Log.runLoggerT logAction $ do
374421
sd@GlobalMain.SerializedDefinition{internedTextCache} <-

0 commit comments

Comments
 (0)