Skip to content

Commit

Permalink
Merge pull request #703 from GaloisInc/issue702
Browse files Browse the repository at this point in the history
issue702
  • Loading branch information
robdockins authored Apr 23, 2020
2 parents aa6030b + ce85155 commit f29f015
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 15 deletions.
12 changes: 7 additions & 5 deletions src/Cryptol/Eval/Concrete.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,14 @@ module Cryptol.Eval.Concrete
) where

import Control.Monad (join,guard,zipWithM)
import Data.List(sortBy)
import Data.Ord(comparing)
import Data.Bits (Bits(..))
import MonadLib( ChoiceT, findOne, lift )

import qualified Data.Map.Strict as Map
import qualified Data.Text as T

import Cryptol.TypeCheck.Solver.InfNat (Nat'(..))
import Cryptol.Eval.Backend
import Cryptol.Eval.Concrete.Value
Expand All @@ -41,10 +47,6 @@ import Cryptol.Utils.Ident (Ident,mkIdent)
import Cryptol.Utils.PP
import Cryptol.Utils.Logger(logPrint)

import Data.Bits (Bits(..))

import qualified Data.Map.Strict as Map
import qualified Data.Text as T


-- Value to Expression conversion ----------------------------------------------
Expand All @@ -61,7 +63,7 @@ toExpr prims t0 v0 = findOne (go t0 v0)

go :: AST.Type -> Value -> ChoiceT Eval Expr
go ty val = case (tNoUser ty, val) of
(TRec tfs, VRecord vfs) -> do
(TRec (sortBy (comparing fst) -> tfs), VRecord vfs) -> do
let fns = Map.keys vfs
guard (map fst tfs == fns)
fes <- zipWithM go (map snd tfs) =<< lift (sequence (Map.elems vfs))
Expand Down
11 changes: 4 additions & 7 deletions src/Cryptol/Symbolic.hs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import Cryptol.Utils.PP

import Prelude ()
import Prelude.Compat

import qualified Data.Map as Map
import Data.Time (NominalDiffTime)

type SatResult = [(Type, Expr, Concrete.Value)]
Expand Down Expand Up @@ -105,7 +105,7 @@ data FinType
| FTIntMod Integer
| FTSeq Int FinType
| FTTuple [FinType]
| FTRecord [(Ident, FinType)]
| FTRecord (Map.Map Ident FinType)

numType :: Integer -> Maybe Int
numType n
Expand All @@ -123,7 +123,7 @@ finType ty =
TVIntMod n -> Just (FTIntMod n)
TVSeq n t -> FTSeq <$> numType n <*> finType t
TVTuple ts -> FTTuple <$> traverse finType ts
TVRec fields -> FTRecord <$> traverse (traverseSnd finType) fields
TVRec fields -> FTRecord . Map.fromList <$> traverse (traverseSnd finType) fields
TVAbstract {} -> Nothing
_ -> Nothing

Expand All @@ -135,7 +135,4 @@ unFinType fty =
FTIntMod n -> tIntMod (tNum n)
FTSeq l ety -> tSeq (tNum l) (unFinType ety)
FTTuple ftys -> tTuple (unFinType <$> ftys)
FTRecord fs -> tRec (zip fns tys)
where
fns = fst <$> fs
tys = unFinType . snd <$> fs
FTRecord fs -> tRec (Map.toList (fmap unFinType fs))
6 changes: 3 additions & 3 deletions src/Cryptol/Symbolic/SBV.hs
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ parseValue (FTSeq n t) cvs =
parseValue (FTTuple ts) cvs = (Eval.VTuple (map Eval.ready vs), cvs')
where (vs, cvs') = parseValues ts cvs
parseValue (FTRecord fs) cvs = (Eval.VRecord (Map.fromList (zip ns (map Eval.ready vs))), cvs')
where (ns, ts) = unzip fs
where (ns, ts) = unzip (Map.toList fs)
(vs, cvs') = parseValues ts cvs

inBoundsIntMod :: Integer -> Eval.SInteger SBV -> Eval.SBit SBV
Expand All @@ -296,7 +296,7 @@ forallFinType ty =
FTSeq n t -> do vs <- replicateM n (forallFinType t)
return $ Eval.VSeq (toInteger n) $ Eval.finiteSeqMap SBV (map pure vs)
FTTuple ts -> Eval.VTuple <$> mapM (fmap pure . forallFinType) ts
FTRecord fs -> Eval.VRecord <$> mapM (fmap pure . forallFinType) (Map.fromList fs)
FTRecord fs -> Eval.VRecord <$> mapM (fmap pure . forallFinType) fs

existsFinType :: FinType -> WriterT [Eval.SBit SBV] SBV.Symbolic Value
existsFinType ty =
Expand All @@ -311,4 +311,4 @@ existsFinType ty =
FTSeq n t -> do vs <- replicateM n (existsFinType t)
return $ Eval.VSeq (toInteger n) $ Eval.finiteSeqMap SBV (map pure vs)
FTTuple ts -> Eval.VTuple <$> mapM (fmap pure . existsFinType) ts
FTRecord fs -> Eval.VRecord <$> mapM (fmap pure . existsFinType) (Map.fromList fs)
FTRecord fs -> Eval.VRecord <$> mapM (fmap pure . existsFinType) fs
2 changes: 2 additions & 0 deletions tests/issues/issue702.icry
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
:sat \(x : {b:Bit, a:Bit}) -> x.a && x.b
:sat \(x : {b:[8], a:Bit}) -> x.b == 0 /\ x.a
5 changes: 5 additions & 0 deletions tests/issues/issue702.icry.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Loading module Cryptol
(\(x : {b : Bit, a : Bit}) -> x.a && x.b)
{a = True, b = True} = True
(\(x : {b : [8], a : Bit}) -> x.b == 0 /\ x.a)
{a = True, b = 0x00} = True

0 comments on commit f29f015

Please sign in to comment.