{-# language MagicHash #-}
{-# language UnboxedTuples #-}
{-# language RoleAnnotations #-}
{-# language UnliftedNewtypes #-}
{-# language KindSignatures #-}
{-# language ScopedTypeVariables #-}
module Data.Primitive.Unlifted.SmallArray.Primops
(
SmallUnliftedArray#
, SmallMutableUnliftedArray#
, newSmallUnliftedArray#
, unsafeNewSmallUnliftedArray#
, emptySmallUnliftedArray#
, sameSmallMutableUnliftedArray#
, shrinkSmallMutableUnliftedArray#
, readSmallUnliftedArray#
, writeSmallUnliftedArray#
, sizeofSmallUnliftedArray#
, getSizeofSmallMutableUnliftedArray#
, indexSmallUnliftedArray#
, unsafeFreezeSmallUnliftedArray#
, unsafeThawSmallUnliftedArray#
, copySmallUnliftedArray#
, copySmallMutableUnliftedArray#
, cloneSmallUnliftedArray#
, cloneSmallMutableUnliftedArray#
, freezeSmallUnliftedArray#
, thawSmallUnliftedArray#
, casSmallUnliftedArray#
) where
import GHC.Exts (Int#,State#,SmallArray#,SmallMutableArray#,Any,TYPE,RuntimeRep(UnliftedRep),unsafeCoerce#)
import qualified GHC.Exts as Exts
newtype SmallUnliftedArray# (a :: TYPE 'UnliftedRep) = SmallUnliftedArray# (SmallArray# Any)
type role SmallUnliftedArray# representational
newtype SmallMutableUnliftedArray# s (a :: TYPE 'UnliftedRep) = SmallMutableUnliftedArray# (SmallMutableArray# s Any)
type role SmallMutableUnliftedArray# nominal representational
newSmallUnliftedArray# :: forall a s. Int# -> a -> State# s -> (# State# s, SmallMutableUnliftedArray# s a #)
newSmallUnliftedArray# :: Int#
-> a -> State# s -> (# State# s, SmallMutableUnliftedArray# s a #)
newSmallUnliftedArray# Int#
sz a
a State# s
s = case Int# -> Any -> State# s -> (# State# s, SmallMutableArray# s Any #)
forall a d.
Int# -> a -> State# d -> (# State# d, SmallMutableArray# d a #)
Exts.newSmallArray# Int#
sz (a -> Any
unsafeCoerce# a
a) State# s
s of
(# State# s
s', SmallMutableArray# s Any
mary #) -> (# State# s
s', SmallMutableArray# s Any -> SmallMutableUnliftedArray# s a
forall s (a :: TYPE 'UnliftedRep).
SmallMutableArray# s Any -> SmallMutableUnliftedArray# s a
SmallMutableUnliftedArray# SmallMutableArray# s Any
mary #)
{-# NOINLINE newSmallUnliftedArray# #-}
unsafeNewSmallUnliftedArray# :: Int# -> State# s -> (# State# s, SmallMutableUnliftedArray# s a #)
unsafeNewSmallUnliftedArray# :: Int# -> State# s -> (# State# s, SmallMutableUnliftedArray# s a #)
unsafeNewSmallUnliftedArray# Int#
sz State# s
s = case Int# -> Any -> State# s -> (# State# s, SmallMutableArray# s Any #)
forall a d.
Int# -> a -> State# d -> (# State# d, SmallMutableArray# d a #)
Exts.newSmallArray# Int#
sz (Nonsense -> Any
unsafeCoerce# Nonsense
Nonsense) State# s
s of
(# State# s
s', SmallMutableArray# s Any
mary #) -> (# State# s
s', SmallMutableArray# s Any -> SmallMutableUnliftedArray# s a
forall s (a :: TYPE 'UnliftedRep).
SmallMutableArray# s Any -> SmallMutableUnliftedArray# s a
SmallMutableUnliftedArray# SmallMutableArray# s Any
mary #)
{-# NOINLINE unsafeNewSmallUnliftedArray# #-}
data Nonsense = Nonsense
empty_small_unlifted_array :: SULA a
empty_small_unlifted_array :: SULA a
empty_small_unlifted_array = SmallUnliftedArray# a -> SULA a
forall (a :: TYPE 'UnliftedRep). SmallUnliftedArray# a -> SULA a
SULA
((State# RealWorld -> SmallUnliftedArray# a)
-> SmallUnliftedArray# a
forall o. (State# RealWorld -> o) -> o
Exts.runRW# ((State# RealWorld -> SmallUnliftedArray# a)
-> SmallUnliftedArray# a)
-> (State# RealWorld -> SmallUnliftedArray# a)
-> SmallUnliftedArray# a
forall a b. (a -> b) -> a -> b
$ \State# RealWorld
s ->
case State# RealWorld -> State# RealWorld
forall d. State# d -> State# d
Exts.noDuplicate# State# RealWorld
s of { State# RealWorld
s' ->
case Int#
-> Any
-> State# RealWorld
-> (# State# RealWorld, SmallMutableArray# RealWorld Any #)
forall a d.
Int# -> a -> State# d -> (# State# d, SmallMutableArray# d a #)
Exts.newSmallArray# Int#
0# (Nonsense -> Any
unsafeCoerce# Nonsense
Nonsense) State# RealWorld
s' of { (# State# RealWorld
s'', SmallMutableArray# RealWorld Any
mary #) ->
case SmallMutableArray# RealWorld Any
-> State# RealWorld -> (# State# RealWorld, SmallArray# Any #)
forall d a.
SmallMutableArray# d a -> State# d -> (# State# d, SmallArray# a #)
Exts.unsafeFreezeSmallArray# SmallMutableArray# RealWorld Any
mary State# RealWorld
s'' of { (# State# RealWorld
_, SmallArray# Any
ary #) ->
SmallArray# Any -> SmallUnliftedArray# a
forall (a :: TYPE 'UnliftedRep).
SmallArray# Any -> SmallUnliftedArray# a
SmallUnliftedArray# SmallArray# Any
ary }}})
{-# NOINLINE empty_small_unlifted_array #-}
data SULA a = SULA (SmallUnliftedArray# a)
emptySmallUnliftedArray# :: (##) -> SmallUnliftedArray# a
emptySmallUnliftedArray# :: (# #) -> SmallUnliftedArray# a
emptySmallUnliftedArray# (##) = case SULA a
forall (a :: TYPE 'UnliftedRep). SULA a
empty_small_unlifted_array of
SULA SmallUnliftedArray# a
ary -> SmallUnliftedArray# a
ary
{-# INLINE emptySmallUnliftedArray# #-}
sameSmallMutableUnliftedArray# :: SmallMutableUnliftedArray# s a -> SmallMutableUnliftedArray# s a -> Int#
sameSmallMutableUnliftedArray# :: SmallMutableUnliftedArray# s a
-> SmallMutableUnliftedArray# s a -> Int#
sameSmallMutableUnliftedArray# (SmallMutableUnliftedArray# SmallMutableArray# s Any
ar1) (SmallMutableUnliftedArray# SmallMutableArray# s Any
ar2)
= SmallMutableArray# s Any -> SmallMutableArray# s Any -> Int#
forall d a.
SmallMutableArray# d a -> SmallMutableArray# d a -> Int#
Exts.sameSmallMutableArray# SmallMutableArray# s Any
ar1 SmallMutableArray# s Any
ar2
{-# INLINE sameSmallMutableUnliftedArray# #-}
shrinkSmallMutableUnliftedArray# :: SmallMutableUnliftedArray# s a -> Int# -> State# s -> State# s
shrinkSmallMutableUnliftedArray# :: SmallMutableUnliftedArray# s a -> Int# -> State# s -> State# s
shrinkSmallMutableUnliftedArray# (SmallMutableUnliftedArray# SmallMutableArray# s Any
ar) Int#
sz State# s
s
= SmallMutableArray# s Any -> Int# -> State# s -> State# s
forall d a. SmallMutableArray# d a -> Int# -> State# d -> State# d
Exts.shrinkSmallMutableArray# SmallMutableArray# s Any
ar Int#
sz State# s
s
{-# INLINE shrinkSmallMutableUnliftedArray# #-}
readSmallUnliftedArray# :: SmallMutableUnliftedArray# s a -> Int# -> State# s -> (# State# s, a #)
readSmallUnliftedArray# :: SmallMutableUnliftedArray# s a
-> Int# -> State# s -> (# State# s, a #)
readSmallUnliftedArray# (SmallMutableUnliftedArray# SmallMutableArray# s Any
mary) Int#
i State# s
s
= (# State# s, Any #) -> (# State# s, a #)
unsafeCoerce# (SmallMutableArray# s Any -> Int# -> State# s -> (# State# s, Any #)
forall d a.
SmallMutableArray# d a -> Int# -> State# d -> (# State# d, a #)
Exts.readSmallArray# SmallMutableArray# s Any
mary Int#
i State# s
s)
{-# NOINLINE readSmallUnliftedArray# #-}
writeSmallUnliftedArray# :: SmallMutableUnliftedArray# s a -> Int# -> a -> State# s -> State# s
writeSmallUnliftedArray# :: SmallMutableUnliftedArray# s a -> Int# -> a -> State# s -> State# s
writeSmallUnliftedArray# (SmallMutableUnliftedArray# SmallMutableArray# s Any
mary) Int#
i a
a State# s
s
= SmallMutableArray# s Any -> Int# -> Any -> State# s -> State# s
forall d a.
SmallMutableArray# d a -> Int# -> a -> State# d -> State# d
Exts.writeSmallArray# SmallMutableArray# s Any
mary Int#
i (a -> Any
unsafeCoerce# a
a) State# s
s
{-# NOINLINE writeSmallUnliftedArray# #-}
sizeofSmallUnliftedArray# :: SmallUnliftedArray# a -> Int#
sizeofSmallUnliftedArray# :: SmallUnliftedArray# a -> Int#
sizeofSmallUnliftedArray# (SmallUnliftedArray# SmallArray# Any
ary) = SmallArray# Any -> Int#
forall a. SmallArray# a -> Int#
Exts.sizeofSmallArray# SmallArray# Any
ary
{-# INLINE sizeofSmallUnliftedArray# #-}
getSizeofSmallMutableUnliftedArray# :: SmallMutableUnliftedArray# s a -> State# s -> (# State# s, Int# #)
getSizeofSmallMutableUnliftedArray# :: SmallMutableUnliftedArray# s a -> State# s -> (# State# s, Int# #)
getSizeofSmallMutableUnliftedArray# (SmallMutableUnliftedArray# SmallMutableArray# s Any
mary) State# s
s
= SmallMutableArray# s Any -> State# s -> (# State# s, Int# #)
forall d a.
SmallMutableArray# d a -> State# d -> (# State# d, Int# #)
Exts.getSizeofSmallMutableArray# SmallMutableArray# s Any
mary State# s
s
{-# INLINE getSizeofSmallMutableUnliftedArray# #-}
indexSmallUnliftedArray# :: SmallUnliftedArray# a -> Int# -> a
indexSmallUnliftedArray# :: SmallUnliftedArray# a -> Int# -> a
indexSmallUnliftedArray# (SmallUnliftedArray# SmallArray# Any
ary) Int#
i
= (# Any #) -> a
unsafeCoerce# (SmallArray# Any -> Int# -> (# Any #)
forall a. SmallArray# a -> Int# -> (# a #)
Exts.indexSmallArray# SmallArray# Any
ary Int#
i)
{-# NOINLINE indexSmallUnliftedArray# #-}
unsafeFreezeSmallUnliftedArray# :: SmallMutableUnliftedArray# s a -> State# s -> (# State# s, SmallUnliftedArray# a #)
unsafeFreezeSmallUnliftedArray# :: SmallMutableUnliftedArray# s a
-> State# s -> (# State# s, SmallUnliftedArray# a #)
unsafeFreezeSmallUnliftedArray# (SmallMutableUnliftedArray# SmallMutableArray# s Any
mary) State# s
s
= case SmallMutableArray# s Any
-> State# s -> (# State# s, SmallArray# Any #)
forall d a.
SmallMutableArray# d a -> State# d -> (# State# d, SmallArray# a #)
Exts.unsafeFreezeSmallArray# SmallMutableArray# s Any
mary State# s
s of
(# State# s
s', SmallArray# Any
ary #) -> (# State# s
s', SmallArray# Any -> SmallUnliftedArray# a
forall (a :: TYPE 'UnliftedRep).
SmallArray# Any -> SmallUnliftedArray# a
SmallUnliftedArray# SmallArray# Any
ary #)
{-# INLINE unsafeFreezeSmallUnliftedArray# #-}
unsafeThawSmallUnliftedArray# :: SmallUnliftedArray# a -> State# s -> (# State# s, SmallMutableUnliftedArray# s a #)
unsafeThawSmallUnliftedArray# :: SmallUnliftedArray# a
-> State# s -> (# State# s, SmallMutableUnliftedArray# s a #)
unsafeThawSmallUnliftedArray# (SmallUnliftedArray# SmallArray# Any
ary) State# s
s
= case SmallArray# Any
-> State# s -> (# State# s, SmallMutableArray# s Any #)
forall a d.
SmallArray# a -> State# d -> (# State# d, SmallMutableArray# d a #)
Exts.unsafeThawSmallArray# SmallArray# Any
ary State# s
s of
(# State# s
s', SmallMutableArray# s Any
mary #) -> (# State# s
s', SmallMutableArray# s Any -> SmallMutableUnliftedArray# s a
forall s (a :: TYPE 'UnliftedRep).
SmallMutableArray# s Any -> SmallMutableUnliftedArray# s a
SmallMutableUnliftedArray# SmallMutableArray# s Any
mary #)
{-# INLINE unsafeThawSmallUnliftedArray# #-}
copySmallUnliftedArray# :: SmallUnliftedArray# a -> Int# -> SmallMutableUnliftedArray# s a -> Int# -> Int# -> State# s -> State# s
copySmallUnliftedArray# :: SmallUnliftedArray# a
-> Int#
-> SmallMutableUnliftedArray# s a
-> Int#
-> Int#
-> State# s
-> State# s
copySmallUnliftedArray# (SmallUnliftedArray# SmallArray# Any
ary) Int#
i1 (SmallMutableUnliftedArray# SmallMutableArray# s Any
mary) Int#
i2 Int#
n State# s
s
= SmallArray# Any
-> Int#
-> SmallMutableArray# s Any
-> Int#
-> Int#
-> State# s
-> State# s
forall a d.
SmallArray# a
-> Int#
-> SmallMutableArray# d a
-> Int#
-> Int#
-> State# d
-> State# d
Exts.copySmallArray# SmallArray# Any
ary Int#
i1 SmallMutableArray# s Any
mary Int#
i2 Int#
n State# s
s
{-# INLINE copySmallUnliftedArray# #-}
copySmallMutableUnliftedArray# :: SmallMutableUnliftedArray# s a -> Int# -> SmallMutableUnliftedArray# s a -> Int# -> Int# -> State# s -> State# s
copySmallMutableUnliftedArray# :: SmallMutableUnliftedArray# s a
-> Int#
-> SmallMutableUnliftedArray# s a
-> Int#
-> Int#
-> State# s
-> State# s
copySmallMutableUnliftedArray# (SmallMutableUnliftedArray# SmallMutableArray# s Any
mary1) Int#
i1 (SmallMutableUnliftedArray# SmallMutableArray# s Any
mary2) Int#
i2 Int#
n State# s
s
= SmallMutableArray# s Any
-> Int#
-> SmallMutableArray# s Any
-> Int#
-> Int#
-> State# s
-> State# s
forall d a.
SmallMutableArray# d a
-> Int#
-> SmallMutableArray# d a
-> Int#
-> Int#
-> State# d
-> State# d
Exts.copySmallMutableArray# SmallMutableArray# s Any
mary1 Int#
i1 SmallMutableArray# s Any
mary2 Int#
i2 Int#
n State# s
s
{-# INLINE copySmallMutableUnliftedArray# #-}
cloneSmallUnliftedArray# :: SmallUnliftedArray# a -> Int# -> Int# -> SmallUnliftedArray# a
cloneSmallUnliftedArray# :: SmallUnliftedArray# a -> Int# -> Int# -> SmallUnliftedArray# a
cloneSmallUnliftedArray# (SmallUnliftedArray# SmallArray# Any
ary) Int#
i Int#
n
= SmallArray# Any -> SmallUnliftedArray# a
forall (a :: TYPE 'UnliftedRep).
SmallArray# Any -> SmallUnliftedArray# a
SmallUnliftedArray# (SmallArray# Any -> Int# -> Int# -> SmallArray# Any
forall a. SmallArray# a -> Int# -> Int# -> SmallArray# a
Exts.cloneSmallArray# SmallArray# Any
ary Int#
i Int#
n)
{-# INLINE cloneSmallUnliftedArray# #-}
cloneSmallMutableUnliftedArray# :: SmallMutableUnliftedArray# s a -> Int# -> Int# -> State# s
-> (# State# s, SmallMutableUnliftedArray# s a #)
cloneSmallMutableUnliftedArray# :: SmallMutableUnliftedArray# s a
-> Int#
-> Int#
-> State# s
-> (# State# s, SmallMutableUnliftedArray# s a #)
cloneSmallMutableUnliftedArray# (SmallMutableUnliftedArray# SmallMutableArray# s Any
mary) Int#
i Int#
n State# s
s
= case SmallMutableArray# s Any
-> Int#
-> Int#
-> State# s
-> (# State# s, SmallMutableArray# s Any #)
forall d a.
SmallMutableArray# d a
-> Int#
-> Int#
-> State# d
-> (# State# d, SmallMutableArray# d a #)
Exts.cloneSmallMutableArray# SmallMutableArray# s Any
mary Int#
i Int#
n State# s
s of
(# State# s
s', SmallMutableArray# s Any
mary' #) -> (# State# s
s', SmallMutableArray# s Any -> SmallMutableUnliftedArray# s a
forall s (a :: TYPE 'UnliftedRep).
SmallMutableArray# s Any -> SmallMutableUnliftedArray# s a
SmallMutableUnliftedArray# SmallMutableArray# s Any
mary' #)
{-# INLINE cloneSmallMutableUnliftedArray# #-}
freezeSmallUnliftedArray# :: SmallMutableUnliftedArray# s a -> Int# -> Int# -> State# s -> (# State# s, SmallUnliftedArray# a #)
freezeSmallUnliftedArray# :: SmallMutableUnliftedArray# s a
-> Int#
-> Int#
-> State# s
-> (# State# s, SmallUnliftedArray# a #)
freezeSmallUnliftedArray# (SmallMutableUnliftedArray# SmallMutableArray# s Any
mary) Int#
i Int#
n State# s
s
= case SmallMutableArray# s Any
-> Int# -> Int# -> State# s -> (# State# s, SmallArray# Any #)
forall d a.
SmallMutableArray# d a
-> Int# -> Int# -> State# d -> (# State# d, SmallArray# a #)
Exts.freezeSmallArray# SmallMutableArray# s Any
mary Int#
i Int#
n State# s
s of
(# State# s
s', SmallArray# Any
ary #) -> (# State# s
s', SmallArray# Any -> SmallUnliftedArray# a
forall (a :: TYPE 'UnliftedRep).
SmallArray# Any -> SmallUnliftedArray# a
SmallUnliftedArray# SmallArray# Any
ary #)
{-# INLINE freezeSmallUnliftedArray# #-}
thawSmallUnliftedArray# :: SmallUnliftedArray# a -> Int# -> Int# -> State# s -> (# State# s, SmallMutableUnliftedArray# s a #)
thawSmallUnliftedArray# :: SmallUnliftedArray# a
-> Int#
-> Int#
-> State# s
-> (# State# s, SmallMutableUnliftedArray# s a #)
thawSmallUnliftedArray# (SmallUnliftedArray# SmallArray# Any
ary) Int#
i Int#
n State# s
s
= case SmallArray# Any
-> Int#
-> Int#
-> State# s
-> (# State# s, SmallMutableArray# s Any #)
forall a d.
SmallArray# a
-> Int#
-> Int#
-> State# d
-> (# State# d, SmallMutableArray# d a #)
Exts.thawSmallArray# SmallArray# Any
ary Int#
i Int#
n State# s
s of
(# State# s
s', SmallMutableArray# s Any
mary #) -> (# State# s
s', SmallMutableArray# s Any -> SmallMutableUnliftedArray# s a
forall s (a :: TYPE 'UnliftedRep).
SmallMutableArray# s Any -> SmallMutableUnliftedArray# s a
SmallMutableUnliftedArray# SmallMutableArray# s Any
mary #)
{-# INLINE thawSmallUnliftedArray# #-}
casSmallUnliftedArray# :: SmallMutableUnliftedArray# s a -> Int# -> a -> a -> State# s -> (# State# s, Int#, a #)
casSmallUnliftedArray# :: SmallMutableUnliftedArray# s a
-> Int# -> a -> a -> State# s -> (# State# s, Int#, a #)
casSmallUnliftedArray# (SmallMutableUnliftedArray# SmallMutableArray# s Any
mary) Int#
i a
x a
y State# s
s
= (# State# s, Int#, Any #) -> (# State# s, Int#, a #)
unsafeCoerce# (SmallMutableArray# s Any
-> Int# -> Any -> Any -> State# s -> (# State# s, Int#, Any #)
forall d a.
SmallMutableArray# d a
-> Int# -> a -> a -> State# d -> (# State# d, Int#, a #)
Exts.casSmallArray# SmallMutableArray# s Any
mary Int#
i (a -> Any
unsafeCoerce# a
x) (a -> Any
unsafeCoerce# a
y) State# s
s)
{-# NOINLINE casSmallUnliftedArray# #-}