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

Sygus2 #1166

Closed
wants to merge 11 commits into from
1 change: 0 additions & 1 deletion crucible-llvm/src/Lang/Crucible/LLVM/Intrinsics/Libc.hs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ import Data.Parameterized.Context ( pattern (:>), pattern Empty )
import qualified Data.Parameterized.Context as Ctx

import What4.Interface
import What4.InterpretedFloatingPoint (IsInterpretedFloatExprBuilder(..))
import What4.ProgramLoc (plSourceLoc)
import qualified What4.SpecialFunctions as W4

Expand Down
7 changes: 4 additions & 3 deletions crucible-llvm/src/Lang/Crucible/LLVM/MemModel/Generic.hs
Original file line number Diff line number Diff line change
Expand Up @@ -790,9 +790,10 @@ readMem' sym w end gsym l0 origMem tp0 alignment (MemWrites ws) =
else do -- We're playing a trick here. By making a fresh constant a proof obligation, we can be
-- sure it always fails. But, because it's a variable, it won't be constant-folded away
-- and we can be relatively sure the annotation will survive.
b <- freshConstant sym (safeSymbol "noSatisfyingWrite") BaseBoolRepr
Partial.Err <$>
Partial.annotateME sym mop (NoSatisfyingWrite tp) b
-- b <- freshConstant sym (safeSymbol "noSatisfyingWrite") BaseBoolRepr
Copy link
Member

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".

-- Partial.Err <$>
-- Partial.annotateME sym mop (NoSatisfyingWrite tp) b
Partial.partErr sym mop (NoSatisfyingWrite tp)

go :: (StorageType -> LLVMPtr sym w -> ReadMem sym (PartLLVMVal sym)) ->
LLVMPtr sym w ->
Expand Down
1 change: 1 addition & 0 deletions crucible-llvm/src/Lang/Crucible/LLVM/MemModel/MemLog.hs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ module Lang.Crucible.LLVM.MemModel.MemLog

-- * Write ranges
, writeRangesMem
, writeSourceSize

-- * Concretization
, concPtr
Expand Down
1,339 changes: 934 additions & 405 deletions crucible-llvm/src/Lang/Crucible/LLVM/SimpleLoopFixpoint.hs

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions crucible-llvm/src/Lang/Crucible/LLVM/SimpleLoopInvariant.hs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ module Lang.Crucible.LLVM.SimpleLoopInvariant
( InvariantEntry(..)
, InvariantPhase(..)
, simpleLoopInvariant
-- , MemorySubstitution(..)
-- , computeMemSubstitution
-- , constructMemSubstitutionCandidate
-- , checkMemSubst
-- , loadMemJoinVariables
-- , storeMemJoinVariables
) where

import Control.Lens
Expand Down
1 change: 0 additions & 1 deletion crucible-llvm/src/Lang/Crucible/LLVM/Translation/Expr.hs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ import Lang.Crucible.LLVM.TypeContext
import Lang.Crucible.Syntax
import Lang.Crucible.Types

import What4.InterpretedFloatingPoint (X86_80Val(..))

