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

Respect VWord/VSeq invariants in parmap implementation #1579

Merged
merged 1 commit into from
Oct 10, 2023
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
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
* Fixed #1455, making anything in scope of the functor in scope at the REPL as
well when an instantiation of the functor is loaded and focused,
design choice (3) on the ticket. In particular, the prelude will be in scope.
* Fix #1578, which caused `parmap` to crash when evaluated on certain types of
sequences.


# 3.0.0 -- 2023-06-26
Expand Down
23 changes: 12 additions & 11 deletions src/Cryptol/Eval/Generic.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1877,22 +1877,23 @@ randomV sym ty seed =
parmapV :: Backend sym => sym -> Prim sym
parmapV sym =
PTyPoly \_a ->
PTyPoly \_b ->
PFinPoly \_n ->
PTyPoly \b ->
PFinPoly \n ->
PFun \f ->
PFun \xs ->
PPrim
do f' <- fromVFun sym <$> f
xs' <- xs
case xs' of
VWord n w ->
do let m = asBitsMap sym w
m' <- sparkParMap sym (\x -> f' (VBit <$> x)) n m
VWord n <$> (bitmapWordVal sym n (fromVBit <$> m'))
VSeq n m ->
VSeq n <$> sparkParMap sym f' n m

_ -> panic "parmapV" ["expected sequence!"]
m <-
case xs' of
VWord _n w ->
let m = asBitsMap sym w in
sparkParMap sym (\x -> f' (VBit <$> x)) n m
VSeq _n m ->
sparkParMap sym f' n m

_ -> panic "parmapV" ["expected finite sequence!"]
mkSeq sym (Nat n) b m


sparkParMap ::
Expand Down
2 changes: 2 additions & 0 deletions tests/issues/T1578.icry
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
parmap (\_ -> True) [0, 1] > 0b00
parmap (\_ -> ()) 0b00 == [(), ()]
3 changes: 3 additions & 0 deletions tests/issues/T1578.icry.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Loading module Cryptol
True
True
Loading