Skip to content

Commit

Permalink
Pass args to the smt solver via --smt-arg (#4021)
Browse files Browse the repository at this point in the history
This change will let us call `z3` with `smt.ematching=false` in booster,
which seems to help with non-linear arithmetic.

---------

Co-authored-by: Jost Berthold <jost.berthold@gmail.com>
  • Loading branch information
goodlyrottenapple and jberthold authored Aug 8, 2024
1 parent b6f8807 commit 9f70027
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
9 changes: 9 additions & 0 deletions booster/library/Booster/CLOptions.hs
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,15 @@ parseSMTOptions =
\Example: '(check-sat-using smt)' (i.e., plain 'check-sat')"
)
)
<*> many
( strOption
( metavar "SMT_ARG"
<> long "smt-arg"
<> help
( "Arguments to be passed to the SMT solver process"
)
)
)
)
where
smtDefaults = defaultSMTOptions
Expand Down
2 changes: 1 addition & 1 deletion booster/library/Booster/SMT/Interface.hs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ hardResetSolver = do
Just solverRef -> do
closeContext ctxt
Log.logMessage ("Restarting SMT solver" :: Text)
(solver, handle) <- connectToSolver
(solver, handle) <- connectToSolver ctxt.options.args
liftIO $ do
writeIORef solverRef solver
writeIORef ctxt.solverClose $ Backend.close handle
Expand Down
10 changes: 6 additions & 4 deletions booster/library/Booster/SMT/Runner.hs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ data SMTOptions = SMTOptions
-- ^ optional retry. Nothing for no retry, 0 for unlimited
, tactic :: Maybe SExpr
-- ^ optional tactic (used verbatim) to replace (check-sat)
, args :: [String]
}
deriving (Eq, Show)

Expand All @@ -70,6 +71,7 @@ defaultSMTOptions =
, timeout = 125
, retryLimit = Just 3
, tactic = Nothing
, args = []
}

data SMTContext = SMTContext
Expand Down Expand Up @@ -97,7 +99,7 @@ mkContext ::
io SMTContext
mkContext opts prelude = do
logMessage ("Starting SMT solver" :: Text)
(solver', handle) <- connectToSolver
(solver', handle) <- connectToSolver opts.args
solver <- liftIO $ newIORef solver'
solverClose <- liftIO $ newIORef $ Backend.close handle
mbTranscriptHandle <- forM opts.transcript $ \path -> do
Expand Down Expand Up @@ -141,9 +143,9 @@ destroyContext ctxt = do
hClose h
liftIO $ join $ readIORef ctxt.solverClose

connectToSolver :: LoggerMIO io => io (Backend.Solver, Backend.Handle)
connectToSolver = do
let config = Backend.defaultConfig
connectToSolver :: LoggerMIO io => [String] -> io (Backend.Solver, Backend.Handle)
connectToSolver args = do
let config = Backend.defaultConfig{Backend.args = args <> Backend.defaultConfig.args}
handle <- liftIO $ Backend.new config
solver <- liftIO $ Backend.initSolver Backend.Queuing $ Backend.toBackend handle
pure (solver, handle)
Expand Down

0 comments on commit 9f70027

Please sign in to comment.