-------------------------------------------------------------------------
-- LLVMExpr
Expand Down
18 changes: 18 additions & 0 deletions crucible/src/Lang/Crucible/Analysis/Fixpoint/Components.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ module Lang.Crucible.Analysis.Fixpoint.Components (
weakTopologicalOrdering,
WTOComponent(..),
SCC(..),
parentWTOComponent,
-- * Special cases
cfgWeakTopologicalOrdering,
cfgSuccessors,
Expand Down Expand Up @@ -239,6 +240,23 @@ unlabeled = Label 0
maxLabel :: Label
maxLabel = Label maxBound

-- | Construct a map from each vertex to the head of its parent WTO component.
-- In particular, the head of a component is mapped to itself. The top vertices
-- are not in the map.
parentWTOComponent :: (Ord n) => [WTOComponent n] -> M.Map n n
parentWTOComponent = F.foldMap' $ \case
SCC scc' -> parentWTOComponent' scc'
Vertex{} -> M.empty

parentWTOComponent' :: (Ord n) => SCC n -> M.Map n n
parentWTOComponent' scc = -- M.singleton (wtoHead scc) (wtoHead scc) <>
F.foldMap'
(\case
SCC scc' -> parentWTOComponent' scc'
Vertex v -> M.singleton v $ wtoHead scc)
(wtoComps scc)


{- Note [Bourdoncle Components]

Bourdoncle components are a weak topological ordering of graph
Expand Down
75 changes: 75 additions & 0 deletions crucible/src/Lang/Crucible/Backend.hs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ module Lang.Crucible.Backend
, addFailedAssertion
, assertIsInteger
, readPartExpr
, runCHC
, proofObligationsAsImplications
, convertProofObligationsAsImplications
, proofObligationsUninterpConstants
, pathConditionUninterpConstants
, ppProofObligation
, backendOptions
, assertThenAssumeConfigOption
Expand All @@ -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
Expand Down Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The 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"
Copy link
Member

Choose a reason for hiding this comment

The 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
Expand Down
2 changes: 1 addition & 1 deletion crucible/src/Lang/Crucible/Backend/ProofGoals.hs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ traverseGoalsWithAssumptions f gls =
-- primarily a debugging aid, to ensure that stack management
-- remains well-bracketed.
newtype FrameIdentifier = FrameIdentifier Word64
deriving(Eq,Ord)
deriving(Eq,Ord,Show)


-- | A data-strucutre that can incrementally collect goals in context.
Expand Down
1 change: 0 additions & 1 deletion crucible/src/Lang/Crucible/CFG/Expr.hs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ import qualified Data.Parameterized.TH.GADT as U
import Data.Parameterized.TraversableFC

import What4.Interface (RoundingMode(..),StringLiteral(..), stringLiteralInfo)
import What4.InterpretedFloatingPoint (X86_80Val(..))

import Lang.Crucible.CFG.Extension
import Lang.Crucible.FunctionHandle
Expand Down
15 changes: 15 additions & 0 deletions crucible/src/Lang/Crucible/FunctionHandle.hs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ module Lang.Crucible.FunctionHandle
, emptyHandleMap
, insertHandleMap
, lookupHandleMap
, updateHandleMap
, searchHandleMap
, handleMapToHandles
-- * Reference cells
Expand All @@ -44,6 +45,7 @@ module Lang.Crucible.FunctionHandle

import Data.Hashable
import Data.Kind
import Data.Functor.Identity
import qualified Data.List as List
import Data.Ord (comparing)

Expand Down Expand Up @@ -217,6 +219,19 @@ lookupHandleMap hdl (FnHandleMap m) =
Just (HandleElt _ x) -> Just x
Nothing -> Nothing

-- | Update the entry of the function handle in the map.
updateHandleMap :: (f args ret -> f args ret)
-> FnHandle args ret
-> FnHandleMap f
-> FnHandleMap f
updateHandleMap f hdl (FnHandleMap m) =
FnHandleMap $ MapF.updatedValue $ runIdentity $
MapF.updateAtKey
(handleID hdl)
(Identity Nothing)
(\(HandleElt hdl' x) -> Identity $ MapF.Set $ HandleElt hdl' $ f x)
m

-- | Lookup the function name in the map by a linear scan of all
-- entries. This will be much slower than using 'lookupHandleMap' to
-- find the function by ID, so the latter should be used if possible.
Expand Down
1 change: 0 additions & 1 deletion crucible/src/Lang/Crucible/Simulator/EvalStmt.hs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ import Prettyprinter

import What4.Config
import What4.Interface
import What4.InterpretedFloatingPoint (freshFloatConstant)
import What4.Partial
import What4.ProgramLoc

Expand Down
11 changes: 1 addition & 10 deletions crucible/src/Lang/Crucible/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,7 @@ module Lang.Crucible.Types
, module Data.Parameterized.NatRepr
, module Data.Parameterized.SymbolRepr
, module What4.BaseTypes
, FloatInfo
, HalfFloat
, SingleFloat
, DoubleFloat
, QuadFloat
, X86_80Float
, DoubleDoubleFloat
, FloatInfoRepr(..)
, FloatInfoToBitWidth
, floatInfoToBVTypeRepr
, module What4.InterpretedFloatingPoint
) where

import Data.Hashable
Expand Down
Loading