Skip to content

Commit

Permalink
Support deepseq in reference evaluator
Browse files Browse the repository at this point in the history
Checks off one box in #1249.
  • Loading branch information
RyanGlScott committed Dec 20, 2024
1 parent 6bd8c5e commit f8245ed
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 3 deletions.
4 changes: 2 additions & 2 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
were incorrectly computed.
([#1773](https://github.com/GaloisInc/cryptol/issues/1773))

* The reference evaluator now evaluates the `toSignedInteger` primitive instead
of panicking.
* The reference evaluator now evaluates the `toSignedInteger` and `deepseq`
primitives instead of panicking.

## New features

Expand Down
30 changes: 29 additions & 1 deletion src/Cryptol/Eval/Reference.lhs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,28 @@ Operations on Values
> where
> g (Nat n) = f n
> g Inf = evalPanic "vFinPoly" ["Expected finite numeric type"]

>
> -- | Reduce a value to normal form.
> forceValue :: Value -> E ()
> forceValue v =
> case v of
> -- Values where the field is already is normal form
> VBit{} -> pure ()
> VInteger{} -> pure ()
> VRational{} -> pure ()
> VFloat{} -> pure ()
> -- Values with fields containing other values to reduce to normal form
> VList _ xs -> forceValues xs
> VTuple xs -> forceValues xs
> VRecord fs -> forceValues $ map snd fs
> VEnum _ xs -> forceValues xs
> -- Lambdas and other abstractions are already in normal form
> VFun{} -> pure ()
> VPoly{} -> pure ()
> VNumPoly{} -> pure ()
> where
> forceValues :: [E Value] -> E ()
> forceValues = mapM_ (\x -> forceValue =<< x)

Environments
------------
Expand Down Expand Up @@ -948,6 +969,13 @@ by corresponding type classes:
> -- executes parmap sequentially
> pure $ VList n (map f' xs')
>
> , "deepseq" ~> VPoly $ \_a -> pure $
> VPoly $ \_b -> pure $
> VFun $ \x -> pure $
> VFun $ \y ->
> do forceValue =<< x
> y
>
> , "error" ~> VPoly $ \_a -> pure $
> VNumPoly $ \_ -> pure $
> VFun $ \s ->
Expand Down
5 changes: 5 additions & 0 deletions tests/issues/issue1249.icry
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,8 @@ toSignedInteger (-1 : [64])
:eval toSignedInteger (-1 : [64])
toSignedInteger (-(2^^63) : [64])
:eval toSignedInteger (-(2^^63) : [64])

// deepseq

deepseq ((), undefined`{()}) True
:eval deepseq ((), undefined`{()}) True
7 changes: 7 additions & 0 deletions tests/issues/issue1249.icry.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,10 @@ Loading module Cryptol
-1
-9223372036854775808
-9223372036854775808

Run-time error: undefined
-- Backtrace --
Cryptol::error called at Cryptol:1062:13--1062:18
Cryptol::undefined called at issue1249.icry:16:14--16:23
Cryptol::deepseq called at issue1249.icry:16:1--16:8
Run-time error: undefined

0 comments on commit f8245ed

Please sign in to comment.