projects
/
haskell-directory.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
f24ac6c
)
GHC.PArr: add bounds checking
author
Manuel M T Chakravarty
<chak@cse.unsw.edu.au>
Fri, 2 Mar 2007 05:32:24 +0000
(
05:32
+0000)
committer
Manuel M T Chakravarty
<chak@cse.unsw.edu.au>
Fri, 2 Mar 2007 05:32:24 +0000
(
05:32
+0000)
GHC/PArr.hs
patch
|
blob
|
history
diff --git
a/GHC/PArr.hs
b/GHC/PArr.hs
index
90f903c
..
fe58b94
100644
(file)
--- a/
GHC/PArr.hs
+++ b/
GHC/PArr.hs
@@
-1,4
+1,4
@@
-{-# OPTIONS_GHC -fparr #-}
+{-# OPTIONS_GHC -fparr -funbox-strict-fields #-}
-----------------------------------------------------------------------------
-- |
-----------------------------------------------------------------------------
-- |
@@
-144,7
+144,7
@@
import Prelude
import GHC.ST ( ST(..), STRep, runST )
import GHC.Exts ( Int#, Array#, Int(I#), MutableArray#, newArray#,
import GHC.ST ( ST(..), STRep, runST )
import GHC.Exts ( Int#, Array#, Int(I#), MutableArray#, newArray#,
- unsafeFreezeArray#, indexArray#, writeArray# )
+ unsafeFreezeArray#, indexArray#, writeArray#, (<#), (>=#) )
infixl 9 !:
infixr 5 +:+
infixl 9 !:
infixr 5 +:+
@@
-637,12
+637,21
@@
scanEFL f = \e a -> (Just a, f e a)
--
indexPArr :: [:e:] -> Int -> e
{-# INLINE indexPArr #-}
--
indexPArr :: [:e:] -> Int -> e
{-# INLINE indexPArr #-}
-indexPArr (PArr _ arr#) (I# i#) =
- case indexArray# arr# i# of (# e #) -> e
+indexPArr (PArr n# arr#) (I# i#)
+ | i# >=# 0# && i# <# n# =
+ case indexArray# arr# i# of (# e #) -> e
+ | otherwise = error $ "indexPArr: out of bounds parallel array index; " ++
+ "idx = " ++ show (I# i#) ++ ", arr len = "
+ ++ show (I# n#)
-- encapsulate writing into a mutable array into the `ST' monad
--
writeMPArr :: MPArr s e -> Int -> e -> ST s ()
{-# INLINE writeMPArr #-}
-- encapsulate writing into a mutable array into the `ST' monad
--
writeMPArr :: MPArr s e -> Int -> e -> ST s ()
{-# INLINE writeMPArr #-}
-writeMPArr (MPArr _ marr#) (I# i#) e = ST $ \s# ->
- case writeArray# marr# i# e s# of s'# -> (# s'#, () #)
+writeMPArr (MPArr n# marr#) (I# i#) e
+ | i# >=# 0# && i# <# n# =
+ ST $ \s# ->
+ case writeArray# marr# i# e s# of s'# -> (# s'#, () #)
+ | otherwise = error $ "writeMPArr: out of bounds parallel array index; " ++
+ "idx = " ++ show (I# i#) ++ ", arr len = "
+ ++ show (I# n#)