array merge requestshttps://gitlab.haskell.org/ghc/packages/array/-/merge_requests2024-02-03T21:38:23Zhttps://gitlab.haskell.org/ghc/packages/array/-/merge_requests/27Update tests for new exception message2024-02-03T21:38:23ZTommy BidneUpdate tests for new exception messageSee https://gitlab.haskell.org/ghc/ghc/-/merge_requests/11737
CI on also complained about the above MR about the `Trustworthy` extension, so I followed its suggestion of switching to `Safe`. But let me know if I should do something els...See https://gitlab.haskell.org/ghc/ghc/-/merge_requests/11737
CI on also complained about the above MR about the `Trustworthy` extension, so I followed its suggestion of switching to `Safe`. But let me know if I should do something else (e.g. remove it entirely).https://gitlab.haskell.org/ghc/packages/array/-/merge_requests/26Make sure the loop counter in newListArray gets unboxed2023-11-08T14:24:57ZmeooowMake sure the loop counter in newListArray gets unboxedFixes #14Fixes #14https://gitlab.haskell.org/ghc/packages/array/-/merge_requests/24Optimize newGenArray a little2023-11-08T13:38:16ZmeooowOptimize newGenArray a little* Use unsafeNewArray_ instead of newAray_. We know we will fill the
array, and newArray_ wastefully initializes it beforehand.
* Avoid safeIndexing the range when writing the elements. range
generates the elements in the required ord...* Use unsafeNewArray_ instead of newAray_. We know we will fill the
array, and newArray_ wastefully initializes it beforehand.
* Avoid safeIndexing the range when writing the elements. range
generates the elements in the required order, so we can simply use an
Int counter.
---
Example benchmark (GHC 9.2.5, -O2):
```
benchmarking newGenArray(current)
time 77.49 μs (77.16 μs .. 77.75 μs)
1.000 R² (1.000 R² .. 1.000 R²)
mean 77.24 μs (77.06 μs .. 77.40 μs)
std dev 569.8 ns (481.4 ns .. 681.8 ns)
benchmarking newGenArray(new)
time 26.37 μs (26.32 μs .. 26.43 μs)
1.000 R² (1.000 R² .. 1.000 R²)
mean 26.34 μs (26.30 μs .. 26.39 μs)
std dev 140.6 ns (110.4 ns .. 198.4 ns)
```
<details>
<summary>Source</summary>
```hs
{-# LANGUAGE BangPatterns #-}
import Criterion.Main
import Data.Array.Base
import Data.Array.IO
main :: IO ()
main = defaultMain
[ bench "newGenArray(current)" $ whnfIO (newGenArray (1,n) pure :: IO (IOUArray Int Int))
, bench "newGenArray(new)" $ whnfIO (newGenArray2 (1,n) pure :: IO (IOUArray Int Int))
]
where
!n = 100000
newGenArray :: (MArray a e m, Ix i) => (i,i) -> (i -> m e) -> m (a i e)
newGenArray (l,u) f = do
marr <- newArray_ (l,u)
let n = safeRangeSize (l,u)
sequence_ [ f i >>= unsafeWrite marr (safeIndex (l,u) n i) | i <- range (l,u)]
return marr
newGenArray2 :: (MArray a e m, Ix i) => (i,i) -> (i -> m e) -> m (a i e)
newGenArray2 bnds f = do
let !_ = safeRangeSize bnds -- To error on a negative size
marr <- unsafeNewArray_ bnds
let g ix k !i = do
x <- f ix
unsafeWrite marr i x
k (i+1)
foldr g (const (return ())) (range bnds) 0
-- Note: We don't worry about the list being too short or too long
-- because of the Ix law: rangeSize bnds == length (range bnds)
return marr
```
</details>https://gitlab.haskell.org/ghc/packages/array/-/merge_requests/16Make listArray and newListArray good consumers2023-11-06T16:43:59ZmeooowMake listArray and newListArray good consumers- Deduplicate `listArrayST`, `listUArrayST` and `newListArray` which have
identical definitions.
- Make `newListArray` use `foldr`, which can fuse with the input list of
elements. `listArray` also benefits because it gets rewritten b...- Deduplicate `listArrayST`, `listUArrayST` and `newListArray` which have
identical definitions.
- Make `newListArray` use `foldr`, which can fuse with the input list of
elements. `listArray` also benefits because it gets rewritten by rules
to use `newListArray`.
Closes #8.
Note: This MR does not change the definition of `listArray` (used when it _does not_ get rewritten), which is also not fusion-friendly due to a `zip [0..] es`. This definition is not used for any of the defined array instances because all of them have rewrite rules, but will be for user-defined instances. It can be made fusion-friendly but needs some changes which I don't want to burden this MR with.https://gitlab.haskell.org/ghc/packages/array/-/merge_requests/25Mark modules as `Trustworthy`2023-11-06T15:57:13ZkonsumlammMark modules as `Trustworthy`This is a first step towards https://gitlab.haskell.org/ghc/packages/array/-/issues/11, to be able to use these modules as a drop-in replacement for the `*.Safe` variants.This is a first step towards https://gitlab.haskell.org/ghc/packages/array/-/issues/11, to be able to use these modules as a drop-in replacement for the `*.Safe` variants.https://gitlab.haskell.org/ghc/packages/array/-/merge_requests/14Round up unboxed Bool arrays to whole-word sizes2023-10-19T00:52:09ZMatthew Cravenclyring@gmail.comRound up unboxed Bool arrays to whole-word sizesFixes ghc/ghc#23132.Fixes ghc/ghc#23132.https://gitlab.haskell.org/ghc/packages/array/-/merge_requests/23Add `MINIMAL` pragma for `MArray`2023-09-08T15:06:36ZkonsumlammAdd `MINIMAL` pragma for `MArray`The default definition for `newArray` uses `unsafeNewArray_`, whose default definition uses `newArray`, so a `MINIMAL` pragma is required to avoid infinite recursion.The default definition for `newArray` uses `unsafeNewArray_`, whose default definition uses `newArray`, so a `MINIMAL` pragma is required to avoid infinite recursion.https://gitlab.haskell.org/ghc/packages/array/-/merge_requests/22Add version to since annotations2023-09-08T15:01:06ZkonsumlammAdd version to since annotationshttps://gitlab.haskell.org/ghc/packages/array/-/merge_requests/21Prepare v0.5.6.0 release2023-07-09T05:30:31ZLei ZhuPrepare v0.5.6.0 releaseWe need to bump the version and update the changelog before cutting a release:)We need to bump the version and update the changelog before cutting a release:)https://gitlab.haskell.org/ghc/packages/array/-/merge_requests/19Array docs constructing arrays2023-07-05T14:50:11ZLei ZhuArray docs constructing arraysRebase !5
/cc @trac-runeks @hellwolf @CarstenKoenigRebase !5
/cc @trac-runeks @hellwolf @CarstenKoenighttps://gitlab.haskell.org/ghc/packages/array/-/merge_requests/20Bump base bound to <4.202023-07-03T13:52:41ZBen GamariBump base bound to <4.20https://gitlab.haskell.org/ghc/packages/array/-/merge_requests/18Add Data.MArray.{modifyArray,modifyArray'}2023-06-18T09:58:10ZmeooowAdd Data.MArray.{modifyArray,modifyArray'}Something I've defined and used many times that feels like it should be provided by the module.
This is a commonly available function in similar modules, for example:
* [`Data.IORef.modifyIORef`](https://hackage.haskell.org/package/bas...Something I've defined and used many times that feels like it should be provided by the module.
This is a commonly available function in similar modules, for example:
* [`Data.IORef.modifyIORef`](https://hackage.haskell.org/package/base-4.18.0.0/docs/Data-IORef.html#v:modifyIORef)
* [`Data.STRef.modifySTRef`](https://hackage.haskell.org/package/base-4.18.0.0/docs/Data-STRef.html#v:modifySTRef)
* [`Data.Vector.Mutable.modify`](https://hackage.haskell.org/package/vector-0.13.0.0/docs/Data-Vector-Mutable.html#v:modify)https://gitlab.haskell.org/ghc/packages/array/-/merge_requests/13Add genArray2023-06-18T08:53:30ZJoachim Breitnermail@joachim-breitner.deAdd genArraya quite useful function that I was missing when working with
`Data.Array` recently.a quite useful function that I was missing when working with
`Data.Array` recently.https://gitlab.haskell.org/ghc/packages/array/-/merge_requests/15Add Data.Array.IArray.(!?)2023-06-18T07:43:46ZFrancesco Gazzettafgaz@fgaz.meAdd Data.Array.IArray.(!?)Similar to operators with the same name in `vector` and other libraries:
`(!?) :: (IArray a e, Ix i) => a i e -> i -> Maybe e`Similar to operators with the same name in `vector` and other libraries:
`(!?) :: (IArray a e, Ix i) => a i e -> i -> Maybe e`https://gitlab.haskell.org/ghc/packages/array/-/merge_requests/17Update note [Inlining and fusion]2023-06-15T09:56:22ZmeooowUpdate note [Inlining and fusion]Update note as suggested in https://gitlab.haskell.org/ghc/packages/array/-/merge_requests/16#note_496857.Update note as suggested in https://gitlab.haskell.org/ghc/packages/array/-/merge_requests/16#note_496857.https://gitlab.haskell.org/ghc/packages/array/-/merge_requests/11replace Haddock hide pragma with not-home to make the Haddocks more readable2023-04-25T14:01:01Zadamreplace Haddock hide pragma with not-home to make the Haddocks more readableadamadamhttps://gitlab.haskell.org/ghc/packages/array/-/merge_requests/12Use less unsafe unsafeCoerce that works with GHCJS2022-08-09T13:19:48ZSylvain HenryUse less unsafe unsafeCoerce that works with GHCJSGHCJS uses the same representation for Addr# and StablePtr#, but not for
Int#.GHCJS uses the same representation for Addr# and StablePtr#, but not for
Int#.https://gitlab.haskell.org/ghc/packages/array/-/merge_requests/8Revert "[Cmm Sized] Adjust"2021-03-02T01:25:56ZJohn EricsonRevert "[Cmm Sized] Adjust"In old GHC:
I8# :: Int# -> Int8
indexInt8OffAddr# :: Addr# -> Int# -> Int#
...
In upcoming GHC 9.2:
I8# :: Int8# -> Int8
indexInt8OffAddr# :: Addr# -> Int# -> Int8#
...
Both of those work with the last array r...In old GHC:
I8# :: Int# -> Int8
indexInt8OffAddr# :: Addr# -> Int# -> Int#
...
In upcoming GHC 9.2:
I8# :: Int8# -> Int8
indexInt8OffAddr# :: Addr# -> Int# -> Int8#
...
Both of those work with the last array release, where the only
requirement is merely that the constructor and primops agree, i.e.:
exists alpha.
I8# :: alpha -> Int8
indexInt8OffAddr# :: Addr# -> Int# -> alpha
In current GHC HEAD, we had
I8# :: Int8# -> Int8
indexInt8OffAddr# :: Addr# -> Int# -> Int#
and it was only because `Int8# /= Int#` that we needed the commit being
reverted. we are about to fix the primops to match the constructors in
accordance with the final 9.2 design, and so we don't need that commit
anymore.
This reverts commit c7a696e3e6d5a6b00d3e00ca694af916f15bcff5.https://gitlab.haskell.org/ghc/packages/array/-/merge_requests/7Use new primops names for converting numbers to and from the native size2021-02-21T19:56:13ZJohn EricsonUse new primops names for converting numbers to and from the native sizeThis is a companion to https://gitlab.haskell.org/ghc/ghc/-/merge_requests/4492.This is a companion to https://gitlab.haskell.org/ghc/ghc/-/merge_requests/4492.https://gitlab.haskell.org/ghc/packages/array/-/merge_requests/4Allow base-4.152020-06-17T18:48:29ZBen GamariAllow base-4.15