module Dahdit.Mem
  ( IxPtr (..)
  , ReadMem (..)
  , readSBSMem
  , viewSBSMem
  , viewBSMem
  , viewVecMem
  , WriteMem (..)
  , writeSBSMem
  , allocBAMem
  , allocPtrMem
  , freezeBAMem
  , freezeSBSMem
  , freezeBSMem
  , freezeVecMem
  , mutAllocBAMem
  , mutFreezeBAMem
  , mutAllocVecMem
  , mutFreezeVecMem
  )
where

import Control.Monad.Primitive (PrimMonad (..), unsafeIOToPrim)
import Control.Monad.ST (runST)
import Dahdit.LiftedPrim (LiftedPrim (..), setByteArrayLifted)
import Dahdit.Proxy (proxyFor)
import Dahdit.Sizes (ByteCount (..), staticByteSize)
import Data.ByteString (ByteString)
import qualified Data.ByteString.Internal as BSI
import Data.ByteString.Short.Internal (ShortByteString (..))
import qualified Data.ByteString.Unsafe as BSU
import Data.Coerce (coerce)
import Data.Foldable (for_)
import Data.Primitive.ByteArray (ByteArray (..), MutableByteArray, cloneByteArray, copyByteArray, copyByteArrayToPtr, freezeByteArray, newByteArray, sizeofMutableByteArray, unsafeFreezeByteArray)
import Data.Primitive.Ptr (copyPtrToMutableByteArray)
import Data.Vector.Storable (MVector, Vector)
import qualified Data.Vector.Storable as VS
import qualified Data.Vector.Storable.Mutable as VSM
import Data.Word (Word8)
import Foreign.ForeignPtr (newForeignPtr)
import Foreign.ForeignPtr.Unsafe (unsafeForeignPtrToPtr)
import Foreign.Marshal.Alloc (callocBytes, finalizerFree, free)
import Foreign.Ptr (Ptr, plusPtr)

-- | A wrapper over 'Ptr' with an additional phantom type index to align with 'ST' state.
newtype IxPtr s = IxPtr {forall s. IxPtr s -> Ptr Word8
unIxPtr :: Ptr Word8}
  deriving stock (Int -> IxPtr s -> ShowS
forall s. Int -> IxPtr s -> ShowS
forall s. [IxPtr s] -> ShowS
forall s. IxPtr s -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [IxPtr s] -> ShowS
$cshowList :: forall s. [IxPtr s] -> ShowS
show :: IxPtr s -> String
$cshow :: forall s. IxPtr s -> String
showsPrec :: Int -> IxPtr s -> ShowS
$cshowsPrec :: forall s. Int -> IxPtr s -> ShowS
Show)
  deriving newtype (IxPtr s -> IxPtr s -> Bool
forall s. IxPtr s -> IxPtr s -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: IxPtr s -> IxPtr s -> Bool
$c/= :: forall s. IxPtr s -> IxPtr s -> Bool
== :: IxPtr s -> IxPtr s -> Bool
$c== :: forall s. IxPtr s -> IxPtr s -> Bool
Eq, IxPtr s -> IxPtr s -> Bool
IxPtr s -> IxPtr s -> Ordering
IxPtr s -> IxPtr s -> IxPtr s
forall s. Eq (IxPtr s)
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall s. IxPtr s -> IxPtr s -> Bool
forall s. IxPtr s -> IxPtr s -> Ordering
forall s. IxPtr s -> IxPtr s -> IxPtr s
min :: IxPtr s -> IxPtr s -> IxPtr s
$cmin :: forall s. IxPtr s -> IxPtr s -> IxPtr s
max :: IxPtr s -> IxPtr s -> IxPtr s
$cmax :: forall s. IxPtr s -> IxPtr s -> IxPtr s
>= :: IxPtr s -> IxPtr s -> Bool
$c>= :: forall s. IxPtr s -> IxPtr s -> Bool
> :: IxPtr s -> IxPtr s -> Bool
$c> :: forall s. IxPtr s -> IxPtr s -> Bool
<= :: IxPtr s -> IxPtr s -> Bool
$c<= :: forall s. IxPtr s -> IxPtr s -> Bool
< :: IxPtr s -> IxPtr s -> Bool
$c< :: forall s. IxPtr s -> IxPtr s -> Bool
compare :: IxPtr s -> IxPtr s -> Ordering
$ccompare :: forall s. IxPtr s -> IxPtr s -> Ordering
Ord)

