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

arrayEq primitive #1713

Merged
merged 3 commits into from
Jul 27, 2022
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
3 changes: 3 additions & 0 deletions cryptol-saw-core/saw/Cryptol.sawcore
Original file line number Diff line number Diff line change
Expand Up @@ -1829,6 +1829,9 @@ ecArrayUpdate = arrayUpdate;
ecArrayCopy : (n : Num) -> (a : sort 0) -> Array (seq n Bool) a -> seq n Bool -> Array (seq n Bool) a -> seq n Bool -> seq n Bool -> Array (seq n Bool) a;
ecArrayCopy = finNumRec (\(n : Num) -> (a : sort 0) -> Array (seq n Bool) a -> seq n Bool -> Array (seq n Bool) a -> seq n Bool -> seq n Bool -> Array (seq n Bool) a) arrayCopy;

ecArrayEq : (n : Num) -> (a : sort 0) -> Array (seq n Bool) a -> Array (seq n Bool) a -> Bool;
ecArrayEq = finNumRec (\ (n : Num) -> (a : sort 0) -> Array (seq n Bool) a -> Array (seq n Bool) a -> Bool) (\ (n:Nat) -> arrayEq (Vec n Bool));

ecArraySet : (n : Num) -> (a : sort 0) -> Array (seq n Bool) a -> seq n Bool -> a -> seq n Bool -> Array (seq n Bool) a;
ecArraySet = finNumRec (\(n : Num) -> (a : sort 0) -> Array (seq n Bool) a -> seq n Bool -> a -> seq n Bool -> Array (seq n Bool) a) arraySet;

Expand Down
1 change: 1 addition & 0 deletions cryptol-saw-core/src/Verifier/SAW/Cryptol.hs
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,7 @@ arrayPrims =
, ("arrayLookup", flip scGlobalDef "Cryptol.ecArrayLookup") -- {a,b} Array a b -> a -> b
, ("arrayUpdate", flip scGlobalDef "Cryptol.ecArrayUpdate") -- {a,b} Array a b -> a -> b -> Array a b
, ("arrayCopy", flip scGlobalDef "Cryptol.ecArrayCopy") -- {n,a} Array [n] a -> [n] -> Array [n] a -> [n] -> [n] -> Array [n] a
, ("arrayEq", flip scGlobalDef "Cryptol.ecArrayEq") -- {a, b} (Array a b) -> (Array a b) -> Bool
, ("arraySet", flip scGlobalDef "Cryptol.ecArraySet") -- {n,a} Array [n] a -> [n] -> a -> [n] -> Array [n] a
, ("arrayRangeEqual", flip scGlobalDef "Cryptol.ecArrayRangeEq") -- {n,a} Array [n] a -> [n] -> Array [n] a -> [n] -> [n] -> Bit
]
Expand Down
9 changes: 6 additions & 3 deletions cryptol-saw-core/src/Verifier/SAW/CryptolEnv.hs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ import qualified Cryptol.ModuleSystem.Renamer as MR
import qualified Cryptol.Utils.Ident as C

import Cryptol.Utils.PP hiding ((</>))
import Cryptol.Utils.Ident (Ident, preludeName, preludeReferenceName
import Cryptol.Utils.Ident (Ident, preludeName, arrayName, preludeReferenceName
, packIdent, interactiveName, identText
, packModName, textToModName, modNameChunks
, prelPrim)
Expand Down Expand Up @@ -189,10 +189,12 @@ initCryptolEnv sc = do
let modEnv1 = modEnv0 { ME.meSearchPath = cryptolPaths ++
(instDir </> "lib") : ME.meSearchPath modEnv0 }

-- Load Cryptol prelude
-- Load Cryptol prelude and magic Array module
(_, modEnv2) <-
liftModuleM modEnv1 $
MB.loadModuleFrom False (MM.FromModule preludeName)
do _ <- MB.loadModuleFrom False (MM.FromModule preludeName)
_ <- MB.loadModuleFrom False (MM.FromModule arrayName)
return ()

-- Load Cryptol reference implementations
((_,refMod), modEnv) <-
Expand All @@ -213,6 +215,7 @@ initCryptolEnv sc = do
return CryptolEnv
{ eImports = [ (OnlyPublic, P.Import preludeName Nothing Nothing)
, (OnlyPublic, P.Import preludeReferenceName (Just preludeReferenceName) Nothing)
, (OnlyPublic, P.Import arrayName Nothing Nothing)
]
, eModuleEnv = modEnv
, eExtraNames = mempty
Expand Down