@@ -63,6 +63,17 @@ throwUnknown reason premises preds = throw $ SMTSolverUnknown reason premises pr
63
63
smtTranslateError :: Text -> a
64
64
smtTranslateError = throw . SMTTranslationError
65
65
66
+ {- | declare-const all introduced variables (free in predicates
67
+ as well as abstraction variables) before sending assertions
68
+ -}
69
+ declareVariables :: Log. LoggerMIO io => TranslationState -> SMT io ()
70
+ declareVariables transState = do
71
+ mapM_
72
+ SMT. runCmd
73
+ [ DeclareConst (mkComment trm) smtId (SMT. smtSort $ sortOfTerm trm)
74
+ | (trm, smtId) <- Map. assocs transState. mappings
75
+ ]
76
+
66
77
{- | Start and initialise an SMT solver instance for use in rewriting:
67
78
- translate the sort declarations from @KoreDefiniton@ to SMT
68
79
- start the solver process
@@ -165,14 +176,16 @@ getModelFor ctxt ps subst
165
176
Log. logMessage $ " SMT translation error: " <> errMsg
166
177
smtTranslateError errMsg
167
178
| Right (smtAsserts, transState) <- translated = Log. withContext " smt" $ do
168
- evalSMT ctxt $ solve smtAsserts transState
179
+ evalSMT ctxt $ do
180
+ declareVariables transState
181
+ solve smtAsserts transState
169
182
where
170
183
solve ::
171
184
[DeclareCommand ] -> TranslationState -> SMT io (Either Response (Map Variable Term ))
172
185
solve smtAsserts transState = do
173
186
opts <- SMT $ gets (. options)
174
187
Log. logMessage $ " Checking, constraint count " <> pack (show $ Map. size subst + length ps)
175
- satResponse <- interactWithSolver smtAsserts transState
188
+ satResponse <- interactWithSolver smtAsserts
176
189
Log. logMessage (" Solver returned " <> (Text. pack $ show satResponse))
177
190
case satResponse of
178
191
Error msg -> do
@@ -215,18 +228,10 @@ getModelFor ctxt ps subst
215
228
mapM (\ (Predicate p) -> Assert (mkComment p) <$> SMT. translateTerm p) ps
216
229
pure $ smtSubst <> smtPs
217
230
218
- interactWithSolver :: [DeclareCommand ] -> TranslationState -> SMT io Response
219
- interactWithSolver smtAsserts transState = do
231
+ interactWithSolver :: [DeclareCommand ] -> SMT io Response
232
+ interactWithSolver smtAsserts = do
220
233
runCmd_ SMT. Push -- assuming the prelude has been run already,
221
234
222
- -- declare-const all introduced variables (free in predicates
223
- -- as well as abstraction variables) before sending assertions
224
- mapM_
225
- runCmd
226
- [ DeclareConst (mkComment trm) smtId (SMT. smtSort $ sortOfTerm trm)
227
- | (trm, smtId) <- Map. assocs transState. mappings
228
- ]
229
-
230
235
-- assert the given predicates
231
236
mapM_ runCmd smtAsserts
232
237
@@ -329,6 +334,7 @@ checkPredicates ctxt givenPs givenSubst psToCheck
329
334
pure Nothing
330
335
| Right ((smtGiven, sexprsToCheck), transState) <- translated = Log. withContext " smt" $ do
331
336
evalSMT ctxt $ do
337
+ declareVariables transState
332
338
solve smtGiven sexprsToCheck transState
333
339
where
334
340
solve ::
@@ -348,7 +354,7 @@ checkPredicates ctxt givenPs givenSubst psToCheck
348
354
]
349
355
Log. logMessage . Pretty. renderOneLineText $
350
356
hsep (" Predicates to check:" : map pretty (Set. toList psToCheck))
351
- result <- runMaybeT $ interactWihtSolver smtGiven sexprsToCheck transState
357
+ result <- runMaybeT $ interactWihtSolver smtGiven sexprsToCheck
352
358
Log. logMessage $
353
359
" Check of Given ∧ P and Given ∧ !P produced "
354
360
<> (Text. pack $ show result)
@@ -398,18 +404,10 @@ checkPredicates ctxt givenPs givenSubst psToCheck
398
404
other -> throwSMT' $ " Unexpected result while calling ':reason-unknown': " <> show other
399
405
400
406
interactWihtSolver ::
401
- [DeclareCommand ] -> [SExpr ] -> TranslationState -> MaybeT (SMT io ) (Response , Response )
402
- interactWihtSolver smtGiven sexprsToCheck transState = do
407
+ [DeclareCommand ] -> [SExpr ] -> MaybeT (SMT io ) (Response , Response )
408
+ interactWihtSolver smtGiven sexprsToCheck = do
403
409
smtRun_ Push
404
410
405
- -- declare-const all introduced variables (free in predicates
406
- -- as well as abstraction variables) before sending assertions
407
- mapM_
408
- smtRun
409
- [ DeclareConst (mkComment trm) smtId (SMT. smtSort $ sortOfTerm trm)
410
- | (trm, smtId) <- Map. assocs transState. mappings
411
- ]
412
-
413
411
-- assert ground truth
414
412
mapM_ smtRun smtGiven
415
413
0 commit comments