class ReadMem r where
  indexMemInBytes :: LiftedPrim a => r -> ByteCount -> a
  cloneArrayMemInBytes :: r -> ByteCount -> ByteCount -> ByteArray

instance ReadMem ByteArray where
  indexMemInBytes :: forall a. LiftedPrim a => ByteArray -> ByteCount -> a
indexMemInBytes = forall a. LiftedPrim a => ByteArray -> ByteCount -> a
indexArrayLiftedInBytes
  cloneArrayMemInBytes :: ByteArray -> ByteCount -> ByteCount -> ByteArray
cloneArrayMemInBytes ByteArray
arr ByteCount
off ByteCount
len = ByteArray -> Int -> Int -> ByteArray
cloneByteArray ByteArray
arr (coerce :: forall a b. Coercible a b => a -> b
coerce ByteCount
off) (coerce :: forall a b. Coercible a b => a -> b
coerce ByteCount
len)

clonePtr :: Ptr Word8 -> ByteCount -> ByteCount -> ByteArray
clonePtr :: Ptr Word8 -> ByteCount -> ByteCount -> ByteArray
clonePtr Ptr Word8
ptr ByteCount
off ByteCount
len = forall a. (forall s. ST s a) -> a
runST forall a b. (a -> b) -> a -> b
$ do
  let wptr :: Ptr Word8
wptr = coerce :: forall a b. Coercible a b => a -> b
coerce (forall a b. Ptr a -> Int -> Ptr b
plusPtr Ptr Word8
ptr (coerce :: forall a b. Coercible a b => a -> b
coerce ByteCount
off)) :: Ptr Word8
  MutableByteArray s
marr <- forall (m :: * -> *).
PrimMonad m =>
Int -> m (MutableByteArray (PrimState m))
newByteArray (coerce :: forall a b. Coercible a b => a -> b
coerce ByteCount
len)
  forall (m :: * -> *) a.
(PrimMonad m, Prim a) =>
MutableByteArray (PrimState m) -> Int -> Ptr a -> Int -> m ()
copyPtrToMutableByteArray MutableByteArray s
marr Int
0 Ptr Word8
wptr (coerce :: forall a b. Coercible a b => a -> b
coerce ByteCount
len)
  forall (m :: * -> *).
PrimMonad m =>
MutableByteArray (PrimState m) -> m ByteArray
unsafeFreezeByteArray MutableByteArray s
marr

instance ReadMem (Ptr Word8) where
  indexMemInBytes :: forall a. LiftedPrim a => Ptr Word8 -> ByteCount -> a
indexMemInBytes = forall a. LiftedPrim a => Ptr Word8 -> ByteCount -> a
indexPtrLiftedInBytes
  cloneArrayMemInBytes :: Ptr Word8 -> ByteCount -> ByteCount -> ByteArray
cloneArrayMemInBytes = Ptr Word8 -> ByteCount -> ByteCount -> ByteArray
clonePtr

readSBSMem :: ReadMem r => r -> ByteCount -> ByteCount -> ShortByteString
readSBSMem :: forall r.
ReadMem r =>
r -> ByteCount -> ByteCount -> ShortByteString
readSBSMem r
mem ByteCount
off ByteCount
len = let !(ByteArray ByteArray#
frozArr) = forall r. ReadMem r => r -> ByteCount -> ByteCount -> ByteArray
cloneArrayMemInBytes r
mem ByteCount
off ByteCount
len in ByteArray# -> ShortByteString
SBS ByteArray#
frozArr

viewSBSMem :: ShortByteString -> ByteArray
viewSBSMem :: ShortByteString -> ByteArray
viewSBSMem (SBS ByteArray#
harr) = ByteArray# -> ByteArray
ByteArray ByteArray#
harr

viewBSMem :: ByteString -> Ptr Word8
viewBSMem :: ByteString -> Ptr Word8
viewBSMem ByteString
bs =
  let (ForeignPtr Word8
fp, Int
_) = ByteString -> (ForeignPtr Word8, Int)
BSI.toForeignPtr0 ByteString
bs
  in  forall a. ForeignPtr a -> Ptr a
