Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MR Solver SMT fixes for testing on Heapster models #1594

Merged
merged 26 commits into from
Feb 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
e3343b0
added parse_core_mod command; made ensureMonadicTerm a bit smarter by…
Feb 12, 2022
61e3b58
fixed mrFunOutType, isCompFunType, and askMRSolver to normalize types
Feb 12, 2022
9655e0f
expanded the notion of a "function name" for MR Solver to include not…
Feb 14, 2022
be6beea
added support for recognizing multiFixM computations to normComp
Feb 14, 2022
8008475
fixed a bug in withUVars; added some debugging around calling into an…
Feb 15, 2022
73d6468
changed mrProvable so now it instantiates all uvars with ExtCnss, so …
Feb 15, 2022
536dcca
whoops, fixed instantiateUVarsM to reverse the list of uvars and subs…
Feb 15, 2022
ab31ae3
added support for the maybe eliminator
Feb 15, 2022
43215b1
Merge branch 'master' into mr-solver/heapster-tests
Feb 17, 2022
a1d5e4f
added applyGlobalOpenTerm and vectorTypeOpenTerm combinators
Feb 18, 2022
2820052
trying a new approach to getting SMT solving to work, by substiting u…
Feb 18, 2022
201c796
whoops: need to coerce the type of the condition in MaybeElim to a pr…
Feb 18, 2022
b388f9a
added back the implementaiton of atBVVec; enriched primBVTermFun to h…
Feb 18, 2022
af6d516
refactored mrProveEq to support proving equality of arbitrary vectors…
Feb 18, 2022
101c8e3
Merge remote-tracking branch 'origin/master' into mr-solver/heapster-…
Feb 19, 2022
338aa0e
got mrProveEq to handle pair types by changing it to return a TermInC…
Feb 19, 2022
5778c25
got mrProveEq to handle pair types by changing it to return a TermInC…
Feb 19, 2022
abb958b
Merge branch 'mr-solver/heapster-tests' of github.com:GaloisInc/saw-s…
Feb 19, 2022
4fbc4c4
reordered some mrRefines cases; removed some unneeded debugging; chan…
Feb 19, 2022
6c324e3
bug fix in mrSetEVarClosed, to instantiate evars in the type of the e…
Feb 19, 2022
4916239
added MR solver test case for the arrays example
Feb 21, 2022
19280f4
added a comment about withUVars being wrong
Feb 21, 2022
26fcc21
changed MR Solver to use the What4 backend in place of SBV
Feb 21, 2022
e4f94a1
lowered the debug level of arrays_mr_solver.saw to 1
Feb 21, 2022
f99ae09
Merge branch 'master' into mr-solver/heapster-tests
Feb 21, 2022
8d0aa64
fix typo in definition of `liftSC5`
m-yac Feb 22, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions heapster-saw/examples/arrays_mr_solver.saw
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
include "arrays.saw";
contains0 <- parse_core_mod "arrays" "contains0";
mr_solver_debug 1 contains0 contains0;
13 changes: 11 additions & 2 deletions saw-core/src/Verifier/SAW/OpenTerm.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@ module Verifier.SAW.OpenTerm (
unitOpenTerm, unitTypeOpenTerm,
stringLitOpenTerm, stringTypeOpenTerm,
trueOpenTerm, falseOpenTerm, boolOpenTerm, boolTypeOpenTerm,
arrayValueOpenTerm, bvLitOpenTerm, bvTypeOpenTerm,
arrayValueOpenTerm, vectorTypeOpenTerm, bvLitOpenTerm, bvTypeOpenTerm,
pairOpenTerm, pairTypeOpenTerm, pairLeftOpenTerm, pairRightOpenTerm,
tupleOpenTerm, tupleTypeOpenTerm, projTupleOpenTerm,
tupleOpenTerm', tupleTypeOpenTerm',
recordOpenTerm, recordTypeOpenTerm, projRecordOpenTerm,
ctorOpenTerm, dataTypeOpenTerm, globalOpenTerm, extCnsOpenTerm,
applyOpenTerm, applyOpenTermMulti, applyPiOpenTerm, piArgOpenTerm,
applyOpenTerm, applyOpenTermMulti, applyGlobalOpenTerm,
applyPiOpenTerm, piArgOpenTerm,
lambdaOpenTerm, lambdaOpenTermMulti, piOpenTerm, piOpenTermMulti,
arrowOpenTerm, letOpenTerm, sawLetOpenTerm,
-- * Monadic operations for building terms with binders
Expand Down Expand Up @@ -179,6 +180,10 @@ bvLitOpenTerm :: [Bool] -> OpenTerm
bvLitOpenTerm bits =
arrayValueOpenTerm boolTypeOpenTerm $ map boolOpenTerm bits

-- | Create a SAW core term for a vector type
vectorTypeOpenTerm :: OpenTerm -> OpenTerm -> OpenTerm
vectorTypeOpenTerm n a = applyGlobalOpenTerm "Prelude.Vec" [n,a]

-- | Create a SAW core term for the type of a bitvector
bvTypeOpenTerm :: Integral a => a -> OpenTerm
bvTypeOpenTerm n =
Expand Down Expand Up @@ -287,6 +292,10 @@ applyOpenTerm (OpenTerm f) (OpenTerm arg) =
applyOpenTermMulti :: OpenTerm -> [OpenTerm] -> OpenTerm
applyOpenTermMulti = foldl applyOpenTerm

-- | Apply a named global to 0 or more arguments
applyGlobalOpenTerm :: Ident -> [OpenTerm] -> OpenTerm
applyGlobalOpenTerm ident = applyOpenTermMulti (globalOpenTerm ident)

-- | Compute the output type of applying a function of a given type to an
-- argument. That is, given @tp@ and @arg@, compute the type of applying any @f@
-- of type @tp@ to @arg@.
Expand Down
29 changes: 21 additions & 8 deletions src/SAWScript/Builtins.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1385,8 +1385,8 @@ tailPrim :: [a] -> TopLevel [a]
tailPrim [] = fail "tail: empty list"
tailPrim (_ : xs) = return xs

parseCore :: String -> TopLevel Term
parseCore input =
parseCoreMod :: String -> String -> TopLevel Term
parseCoreMod mnm_str input =
do sc <- getSharedContext
let base = "<interactive>"
path = "<interactive>"
Expand All @@ -1397,18 +1397,29 @@ parseCore input =
do let msg = show err
printOutLnTop Opts.Error msg
fail msg
let mnm = Just $ mkModuleName ["Cryptol"]
err_or_t <- io $ runTCM (typeInferComplete uterm) sc mnm []
let mnm =
mkModuleName $ Text.splitOn (Text.pack ".") $ Text.pack mnm_str
_ <- io $ scFindModule sc mnm -- Check that mnm exists
err_or_t <- io $ runTCM (typeInferComplete uterm) sc (Just mnm) []
case err_or_t of
Left err -> fail (show err)
Right (TC.TypedTerm x _) -> return x

parseCore :: String -> TopLevel Term
parseCore = parseCoreMod "Cryptol"

parse_core :: String -> TopLevel TypedTerm
parse_core input = do
t <- parseCore input
sc <- getSharedContext
io $ mkTypedTerm sc t

parse_core_mod :: String -> String -> TopLevel TypedTerm
parse_core_mod mnm input = do
t <- parseCoreMod mnm input
sc <- getSharedContext
io $ mkTypedTerm sc t

prove_core :: ProofScript () -> String -> TopLevel Theorem
prove_core script input =
do sc <- getSharedContext
Expand Down Expand Up @@ -1540,16 +1551,18 @@ monadifyTypedTerm sc t =

-- | Ensure that a 'TypedTerm' has been monadified
ensureMonadicTerm :: SharedContext -> TypedTerm -> TopLevel TypedTerm
ensureMonadicTerm _ t
| TypedTermOther tp <- ttType t
, Prover.isCompFunType tp = return t
ensureMonadicTerm sc t
| TypedTermOther tp <- ttType t =
io (Prover.isCompFunType sc tp) >>= \case
True -> return t
False -> monadifyTypedTerm sc t
ensureMonadicTerm sc t = monadifyTypedTerm sc t

mrSolver :: SharedContext -> Int -> TypedTerm -> TypedTerm -> TopLevel Bool
mrSolver sc dlvl t1 t2 =
do m1 <- ttTerm <$> ensureMonadicTerm sc t1
m2 <- ttTerm <$> ensureMonadicTerm sc t2
res <- liftIO $ Prover.askMRSolver sc dlvl SBV.z3 Nothing m1 m2
res <- liftIO $ Prover.askMRSolver sc dlvl Nothing m1 m2
case res of
Just err -> io (putStrLn $ Prover.showMRFailure err) >> return False
Nothing -> return True
Expand Down
7 changes: 7 additions & 0 deletions src/SAWScript/Interpreter.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2225,6 +2225,13 @@ primitives = Map.fromList
[ "Parse a Term from a String in SAWCore syntax."
]

, prim "parse_core_mod" "String -> String -> Term"
(funVal2 parse_core_mod)
Current
[ "Parse a Term from the second supplied String in SAWCore syntax,"
, "relative to the module specified by the first String"
]

, prim "prove_core" "ProofScript () -> String -> TopLevel Theorem"
(pureVal prove_core)
Current
Expand Down
Loading