Skip to content

Commit

Permalink
Support building with sbv-10.*
Browse files Browse the repository at this point in the history
`sbv-10.*` brings in two changes to the SBV internals that affects SAW:

1. `sbv-10.0` removes the `generateSMTBenchmark` function in favor of two
   separate `generateSMTBenchmarkSat` and `generateSMTBenchmarkProof` functions.
   We use the `generateSMTBenchmarkSat` variant in `SAWScript.Prover.Exporter`.
2. `sbv-10.0` changes the `Maybe [String]` argument to `svUninterpreted` (which
   we use in `saw-core-sbv`'s `Verifier.SAW.Simulator.SBV`) to a `UICodeKind`
   argument, where `UINone` is now what used to be denoted with `Nothing`.

We now use the appropriate CPP to make SAW compile before and after these
changes. See also GaloisInc/cryptol#1513, which was in similar territory.
  • Loading branch information
RyanGlScott committed Nov 20, 2023
1 parent 10abf84 commit 92264c6
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
2 changes: 1 addition & 1 deletion saw-core-sbv/saw-core-sbv.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ library
lens,
mtl,
saw-core,
sbv >= 9.1 && < 9.3,
sbv >= 9.1 && < 10.3,
text,
transformers,
vector
Expand Down
12 changes: 11 additions & 1 deletion saw-core-sbv/src/Verifier/SAW/Simulator/SBV.hs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ module Verifier.SAW.Simulator.SBV
) where

import Data.SBV.Dynamic
#if MIN_VERSION_sbv(10,0,0)
import Data.SBV.Internals (UICodeKind(..))
#endif

import Verifier.SAW.Simulator.SBV.SWord

Expand Down Expand Up @@ -667,7 +670,14 @@ parseUninterpreted cws nm ty =
_ -> fail $ "could not create uninterpreted type for " ++ show ty

mkUninterpreted :: Kind -> [SVal] -> String -> SVal
mkUninterpreted k args nm = svUninterpreted k nm' Nothing args
mkUninterpreted k args nm =
svUninterpreted k nm'
#if MIN_VERSION_sbv(10,0,0)
UINone
#else
Nothing
#endif
args
where nm' = "|" ++ nm ++ "|" -- enclose name to allow primes and other non-alphanum chars

sbvSATQuery :: SharedContext -> Map Ident SPrim -> SATQuery -> IO ([Labeler], [ExtCns Term], Symbolic SBool)
Expand Down
2 changes: 1 addition & 1 deletion saw-script.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ library
, saw-core-coq
, saw-core-sbv
, saw-core-what4
, sbv >= 9.1 && < 9.3
, sbv >= 9.1 && < 10.3
, serialise
, split
, temporary
Expand Down
5 changes: 5 additions & 0 deletions src/SAWScript/Prover/Exporter.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{-# Language CPP #-}
{-# Language GADTs #-}
{-# Language ImplicitParams #-}
{-# Language NamedFieldPuns #-}
Expand Down Expand Up @@ -299,8 +300,12 @@ write_smtlib2_w4 f (TypedTerm schema t) = do
writeSMTLib2 :: FilePath -> SATQuery -> TopLevel ()
writeSMTLib2 f satq = getSharedContext >>= \sc -> io $
do (_, _, l) <- SBV.sbvSATQuery sc mempty satq
#if MIN_VERSION_sbv(10,0,0)
txt <- SBV.generateSMTBenchmarkSat l
#else
let isSat = True -- l is encoded as an existential formula
txt <- SBV.generateSMTBenchmark isSat l
#endif
writeFile f txt

-- | Write a SAT query an SMT-Lib version 2 file.
Expand Down

0 comments on commit 92264c6

Please sign in to comment.