unsafeForeignPtrToPtr ForeignPtr Word8
fp

viewVecMem :: Vector Word8 -> Ptr Word8
viewVecMem :: Vector Word8 -> Ptr Word8
viewVecMem Vector Word8
vec =
  let (ForeignPtr Word8
fp, Int
_) = forall a. Storable a => Vector a -> (ForeignPtr a, Int)
VS.unsafeToForeignPtr0 Vector Word8
vec
  in  forall a. ForeignPtr a -> Ptr a
unsafeForeignPtrToPtr ForeignPtr Word8
fp

mutViewVecMem :: MVector s Word8 -> Ptr Word8
mutViewVecMem :: forall s. MVector s Word8 -> Ptr Word8
mutViewVecMem MVector s Word8
mvec =
  let (ForeignPtr Word8
fp, Int
_) = forall a s. Storable a => MVector s a -> (ForeignPtr a, Int)
VSM.unsafeToForeignPtr0 MVector s Word8
mvec
  in  forall a. ForeignPtr a -> Ptr a
unsafeForeignPtrToPtr ForeignPtr Word8
fp

class PrimMonad m => WriteMem q m where
  writeMemInBytes :: LiftedPrim a => a -> q (PrimState m) -> ByteCount -> m ()
  copyArrayMemInBytes :: ByteArray -> ByteCount -> ByteCount -> q (PrimState m) -> ByteCount -> m ()
  setMemInBytes :: LiftedPrim a => ByteCount -> a -> q (PrimState m) -> ByteCount -> m ()

instance PrimMonad m => WriteMem MutableByteArray m where
  writeMemInBytes :: forall a.
