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

Regression in vector Primitive/Unboxed.Mutable move operations #811

Closed
dfordivam opened this issue Aug 19, 2021 · 4 comments
Closed

Regression in vector Primitive/Unboxed.Mutable move operations #811

dfordivam opened this issue Aug 19, 2021 · 4 comments

Comments

@dfordivam
Copy link
Contributor

This issue was discovered with the following test failure of the vector package. The tests work fine with ghcjs 8.6.5.

  Data.Vector.Primitive.Mutable (Move):          FAIL
    *** Failed! Falsified (after 4 tests):
    [1,0,-2]
    Move: ([1,0,-2],2,0,1)
    Use --quickcheck-replay=430678 to reproduce.
  Data.Vector.Unboxed.Mutable (Move):            FAIL
    *** Failed! Falsified (after 6 tests):
    [0,2,-3,-5]
    Move: ([0,2,-3,-5],0,3,1)
    Use --quickcheck-replay=189345 to reproduce.

And could be easily reproduced as done here. (Here I am using an older haskell.nix because the latest ghcjs has a different bug #809 )

git clone https://github.com/dfordivam/try-haskell-nix.git
cd try-haskell-nix
nix-build vector-ghcjs-issue/default.nix -A projectCross.ghcjs.hsPkgs.hello-world.components.exes.hello-world
@dfordivam
Copy link
Contributor Author

On further digging I could figure out that this is a primitive pkg issue

import Data.Primitive.ByteArray
import Data.Primitive.Types

main :: IO ()
main = do
  let src = byteArrayFromList [0, 1, 2 :: Int]
  print src
  a <- unsafeThawByteArray src
  let srcLoc = 0
      dstLoc = 1
      sz = (sizeOf (undefined :: Int))
      len = 2
  moveByteArray a (srcLoc * sz) a (dstLoc * sz) (len * sz)
  b <- unsafeFreezeByteArray a
  print b
  if b == byteArrayFromList [0, 1, 2 :: Int]
    then putStrLn "Fail"
    else putStrLn "Pass"

@luite
Copy link
Member

luite commented Aug 25, 2021

thanks for the good testcase. I think 929e11f fixes this.

@dfordivam
Copy link
Contributor Author

@luite Thanks for looking into the issue. I am afraid that this commit only fixes part of the issue. The below test shows the problematic case. I have a fix here #814

test4 = do
  let srcLoc = 1
      dstLoc = 0
      sz = (sizeOf (undefined :: Word8))
      len = 2
      src = [0, 1, 2, 3 :: Word8]
  print (byteArrayFromList src)
  a <- newByteArray (length src * sz)
  copyByteArray a 0 (byteArrayFromList src) 0 (length src * sz)
  moveByteArray a (dstLoc * sz) a (srcLoc * sz) (len * sz)
  b <- unsafeFreezeByteArray a
  print b
  if b /= byteArrayFromList [1, 2, 2, 3 :: Word8]
    then putStrLn "Fail"
    else putStrLn "Pass"

@dfordivam
Copy link
Contributor Author

fix has been merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants