Fold integer-simple.git into ghc.git (re #8545)
[ghc.git] / testsuite / tests / perf / should_run / InlineCloneArrayAlloc.hs
1 {-# LANGUAGE MagicHash, UnboxedTuples #-}
2 module Main where
3
4 import GHC.Exts
5 import GHC.IO
6
7 main :: IO ()
8 main = do
9 marr <- newArray
10 loop 10000000 (unMArray marr)
11 where
12 loop :: Int -> MutableArray# RealWorld () -> IO ()
13 loop 0 _ = return ()
14 loop i marr = freezeArray marr >> loop (i-1) marr
15
16 data MArray = MArray { unMArray :: !(MutableArray# RealWorld ()) }
17
18 newArray :: IO MArray
19 newArray = IO $ \s -> case newArray# 16# () s of
20 (# s', marr# #) -> (# s', MArray marr# #)
21
22 freezeArray :: MutableArray# RealWorld () -> IO ()
23 freezeArray marr# = IO $ \s -> case freezeArray# marr# 0# 16# s of
24 (# s', _ #) -> (# s', () #)