LiftedPrim a =>
a -> MutableByteArray (PrimState m) -> ByteCount -> m ()
writeMemInBytes a
val MutableByteArray (PrimState m)
mem ByteCount
off = forall a (m :: * -> *).
(LiftedPrim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> ByteCount -> a -> m ()
writeArrayLiftedInBytes MutableByteArray (PrimState m)
mem ByteCount
off a
val
  copyArrayMemInBytes :: ByteArray
-> ByteCount
-> ByteCount
-> MutableByteArray (PrimState m)
-> ByteCount
-> m ()
copyArrayMemInBytes ByteArray
arr ByteCount
arrOff ByteCount
arrLen MutableByteArray (PrimState m)
mem ByteCount
off = forall (m :: * -> *).
PrimMonad m =>
MutableByteArray (PrimState m)
-> Int -> ByteArray -> Int -> Int -> m ()
copyByteArray MutableByteArray (PrimState m)
mem (coerce :: forall a b. Coercible a b => a -> b
coerce ByteCount
off) ByteArray
arr (coerce :: forall a b. Coercible a b => a -> b
coerce ByteCount
arrOff) (coerce :: forall a b. Coercible a b => a -> b
coerce ByteCount
arrLen)
  setMemInBytes :: forall a.
LiftedPrim a =>
ByteCount
-> a -> MutableByteArray (PrimState m) -> ByteCount -> m ()
setMemInBytes ByteCount
len a
val MutableByteArray (PrimState m)
mem ByteCount
off = forall (m :: * -> *) a.
(PrimMonad m, LiftedPrim a) =>
MutableByteArray (PrimState m)
-> ByteCount -> ByteCount -> a -> m ()
setByteArrayLifted MutableByteArray (PrimState m)
mem ByteCount
off ByteCount
len a
val

copyPtr :: PrimMonad m => ByteArray -> ByteCount -> ByteCount -> Ptr Word8 -> ByteCount -> m ()
copyPtr :: forall (m :: * -> *).
PrimMonad m =>
ByteArray
-> ByteCount -> ByteCount -> Ptr Word8 -> ByteCount -> m ()
copyPtr ByteArray
arr ByteCount
arrOff ByteCount
arrLen Ptr Word8
ptr ByteCount
off =
  let wptr :: Ptr Word8
wptr = coerce :: forall a b. Coercible a b => a -> b
coerce (forall a b. Ptr a -> Int -> Ptr b
plusPtr Ptr Word8
ptr (coerce :: forall a b. Coercible a b => a -> b
coerce ByteCount
off)) :: Ptr Word8
  in  forall (m :: * -> *) a.
(PrimMonad m, Prim a) =>
Ptr a -> ByteArray -> Int -> Int -> m ()
copyByteArrayToPtr Ptr Word8
wptr ByteArray
arr (coerce :: forall a b. Coercible a b => a -> b
coerce ByteCount
arrOff) (coerce :: forall a b. Coercible a b => a -> b
coerce ByteCount
arrLen)

setPtr :: (PrimMonad m, LiftedPrim a) => ByteCount -> a -> Ptr Word8 -> ByteCount -> m ()
setPtr :: forall (m :: * -> *) a.
(PrimMonad m, LiftedPrim a) =>
ByteCount -> a -> Ptr Word8 -> ByteCount -> m ()
setPtr ByteCount
len a
val Ptr Word8
ptr ByteCount
off = do
  let elemSize :: ByteCount
elemSize = forall a. StaticByteSized a => Proxy a -> ByteCount
staticByteSize (forall a. a -> Proxy a
proxyFor a
val)
      elemLen :: ByteCount
elemLen = forall a. Integral a => a -> a -> a
div (coerce :: forall a b. Coercible a b => a -> b
coerce ByteCount
len) ByteCount
elemSize
  forall (t :: * -> *) (f :: * -> *) a b.
(Foldable t, Applicative f) =>
t a -> (a -> f b) -> f ()
for_ [ByteCount
0 .. ByteCount
elemLen forall a. Num a => a -> a -> a
- ByteCount
1] forall a b. (a -> b) -> a -> b
$ \ByteCount
pos ->
    forall a (m :: * -> *).
(LiftedPrim a, PrimMonad m) =>
Ptr Word8 -> ByteCount -> a -> m ()
writePtrLiftedInBytes Ptr Word8
ptr (ByteCount
off forall a. Num a => a -> a -> a
+ ByteCount
pos forall a. Num a => a -> a -> a
* ByteCount
elemSize) a
val

instance PrimMonad m => WriteMem IxPtr m where
  writeMemInBytes :: forall a.
LiftedPrim a =>
a -> IxPtr (PrimState m) -> ByteCount -> m ()
writeMemInBytes a
val IxPtr (PrimState m)
mem ByteCount
off = forall a (m :: * -> *).
(LiftedPrim a, PrimMonad m) =>
Ptr Word8 -> ByteCount -> a -> m ()
writePtrLiftedInBytes (forall s. IxPtr s -> Ptr Word8
unIxPtr IxPtr (PrimState m)
mem) ByteCount
off a
val
  copyArrayMemInBytes :: ByteArray
-> ByteCount
-> ByteCount
-> IxPtr (PrimState m)
-> ByteCount
-> m ()
copyArrayMemInBytes ByteArray
arr ByteCount
arrOff ByteCount
arrLen = forall (m :: * -> *).
PrimMonad m =>
ByteArray
-> ByteCount -> ByteCount -> Ptr Word8 -> ByteCount -> m ()
copyPtr ByteArray
arr ByteCount
arrOff ByteCount
arrLen forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s. IxPtr s -> Ptr Word8
unIxPtr
  setMemInBytes :: forall a.
LiftedPrim a =>
ByteCount -> a -> IxPtr (PrimState m) -> ByteCount -> m ()
setMemInBytes ByteCount
len a
val = forall (m :: * -> *) a.
(PrimMonad m, LiftedPrim a) =>
ByteCount -> a -> Ptr Word8 -> ByteCount -> m ()
setPtr ByteCount
len a
val forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s. IxPtr s -> Ptr Word8
unIxPtr

writeSBSMem :: WriteMem q m => ShortByteString -> ByteCount -> q (PrimState m) -> ByteCount -> m ()
writeSBSMem :: forall (q :: * -> *) (m :: * -> *).
WriteMem q m =>
ShortByteString
-> ByteCount -> q (PrimState m) -> ByteCount -> m ()
writeSBSMem (SBS ByteArray#
harr) = forall (q :: * -> *) (m :: * -> *).
WriteMem q m =>
ByteArray
-> ByteCount -> ByteCount -> q (PrimState m) -> ByteCount -> m ()
copyArrayMemInBytes (ByteArray# -> ByteArray
ByteArray ByteArray#
harr) ByteCount
0

freezeBAMem :: PrimMonad m => MutableByteArray (PrimState m) -> ByteCount -> ByteCount -> m ByteArray
freezeBAMem :: forall (m :: * -> *).
PrimMonad m =>
MutableByteArray (PrimState m)
-> ByteCount -> ByteCount -> m ByteArray
freezeBAMem MutableByteArray (PrimState m)
marr (ByteCount Int
startOff) (ByteCount Int
endOff) =
  if Int
startOff forall a. Eq a => a -> a -> Bool
== Int
0 Bool -> Bool -> Bool
&& Int
endOff forall a. Eq a => a -> a -> Bool
== forall s. MutableByteArray s -> Int
sizeofMutableByteArray MutableByteArray (PrimState m)
marr
    then forall (m :: * -> *).
PrimMonad m =>
MutableByteArray (PrimState m) -> m ByteArray
unsafeFreezeByteArray MutableByteArray (PrimState m)
marr
    else forall (m :: * -> *).
PrimMonad m =>
MutableByteArray (PrimState m) -> Int -> Int -> m ByteArray
freezeByteArray MutableByteArray (PrimState m)
marr Int
startOff (Int
endOff forall a. Num a => a -> a -> a
- Int
startOff)

freezeSBSMem :: PrimMonad m => MutableByteArray (PrimState m) -> ByteCount -> ByteCount -> m ShortByteString
freezeSBSMem :: forall (m :: * -> *).
PrimMonad m =>
MutableByteArray (PrimState m)
-> ByteCount -> ByteCount -> m ShortByteString
freezeSBSMem MutableByteArray (PrimState m)
marr ByteCount
startOff ByteCount
endOff = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\(ByteArray ByteArray#
harr) -> ByteArray# -> ShortByteString
SBS ByteArray#
harr) (forall (m :: * -> *).
PrimMonad m =>
MutableByteArray (PrimState m)
-> ByteCount -> ByteCount -> m ByteArray
freezeBAMem MutableByteArray (PrimState m)
marr ByteCount
startOff ByteCount
endOff)

