Commit 11778f74 authored by Ben Gamari's avatar Ben Gamari Committed by Ben Gamari
Browse files

Add testcase for getSizeofMutableByteArray#

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
parent d1ebbb0c
{-# 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# #))
......@@ -12,3 +12,4 @@ test('T10678',
only_ways('normal')
],
compile_and_run, ['-O'])
test('T11296', normal, compile_and_run, [''])
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment