@@ -41,6 +41,7 @@ import Numeric.Natural
41
41
import Prettyprinter (comma , hsep , punctuate , (<+>) )
42
42
import System.Clock (Clock (Monotonic ), diffTimeSpec , getTime , toNanoSecs )
43
43
44
+ import Booster.CLOptions (RewriteOptions (.. ))
44
45
import Booster.Definition.Attributes.Base (UniqueId , getUniqueId , uniqueId )
45
46
import Booster.Definition.Base (KoreDefinition (.. ))
46
47
import Booster.Definition.Base qualified as Definition (RewriteRule (.. ))
@@ -53,6 +54,7 @@ import Booster.Pattern.Bool (pattern TrueBool)
53
54
import Booster.Pattern.Match (FailReason (.. ), MatchResult (.. ), MatchType (.. ), matchTerms )
54
55
import Booster.Pattern.Pretty
55
56
import Booster.Pattern.Rewrite (
57
+ RewriteConfig (.. ),
56
58
RewriteFailed (.. ),
57
59
RewriteResult (.. ),
58
60
RewriteTrace (.. ),
@@ -108,7 +110,7 @@ respond stateVar request =
108
110
| isJust req. stepTimeout -> pure $ Left $ RpcError. unsupportedOption (" step-timeout" :: String )
109
111
| isJust req. movingAverageStepTimeout ->
110
112
pure $ Left $ RpcError. unsupportedOption (" moving-average-step-timeout" :: String )
111
- RpcTypes. Execute req -> withModule req. _module $ \ (def, mLlvmLibrary, mSMTOptions) -> Booster.Log. withContext CtxExecute $ do
113
+ RpcTypes. Execute req -> withModule req. _module $ \ (def, mLlvmLibrary, mSMTOptions, rewriteOpts ) -> Booster.Log. withContext CtxExecute $ do
112
114
start <- liftIO $ getTime Monotonic
113
115
-- internalise given constrained term
114
116
let internalised = runExcept $ internalisePattern DisallowAlias CheckSubsorts Nothing def req. state. term
@@ -152,8 +154,25 @@ respond stateVar request =
152
154
]
153
155
154
156
solver <- maybe (SMT. noSolver) (SMT. initSolver def) mSMTOptions
157
+
158
+ logger <- getLogger
159
+ prettyModifiers <- getPrettyModifiers
160
+ let rewriteConfig =
161
+ RewriteConfig
162
+ { definition = def
163
+ , llvmApi = mLlvmLibrary
164
+ , smtSolver = solver
165
+ , varsToAvoid = substVars
166
+ , doTracing
167
+ , logger
168
+ , prettyModifiers
169
+ , mbMaxDepth = mbDepth
170
+ , mbSimplify = rewriteOpts. interimSimplification
171
+ , cutLabels = cutPoints
172
+ , terminalLabels = terminals
173
+ }
155
174
result <-
156
- performRewrite doTracing def mLlvmLibrary solver substVars mbDepth cutPoints terminals substPat
175
+ performRewrite rewriteConfig substPat
157
176
SMT. finaliseSolver solver
158
177
stop <- liftIO $ getTime Monotonic
159
178
let duration =
@@ -224,7 +243,7 @@ respond stateVar request =
224
243
Booster.Log. logMessage $
225
244
" Added a new module. Now in scope: " <> Text. intercalate " , " (Map. keys newDefinitions)
226
245
pure $ RpcTypes. AddModule $ RpcTypes. AddModuleResult moduleHash
227
- RpcTypes. Simplify req -> withModule req. _module $ \ (def, mLlvmLibrary, mSMTOptions) -> Booster.Log. withContext CtxSimplify $ do
246
+ RpcTypes. Simplify req -> withModule req. _module $ \ (def, mLlvmLibrary, mSMTOptions, _ ) -> Booster.Log. withContext CtxSimplify $ do
228
247
start <- liftIO $ getTime Monotonic
229
248
let internalised =
230
249
runExcept $ internaliseTermOrPredicate DisallowAlias CheckSubsorts Nothing def req. state. term
@@ -315,11 +334,11 @@ respond stateVar request =
315
334
RpcTypes. SimplifyResult {state, logs = mkTraces duration}
316
335
pure $ second mkSimplifyResponse result
317
336
RpcTypes. GetModel req -> withModule req. _module $ \ case
318
- (_, _, Nothing ) -> do
337
+ (_, _, Nothing , _ ) -> do
319
338
withContext CtxGetModel $
320
339
logMessage' (" get-model request, not supported without SMT solver" :: Text )
321
340
pure $ Left RpcError. notImplemented
322
- (def, _, Just smtOptions) -> do
341
+ (def, _, Just smtOptions, _ ) -> do
323
342
let internalised =
324
343
runExcept $
325
344
internaliseTermOrPredicate DisallowAlias CheckSubsorts Nothing def req. state. term
@@ -419,7 +438,7 @@ respond stateVar request =
419
438
{ satisfiable = RpcTypes. Sat
420
439
, substitution
421
440
}
422
- RpcTypes. Implies req -> withModule req. _module $ \ (def, mLlvmLibrary, mSMTOptions) -> Booster.Log. withContext CtxImplies $ do
441
+ RpcTypes. Implies req -> withModule req. _module $ \ (def, mLlvmLibrary, mSMTOptions, _ ) -> Booster.Log. withContext CtxImplies $ do
423
442
-- internalise given constrained term
424
443
let internalised =
425
444
runExcept . internalisePattern DisallowAlias CheckSubsorts Nothing def . fst . extractExistentials
@@ -504,7 +523,7 @@ respond stateVar request =
504
523
where
505
524
withModule ::
506
525
Maybe Text ->
507
- ( (KoreDefinition , Maybe LLVM. API , Maybe SMT. SMTOptions ) ->
526
+ ( (KoreDefinition , Maybe LLVM. API , Maybe SMT. SMTOptions, RewriteOptions ) ->
508
527
m (Either ErrorObj (RpcTypes. API 'RpcTypes.Res ))
509
528
) ->
510
529
m (Either ErrorObj (RpcTypes. API 'RpcTypes.Res ))
@@ -513,7 +532,7 @@ respond stateVar request =
513
532
let mainName = fromMaybe state. defaultMain mbMainModule
514
533
case Map. lookup mainName state. definitions of
515
534
Nothing -> pure $ Left $ RpcError. backendError $ RpcError. CouldNotFindModule mainName
516
- Just d -> action (d, state. mLlvmLibrary, state. mSMTOptions)
535
+ Just d -> action (d, state. mLlvmLibrary, state. mSMTOptions, state . rewriteOptions )
517
536
518
537
doesNotImply s l r =
519
538
pure $
@@ -571,9 +590,11 @@ data ServerState = ServerState
571
590
, defaultMain :: Text
572
591
-- ^ default main module (initially from command line, could be changed later)
573
592
, mLlvmLibrary :: Maybe LLVM. API
574
- -- ^ optional LLVM simplification library
593
+ -- ^ Read-only: optional LLVM simplification library
575
594
, mSMTOptions :: Maybe SMT. SMTOptions
576
- -- ^ (optional) SMT solver options
595
+ -- ^ Read-only: (optional) SMT solver options
596
+ , rewriteOptions :: RewriteOptions
597
+ -- ^ Read-only: configuration related to booster rewriting
577
598
, addedModules :: Map Text Text
578
599
-- ^ map of raw modules added via add-module
579
600
}
0 commit comments