run-st 0.1.1.0 → 0.1.3.0
raw patch · 3 files changed
+44/−9 lines, 3 filesdep ~basedep ~primitive
Dependency ranges changed: base, primitive
Files
- CHANGELOG.md +6/−0
- run-st.cabal +4/−4
- src/Control/Monad/ST/Run.hs +34/−5
CHANGELOG.md view
@@ -1,5 +1,11 @@ # Revision history for run-st +## 0.1.2.0 -- 2023-05-03++* Add `runIntIntByteArrayST`+* Add `runIntLiftedTypeST`+* Add `runMaybeByteArrayST`+ ## 0.1.1.0 -- 2020-01-16 * Add support for a lot more types.
run-st.cabal view
@@ -1,13 +1,13 @@ cabal-version: 2.2 name: run-st-version: 0.1.1.0+version: 0.1.3.0 synopsis: runST without boxing penalty description: This package provides specializations of `runST` that avoid a needless data-constructor allocation for the returned value. If <https://gitlab.haskell.org/ghc/ghc/issues/15127 issue 15127> is resolved, this package will no longer be necessary.- + homepage: https://github.com/andrewthad/run-st bug-reports: https://github.com/andrewthad/run-st/issues license: BSD-3-Clause@@ -21,8 +21,8 @@ library exposed-modules: Control.Monad.ST.Run build-depends:- , base >=4.11.1 && <5- , primitive >=0.7 && <0.8+ , base >=4.12 && <5+ , primitive >=0.7 && <0.10 , primitive-unlifted >=0.1.1 && <0.2 hs-source-dirs: src default-language: Haskell2010
src/Control/Monad/ST/Run.hs view
@@ -1,4 +1,5 @@ {-# language BangPatterns #-}+{-# language KindSignatures #-} {-# language MagicHash #-} {-# language RankNTypes #-} {-# language UnboxedTuples #-}@@ -27,20 +28,25 @@ -- * Tuples , runIntArrayST , runIntByteArrayST+ , runIntLiftedTypeST+ , runIntIntByteArrayST , runWordArrayST , runWordByteArrayST+ -- * Maybes+ , runMaybeByteArrayST ) where -import GHC.Word (Word8(W8#),Word16(W16#),Word32(W32#))-import GHC.Int (Int8(I8#),Int16(I16#),Int32(I32#))-import GHC.Exts (Char(C#),Int(I#),Word(W#),runRW#)-import GHC.Exts (Double(D#),Float(F#))+import Data.Kind (Type) import Data.Primitive.Array (Array(Array))-import Data.Primitive.SmallArray (SmallArray(SmallArray)) import Data.Primitive.ByteArray (ByteArray(ByteArray)) import Data.Primitive.PrimArray (PrimArray(PrimArray))+import Data.Primitive.SmallArray (SmallArray(SmallArray)) import Data.Primitive.Unlifted.Array (UnliftedArray(UnliftedArray))+import GHC.Exts (Char(C#),Int(I#),Word(W#),runRW#)+import GHC.Exts (Double(D#),Float(F#))+import GHC.Int (Int8(I8#),Int16(I16#),Int32(I32#)) import GHC.ST (ST(ST))+import GHC.Word (Word8(W8#),Word16(W16#),Word32(W32#)) runArrayST :: (forall s. ST s (Array a)) -> Array a {-# inline runArrayST #-}@@ -118,15 +124,38 @@ let !(# t0, t1 #) = runRW# (\s0 -> case f of { ST g -> case g s0 of { (# _, ( W# r0, Array r1 ) #) -> (# r0, r1 #) }}) in (W# t0, Array t1) +runIntLiftedTypeST :: forall (a :: Type). (forall s. ST s (Int, a)) -> (Int, a)+{-# inline runIntLiftedTypeST #-}+runIntLiftedTypeST f =+ let !(# t0, t1 #) = runRW# (\s0 -> case f of { ST g -> case g s0 of { (# _, ( I# r0, r1 ) #) -> (# r0, r1 #) }})+ in (I# t0, t1)+ runIntByteArrayST :: (forall s. ST s (Int, ByteArray)) -> (Int, ByteArray) {-# inline runIntByteArrayST #-} runIntByteArrayST f = let !(# t0, t1 #) = runRW# (\s0 -> case f of { ST g -> case g s0 of { (# _, ( I# r0, ByteArray r1 ) #) -> (# r0, r1 #) }}) in (I# t0, ByteArray t1) +runIntIntByteArrayST :: (forall s. ST s (Int, Int, ByteArray)) -> (Int, Int, ByteArray)+{-# inline runIntIntByteArrayST #-}+runIntIntByteArrayST f =+ let !(# t0, t1, t2 #) = runRW# (\s0 -> case f of { ST g -> case g s0 of { (# _, ( I# r0, I# r1, ByteArray r2 ) #) -> (# r0, r1, r2 #) }})+ in (I# t0, I# t1, ByteArray t2)+ runWordByteArrayST :: (forall s. ST s (Word, ByteArray)) -> (Word, ByteArray) {-# inline runWordByteArrayST #-} runWordByteArrayST f = let !(# t0, t1 #) = runRW# (\s0 -> case f of { ST g -> case g s0 of { (# _, ( W# r0, ByteArray r1 ) #) -> (# r0, r1 #) }}) in (W# t0, ByteArray t1) +runMaybeByteArrayST :: (forall s. ST s (Maybe ByteArray)) -> Maybe ByteArray+{-# inline runMaybeByteArrayST #-}+runMaybeByteArrayST f =+ let !x = runRW#+ (\s0 -> case f of { ST g -> case g s0 of+ { (# _, Just (ByteArray r2 ) #) -> (# | r2 #)+ ; (# _, Nothing #) -> (# (# #) | #)+ }})+ in case x of+ (# (# #) | #) -> Nothing+ (# | y #) -> Just (ByteArray y)