-
Notifications
You must be signed in to change notification settings - Fork 42
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
Sygus2 #1166
Sygus2 #1166
Changes from 8 commits
ebbcd4e
39e9c1e
63f2c2a
f5422da
8813bd4
72d90c0
34651c6
803a8be
c428da0
08b51b6
7617969
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -95,6 +95,11 @@ module Lang.Crucible.Backend | |
, addFailedAssertion | ||
, assertIsInteger | ||
, readPartExpr | ||
, runCHC | ||
, proofObligationsAsImplications | ||
, convertProofObligationsAsImplications | ||
, proofObligationsUninterpConstants | ||
, pathConditionUninterpConstants | ||
, ppProofObligation | ||
, backendOptions | ||
, assertThenAssumeConfigOption | ||
|
@@ -110,17 +115,25 @@ import Data.Functor.Identity | |
import Data.Functor.Const | ||
import qualified Data.Sequence as Seq | ||
import Data.Sequence (Seq) | ||
import Data.Set (Set) | ||
import qualified Prettyprinter as PP | ||
import GHC.Stack | ||
import System.IO | ||
|
||
import Data.Parameterized.Map (MapF) | ||
|
||
import What4.Concrete | ||
import What4.Config | ||
import What4.Expr.Builder | ||
import What4.Interface | ||
import What4.InterpretedFloatingPoint | ||
import What4.LabeledPred | ||
import What4.Partial | ||
import What4.ProgramLoc | ||
import What4.Expr (GroundValue, GroundValueWrapper(..)) | ||
import What4.Solver | ||
import qualified What4.Solver.CVC5 as CVC5 | ||
import qualified What4.Solver.Z3 as Z3 | ||
|
||
import qualified Lang.Crucible.Backend.AssumptionStack as AS | ||
import qualified Lang.Crucible.Backend.ProofGoals as PG | ||
|
@@ -613,6 +626,68 @@ readPartExpr bak (PE p v) msg = do | |
addAssertion bak (LabeledPred p (SimError loc msg)) | ||
return v | ||
|
||
|
||
-- | Run the CHC solver on the current proof obligations, and return the | ||
-- solution as a substitution from the uninterpreted functions to their | ||
-- definitions. | ||
runCHC :: | ||
(IsSymBackend sym bak, sym ~ ExprBuilder t st fs, MonadIO m) => | ||
bak -> | ||
[SomeSymFn sym] -> | ||
m (MapF (SymFnWrapper sym) (SymFnWrapper sym)) | ||
runCHC bak uninterp_inv_fns = liftIO $ do | ||
let sym = backendGetSym bak | ||
|
||
implications <- proofObligationsAsImplications bak | ||
clearProofObligations bak | ||
|
||
withFile "foo.smt2" WriteMode $ \handle -> | ||
Z3.writeZ3HornSMT2File sym True handle uninterp_inv_fns implications | ||
withFile "foo.sy" WriteMode $ \handle -> | ||
CVC5.writeCVC5SyFile sym handle uninterp_inv_fns implications | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Currently, always creates these files which record the attempted solver operation for examination in case of failure. Creating these should be configurable; used for debugging only. |
||
|
||
-- log to stdout | ||
let logData = defaultLogData | ||
{ logCallbackVerbose = \_ -> putStrLn | ||
, logReason = "SAW inv" | ||
} | ||
Z3.runZ3Horn sym True logData uninterp_inv_fns implications >>= \case | ||
Sat sub -> return sub | ||
Unsat{} -> fail "Prover returned Infeasible" | ||
Unknown -> fail "Prover returned Fail" | ||
-- CVC5.runCVC5SyGuS sym logData uninterp_inv_fns implications >>= \case | ||
-- Sat sub -> return sub | ||
-- Unsat{} -> fail "Prover returned Infeasible" | ||
-- Unknown -> fail "Prover returned Fail" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Needs to have some option to select which solver to use (other than commenting and recompiling as used here). |
||
|
||
|
||
-- | Get proof obligations as What4 implications. | ||
proofObligationsAsImplications :: IsSymBackend sym bak => bak -> IO [Pred sym] | ||
proofObligationsAsImplications bak = do | ||
let sym = backendGetSym bak | ||
convertProofObligationsAsImplications sym =<< getProofObligations bak | ||
|
||
-- | Convert proof obligations to What4 implications. | ||
convertProofObligationsAsImplications :: IsSymInterface sym => sym -> ProofObligations sym -> IO [Pred sym] | ||
convertProofObligationsAsImplications sym goals = do | ||
let obligations = maybe [] PG.goalsToList goals | ||
forM obligations $ \(AS.ProofGoal hyps (LabeledPred concl _err)) -> do | ||
hyp <- assumptionsPred sym hyps | ||
impliesPred sym hyp concl | ||
|
||
-- | Get the set of uninterpreted constants that appear in the path condition. | ||
pathConditionUninterpConstants :: IsSymBackend sym bak => bak -> IO (Set (Some (BoundVar sym))) | ||
pathConditionUninterpConstants bak = do | ||
let sym = backendGetSym bak | ||
exprUninterpConstants sym <$> getPathCondition bak | ||
|
||
-- | Get the set of uninterpreted constants that appear in the proof obligations. | ||
proofObligationsUninterpConstants :: IsSymBackend sym bak => bak -> IO (Set (Some (BoundVar sym))) | ||
proofObligationsUninterpConstants bak = do | ||
let sym = backendGetSym bak | ||
foldMap (exprUninterpConstants sym) <$> proofObligationsAsImplications bak | ||
|
||
|
||
ppProofObligation :: IsExprBuilder sym => sym -> ProofObligation sym -> IO (PP.Doc ann) | ||
ppProofObligation sym (AS.ProofGoal asmps gl) = | ||
do as <- flattenAssumptions sym asmps | ||
|
+4 −1 | .github/workflows/gen_matrix.pl | |
+3 −1 | .github/workflows/test.yml | |
+5 −5 | README.md | |
+8 −0 | what4/CHANGES.md | |
+1 −0 | what4/README.md | |
+444 −21 | what4/src/What4/Expr/Builder.hs | |
+24 −1 | what4/src/What4/Interface.hs | |
+28 −1 | what4/src/What4/Protocol/SMTLib2.hs | |
+5 −3 | what4/src/What4/Protocol/SMTWriter.hs | |
+11 −0 | what4/src/What4/Solver.hs | |
+158 −0 | what4/src/What4/Solver/Bitwuzla.hs | |
+88 −9 | what4/src/What4/Solver/Z3.hs | |
+0 −6 | what4/src/What4/Utils/Versions.hs | |
+2 −1 | what4/test/AdapterTest.hs | |
+2 −1 | what4/test/InvariantSynthesis.hs | |
+3 −0 | what4/test/OnlineSolverTest.hs | |
+4 −3 | what4/what4.cabal |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be controlled by some sort of config or saw option. The intent is to avoid very large sets of fresh constants due to the "trick".