Skip to content
This repository has been archived by the owner on Jun 9, 2021. It is now read-only.

Commit

Permalink
Merge pull request #92 from GaloisInc/unint-poly
Browse files Browse the repository at this point in the history
Support uninterpreted polymorphic functions in sbv/what4 backends.
  • Loading branch information
brianhuffman authored Oct 21, 2020
2 parents 3dd70af + 7049e5c commit 066e7a8
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
5 changes: 4 additions & 1 deletion saw-core-sbv/src/Verifier/SAW/Simulator/SBV.hs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,10 @@ flattenSValue v = do
VCtorApp i (V.toList->ts) -> do (xss, ss) <- unzip <$> traverse (force >=> flattenSValue) ts
return (concat xss, "_" ++ identName i ++ concat ss)
VNat n -> return ([], "_" ++ show n)
_ -> fail $ "Could not create sbv argument for " ++ show v
TValue (suffixTValue -> Just s)
-> return ([], s)
VFun _ -> fail "Cannot create uninterpreted higher-order function"
_ -> fail $ "Cannot create uninterpreted function with argument " ++ show v

vWord :: SWord -> SValue
vWord lv = VWord lv
Expand Down
6 changes: 5 additions & 1 deletion saw-core-what4/src/Verifier/SAW/Simulator/What4.hs
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,11 @@ applyUnintApp app0 v =
VCtorApp i xv -> foldM applyUnintApp app' =<< traverse force xv
where app' = suffixUnintApp ("_" ++ identName i) app0
VNat n -> return (suffixUnintApp ("_" ++ show n) app0)
_ -> fail $ "Could not create argument for " ++ show v
TValue (suffixTValue -> Just s)
-> return (suffixUnintApp s app0)
VFun _ -> fail "Cannot create uninterpreted higher-order function"
_ -> fail $ "Cannot create uninterpreted function with argument " ++ show v


------------------------------------------------------------

Expand Down
25 changes: 25 additions & 0 deletions saw-core/src/Verifier/SAW/Simulator/Value.hs
Original file line number Diff line number Diff line change
Expand Up @@ -259,3 +259,28 @@ asFiniteTypeTValue v =
FTRec <$> Map.fromList <$>
mapM (\(fld,tp) -> (fld,) <$> asFiniteTypeTValue tp) elem_tps
_ -> Nothing

-- | A (partial) injective mapping from type values to strings. These
-- are intended to be useful as suffixes for names of type instances
-- of uninterpreted constants.
suffixTValue :: TValue sym -> Maybe String
suffixTValue tv =
case tv of
VVecType n a ->
do a' <- suffixTValue a
Just ("_Vec_" ++ show n ++ a')
VBoolType -> Just "_Bool"
VIntType -> Just "_Int"
VArrayType a b ->
do a' <- suffixTValue a
b' <- suffixTValue b
Just ("_Array" ++ a' ++ b')
VPiType _ _ -> Nothing
VUnitType -> Just "_Unit"
VPairType a b ->
do a' <- suffixTValue a
b' <- suffixTValue b
Just ("_Pair" ++ a' ++ b')
VDataType {} -> Nothing
VRecordType {} -> Nothing
VSort {} -> Nothing

0 comments on commit 066e7a8

Please sign in to comment.