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

Support uninterpreted polymorphic functions in sbv/what4 backends. #92

Merged
merged 2 commits into from
Oct 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this function for selecting type-based suffixes injective? I think it is, but it isn't immediately clear.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is. Basically it serializes the TValue with a pre-order traversal, and all the strings it uses to represent the nodes are distinct. So you could always unambiguously parse them back in.

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