-
Notifications
You must be signed in to change notification settings - Fork 62
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
Add support for arrayCopy, arraySet, and arrayRangeEqual primitives #1428
Changes from 1 commit
858afd6
ecebbe2
0daf9c7
484e439
ac5c38e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -367,6 +367,15 @@ scEq sym sc tp x y = | |
BaseBoolRepr -> scBoolEq sc x y | ||
BaseRealRepr -> scRealEq sym sc x y | ||
BaseIntegerRepr -> scIntEq sc x y | ||
BaseArrayRepr idxTypes range | ||
| Ctx.Empty Ctx.:> idx_type <- idxTypes -> | ||
do let SAWExpr x' = x | ||
let SAWExpr y' = y | ||
sc_idx_type <- baseSCType sym sc idx_type | ||
sc_elm_type <- baseSCType sym sc range | ||
SAWExpr <$> SC.scArrayEq sc sc_idx_type sc_elm_type x' y' | ||
| otherwise -> | ||
unsupported sym ("SAW backend: equality comparison on unsupported multidimensional array type:" ++ show tp) | ||
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. Is the reason not to support multi-dimensional arrays here that it would be extra work, in this function, that we don't need right now? Or are there limitations elsewhere in the codebase that would make it hard to support them? 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. we don't support multi-dimensional arrays in cryptol or saw-core, and we don't need them at the moment. Adding representation for multi-dimensional arrays in cryptol and saw-core, and translations for all the round-tripping would add a lot of complexity, and I wanted to keep things simple |
||
BaseBVRepr w -> | ||
do let SAWExpr x' = x | ||
let SAWExpr y' = y | ||
|
@@ -797,6 +806,35 @@ evaluateExpr sym st sc cache = f [] | |
SAWExpr <$> SC.scArrayUpdate sc sc_idx_type sc_elm_type sc_arr sc_idx sc_elm | ||
| otherwise -> unimplemented "multidimensional UpdateArray" | ||
|
||
B.CopyArray w a_repr dest_arr dest_idx src_arr src_idx len _dest_end_idx _src_end_idx -> | ||
do sc_w <- SC.scNat sc (natValue w) | ||
sc_a <- baseSCType sym sc a_repr | ||
sc_dest_arr <- f env dest_arr | ||
sc_dest_idx <- f env dest_idx | ||
sc_src_arr <- f env src_arr | ||
sc_src_idx <- f env src_idx | ||
sc_len <- f env len | ||
SAWExpr <$> SC.scArrayCopy sc sc_w sc_a sc_dest_arr sc_dest_idx sc_src_arr sc_src_idx sc_len | ||
|
||
B.SetArray w a_repr arr idx val len _end_idx -> | ||
do sc_w <- SC.scNat sc (natValue w) | ||
sc_a <- baseSCType sym sc a_repr | ||
sc_arr <- f env arr | ||
sc_idx <- f env idx | ||
sc_val <- f env val | ||
sc_len <- f env len | ||
SAWExpr <$> SC.scArraySet sc sc_w sc_a sc_arr sc_idx sc_val sc_len | ||
|
||
B.EqualArrayRange w a_repr x_arr x_idx y_arr y_idx len _x_end_idx _y_end_idx -> | ||
do sc_w <- SC.scNat sc (natValue w) | ||
sc_a <- baseSCType sym sc a_repr | ||
sc_x_arr <- f env x_arr | ||
sc_x_idx <- f env x_idx | ||
sc_y_arr <- f env y_arr | ||
sc_y_idx <- f env y_idx | ||
sc_len <- f env len | ||
SAWExpr <$> SC.scArrayRangeEq sc sc_w sc_a sc_x_arr sc_x_idx sc_y_arr sc_y_idx sc_len | ||
|
||
B.IntDiv x y -> | ||
do x' <- f env x | ||
y' <- f env y | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -231,6 +231,9 @@ module Verifier.SAW.SharedTerm | |
, scArrayLookup | ||
, scArrayUpdate | ||
, scArrayEq | ||
, scArrayCopy | ||
, scArraySet | ||
, scArrayRangeEq | ||
-- ** Utilities | ||
-- , scTrue | ||
-- , scFalse | ||
|
@@ -2230,7 +2233,7 @@ scArrayConstant sc a b e = scGlobalApply sc "Prelude.arrayConstant" [a, b, e] | |
scArrayLookup :: SharedContext -> Term -> Term -> Term -> Term -> IO Term | ||
scArrayLookup sc a b f i = scGlobalApply sc "Prelude.arrayLookup" [a, b, f, i] | ||
|
||
-- Create a term computing an array updated at a particular index. | ||
-- | Create a term computing an array updated at a particular index. | ||
-- | ||
-- > arrayUpdate : (a b : sort 0) -> (Array a b) -> a -> b -> (Array a b); | ||
scArrayUpdate :: SharedContext -> Term -> Term -> Term -> Term -> Term -> IO Term | ||
|
@@ -2242,6 +2245,18 @@ scArrayUpdate sc a b f i e = scGlobalApply sc "Prelude.arrayUpdate" [a, b, f, i, | |
scArrayEq :: SharedContext -> Term -> Term -> Term -> Term -> IO Term | ||
scArrayEq sc a b x y = scGlobalApply sc "Prelude.arrayEq" [a, b, x, y] | ||
|
||
-- > arrayCopy : (n : Nat) -> (a : sort 0) -> Array (Vec n Bool) a -> Vec n Bool -> Array (Vec n Bool) a -> Vec n Bool -> Vec n Bool -> Array (Vec n Bool) a; | ||
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. Let's list the names of the arguments for these. There are a lot of them, and it's easy to swap around src/dest, etc. |
||
scArrayCopy :: SharedContext -> Term -> Term -> Term -> Term -> Term -> Term -> Term -> IO Term | ||
scArrayCopy sc n a f i g j l = scGlobalApply sc "Prelude.arrayCopy" [n, a, f, i, g, j, l] | ||
|
||
-- > arraySet : (n : Nat) -> (a : sort 0) -> Array (Vec n Bool) a -> Vec n Bool -> a -> Vec n Bool -> Array (Vec n Bool) a; | ||
scArraySet :: SharedContext -> Term -> Term -> Term -> Term -> Term -> Term -> IO Term | ||
scArraySet sc n a f i e l = scGlobalApply sc "Prelude.arraySet" [n, a, f, i, e, l] | ||
|
||
-- > arrayRangeEq : (n : Nat) -> (a : sort 0) -> Array (Vec n Bool) a -> Vec n Bool -> Array (Vec n Bool) a -> Vec n Bool -> Vec n Bool -> Bool; | ||
scArrayRangeEq :: SharedContext -> Term -> Term -> Term -> Term -> Term -> Term -> Term -> IO Term | ||
scArrayRangeEq sc n a f i g j l = scGlobalApply sc "Prelude.arrayRangeEq" [n, a, f, i, g, j, l] | ||
|
||
------------------------------------------------------------ | ||
-- | The default instance of the SharedContext operations. | ||
mkSharedContext :: IO SharedContext | ||
|
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 PR wouldn't be the place to implement it, probably, but doesn't the SBV library have support for SMT arrays? Is there anything stopping us from supporting them?
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.
As I recall, the "dynamic" SBV interface we use doesn't expose that functionality. I should double check to be sure, but I think that's why we don't support arrays or uninterpreted functions via Cryptol or SAW. It's one of the reasons I want to find a way to use the standard interface instead.
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.
I don't remember exactly why I didn't implement array support in the SBV backend in the first place. I am not that familiar with SBV, if it's not that complicated we could add support in the future