Skip to content

Commit

Permalink
Remove dependency on run-st library
Browse files Browse the repository at this point in the history
A simple test has been added at sample/TakeLetter.hs. This demonstrates that
there is no regression to the GHC Core from replacing runByteArrayST
with runST.
  • Loading branch information
andrewthad committed Feb 26, 2024
1 parent 119baed commit cbe865b
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 10 deletions.
1 change: 0 additions & 1 deletion bytesmith.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ library
, contiguous >=0.6 && <0.7
, natural-arithmetic >=0.1.3
, primitive >=0.7 && <0.10
, run-st >=0.1 && <0.2
, text-short >=0.1.3 && <0.2
, wide-word >=0.1.0.9 && <0.2

Expand Down
17 changes: 17 additions & 0 deletions sample/TakeLetter.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{-# language MagicHash #-}

-- Build with:
-- ghc -fforce-recomp -O2 -ddump-simpl -dsuppress-all -ddump-to-file sample/TakeLetter.hs
-- to examine GHC optimizations.
module TakeLetter
( takeLetter
) where

import Data.Bytes.Parser (Parser)
import Data.Text.Short (ShortText)
import Data.Bytes.Parser.Ascii (takeShortWhile)
import GHC.Exts

takeLetter :: Parser e s ShortText
{-# noinline takeLetter #-}
takeLetter = takeShortWhile (== 'A')
6 changes: 3 additions & 3 deletions src/Data/Bytes/Parser/Ascii.hs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ module Data.Bytes.Parser.Ascii

import Prelude hiding (any, fail, length, takeWhile)

import Control.Monad.ST.Run (runByteArrayST)
import Control.Monad.ST (runST)
import Data.Bits (clearBit)
import Data.Bytes.Parser.Internal (Parser (..), Result (..), Result#, indexLatinCharArray, uneffectful, uneffectful#, upcastUnitSuccess)
import Data.Bytes.Types (Bytes (..))
Expand Down Expand Up @@ -115,7 +115,7 @@ takeShortWhile p = do
end <- Unsafe.cursor
src <- Unsafe.expose
let len = end - start
!r = runByteArrayST $ do
!r = runST $ do
marr <- PM.newByteArray len
PM.copyByteArray marr 0 src start len
PM.unsafeFreezeByteArray marr
Expand All @@ -136,7 +136,7 @@ shortTrailedBy e !c = do
end <- Unsafe.cursor
src <- Unsafe.expose
let len = end - start - 1
!r = runByteArrayST $ do
!r = runST $ do
marr <- PM.newByteArray len
PM.copyByteArray marr 0 src start len
PM.unsafeFreezeByteArray marr
Expand Down
12 changes: 6 additions & 6 deletions src/Data/Bytes/Parser/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ module Data.Bytes.Parser.Internal
import Prelude hiding (any, fail, length, takeWhile)

import Control.Applicative (Alternative)
import Control.Monad.ST.Run (runByteArrayST)
import Control.Monad.ST (runST)
import Data.Bytes.Types (Bytes (..))
import Data.Kind (Type)
import Data.Primitive (ByteArray (ByteArray))
Expand Down Expand Up @@ -169,7 +169,7 @@ upcastUnitSuccess :: (# Int#, Int# #) -> Result# e ()
upcastUnitSuccess (# b, c #) = (# | (# (), b, c #) #)

swapArray16 :: Bytes -> ByteArray
swapArray16 (Bytes {array, offset, length}) = runByteArrayST $ do
swapArray16 (Bytes {array, offset, length}) = runST $ do
dst <- PM.newByteArray length
let go !ixSrc !ixDst !len =
if len > 0
Expand All @@ -184,7 +184,7 @@ swapArray16 (Bytes {array, offset, length}) = runByteArrayST $ do
PM.unsafeFreezeByteArray dst

swapArray32 :: Bytes -> ByteArray
swapArray32 (Bytes {array, offset, length}) = runByteArrayST $ do
swapArray32 (Bytes {array, offset, length}) = runST $ do
dst <- PM.newByteArray length
let go !ixSrc !ixDst !len =
if len > 0
Expand All @@ -203,7 +203,7 @@ swapArray32 (Bytes {array, offset, length}) = runByteArrayST $ do
PM.unsafeFreezeByteArray dst

swapArray64 :: Bytes -> ByteArray
swapArray64 (Bytes {array, offset, length}) = runByteArrayST $ do
swapArray64 (Bytes {array, offset, length}) = runST $ do
dst <- PM.newByteArray length
let go !ixSrc !ixDst !len =
if len > 0
Expand All @@ -230,7 +230,7 @@ swapArray64 (Bytes {array, offset, length}) = runByteArrayST $ do
PM.unsafeFreezeByteArray dst

swapArray128 :: Bytes -> ByteArray
swapArray128 (Bytes {array, offset, length}) = runByteArrayST $ do
swapArray128 (Bytes {array, offset, length}) = runST $ do
dst <- PM.newByteArray length
let go !ixSrc !ixDst !len =
if len > 0
Expand Down Expand Up @@ -273,7 +273,7 @@ swapArray128 (Bytes {array, offset, length}) = runByteArrayST $ do
PM.unsafeFreezeByteArray dst

swapArray256 :: Bytes -> ByteArray
swapArray256 (Bytes {array, offset, length}) = runByteArrayST $ do
swapArray256 (Bytes {array, offset, length}) = runST $ do
dst <- PM.newByteArray length
let go !ixSrc !ixDst !len =
if len > 0
Expand Down

0 comments on commit cbe865b

Please sign in to comment.