{-# LANGUAGE CPP #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE Unsafe #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE MagicHash #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ViewPatterns #-}
{-# LANGUAGE UnboxedTuples #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE DefaultSignatures #-}
#if __GLASGOW_HASKELL__ < 806
{-# LANGUAGE TypeInType #-}
#endif
{-# OPTIONS_HADDOCK not-home #-}
module Data.Struct.Internal where
import Control.Exception
import Control.Monad.Primitive
import Control.Monad.ST
import Data.Primitive
import Data.Coerce
import GHC.Exts
#if MIN_VERSION_base(4,15,0)
import Unsafe.Coerce (unsafeCoerceUnlifted)
#endif
#ifdef HLINT
{-# ANN module "HLint: ignore Eta reduce" #-}
{-# ANN module "HLint: ignore Unused LANGUAGE pragma" #-}
{-# ANN module "HLint: ignore Avoid lambda" #-}
{-# ANN module "HLint: ignore Redundant lambda" #-}
#endif
data NullPointerException = NullPointerException deriving (Int -> NullPointerException -> ShowS
[NullPointerException] -> ShowS
NullPointerException -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [NullPointerException] -> ShowS
$cshowList :: [NullPointerException] -> ShowS
show :: NullPointerException -> String
$cshow :: NullPointerException -> String
showsPrec :: Int -> NullPointerException -> ShowS
$cshowsPrec :: Int -> NullPointerException -> ShowS
Show, Show NullPointerException
Typeable NullPointerException
SomeException -> Maybe NullPointerException
NullPointerException -> String
NullPointerException -> SomeException
forall e.
Typeable e
-> Show e
-> (e -> SomeException)
-> (SomeException -> Maybe e)
-> (e -> String)
-> Exception e
displayException :: NullPointerException -> String
$cdisplayException :: NullPointerException -> String
fromException :: SomeException -> Maybe NullPointerException
$cfromException :: SomeException -> Maybe NullPointerException
toException :: NullPointerException -> SomeException
$ctoException :: NullPointerException -> SomeException
Exception)
data Dict p where
Dict :: p => Dict p
st :: PrimMonad m => ST (PrimState m) a -> m a
st :: forall (m :: * -> *) a. PrimMonad m => ST (PrimState m) a -> m a
st = forall (m1 :: * -> *) (m2 :: * -> *) a.
(PrimBase m1, PrimMonad m2, PrimState m1 ~ PrimState m2) =>
m1 a -> m2 a
primToPrim
{-# INLINE[0] st #-}
class Struct t where
struct :: Dict (Coercible (t s) (Object s))
#ifndef HLINT
default struct :: Coercible (t s) (Object s) => Dict (Coercible (t s) (Object s))
#endif
struct = forall (p :: Constraint). p => Dict p
Dict
{-# MINIMAL #-}
data Object s = Object { forall s. Object s -> SmallMutableArray# s Any
runObject :: SmallMutableArray# s Any }
instance Struct Object
coerceF :: Dict (Coercible a b) -> a -> b
coerceF :: forall a b. Dict (Coercible a b) -> a -> b
coerceF Dict (Coercible a b)
Dict = coerce :: forall a b. Coercible a b => a -> b
coerce
{-# INLINE coerceF #-}
coerceB :: Dict (Coercible a b) -> b -> a
coerceB :: forall a b. Dict (Coercible a b) -> b -> a
coerceB Dict (Coercible a b)
Dict = coerce :: forall a b. Coercible a b => a -> b
coerce
{-# INLINE coerceB #-}
destruct :: Struct t => t s -> SmallMutableArray# s Any
destruct :: forall (t :: * -> *) s. Struct t => t s -> SmallMutableArray# s Any
destruct = \t s
x -> forall s. Object s -> SmallMutableArray# s Any
runObject (forall a b. Dict (Coercible a b) -> a -> b
coerceF forall (t :: * -> *) s.
Struct t =>
Dict (Coercible (t s) (Object s))
struct t s
x)
{-# INLINE destruct #-}
construct :: Struct t => SmallMutableArray# s Any -> t s
construct :: forall (t :: * -> *) s. Struct t => SmallMutableArray# s Any -> t s
construct = \SmallMutableArray# s Any
x -> forall a b. Dict (Coercible a b) -> b -> a
coerceB forall (t :: * -> *) s.
Struct t =>
Dict (Coercible (t s) (Object s))
struct (forall s. SmallMutableArray# s Any -> Object s
Object SmallMutableArray# s Any
x)
{-# INLINE construct #-}
unsafeCoerceStruct :: (Struct x, Struct y) => x s -> y s
unsafeCoerceStruct :: forall (x :: * -> *) (y :: * -> *) s.
(Struct x, Struct y) =>
x s -> y s
unsafeCoerceStruct x s
x = forall (t :: * -> *) s. Struct t => SmallMutableArray# s Any -> t s
construct (forall (t :: * -> *) s. Struct t => t s -> SmallMutableArray# s Any
destruct x s
x)
eqStruct :: Struct t => t s -> t s -> Bool
eqStruct :: forall (t :: * -> *) s. Struct t => t s -> t s -> Bool
eqStruct = \t s
x t s
y -> Int# -> Bool
isTrue# (forall (t :: * -> *) s. Struct t => t s -> SmallMutableArray# s Any
destruct t s
x forall d a.
SmallMutableArray# d a -> SmallMutableArray# d a -> Int#
`sameSmallMutableArray#` forall (t :: * -> *) s. Struct t => t s -> SmallMutableArray# s Any
destruct t s
y)
{-# INLINE eqStruct #-}
instance Eq (Object s) where
== :: Object s -> Object s -> Bool
(==) = forall (t :: * -> *) s. Struct t => t s -> t s -> Bool
eqStruct
#ifndef HLINT
pattern Struct :: Struct t => () => SmallMutableArray# s Any -> t s
pattern $bStruct :: forall (t :: * -> *) s. Struct t => SmallMutableArray# s Any -> t s
$mStruct :: forall {r} {t :: * -> *} {s}.
Struct t =>
t s -> (SmallMutableArray# s Any -> r) -> ((# #) -> r) -> r
Struct x <- (destruct -> x) where
Struct SmallMutableArray# s Any
x = forall (t :: * -> *) s. Struct t => SmallMutableArray# s Any -> t s
construct SmallMutableArray# s Any
x
#endif
alloc :: (PrimMonad m, Struct t) => Int -> m (t (PrimState m))
alloc :: forall (m :: * -> *) (t :: * -> *).
(PrimMonad m, Struct t) =>
Int -> m (t (PrimState m))
alloc (I# Int#
n#) = forall (m :: * -> *) a.
PrimMonad m =>
(State# (PrimState m) -> (# State# (PrimState m), a #)) -> m a
primitive forall a b. (a -> b) -> a -> b
$ \State# (PrimState m)
s -> case forall a d.
Int# -> a -> State# d -> (# State# d, SmallMutableArray# d a #)
newSmallArray# Int#
n# forall a. HasCallStack => a
undefined State# (PrimState m)
s of (# State# (PrimState m)
s', SmallMutableArray# (PrimState m) Any
b #) -> (# State# (PrimState m)
s', forall (t :: * -> *) s. Struct t => SmallMutableArray# s Any -> t s
construct SmallMutableArray# (PrimState m) Any
b #)
data Box = Box Null
data Null = Null
isNil :: Struct t => t s -> Bool
isNil :: forall (t :: * -> *) s. Struct t => t s -> Bool
isNil t s
t = Int# -> Bool
isTrue# (
#if MIN_VERSION_base(4,17,0)
reallyUnsafePtrEquality#
#else
unsafeCoerce# :: forall a b. a -> b
unsafeCoerce# forall a. a -> a -> Int#
reallyUnsafePtrEquality#
#endif
(forall (t :: * -> *) s. Struct t => t s -> SmallMutableArray# s Any
destruct t s
t) Null
Null)
{-# INLINE isNil #-}
#ifndef HLINT
pattern Nil :: Struct t => () => t s
pattern $bNil :: forall (t :: * -> *) s. Struct t => t s
$mNil :: forall {r} {t :: * -> *} {s}.
Struct t =>
t s -> ((# #) -> r) -> ((# #) -> r) -> r
Nil <- (isNil -> True) where
Nil = unsafeCoerce# :: forall a b. a -> b
unsafeCoerce# Null -> Box
Box Null
Null
#endif
writeSmallMutableArraySmallArray# :: SmallMutableArray# s Any -> Int# -> SmallMutableArray# s Any -> State# s -> State# s
#if MIN_VERSION_base(4,17,0)
writeSmallMutableArraySmallArray# m i a s = writeSmallArray# (unsafeCoerceUnlifted m) i a s
#else
writeSmallMutableArraySmallArray# :: forall s.
SmallMutableArray# s Any
-> Int# -> SmallMutableArray# s Any -> State# s -> State# s
writeSmallMutableArraySmallArray# SmallMutableArray# s Any
m Int#
i SmallMutableArray# s Any
a State# s
s = unsafeCoerce# :: forall a b. a -> b
unsafeCoerce# forall d a.
SmallMutableArray# d a -> Int# -> a -> State# d -> State# d
writeSmallArray# SmallMutableArray# s Any
m Int#
i SmallMutableArray# s Any
a State# s
s
#endif
{-# INLINE writeSmallMutableArraySmallArray# #-}
readSmallMutableArraySmallArray# :: SmallMutableArray# s Any -> Int# -> State# s -> (# State# s, SmallMutableArray# s Any #)
#if MIN_VERSION_base(4,17,0)
readSmallMutableArraySmallArray# m i s = readSmallArray# (unsafeCoerceUnlifted m) i s
#else
readSmallMutableArraySmallArray# :: forall s.
SmallMutableArray# s Any
-> Int# -> State# s -> (# State# s, SmallMutableArray# s Any #)
readSmallMutableArraySmallArray# SmallMutableArray# s Any
m Int#
i State# s
s = unsafeCoerce# :: forall a b. a -> b
unsafeCoerce# forall d a.
SmallMutableArray# d a -> Int# -> State# d -> (# State# d, a #)
readSmallArray# SmallMutableArray# s Any
m Int#
i State# s
s
#endif
{-# INLINE readSmallMutableArraySmallArray# #-}
writeMutableByteArraySmallArray# :: SmallMutableArray# s Any -> Int# -> MutableByteArray# s -> State# s -> State# s
#if MIN_VERSION_base(4,17,0)
writeMutableByteArraySmallArray# m i a s = writeSmallArray# (unsafeCoerceUnlifted m) i a s
#else
writeMutableByteArraySmallArray# :: forall s.
SmallMutableArray# s Any
-> Int# -> MutableByteArray# s -> State# s -> State# s
writeMutableByteArraySmallArray# SmallMutableArray# s Any
m Int#
i MutableByteArray# s
a State# s
s = unsafeCoerce# :: forall a b. a -> b
unsafeCoerce# forall d a.
SmallMutableArray# d a -> Int# -> a -> State# d -> State# d
writeSmallArray# SmallMutableArray# s Any
m Int#
i MutableByteArray# s
a State# s
s
#endif
{-# INLINE writeMutableByteArraySmallArray# #-}
readMutableByteArraySmallArray# :: SmallMutableArray# s Any -> Int# -> State# s -> (# State# s, MutableByteArray# s #)
#if MIN_VERSION_base(4,17,0)
readMutableByteArraySmallArray# m i s = readSmallArray# (unsafeCoerceUnlifted m) i s
#else
readMutableByteArraySmallArray# :: forall s.
SmallMutableArray# s Any
-> Int# -> State# s -> (# State# s, MutableByteArray# s #)
readMutableByteArraySmallArray# SmallMutableArray# s Any
m Int#
i State# s
s = unsafeCoerce# :: forall a b. a -> b
unsafeCoerce# forall d a.
SmallMutableArray# d a -> Int# -> State# d -> (# State# d, a #)
readSmallArray# SmallMutableArray# s Any
m Int#
i State# s
s
#endif
{-# INLINE readMutableByteArraySmallArray# #-}
casSmallMutableArraySmallArray# :: SmallMutableArray# s Any -> Int# -> SmallMutableArray# s Any -> SmallMutableArray# s Any -> State# s -> (# State# s, Int#, SmallMutableArray# s Any #)
#if MIN_VERSION_base(4,17,0)
casSmallMutableArraySmallArray# m i o n s = casSmallArray# (unsafeCoerceUnlifted m) i o n s
#else
casSmallMutableArraySmallArray# :: forall s.
SmallMutableArray# s Any
-> Int#
-> SmallMutableArray# s Any
-> SmallMutableArray# s Any
-> State# s
-> (# State# s, Int#, SmallMutableArray# s Any #)
casSmallMutableArraySmallArray# SmallMutableArray# s Any
m Int#
i SmallMutableArray# s Any
o SmallMutableArray# s Any
n State# s
s = unsafeCoerce# :: forall a b. a -> b
unsafeCoerce# forall d a.
SmallMutableArray# d a
-> Int# -> a -> a -> State# d -> (# State# d, Int#, a #)
casSmallArray# SmallMutableArray# s Any
m Int#
i SmallMutableArray# s Any
o SmallMutableArray# s Any
n State# s
s
#endif
{-# INLINE casSmallMutableArraySmallArray# #-}
#if !(MIN_VERSION_base(4,15,0))
unsafeCoerceUnlifted :: forall (a :: TYPE UnliftedRep) (b :: TYPE UnliftedRep). a -> b
unsafeCoerceUnlifted = unsafeCoerce#
#endif
#if !(MIN_VERSION_base(4,10,0))
type UnliftedRep = PtrRepUnlifted
#endif
data Slot x y = Slot
(forall s. SmallMutableArray# s Any -> State# s -> (# State# s, SmallMutableArray# s Any #))
(forall s. SmallMutableArray# s Any -> SmallMutableArray# s Any -> State# s -> State# s)
(forall s. SmallMutableArray# s Any -> SmallMutableArray# s Any -> SmallMutableArray# s Any -> State# s -> (# State# s, Int#, SmallMutableArray# s Any #))
class Precomposable t where
( # ) :: Slot x y -> t y z -> t x z
instance Precomposable Slot where
Slot forall s.
SmallMutableArray# s Any
-> State# s -> (# State# s, SmallMutableArray# s Any #)
gxy forall s.
SmallMutableArray# s Any
-> SmallMutableArray# s Any -> State# s -> State# s
_ forall s.
SmallMutableArray# s Any
-> SmallMutableArray# s Any
-> SmallMutableArray# s Any
-> State# s
-> (# State# s, Int#, SmallMutableArray# s Any #)
_ # :: forall (x :: k) (y :: k) (z :: k). Slot x y -> Slot y z -> Slot x z
# Slot forall s.
SmallMutableArray# s Any
-> State# s -> (# State# s, SmallMutableArray# s Any #)
gyz forall s.
SmallMutableArray# s Any
-> SmallMutableArray# s Any -> State# s -> State# s
syz forall s.
SmallMutableArray# s Any
-> SmallMutableArray# s Any
-> SmallMutableArray# s Any
-> State# s
-> (# State# s, Int#, SmallMutableArray# s Any #)
cyz = forall {k} {k} (x :: k) (y :: k).
(forall s.
SmallMutableArray# s Any
-> State# s -> (# State# s, SmallMutableArray# s Any #))
-> (forall s.
SmallMutableArray# s Any
-> SmallMutableArray# s Any -> State# s -> State# s)
-> (forall s.
SmallMutableArray# s Any
-> SmallMutableArray# s Any
-> SmallMutableArray# s Any
-> State# s
-> (# State# s, Int#, SmallMutableArray# s Any #))
-> Slot x y
Slot
(\SmallMutableArray# s Any
x State# s
s -> case forall s.
SmallMutableArray# s Any
-> State# s -> (# State# s, SmallMutableArray# s Any #)
gxy SmallMutableArray# s Any
x State# s
s of (# State# s
s', SmallMutableArray# s Any
y #) -> forall s.
SmallMutableArray# s Any
-> State# s -> (# State# s, SmallMutableArray# s Any #)
gyz SmallMutableArray# s Any
y State# s
s')
(\SmallMutableArray# s Any
x SmallMutableArray# s Any
z State# s
s -> case forall s.
SmallMutableArray# s Any
-> State# s -> (# State# s, SmallMutableArray# s Any #)
gxy SmallMutableArray# s Any
x State# s
s of (# State# s
s', SmallMutableArray# s Any
y #) -> forall s.
SmallMutableArray# s Any
-> SmallMutableArray# s Any -> State# s -> State# s
syz SmallMutableArray# s Any
y SmallMutableArray# s Any
z State# s
s')
(\SmallMutableArray# s Any
x SmallMutableArray# s Any
o SmallMutableArray# s Any
n State# s
s -> case forall s.
SmallMutableArray# s Any
-> State# s -> (# State# s, SmallMutableArray# s Any #)
gxy SmallMutableArray# s Any
x State# s
s of (# State# s
s', SmallMutableArray# s Any
y #) -> forall s.
SmallMutableArray# s Any
-> SmallMutableArray# s Any
-> SmallMutableArray# s Any
-> State# s
-> (# State# s, Int#, SmallMutableArray# s Any #)
cyz SmallMutableArray# s Any
y SmallMutableArray# s Any
o SmallMutableArray# s Any
n State# s
s')
slot :: Int -> Slot s t
slot :: forall {k} {k} (s :: k) (t :: k). Int -> Slot s t
slot (I# Int#
i) = forall {k} {k} (x :: k) (y :: k).
(forall s.
SmallMutableArray# s Any
-> State# s -> (# State# s, SmallMutableArray# s Any #))
-> (forall s.
SmallMutableArray# s Any
-> SmallMutableArray# s Any -> State# s -> State# s)
-> (forall s.
SmallMutableArray# s Any
-> SmallMutableArray# s Any
-> SmallMutableArray# s Any
-> State# s
-> (# State# s, Int#, SmallMutableArray# s Any #))
-> Slot x y
Slot
(\SmallMutableArray# s Any
m State# s
s -> forall s.
SmallMutableArray# s Any
-> Int# -> State# s -> (# State# s, SmallMutableArray# s Any #)
readSmallMutableArraySmallArray# SmallMutableArray# s Any
m Int#
i State# s
s)
(\SmallMutableArray# s Any
m SmallMutableArray# s Any
a State# s
s -> forall s.
SmallMutableArray# s Any
-> Int# -> SmallMutableArray# s Any -> State# s -> State# s
writeSmallMutableArraySmallArray# SmallMutableArray# s Any
m Int#
i SmallMutableArray# s Any
a State# s
s)
(\SmallMutableArray# s Any
m SmallMutableArray# s Any
o SmallMutableArray# s Any
n State# s
s -> forall s.
SmallMutableArray# s Any
-> Int#
-> SmallMutableArray# s Any
-> SmallMutableArray# s Any
-> State# s
-> (# State# s, Int#, SmallMutableArray# s Any #)
casSmallMutableArraySmallArray# SmallMutableArray# s Any
m Int#
i SmallMutableArray# s Any
o SmallMutableArray# s Any
n State# s
s)
get :: (PrimMonad m, Struct x, Struct y) => Slot x y -> x (PrimState m) -> m (y (PrimState m))
get :: forall (m :: * -> *) (x :: * -> *) (y :: * -> *).
(PrimMonad m, Struct x, Struct y) =>
Slot x y -> x (PrimState m) -> m (y (PrimState m))
get (Slot forall s.
SmallMutableArray# s Any
-> State# s -> (# State# s, SmallMutableArray# s Any #)
go forall s.
SmallMutableArray# s Any
-> SmallMutableArray# s Any -> State# s -> State# s
_ forall s.
SmallMutableArray# s Any
-> SmallMutableArray# s Any
-> SmallMutableArray# s Any
-> State# s
-> (# State# s, Int#, SmallMutableArray# s Any #)
_) = \x (PrimState m)
x -> forall (m :: * -> *) a.
PrimMonad m =>
(State# (PrimState m) -> (# State# (PrimState m), a #)) -> m a
primitive forall a b. (a -> b) -> a -> b
$ \State# (PrimState m)
s -> case forall s.
SmallMutableArray# s Any
-> State# s -> (# State# s, SmallMutableArray# s Any #)
go (forall (t :: * -> *) s. Struct t => t s -> SmallMutableArray# s Any
destruct x (PrimState m)
x) State# (PrimState m)
s of
(# State# (PrimState m)
s', SmallMutableArray# (PrimState m) Any
y #) -> (# State# (PrimState m)
s', forall (t :: * -> *) s. Struct t => SmallMutableArray# s Any -> t s
construct SmallMutableArray# (PrimState m) Any
y #)
{-# INLINE get #-}
set :: (PrimMonad m, Struct x, Struct y) => Slot x y -> x (PrimState m) -> y (PrimState m) -> m ()
set :: forall (m :: * -> *) (x :: * -> *) (y :: * -> *).
(PrimMonad m, Struct x, Struct y) =>
Slot x y -> x (PrimState m) -> y (PrimState m) -> m ()
set (Slot forall s.
SmallMutableArray# s Any
-> State# s -> (# State# s, SmallMutableArray# s Any #)
_ forall s.
SmallMutableArray# s Any
-> SmallMutableArray# s Any -> State# s -> State# s
go forall s.
SmallMutableArray# s Any
-> SmallMutableArray# s Any
-> SmallMutableArray# s Any
-> State# s
-> (# State# s, Int#, SmallMutableArray# s Any #)
_) = \x (PrimState m)
x y (PrimState m)
y -> forall (m :: * -> *).
PrimMonad m =>
(State# (PrimState m) -> State# (PrimState m)) -> m ()
primitive_ (forall s.
SmallMutableArray# s Any
-> SmallMutableArray# s Any -> State# s -> State# s
go (forall (t :: * -> *) s. Struct t => t s -> SmallMutableArray# s Any
destruct x (PrimState m)
x) (forall (t :: * -> *) s. Struct t => t s -> SmallMutableArray# s Any
destruct y (PrimState m)
y))
{-# INLINE set #-}
cas :: (PrimMonad m, Struct x, Struct y) => Slot x y -> x (PrimState m) -> y (PrimState m) -> y (PrimState m) -> m (Bool, y (PrimState m))
cas :: forall (m :: * -> *) (x :: * -> *) (y :: * -> *).
(PrimMonad m, Struct x, Struct y) =>
Slot x y
-> x (PrimState m)
-> y (PrimState m)
-> y (PrimState m)
-> m (Bool, y (PrimState m))
cas (Slot forall s.
SmallMutableArray# s Any
-> State# s -> (# State# s, SmallMutableArray# s Any #)
_ forall s.
SmallMutableArray# s Any
-> SmallMutableArray# s Any -> State# s -> State# s
_ forall s.
SmallMutableArray# s Any
-> SmallMutableArray# s Any
-> SmallMutableArray# s Any
-> State# s
-> (# State# s, Int#, SmallMutableArray# s Any #)
go) = \x (PrimState m)
m y (PrimState m)
o y (PrimState m)
n -> forall (m :: * -> *) a.
PrimMonad m =>
(State# (PrimState m) -> (# State# (PrimState m), a #)) -> m a
primitive forall a b. (a -> b) -> a -> b
$ \State# (PrimState m)
s -> case forall s.
SmallMutableArray# s Any
-> SmallMutableArray# s Any
-> SmallMutableArray# s Any
-> State# s
-> (# State# s, Int#, SmallMutableArray# s Any #)
go (forall (t :: * -> *) s. Struct t => t s -> SmallMutableArray# s Any
destruct x (PrimState m)
m) (forall (t :: * -> *) s. Struct t => t s -> SmallMutableArray# s Any
destruct y (PrimState m)
o) (forall (t :: * -> *) s. Struct t => t s -> SmallMutableArray# s Any
destruct y (PrimState m)
n) State# (PrimState m)
s of
(# State# (PrimState m)
s', Int#
i, SmallMutableArray# (PrimState m) Any
r #) -> (# State# (PrimState m)
s', (forall a. Int# -> a
tagToEnum# Int#
i :: Bool, forall (t :: * -> *) s. Struct t => SmallMutableArray# s Any -> t s
construct SmallMutableArray# (PrimState m) Any
r) #)
data Field x a = Field
(forall s. SmallMutableArray# s Any -> State# s -> (# State# s, a #))
(forall s. SmallMutableArray# s Any -> a -> State# s -> State# s)
instance Precomposable Field where
Slot forall s.
SmallMutableArray# s Any
-> State# s -> (# State# s, SmallMutableArray# s Any #)
gxy forall s.
SmallMutableArray# s Any
-> SmallMutableArray# s Any -> State# s -> State# s
_ forall s.
SmallMutableArray# s Any
-> SmallMutableArray# s Any
-> SmallMutableArray# s Any
-> State# s
-> (# State# s, Int#, SmallMutableArray# s Any #)
_ # :: forall (x :: k) (y :: k) z. Slot x y -> Field y z -> Field x z
# Field forall s. SmallMutableArray# s Any -> State# s -> (# State# s, z #)
gyz forall s. SmallMutableArray# s Any -> z -> State# s -> State# s
syz = forall {k} (x :: k) a.
(forall s.
SmallMutableArray# s Any -> State# s -> (# State# s, a #))
-> (forall s.
SmallMutableArray# s Any -> a -> State# s -> State# s)
-> Field x a
Field
(\SmallMutableArray# s Any
x State# s
s -> case forall s.
SmallMutableArray# s Any
-> State# s -> (# State# s, SmallMutableArray# s Any #)
gxy SmallMutableArray# s Any
x State# s
s of (# State# s
s', SmallMutableArray# s Any
y #) -> forall s. SmallMutableArray# s Any -> State# s -> (# State# s, z #)
gyz SmallMutableArray# s Any
y State# s
s')
(\SmallMutableArray# s Any
x z
z State# s
s -> case forall s.
SmallMutableArray# s Any
-> State# s -> (# State# s, SmallMutableArray# s Any #)
gxy SmallMutableArray# s Any
x State# s
s of (# State# s
s', SmallMutableArray# s Any
y #) -> forall s. SmallMutableArray# s Any -> z -> State# s -> State# s
syz SmallMutableArray# s Any
y z
z State# s
s')
field :: Int -> Field s a
field :: forall {k} (s :: k) a. Int -> Field s a
field (I# Int#
i) = forall {k} (x :: k) a.
(forall s.
SmallMutableArray# s Any -> State# s -> (# State# s, a #))
-> (forall s.
SmallMutableArray# s Any -> a -> State# s -> State# s)
-> Field x a
Field
(\SmallMutableArray# s Any
m State# s
s -> forall d a.
SmallMutableArray# d a -> Int# -> State# d -> (# State# d, a #)
readSmallArray# (forall (a :: UnliftedType) (b :: UnliftedType). a -> b
unsafeCoerceUnlifted SmallMutableArray# s Any
m) Int#
i State# s
s)
(\SmallMutableArray# s Any
m a
a State# s
s -> forall d a.
SmallMutableArray# d a -> Int# -> a -> State# d -> State# d
writeSmallArray# (forall (a :: UnliftedType) (b :: UnliftedType). a -> b
unsafeCoerceUnlifted SmallMutableArray# s Any
m) Int#
i a
a State# s
s)
{-# INLINE field #-}
unboxedField :: Prim a => Int -> Int -> Field s a
unboxedField :: forall {k} a (s :: k). Prim a => Int -> Int -> Field s a
unboxedField (I# Int#
i) (I# Int#
j) = forall {k} (x :: k) a.
(forall s.
SmallMutableArray# s Any -> State# s -> (# State# s, a #))
-> (forall s.
SmallMutableArray# s Any -> a -> State# s -> State# s)
-> Field x a
Field
(\SmallMutableArray# s Any
m State# s
s -> case forall s.
SmallMutableArray# s Any
-> Int# -> State# s -> (# State# s, MutableByteArray# s #)
readMutableByteArraySmallArray# SmallMutableArray# s Any
m Int#
i State# s
s of
(# State# s
s', MutableByteArray# s
mba #) -> forall a s.
Prim a =>
MutableByteArray# s -> Int# -> State# s -> (# State# s, a #)
readByteArray# MutableByteArray# s
mba Int#
j State# s
s')
(\SmallMutableArray# s Any
m a
a State# s
s -> case forall s.
SmallMutableArray# s Any
-> Int# -> State# s -> (# State# s, MutableByteArray# s #)
readMutableByteArraySmallArray# SmallMutableArray# s Any
m Int#
i State# s
s of
(# State# s
s', MutableByteArray# s
mba #) -> forall a s.
Prim a =>
MutableByteArray# s -> Int# -> a -> State# s -> State# s
writeByteArray# MutableByteArray# s
mba Int#
j a
a State# s
s')
{-# INLINE unboxedField #-}
initializeUnboxedField ::
(PrimMonad m, Struct x) =>
Int ->
Int ->
Int ->
x (PrimState m) ->
m (MutableByteArray (PrimState m))
initializeUnboxedField :: forall (m :: * -> *) (x :: * -> *).
(PrimMonad m, Struct x) =>
Int
-> Int
-> Int
-> x (PrimState m)
-> m (MutableByteArray (PrimState m))
initializeUnboxedField (I# Int#
i) (I# Int#
n) (I# Int#
z) x (PrimState m)
m =
forall (m :: * -> *) a.
PrimMonad m =>
(State# (PrimState m) -> (# State# (PrimState m), a #)) -> m a
primitive forall a b. (a -> b) -> a -> b
$ \State# (PrimState m)
s ->
case forall d. Int# -> State# d -> (# State# d, MutableByteArray# d #)
newByteArray# (Int#
n Int# -> Int# -> Int#
*# Int#
z) State# (PrimState m)
s of
(# State# (PrimState m)
s1, MutableByteArray# (PrimState m)
mba #) ->
(# forall s.
SmallMutableArray# s Any
-> Int# -> MutableByteArray# s -> State# s -> State# s
writeMutableByteArraySmallArray# (forall (t :: * -> *) s. Struct t => t s -> SmallMutableArray# s Any
destruct x (PrimState m)
m) Int#
i MutableByteArray# (PrimState m)
mba State# (PrimState m)
s1, forall s. MutableByteArray# s -> MutableByteArray s
MutableByteArray MutableByteArray# (PrimState m)
mba #)
{-# INLINE initializeUnboxedField #-}
getField :: (PrimMonad m, Struct x) => Field x a -> x (PrimState m) -> m a
getField :: forall (m :: * -> *) (x :: * -> *) a.
(PrimMonad m, Struct x) =>
Field x a -> x (PrimState m) -> m a
getField (Field forall s. SmallMutableArray# s Any -> State# s -> (# State# s, a #)
go forall s. SmallMutableArray# s Any -> a -> State# s -> State# s
_) = \x (PrimState m)
x -> forall (m :: * -> *) a.
PrimMonad m =>
(State# (PrimState m) -> (# State# (PrimState m), a #)) -> m a
primitive (forall s. SmallMutableArray# s Any -> State# s -> (# State# s, a #)
go (forall (t :: * -> *) s. Struct t => t s -> SmallMutableArray# s Any
destruct x (PrimState m)
x))
{-# INLINE getField #-}
setField :: (PrimMonad m, Struct x) => Field x a -> x (PrimState m) -> a -> m ()
setField :: forall (m :: * -> *) (x :: * -> *) a.
(PrimMonad m, Struct x) =>
Field x a -> x (PrimState m) -> a -> m ()
setField (Field forall s. SmallMutableArray# s Any -> State# s -> (# State# s, a #)
_ forall s. SmallMutableArray# s Any -> a -> State# s -> State# s
go) = \x (PrimState m)
x a
y -> forall (m :: * -> *).
PrimMonad m =>
(State# (PrimState m) -> State# (PrimState m)) -> m ()
primitive_ (forall s. SmallMutableArray# s Any -> a -> State# s -> State# s
go (forall (t :: * -> *) s. Struct t => t s -> SmallMutableArray# s Any
destruct x (PrimState m)
x) a
y)
{-# INLINE setField #-}
modifyField :: (Struct x, PrimMonad m) => Field x a -> x (PrimState m) -> (a -> a) -> m ()
modifyField :: forall (x :: * -> *) (m :: * -> *) a.
(Struct x, PrimMonad m) =>
Field x a -> x (PrimState m) -> (a -> a) -> m ()
modifyField Field x a
s = \x (PrimState m)
o a -> a
f -> forall (m :: * -> *) a. PrimMonad m => ST (PrimState m) a -> m a
st (forall (m :: * -> *) (x :: * -> *) a.
(PrimMonad m, Struct x) =>
Field x a -> x (PrimState m) -> a -> m ()
setField Field x a
s x (PrimState m)
o forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> a
f forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< forall (m :: * -> *) (x :: * -> *) a.
(PrimMonad m, Struct x) =>
Field x a -> x (PrimState m) -> m a
getField Field x a
s x (PrimState m)
o)
{-# INLINE modifyField #-}
modifyField' :: (Struct x, PrimMonad m) => Field x a -> x (PrimState m) -> (a -> a) -> m ()
modifyField' :: forall (x :: * -> *) (m :: * -> *) a.
(Struct x, PrimMonad m) =>
Field x a -> x (PrimState m) -> (a -> a) -> m ()
modifyField' Field x a
s = \x (PrimState m)
o a -> a
f -> forall (m :: * -> *) a. PrimMonad m => ST (PrimState m) a -> m a
st (forall (m :: * -> *) (x :: * -> *) a.
(PrimMonad m, Struct x) =>
Field x a -> x (PrimState m) -> a -> m ()
setField Field x a
s x (PrimState m)
o forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< (\a
x -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$! a -> a
f a
x) forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< forall (m :: * -> *) (x :: * -> *) a.
(PrimMonad m, Struct x) =>
Field x a -> x (PrimState m) -> m a
getField Field x a
s x (PrimState m)
o)
{-# INLINE modifyField' #-}