freezeBSMem :: PrimMonad m => IxPtr (PrimState m) -> ByteCount -> ByteCount -> m ByteString
freezeBSMem :: forall (m :: * -> *).
PrimMonad m =>
IxPtr (PrimState m) -> ByteCount -> ByteCount -> m ByteString
freezeBSMem (IxPtr Ptr Word8
ptr) ByteCount
startOff ByteCount
endOff =
  forall (m :: * -> *) a. PrimMonad m => IO a -> m a
unsafeIOToPrim forall a b. (a -> b) -> a -> b
$
    Ptr Word8 -> Int -> IO () -> IO ByteString
BSU.unsafePackCStringFinalizer
      (forall a b. Ptr a -> Int -> Ptr b
plusPtr Ptr Word8
ptr (ByteCount -> Int
unByteCount ByteCount
startOff))
      (ByteCount -> Int
unByteCount (ByteCount
endOff forall a. Num a => a -> a -> a
- ByteCount
startOff))
      (forall a. Ptr a -> IO ()
free Ptr Word8
ptr)

freezeVecMem :: PrimMonad m => IxPtr (PrimState m) -> ByteCount -> ByteCount -> m (Vector Word8)
freezeVecMem :: forall (m :: * -> *).
PrimMonad m =>
IxPtr (PrimState m) -> ByteCount -> ByteCount -> m (Vector Word8)
freezeVecMem (IxPtr Ptr Word8
ptr) ByteCount
_ ByteCount
len = forall (m :: * -> *) a. PrimMonad m => IO a -> m a
unsafeIOToPrim (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\ForeignPtr Word8
fp -> forall a. Storable a => ForeignPtr a -> Int -> Vector a
VS.unsafeFromForeignPtr0 ForeignPtr Word8
fp (coerce :: forall a b. Coercible a b => a -> b
coerce ByteCount
len)) (forall a. FinalizerPtr a -> Ptr a -> IO (ForeignPtr a)
newForeignPtr forall a. FinalizerPtr a
finalizerFree Ptr Word8
ptr))

