Add testcase for getSizeofMutableByteArray#
authorBen Gamari <bgamari@smart-cactus.org>
Sun, 27 Dec 2015 16:49:03 +0000 (17:49 +0100)
committerBen Gamari <ben@smart-cactus.org>
Sun, 27 Dec 2015 17:47:53 +0000 (18:47 +0100)
In an attempt to track down #11296. Unfortunately the primop appears
to be working as expected.

Test Plan: validate

Reviewers: hvr, austin

Subscribers: thomie

Differential Revision: https://phabricator.haskell.org/D1706

GHC Trac Issues: #11296

testsuite/tests/primops/should_run/T11296.hs [new file with mode: 0644]
testsuite/tests/primops/should_run/T11296.stdout [new file with mode: 0644]
testsuite/tests/primops/should_run/all.T

diff --git a/testsuite/tests/primops/should_run/T11296.hs b/testsuite/tests/primops/should_run/T11296.hs
new file mode 100644 (file)
index 0000000..c487974
--- /dev/null
@@ -0,0 +1,30 @@
+{-# LANGUAGE MagicHash #-}
+{-# LANGUAGE UnboxedTuples #-}
+
+import Control.Monad (unless)
+import GHC.Exts
+import GHC.Types
+
+data ByteArray s = BA (MutableByteArray# s)
+
+main :: IO ()
+main = do
+    ba# <- IO (\s0 -> case newByteArray# 256# s0 of
+                        (# s1, ba# #) -> (# s1, BA ba# #))
+    let go n = do
+            shrink ba# n
+            sz <- getSize ba#
+            unless (sz == n) $ print (sz, n)
+    mapM go [128, 64, 63, 32, 2, 1]
+    return ()
+
+shrink :: ByteArray RealWorld -> Int -> IO ()
+shrink (BA ba#) (I# n#) = IO (\s ->
+    case shrinkMutableByteArray# ba# n# s of
+      s' -> (# s', () #))
+
+getSize :: ByteArray RealWorld -> IO Int
+getSize (BA ba#) = IO (\s ->
+    case getSizeofMutableByteArray# ba# s of
+      (# s', n# #) -> (# s', I# n# #))
+
diff --git a/testsuite/tests/primops/should_run/T11296.stdout b/testsuite/tests/primops/should_run/T11296.stdout
new file mode 100644 (file)
index 0000000..e69de29
index 2003fc3..68a2d56 100644 (file)
@@ -12,3 +12,4 @@ test('T10678',
       only_ways('normal')
      ],
      compile_and_run, ['-O'])
+test('T11296', normal, compile_and_run, [''])