allocPtrMem :: PrimMonad m => ByteCount -> ByteCount -> m (IxPtr (PrimState m), Maybe (IO ()))
allocPtrMem :: forall (m :: * -> *).
PrimMonad m =>
ByteCount -> ByteCount -> m (IxPtr (PrimState m), Maybe (IO ()))
allocPtrMem ByteCount
off ByteCount
len = do
  let cap :: ByteCount
cap = ByteCount
off forall a. Num a => a -> a -> a
+ ByteCount
len
  Ptr Word8
ptr <- forall (m :: * -> *) a. PrimMonad m => IO a -> m a
unsafeIOToPrim (forall a. Int -> IO (Ptr a)
callocBytes (ByteCount -> Int
unByteCount ByteCount
cap))
  forall (f :: * -> *) a. Applicative f => a -> f a
pure (forall s. Ptr Word8 -> IxPtr s
IxPtr Ptr Word8
ptr, forall a. a -> Maybe a
Just (forall a. Ptr a -> IO ()
free Ptr Word8
ptr))

allocBAMem :: PrimMonad m => ByteCount -> ByteCount -> m (MutableByteArray (PrimState m), Maybe (IO ()))
allocBAMem :: forall (m :: * -> *).
PrimMonad m =>
ByteCount
-> ByteCount -> m (MutableByteArray (PrimState m), Maybe (IO ()))
allocBAMem ByteCount
off ByteCount
len = do
  let cap :: ByteCount
cap = ByteCount
off forall a. Num a => a -> a -> a
+ ByteCount
len
  MutableByteArray (PrimState m)
arr <- forall (m :: * -> *).
PrimMonad m =>
Int -> m (MutableByteArray (PrimState m))
newByteArray (ByteCount -> Int
unByteCount ByteCount
cap)
  forall (f :: * -> *) a. Applicative f => a -> f a
pure (MutableByteArray (PrimState m)
arr, forall a. Maybe a
Nothing)

mutAllocBAMem :: PrimMonad m => MutableByteArray (PrimState m) -> ByteCount -> ByteCount -> m (MutableByteArray (PrimState m), Maybe (IO ()))
mutAllocBAMem :: forall (m :: * -> *).
PrimMonad m =>
MutableByteArray (PrimState m)
-> ByteCount
-> ByteCount
-> m (MutableByteArray (PrimState m), Maybe (IO ()))
mutAllocBAMem MutableByteArray (PrimState m)
u ByteCount
_ ByteCount
_ = forall (f :: * -> *) a. Applicative f => a -> f a
pure (MutableByteArray (PrimState m)
u, forall a. Maybe a
Nothing)

mutFreezeBAMem :: PrimMonad m => MutableByteArray (PrimState m) -> ByteCount -> ByteCount -> m ByteCount
mutFreezeBAMem :: forall (m :: * -> *).
PrimMonad m =>
MutableByteArray (PrimState m)
-> ByteCount -> ByteCount -> m ByteCount
mutFreezeBAMem MutableByteArray (PrimState m)
_ ByteCount
_ = forall (f :: * -> *) a. Applicative f => a -> f a
pure

mutAllocVecMem :: PrimMonad m => MVector (PrimState m) Word8 -> ByteCount -> ByteCount -> m (IxPtr (PrimState m), Maybe (IO ()))
mutAllocVecMem :: forall (m :: * -> *).
PrimMonad m =>
MVector (PrimState m) Word8
-> ByteCount -> ByteCount -> m (IxPtr (PrimState m), Maybe (IO ()))
mutAllocVecMem MVector (PrimState m) Word8
u ByteCount
_ ByteCount
_ = forall (f :: * -> *) a. Applicative f => a -> f a
pure (forall s. Ptr Word8 -> IxPtr s
IxPtr (forall s. MVector s Word8 -> Ptr Word8
mutViewVecMem MVector (PrimState m) Word8
u), forall a. Maybe a
Nothing)

mutFreezeVecMem :: PrimMonad m => IxPtr (PrimState m) -> ByteCount -> ByteCount -> m ByteCount
mutFreezeVecMem :: forall (m :: * -> *).
PrimMonad m =>
IxPtr (PrimState m) -> ByteCount -> ByteCount -> m ByteCount
mutFreezeVecMem IxPtr (PrimState m)
_ ByteCount
_ = forall (f :: * -> *) a. Applicative f => a -> f a
pure