{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE Trustworthy #-}
module Futhark.Internalise.TypesValues
(
internaliseReturnType,
internaliseLambdaReturnType,
internaliseEntryReturnType,
internaliseType,
internaliseParamTypes,
internaliseLoopParamType,
internalisePrimType,
internalisedTypeSize,
internaliseSumType,
internalisePrimValue,
)
where
import Control.Monad.Reader
import Control.Monad.State
import Data.List (delete, find, foldl')
import qualified Data.Map.Strict as M
import Data.Maybe
import Futhark.IR.SOACS as I
import Futhark.Internalise.Monad
import qualified Language.Futhark as E
internaliseUniqueness :: E.Uniqueness -> I.Uniqueness
internaliseUniqueness :: Uniqueness -> Uniqueness
internaliseUniqueness Uniqueness
E.Nonunique = Uniqueness
I.Nonunique
internaliseUniqueness Uniqueness
E.Unique = Uniqueness
I.Unique
newtype TypeState = TypeState {TypeState -> Int
typeCounter :: Int}
newtype InternaliseTypeM a
= InternaliseTypeM (StateT TypeState InternaliseM a)
deriving ((forall a b. (a -> b) -> InternaliseTypeM a -> InternaliseTypeM b)
-> (forall a b. a -> InternaliseTypeM b -> InternaliseTypeM a)
-> Functor InternaliseTypeM
forall a b. a -> InternaliseTypeM b -> InternaliseTypeM a
forall a b. (a -> b) -> InternaliseTypeM a -> InternaliseTypeM b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: forall a b. a -> InternaliseTypeM b -> InternaliseTypeM a
$c<$ :: forall a b. a -> InternaliseTypeM b -> InternaliseTypeM a
fmap :: forall a b. (a -> b) -> InternaliseTypeM a -> InternaliseTypeM b
$cfmap :: forall a b. (a -> b) -> InternaliseTypeM a -> InternaliseTypeM b
Functor, Functor InternaliseTypeM
Functor InternaliseTypeM
-> (forall a. a -> InternaliseTypeM a)
-> (forall a b.
InternaliseTypeM (a -> b)
-> InternaliseTypeM a -> InternaliseTypeM b)
-> (forall a b c.
(a -> b -> c)
-> InternaliseTypeM a -> InternaliseTypeM b -> InternaliseTypeM c)
-> (forall a b.
InternaliseTypeM a -> InternaliseTypeM b -> InternaliseTypeM b)
-> (forall a b.
InternaliseTypeM a -> InternaliseTypeM b -> InternaliseTypeM a)
-> Applicative InternaliseTypeM
forall a. a -> InternaliseTypeM a
forall a b.
InternaliseTypeM a -> InternaliseTypeM b -> InternaliseTypeM a
forall a b.
InternaliseTypeM a -> InternaliseTypeM b -> InternaliseTypeM b
forall a b.
InternaliseTypeM (a -> b)
-> InternaliseTypeM a -> InternaliseTypeM b
forall a b c.
(a -> b -> c)
-> InternaliseTypeM a -> InternaliseTypeM b -> InternaliseTypeM c
forall (f :: * -> *).
Functor f
-> (forall a. a -> f a)
-> (forall a b. f (a -> b) -> f a -> f b)
-> (forall a b c. (a -> b -> c) -> f a -> f b -> f c)
-> (forall a b. f a -> f b -> f b)
-> (forall a b. f a -> f b -> f a)
-> Applicative f
<* :: forall a b.
InternaliseTypeM a -> InternaliseTypeM b -> InternaliseTypeM a
$c<* :: forall a b.
InternaliseTypeM a -> InternaliseTypeM b -> InternaliseTypeM a
*> :: forall a b.
InternaliseTypeM a -> InternaliseTypeM b -> InternaliseTypeM b
$c*> :: forall a b.
InternaliseTypeM a -> InternaliseTypeM b -> InternaliseTypeM b
liftA2 :: forall a b c.
(a -> b -> c)
-> InternaliseTypeM a -> InternaliseTypeM b -> InternaliseTypeM c
$cliftA2 :: forall a b c.
(a -> b -> c)
-> InternaliseTypeM a -> InternaliseTypeM b -> InternaliseTypeM c
<*> :: forall a b.
InternaliseTypeM (a -> b)
-> InternaliseTypeM a -> InternaliseTypeM b
$c<*> :: forall a b.
InternaliseTypeM (a -> b)
-> InternaliseTypeM a -> InternaliseTypeM b
pure :: forall a. a -> InternaliseTypeM a
$cpure :: forall a. a -> InternaliseTypeM a
Applicative, Applicative InternaliseTypeM
Applicative InternaliseTypeM
-> (forall a b.
InternaliseTypeM a
-> (a -> InternaliseTypeM b) -> InternaliseTypeM b)
-> (forall a b.
InternaliseTypeM a -> InternaliseTypeM b -> InternaliseTypeM b)
-> (forall a. a -> InternaliseTypeM a)
-> Monad InternaliseTypeM
forall a. a -> InternaliseTypeM a
forall a b.
InternaliseTypeM a -> InternaliseTypeM b -> InternaliseTypeM b
forall a b.
InternaliseTypeM a
-> (a -> InternaliseTypeM b) -> InternaliseTypeM b
forall (m :: * -> *).
Applicative m
-> (forall a b. m a -> (a -> m b) -> m b)
-> (forall a b. m a -> m b -> m b)
-> (forall a. a -> m a)
-> Monad m
return :: forall a. a -> InternaliseTypeM a
$creturn :: forall a. a -> InternaliseTypeM a
>> :: forall a b.
InternaliseTypeM a -> InternaliseTypeM b -> InternaliseTypeM b
$c>> :: forall a b.
InternaliseTypeM a -> InternaliseTypeM b -> InternaliseTypeM b
>>= :: forall a b.
InternaliseTypeM a
-> (a -> InternaliseTypeM b) -> InternaliseTypeM b
$c>>= :: forall a b.
InternaliseTypeM a
-> (a -> InternaliseTypeM b) -> InternaliseTypeM b
Monad, MonadState TypeState)
liftInternaliseM :: InternaliseM a -> InternaliseTypeM a
liftInternaliseM :: forall a. InternaliseM a -> InternaliseTypeM a
liftInternaliseM = StateT TypeState InternaliseM a -> InternaliseTypeM a
forall a. StateT TypeState InternaliseM a -> InternaliseTypeM a
InternaliseTypeM (StateT TypeState InternaliseM a -> InternaliseTypeM a)
-> (InternaliseM a -> StateT TypeState InternaliseM a)
-> InternaliseM a
-> InternaliseTypeM a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. InternaliseM a -> StateT TypeState InternaliseM a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift
runInternaliseTypeM ::
InternaliseTypeM a ->
InternaliseM a
runInternaliseTypeM :: forall a. InternaliseTypeM a -> InternaliseM a
runInternaliseTypeM (InternaliseTypeM StateT TypeState InternaliseM a
m) =
StateT TypeState InternaliseM a -> TypeState -> InternaliseM a
forall (m :: * -> *) s a. Monad m => StateT s m a -> s -> m a
evalStateT StateT TypeState InternaliseM a
m (TypeState -> InternaliseM a) -> TypeState -> InternaliseM a
forall a b. (a -> b) -> a -> b
$ Int -> TypeState
TypeState Int
0
internaliseParamTypes ::
[E.TypeBase (E.DimDecl VName) ()] ->
InternaliseM [[I.TypeBase Shape Uniqueness]]
internaliseParamTypes :: [StructType] -> InternaliseM [[TypeBase Shape Uniqueness]]
internaliseParamTypes [StructType]
ts =
InternaliseTypeM [[TypeBase Shape Uniqueness]]
-> InternaliseM [[TypeBase Shape Uniqueness]]
forall a. InternaliseTypeM a -> InternaliseM a
runInternaliseTypeM (InternaliseTypeM [[TypeBase Shape Uniqueness]]
-> InternaliseM [[TypeBase Shape Uniqueness]])
-> InternaliseTypeM [[TypeBase Shape Uniqueness]]
-> InternaliseM [[TypeBase Shape Uniqueness]]
forall a b. (a -> b) -> a -> b
$ (StructType -> InternaliseTypeM [TypeBase Shape Uniqueness])
-> [StructType] -> InternaliseTypeM [[TypeBase Shape Uniqueness]]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (([TypeBase ExtShape Uniqueness] -> [TypeBase Shape Uniqueness])
-> InternaliseTypeM [TypeBase ExtShape Uniqueness]
-> InternaliseTypeM [TypeBase Shape Uniqueness]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((TypeBase ExtShape Uniqueness -> TypeBase Shape Uniqueness)
-> [TypeBase ExtShape Uniqueness] -> [TypeBase Shape Uniqueness]
forall a b. (a -> b) -> [a] -> [b]
map TypeBase ExtShape Uniqueness -> TypeBase Shape Uniqueness
forall {u}. TypeBase ExtShape u -> TypeBase Shape u
onType) (InternaliseTypeM [TypeBase ExtShape Uniqueness]
-> InternaliseTypeM [TypeBase Shape Uniqueness])
-> (StructType -> InternaliseTypeM [TypeBase ExtShape Uniqueness])
-> StructType
-> InternaliseTypeM [TypeBase Shape Uniqueness]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. StructType -> InternaliseTypeM [TypeBase ExtShape Uniqueness]
internaliseTypeM) [StructType]
ts
where
onType :: TypeBase ExtShape u -> TypeBase Shape u
onType = TypeBase Shape u -> Maybe (TypeBase Shape u) -> TypeBase Shape u
forall a. a -> Maybe a -> a
fromMaybe TypeBase Shape u
forall {a}. a
bad (Maybe (TypeBase Shape u) -> TypeBase Shape u)
-> (TypeBase ExtShape u -> Maybe (TypeBase Shape u))
-> TypeBase ExtShape u
-> TypeBase Shape u
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TypeBase ExtShape u -> Maybe (TypeBase Shape u)
forall u. TypeBase ExtShape u -> Maybe (TypeBase Shape u)
hasStaticShape
bad :: a
bad = String -> a
forall a. HasCallStack => String -> a
error (String -> a) -> String -> a
forall a b. (a -> b) -> a -> b
$ String
"internaliseParamTypes: " String -> String -> String
forall a. [a] -> [a] -> [a]
++ [StructType] -> String
forall a. Pretty a => a -> String
pretty [StructType]
ts
fixupTypes :: [TypeBase shape1 u1] -> [TypeBase shape2 u2] -> [TypeBase shape2 u2]
fixupTypes :: forall shape1 u1 shape2 u2.
[TypeBase shape1 u1]
-> [TypeBase shape2 u2] -> [TypeBase shape2 u2]
fixupTypes = (TypeBase shape1 u1 -> TypeBase shape2 u2 -> TypeBase shape2 u2)
-> [TypeBase shape1 u1]
-> [TypeBase shape2 u2]
-> [TypeBase shape2 u2]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith TypeBase shape1 u1 -> TypeBase shape2 u2 -> TypeBase shape2 u2
forall {shape} {u} {shape} {u}.
TypeBase shape u -> TypeBase shape u -> TypeBase shape u
fixup
where
fixup :: TypeBase shape u -> TypeBase shape u -> TypeBase shape u
fixup (Acc VName
acc Shape
ispace [Type]
ts u
_) (Acc VName
_ Shape
_ [Type]
_ u
u2) = VName -> Shape -> [Type] -> u -> TypeBase shape u
forall shape u. VName -> Shape -> [Type] -> u -> TypeBase shape u
Acc VName
acc Shape
ispace [Type]
ts u
u2
fixup TypeBase shape u
_ TypeBase shape u
t = TypeBase shape u
t
internaliseLoopParamType ::
E.TypeBase (E.DimDecl VName) () ->
[TypeBase shape u] ->
InternaliseM [I.TypeBase Shape Uniqueness]
internaliseLoopParamType :: forall shape u.
StructType
-> [TypeBase shape u] -> InternaliseM [TypeBase Shape Uniqueness]
internaliseLoopParamType StructType
et [TypeBase shape u]
ts =
[TypeBase shape u]
-> [TypeBase Shape Uniqueness] -> [TypeBase Shape Uniqueness]
forall shape1 u1 shape2 u2.
[TypeBase shape1 u1]
-> [TypeBase shape2 u2] -> [TypeBase shape2 u2]
fixupTypes [TypeBase shape u]
ts ([TypeBase Shape Uniqueness] -> [TypeBase Shape Uniqueness])
-> ([[TypeBase Shape Uniqueness]] -> [TypeBase Shape Uniqueness])
-> [[TypeBase Shape Uniqueness]]
-> [TypeBase Shape Uniqueness]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [[TypeBase Shape Uniqueness]] -> [TypeBase Shape Uniqueness]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat ([[TypeBase Shape Uniqueness]] -> [TypeBase Shape Uniqueness])
-> InternaliseM [[TypeBase Shape Uniqueness]]
-> InternaliseM [TypeBase Shape Uniqueness]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [StructType] -> InternaliseM [[TypeBase Shape Uniqueness]]
internaliseParamTypes [StructType
et]
internaliseReturnType ::
E.TypeBase (E.DimDecl VName) () ->
[TypeBase shape u] ->
InternaliseM [I.TypeBase ExtShape Uniqueness]
internaliseReturnType :: forall shape u.
StructType
-> [TypeBase shape u]
-> InternaliseM [TypeBase ExtShape Uniqueness]
internaliseReturnType StructType
et [TypeBase shape u]
ts =
[TypeBase shape u]
-> [TypeBase ExtShape Uniqueness] -> [TypeBase ExtShape Uniqueness]
forall shape1 u1 shape2 u2.
[TypeBase shape1 u1]
-> [TypeBase shape2 u2] -> [TypeBase shape2 u2]
fixupTypes [TypeBase shape u]
ts ([TypeBase ExtShape Uniqueness] -> [TypeBase ExtShape Uniqueness])
-> InternaliseM [TypeBase ExtShape Uniqueness]
-> InternaliseM [TypeBase ExtShape Uniqueness]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> InternaliseTypeM [TypeBase ExtShape Uniqueness]
-> InternaliseM [TypeBase ExtShape Uniqueness]
forall a. InternaliseTypeM a -> InternaliseM a
runInternaliseTypeM (StructType -> InternaliseTypeM [TypeBase ExtShape Uniqueness]
internaliseTypeM StructType
et)
internaliseLambdaReturnType ::
E.TypeBase (E.DimDecl VName) () ->
[TypeBase shape u] ->
InternaliseM [I.TypeBase Shape NoUniqueness]
internaliseLambdaReturnType :: forall shape u.
StructType -> [TypeBase shape u] -> InternaliseM [Type]
internaliseLambdaReturnType StructType
et [TypeBase shape u]
ts =
(TypeBase Shape Uniqueness -> Type)
-> [TypeBase Shape Uniqueness] -> [Type]
forall a b. (a -> b) -> [a] -> [b]
map TypeBase Shape Uniqueness -> Type
forall shape.
TypeBase shape Uniqueness -> TypeBase shape NoUniqueness
fromDecl ([TypeBase Shape Uniqueness] -> [Type])
-> InternaliseM [TypeBase Shape Uniqueness] -> InternaliseM [Type]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> StructType
-> [TypeBase shape u] -> InternaliseM [TypeBase Shape Uniqueness]
forall shape u.
StructType
-> [TypeBase shape u] -> InternaliseM [TypeBase Shape Uniqueness]
internaliseLoopParamType StructType
et [TypeBase shape u]
ts
internaliseEntryReturnType ::
E.TypeBase (E.DimDecl VName) () ->
InternaliseM [[I.TypeBase ExtShape Uniqueness]]
internaliseEntryReturnType :: StructType -> InternaliseM [[TypeBase ExtShape Uniqueness]]
internaliseEntryReturnType StructType
et =
InternaliseTypeM [[TypeBase ExtShape Uniqueness]]
-> InternaliseM [[TypeBase ExtShape Uniqueness]]
forall a. InternaliseTypeM a -> InternaliseM a
runInternaliseTypeM (InternaliseTypeM [[TypeBase ExtShape Uniqueness]]
-> InternaliseM [[TypeBase ExtShape Uniqueness]])
-> ([StructType]
-> InternaliseTypeM [[TypeBase ExtShape Uniqueness]])
-> [StructType]
-> InternaliseM [[TypeBase ExtShape Uniqueness]]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (StructType -> InternaliseTypeM [TypeBase ExtShape Uniqueness])
-> [StructType]
-> InternaliseTypeM [[TypeBase ExtShape Uniqueness]]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM StructType -> InternaliseTypeM [TypeBase ExtShape Uniqueness]
internaliseTypeM ([StructType] -> InternaliseM [[TypeBase ExtShape Uniqueness]])
-> [StructType] -> InternaliseM [[TypeBase ExtShape Uniqueness]]
forall a b. (a -> b) -> a -> b
$
case StructType -> Maybe [StructType]
forall dim as. TypeBase dim as -> Maybe [TypeBase dim as]
E.isTupleRecord StructType
et of
Just [StructType]
ets | Bool -> Bool
not (Bool -> Bool) -> Bool -> Bool
forall a b. (a -> b) -> a -> b
$ [StructType] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [StructType]
ets -> [StructType]
ets
Maybe [StructType]
_ -> [StructType
et]
internaliseType ::
E.TypeBase (E.DimDecl VName) () ->
InternaliseM [I.TypeBase I.ExtShape Uniqueness]
internaliseType :: StructType -> InternaliseM [TypeBase ExtShape Uniqueness]
internaliseType = InternaliseTypeM [TypeBase ExtShape Uniqueness]
-> InternaliseM [TypeBase ExtShape Uniqueness]
forall a. InternaliseTypeM a -> InternaliseM a
runInternaliseTypeM (InternaliseTypeM [TypeBase ExtShape Uniqueness]
-> InternaliseM [TypeBase ExtShape Uniqueness])
-> (StructType -> InternaliseTypeM [TypeBase ExtShape Uniqueness])
-> StructType
-> InternaliseM [TypeBase ExtShape Uniqueness]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. StructType -> InternaliseTypeM [TypeBase ExtShape Uniqueness]
internaliseTypeM
newId :: InternaliseTypeM Int
newId :: InternaliseTypeM Int
newId = do
Int
i <- (TypeState -> Int) -> InternaliseTypeM Int
forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets TypeState -> Int
typeCounter
(TypeState -> TypeState) -> InternaliseTypeM ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify ((TypeState -> TypeState) -> InternaliseTypeM ())
-> (TypeState -> TypeState) -> InternaliseTypeM ()
forall a b. (a -> b) -> a -> b
$ \TypeState
s -> TypeState
s {typeCounter :: Int
typeCounter = Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1}
Int -> InternaliseTypeM Int
forall (m :: * -> *) a. Monad m => a -> m a
return Int
i
internaliseDim ::
E.DimDecl VName ->
InternaliseTypeM ExtSize
internaliseDim :: DimDecl VName -> InternaliseTypeM (Ext SubExp)
internaliseDim DimDecl VName
d =
case DimDecl VName
d of
E.AnyDim Maybe VName
_ -> Int -> Ext SubExp
forall a. Int -> Ext a
Ext (Int -> Ext SubExp)
-> InternaliseTypeM Int -> InternaliseTypeM (Ext SubExp)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> InternaliseTypeM Int
newId
E.ConstDim Int
n -> Ext SubExp -> InternaliseTypeM (Ext SubExp)
forall (m :: * -> *) a. Monad m => a -> m a
return (Ext SubExp -> InternaliseTypeM (Ext SubExp))
-> Ext SubExp -> InternaliseTypeM (Ext SubExp)
forall a b. (a -> b) -> a -> b
$ SubExp -> Ext SubExp
forall a. a -> Ext a
Free (SubExp -> Ext SubExp) -> SubExp -> Ext SubExp
forall a b. (a -> b) -> a -> b
$ IntType -> Integer -> SubExp
intConst IntType
I.Int64 (Integer -> SubExp) -> Integer -> SubExp
forall a b. (a -> b) -> a -> b
$ Int -> Integer
forall a. Integral a => a -> Integer
toInteger Int
n
E.NamedDim QualName VName
name -> QualName VName -> InternaliseTypeM (Ext SubExp)
namedDim QualName VName
name
where
namedDim :: QualName VName -> InternaliseTypeM (Ext SubExp)
namedDim (E.QualName [VName]
_ VName
name) = do
Maybe [SubExp]
subst <- InternaliseM (Maybe [SubExp]) -> InternaliseTypeM (Maybe [SubExp])
forall a. InternaliseM a -> InternaliseTypeM a
liftInternaliseM (InternaliseM (Maybe [SubExp])
-> InternaliseTypeM (Maybe [SubExp]))
-> InternaliseM (Maybe [SubExp])
-> InternaliseTypeM (Maybe [SubExp])
forall a b. (a -> b) -> a -> b
$ VName -> InternaliseM (Maybe [SubExp])
lookupSubst VName
name
case Maybe [SubExp]
subst of
Just [SubExp
v] -> Ext SubExp -> InternaliseTypeM (Ext SubExp)
forall (m :: * -> *) a. Monad m => a -> m a
return (Ext SubExp -> InternaliseTypeM (Ext SubExp))
-> Ext SubExp -> InternaliseTypeM (Ext SubExp)
forall a b. (a -> b) -> a -> b
$ SubExp -> Ext SubExp
forall a. a -> Ext a
I.Free SubExp
v
Maybe [SubExp]
_ -> Ext SubExp -> InternaliseTypeM (Ext SubExp)
forall (m :: * -> *) a. Monad m => a -> m a
return (Ext SubExp -> InternaliseTypeM (Ext SubExp))
-> Ext SubExp -> InternaliseTypeM (Ext SubExp)
forall a b. (a -> b) -> a -> b
$ SubExp -> Ext SubExp
forall a. a -> Ext a
I.Free (SubExp -> Ext SubExp) -> SubExp -> Ext SubExp
forall a b. (a -> b) -> a -> b
$ VName -> SubExp
I.Var VName
name
internaliseTypeM ::
E.StructType ->
InternaliseTypeM [I.TypeBase ExtShape Uniqueness]
internaliseTypeM :: StructType -> InternaliseTypeM [TypeBase ExtShape Uniqueness]
internaliseTypeM StructType
orig_t =
case StructType
orig_t of
E.Array ()
_ Uniqueness
u ScalarTypeBase (DimDecl VName) ()
et ShapeDecl (DimDecl VName)
shape -> do
[Ext SubExp]
dims <- ShapeDecl (DimDecl VName) -> InternaliseTypeM [Ext SubExp]
internaliseShape ShapeDecl (DimDecl VName)
shape
[TypeBase ExtShape Uniqueness]
ets <- StructType -> InternaliseTypeM [TypeBase ExtShape Uniqueness]
internaliseTypeM (StructType -> InternaliseTypeM [TypeBase ExtShape Uniqueness])
-> StructType -> InternaliseTypeM [TypeBase ExtShape Uniqueness]
forall a b. (a -> b) -> a -> b
$ ScalarTypeBase (DimDecl VName) () -> StructType
forall dim as. ScalarTypeBase dim as -> TypeBase dim as
E.Scalar ScalarTypeBase (DimDecl VName) ()
et
[TypeBase ExtShape Uniqueness]
-> InternaliseTypeM [TypeBase ExtShape Uniqueness]
forall (m :: * -> *) a. Monad m => a -> m a
return [TypeBase ExtShape Uniqueness
-> ExtShape -> Uniqueness -> TypeBase ExtShape Uniqueness
forall shape u_unused u.
ArrayShape shape =>
TypeBase shape u_unused -> shape -> u -> TypeBase shape u
I.arrayOf TypeBase ExtShape Uniqueness
et' ([Ext SubExp] -> ExtShape
forall d. [d] -> ShapeBase d
Shape [Ext SubExp]
dims) (Uniqueness -> TypeBase ExtShape Uniqueness)
-> Uniqueness -> TypeBase ExtShape Uniqueness
forall a b. (a -> b) -> a -> b
$ Uniqueness -> Uniqueness
internaliseUniqueness Uniqueness
u | TypeBase ExtShape Uniqueness
et' <- [TypeBase ExtShape Uniqueness]
ets]
E.Scalar (E.Prim PrimType
bt) ->
[TypeBase ExtShape Uniqueness]
-> InternaliseTypeM [TypeBase ExtShape Uniqueness]
forall (m :: * -> *) a. Monad m => a -> m a
return [PrimType -> TypeBase ExtShape Uniqueness
forall shape u. PrimType -> TypeBase shape u
I.Prim (PrimType -> TypeBase ExtShape Uniqueness)
-> PrimType -> TypeBase ExtShape Uniqueness
forall a b. (a -> b) -> a -> b
$ PrimType -> PrimType
internalisePrimType PrimType
bt]
E.Scalar (E.Record Map Name StructType
ets)
| Map Name StructType -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null Map Name StructType
ets -> [TypeBase ExtShape Uniqueness]
-> InternaliseTypeM [TypeBase ExtShape Uniqueness]
forall (m :: * -> *) a. Monad m => a -> m a
return [PrimType -> TypeBase ExtShape Uniqueness
forall shape u. PrimType -> TypeBase shape u
I.Prim PrimType
I.Unit]
| Bool
otherwise ->
[[TypeBase ExtShape Uniqueness]] -> [TypeBase ExtShape Uniqueness]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat ([[TypeBase ExtShape Uniqueness]]
-> [TypeBase ExtShape Uniqueness])
-> InternaliseTypeM [[TypeBase ExtShape Uniqueness]]
-> InternaliseTypeM [TypeBase ExtShape Uniqueness]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ((Name, StructType)
-> InternaliseTypeM [TypeBase ExtShape Uniqueness])
-> [(Name, StructType)]
-> InternaliseTypeM [[TypeBase ExtShape Uniqueness]]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (StructType -> InternaliseTypeM [TypeBase ExtShape Uniqueness]
internaliseTypeM (StructType -> InternaliseTypeM [TypeBase ExtShape Uniqueness])
-> ((Name, StructType) -> StructType)
-> (Name, StructType)
-> InternaliseTypeM [TypeBase ExtShape Uniqueness]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Name, StructType) -> StructType
forall a b. (a, b) -> b
snd) (Map Name StructType -> [(Name, StructType)]
forall a. Map Name a -> [(Name, a)]
E.sortFields Map Name StructType
ets)
E.Scalar (E.TypeVar ()
_ Uniqueness
u TypeName
tn [E.TypeArgType StructType
arr_t SrcLoc
_])
| VName -> Int
baseTag (TypeName -> VName
E.typeLeaf TypeName
tn) Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
E.maxIntrinsicTag,
VName -> String
baseString (TypeName -> VName
E.typeLeaf TypeName
tn) String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== String
"acc" -> do
[Type]
ts <- (TypeBase ExtShape Uniqueness -> Type)
-> [TypeBase ExtShape Uniqueness] -> [Type]
forall a b. (a -> b) -> [a] -> [b]
map (TypeBase Shape Uniqueness -> Type
forall shape.
TypeBase shape Uniqueness -> TypeBase shape NoUniqueness
fromDecl (TypeBase Shape Uniqueness -> Type)
-> (TypeBase ExtShape Uniqueness -> TypeBase Shape Uniqueness)
-> TypeBase ExtShape Uniqueness
-> Type
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TypeBase ExtShape Uniqueness -> TypeBase Shape Uniqueness
forall {u}. TypeBase ExtShape u -> TypeBase Shape u
onAccType) ([TypeBase ExtShape Uniqueness] -> [Type])
-> InternaliseTypeM [TypeBase ExtShape Uniqueness]
-> InternaliseTypeM [Type]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> StructType -> InternaliseTypeM [TypeBase ExtShape Uniqueness]
internaliseTypeM StructType
arr_t
VName
acc_param <- InternaliseM VName -> InternaliseTypeM VName
forall a. InternaliseM a -> InternaliseTypeM a
liftInternaliseM (InternaliseM VName -> InternaliseTypeM VName)
-> InternaliseM VName -> InternaliseTypeM VName
forall a b. (a -> b) -> a -> b
$ String -> InternaliseM VName
forall (m :: * -> *). MonadFreshNames m => String -> m VName
newVName String
"acc_cert"
let acc_t :: TypeBase shape Uniqueness
acc_t = VName -> Shape -> [Type] -> Uniqueness -> TypeBase shape Uniqueness
forall shape u. VName -> Shape -> [Type] -> u -> TypeBase shape u
Acc VName
acc_param ([SubExp] -> Shape
forall d. [d] -> ShapeBase d
Shape [Int -> [Type] -> SubExp
forall u. Int -> [TypeBase Shape u] -> SubExp
arraysSize Int
0 [Type]
ts]) ((Type -> Type) -> [Type] -> [Type]
forall a b. (a -> b) -> [a] -> [b]
map Type -> Type
forall shape u.
ArrayShape shape =>
TypeBase shape u -> TypeBase shape u
rowType [Type]
ts) (Uniqueness -> TypeBase shape Uniqueness)
-> Uniqueness -> TypeBase shape Uniqueness
forall a b. (a -> b) -> a -> b
$ Uniqueness -> Uniqueness
internaliseUniqueness Uniqueness
u
[TypeBase ExtShape Uniqueness]
-> InternaliseTypeM [TypeBase ExtShape Uniqueness]
forall (m :: * -> *) a. Monad m => a -> m a
return [TypeBase ExtShape Uniqueness
forall {shape}. TypeBase shape Uniqueness
acc_t]
E.Scalar E.TypeVar {} ->
String -> InternaliseTypeM [TypeBase ExtShape Uniqueness]
forall a. HasCallStack => String -> a
error String
"internaliseTypeM: cannot handle type variable."
E.Scalar E.Arrow {} ->
String -> InternaliseTypeM [TypeBase ExtShape Uniqueness]
forall a. HasCallStack => String -> a
error (String -> InternaliseTypeM [TypeBase ExtShape Uniqueness])
-> String -> InternaliseTypeM [TypeBase ExtShape Uniqueness]
forall a b. (a -> b) -> a -> b
$ String
"internaliseTypeM: cannot handle function type: " String -> String -> String
forall a. [a] -> [a] -> [a]
++ StructType -> String
forall a. Pretty a => a -> String
pretty StructType
orig_t
E.Scalar (E.Sum Map Name [StructType]
cs) -> do
([TypeBase ExtShape Uniqueness]
ts, Map Name (Int, [Int])
_) <-
Map Name [TypeBase ExtShape Uniqueness]
-> ([TypeBase ExtShape Uniqueness], Map Name (Int, [Int]))
internaliseConstructors
(Map Name [TypeBase ExtShape Uniqueness]
-> ([TypeBase ExtShape Uniqueness], Map Name (Int, [Int])))
-> InternaliseTypeM (Map Name [TypeBase ExtShape Uniqueness])
-> InternaliseTypeM
([TypeBase ExtShape Uniqueness], Map Name (Int, [Int]))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ([StructType] -> InternaliseTypeM [TypeBase ExtShape Uniqueness])
-> Map Name [StructType]
-> InternaliseTypeM (Map Name [TypeBase ExtShape Uniqueness])
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (([[TypeBase ExtShape Uniqueness]]
-> [TypeBase ExtShape Uniqueness])
-> InternaliseTypeM [[TypeBase ExtShape Uniqueness]]
-> InternaliseTypeM [TypeBase ExtShape Uniqueness]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [[TypeBase ExtShape Uniqueness]] -> [TypeBase ExtShape Uniqueness]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat (InternaliseTypeM [[TypeBase ExtShape Uniqueness]]
-> InternaliseTypeM [TypeBase ExtShape Uniqueness])
-> ([StructType]
-> InternaliseTypeM [[TypeBase ExtShape Uniqueness]])
-> [StructType]
-> InternaliseTypeM [TypeBase ExtShape Uniqueness]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (StructType -> InternaliseTypeM [TypeBase ExtShape Uniqueness])
-> [StructType]
-> InternaliseTypeM [[TypeBase ExtShape Uniqueness]]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM StructType -> InternaliseTypeM [TypeBase ExtShape Uniqueness]
internaliseTypeM) Map Name [StructType]
cs
[TypeBase ExtShape Uniqueness]
-> InternaliseTypeM [TypeBase ExtShape Uniqueness]
forall (m :: * -> *) a. Monad m => a -> m a
return ([TypeBase ExtShape Uniqueness]
-> InternaliseTypeM [TypeBase ExtShape Uniqueness])
-> [TypeBase ExtShape Uniqueness]
-> InternaliseTypeM [TypeBase ExtShape Uniqueness]
forall a b. (a -> b) -> a -> b
$ PrimType -> TypeBase ExtShape Uniqueness
forall shape u. PrimType -> TypeBase shape u
I.Prim (IntType -> PrimType
I.IntType IntType
I.Int8) TypeBase ExtShape Uniqueness
-> [TypeBase ExtShape Uniqueness] -> [TypeBase ExtShape Uniqueness]
forall a. a -> [a] -> [a]
: [TypeBase ExtShape Uniqueness]
ts
where
internaliseShape :: ShapeDecl (DimDecl VName) -> InternaliseTypeM [Ext SubExp]
internaliseShape = (DimDecl VName -> InternaliseTypeM (Ext SubExp))
-> [DimDecl VName] -> InternaliseTypeM [Ext SubExp]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM DimDecl VName -> InternaliseTypeM (Ext SubExp)
internaliseDim ([DimDecl VName] -> InternaliseTypeM [Ext SubExp])
-> (ShapeDecl (DimDecl VName) -> [DimDecl VName])
-> ShapeDecl (DimDecl VName)
-> InternaliseTypeM [Ext SubExp]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShapeDecl (DimDecl VName) -> [DimDecl VName]
forall dim. ShapeDecl dim -> [dim]
E.shapeDims
onAccType :: TypeBase ExtShape u -> TypeBase Shape u
onAccType = TypeBase Shape u -> Maybe (TypeBase Shape u) -> TypeBase Shape u
forall a. a -> Maybe a -> a
fromMaybe TypeBase Shape u
forall {a}. a
bad (Maybe (TypeBase Shape u) -> TypeBase Shape u)
-> (TypeBase ExtShape u -> Maybe (TypeBase Shape u))
-> TypeBase ExtShape u
-> TypeBase Shape u
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TypeBase ExtShape u -> Maybe (TypeBase Shape u)
forall u. TypeBase ExtShape u -> Maybe (TypeBase Shape u)
hasStaticShape
bad :: a
bad = String -> a
forall a. HasCallStack => String -> a
error (String -> a) -> String -> a
forall a b. (a -> b) -> a -> b
$ String
"internaliseTypeM Acc: " String -> String -> String
forall a. [a] -> [a] -> [a]
++ StructType -> String
forall a. Pretty a => a -> String
pretty StructType
orig_t
internaliseConstructors ::
M.Map Name [I.TypeBase ExtShape Uniqueness] ->
( [I.TypeBase ExtShape Uniqueness],
M.Map Name (Int, [Int])
)
internaliseConstructors :: Map Name [TypeBase ExtShape Uniqueness]
-> ([TypeBase ExtShape Uniqueness], Map Name (Int, [Int]))
internaliseConstructors Map Name [TypeBase ExtShape Uniqueness]
cs =
(([TypeBase ExtShape Uniqueness], Map Name (Int, [Int]))
-> ((Name, [TypeBase ExtShape Uniqueness]), Int)
-> ([TypeBase ExtShape Uniqueness], Map Name (Int, [Int])))
-> ([TypeBase ExtShape Uniqueness], Map Name (Int, [Int]))
-> [((Name, [TypeBase ExtShape Uniqueness]), Int)]
-> ([TypeBase ExtShape Uniqueness], Map Name (Int, [Int]))
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' ([TypeBase ExtShape Uniqueness], Map Name (Int, [Int]))
-> ((Name, [TypeBase ExtShape Uniqueness]), Int)
-> ([TypeBase ExtShape Uniqueness], Map Name (Int, [Int]))
forall {k} {t :: * -> *} {shape} {a}.
(Ord k, Foldable t, Eq shape) =>
([TypeBase shape Uniqueness], Map k (a, [Int]))
-> ((k, t (TypeBase shape Uniqueness)), a)
-> ([TypeBase shape Uniqueness], Map k (a, [Int]))
onConstructor ([TypeBase ExtShape Uniqueness], Map Name (Int, [Int]))
forall a. Monoid a => a
mempty ([((Name, [TypeBase ExtShape Uniqueness]), Int)]
-> ([TypeBase ExtShape Uniqueness], Map Name (Int, [Int])))
-> [((Name, [TypeBase ExtShape Uniqueness]), Int)]
-> ([TypeBase ExtShape Uniqueness], Map Name (Int, [Int]))
forall a b. (a -> b) -> a -> b
$ [(Name, [TypeBase ExtShape Uniqueness])]
-> [Int] -> [((Name, [TypeBase ExtShape Uniqueness]), Int)]
forall a b. [a] -> [b] -> [(a, b)]
zip (Map Name [TypeBase ExtShape Uniqueness]
-> [(Name, [TypeBase ExtShape Uniqueness])]
forall a. Map Name a -> [(Name, a)]
E.sortConstrs Map Name [TypeBase ExtShape Uniqueness]
cs) [Int
0 ..]
where
onConstructor :: ([TypeBase shape Uniqueness], Map k (a, [Int]))
-> ((k, t (TypeBase shape Uniqueness)), a)
-> ([TypeBase shape Uniqueness], Map k (a, [Int]))
onConstructor ([TypeBase shape Uniqueness]
ts, Map k (a, [Int])
mapping) ((k
c, t (TypeBase shape Uniqueness)
c_ts), a
i) =
let ([(TypeBase shape NoUniqueness, Int)]
_, [Int]
js, [TypeBase shape Uniqueness]
new_ts) =
(([(TypeBase shape NoUniqueness, Int)], [Int],
[TypeBase shape Uniqueness])
-> TypeBase shape Uniqueness
-> ([(TypeBase shape NoUniqueness, Int)], [Int],
[TypeBase shape Uniqueness]))
-> ([(TypeBase shape NoUniqueness, Int)], [Int],
[TypeBase shape Uniqueness])
-> t (TypeBase shape Uniqueness)
-> ([(TypeBase shape NoUniqueness, Int)], [Int],
[TypeBase shape Uniqueness])
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' ([(TypeBase shape NoUniqueness, Int)], [Int],
[TypeBase shape Uniqueness])
-> TypeBase shape Uniqueness
-> ([(TypeBase shape NoUniqueness, Int)], [Int],
[TypeBase shape Uniqueness])
forall {shape}.
Eq shape =>
([(TypeBase shape NoUniqueness, Int)], [Int],
[TypeBase shape Uniqueness])
-> TypeBase shape Uniqueness
-> ([(TypeBase shape NoUniqueness, Int)], [Int],
[TypeBase shape Uniqueness])
f ([TypeBase shape NoUniqueness]
-> [Int] -> [(TypeBase shape NoUniqueness, Int)]
forall a b. [a] -> [b] -> [(a, b)]
zip ((TypeBase shape Uniqueness -> TypeBase shape NoUniqueness)
-> [TypeBase shape Uniqueness] -> [TypeBase shape NoUniqueness]
forall a b. (a -> b) -> [a] -> [b]
map TypeBase shape Uniqueness -> TypeBase shape NoUniqueness
forall shape.
TypeBase shape Uniqueness -> TypeBase shape NoUniqueness
fromDecl [TypeBase shape Uniqueness]
ts) [Int
0 ..], [Int]
forall a. Monoid a => a
mempty, [TypeBase shape Uniqueness]
forall a. Monoid a => a
mempty) t (TypeBase shape Uniqueness)
c_ts
in ([TypeBase shape Uniqueness]
ts [TypeBase shape Uniqueness]
-> [TypeBase shape Uniqueness] -> [TypeBase shape Uniqueness]
forall a. [a] -> [a] -> [a]
++ [TypeBase shape Uniqueness]
new_ts, k -> (a, [Int]) -> Map k (a, [Int]) -> Map k (a, [Int])
forall k a. Ord k => k -> a -> Map k a -> Map k a
M.insert k
c (a
i, [Int]
js) Map k (a, [Int])
mapping)
where
f :: ([(TypeBase shape NoUniqueness, Int)], [Int],
[TypeBase shape Uniqueness])
-> TypeBase shape Uniqueness
-> ([(TypeBase shape NoUniqueness, Int)], [Int],
[TypeBase shape Uniqueness])
f ([(TypeBase shape NoUniqueness, Int)]
ts', [Int]
js, [TypeBase shape Uniqueness]
new_ts) TypeBase shape Uniqueness
t
| Just (TypeBase shape NoUniqueness
_, Int
j) <- ((TypeBase shape NoUniqueness, Int) -> Bool)
-> [(TypeBase shape NoUniqueness, Int)]
-> Maybe (TypeBase shape NoUniqueness, Int)
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Maybe a
find ((TypeBase shape NoUniqueness -> TypeBase shape NoUniqueness -> Bool
forall a. Eq a => a -> a -> Bool
== TypeBase shape Uniqueness -> TypeBase shape NoUniqueness
forall shape.
TypeBase shape Uniqueness -> TypeBase shape NoUniqueness
fromDecl TypeBase shape Uniqueness
t) (TypeBase shape NoUniqueness -> Bool)
-> ((TypeBase shape NoUniqueness, Int)
-> TypeBase shape NoUniqueness)
-> (TypeBase shape NoUniqueness, Int)
-> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (TypeBase shape NoUniqueness, Int) -> TypeBase shape NoUniqueness
forall a b. (a, b) -> a
fst) [(TypeBase shape NoUniqueness, Int)]
ts' =
( (TypeBase shape NoUniqueness, Int)
-> [(TypeBase shape NoUniqueness, Int)]
-> [(TypeBase shape NoUniqueness, Int)]
forall a. Eq a => a -> [a] -> [a]
delete (TypeBase shape Uniqueness -> TypeBase shape NoUniqueness
forall shape.
TypeBase shape Uniqueness -> TypeBase shape NoUniqueness
fromDecl TypeBase shape Uniqueness
t, Int
j) [(TypeBase shape NoUniqueness, Int)]
ts',
[Int]
js [Int] -> [Int] -> [Int]
forall a. [a] -> [a] -> [a]
++ [Int
j],
[TypeBase shape Uniqueness]
new_ts
)
| Bool
otherwise =
( [(TypeBase shape NoUniqueness, Int)]
ts',
[Int]
js [Int] -> [Int] -> [Int]
forall a. [a] -> [a] -> [a]
++ [[TypeBase shape Uniqueness] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [TypeBase shape Uniqueness]
ts Int -> Int -> Int
forall a. Num a => a -> a -> a
+ [TypeBase shape Uniqueness] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [TypeBase shape Uniqueness]
new_ts],
[TypeBase shape Uniqueness]
new_ts [TypeBase shape Uniqueness]
-> [TypeBase shape Uniqueness] -> [TypeBase shape Uniqueness]
forall a. [a] -> [a] -> [a]
++ [TypeBase shape Uniqueness
t]
)
internaliseSumType ::
M.Map Name [E.StructType] ->
InternaliseM
( [I.TypeBase ExtShape Uniqueness],
M.Map Name (Int, [Int])
)
internaliseSumType :: Map Name [StructType]
-> InternaliseM
([TypeBase ExtShape Uniqueness], Map Name (Int, [Int]))
internaliseSumType Map Name [StructType]
cs =
InternaliseTypeM
([TypeBase ExtShape Uniqueness], Map Name (Int, [Int]))
-> InternaliseM
([TypeBase ExtShape Uniqueness], Map Name (Int, [Int]))
forall a. InternaliseTypeM a -> InternaliseM a
runInternaliseTypeM (InternaliseTypeM
([TypeBase ExtShape Uniqueness], Map Name (Int, [Int]))
-> InternaliseM
([TypeBase ExtShape Uniqueness], Map Name (Int, [Int])))
-> InternaliseTypeM
([TypeBase ExtShape Uniqueness], Map Name (Int, [Int]))
-> InternaliseM
([TypeBase ExtShape Uniqueness], Map Name (Int, [Int]))
forall a b. (a -> b) -> a -> b
$
Map Name [TypeBase ExtShape Uniqueness]
-> ([TypeBase ExtShape Uniqueness], Map Name (Int, [Int]))
internaliseConstructors
(Map Name [TypeBase ExtShape Uniqueness]
-> ([TypeBase ExtShape Uniqueness], Map Name (Int, [Int])))
-> InternaliseTypeM (Map Name [TypeBase ExtShape Uniqueness])
-> InternaliseTypeM
([TypeBase ExtShape Uniqueness], Map Name (Int, [Int]))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ([StructType] -> InternaliseTypeM [TypeBase ExtShape Uniqueness])
-> Map Name [StructType]
-> InternaliseTypeM (Map Name [TypeBase ExtShape Uniqueness])
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (([[TypeBase ExtShape Uniqueness]]
-> [TypeBase ExtShape Uniqueness])
-> InternaliseTypeM [[TypeBase ExtShape Uniqueness]]
-> InternaliseTypeM [TypeBase ExtShape Uniqueness]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [[TypeBase ExtShape Uniqueness]] -> [TypeBase ExtShape Uniqueness]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat (InternaliseTypeM [[TypeBase ExtShape Uniqueness]]
-> InternaliseTypeM [TypeBase ExtShape Uniqueness])
-> ([StructType]
-> InternaliseTypeM [[TypeBase ExtShape Uniqueness]])
-> [StructType]
-> InternaliseTypeM [TypeBase ExtShape Uniqueness]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (StructType -> InternaliseTypeM [TypeBase ExtShape Uniqueness])
-> [StructType]
-> InternaliseTypeM [[TypeBase ExtShape Uniqueness]]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM StructType -> InternaliseTypeM [TypeBase ExtShape Uniqueness]
internaliseTypeM) Map Name [StructType]
cs
internalisedTypeSize :: E.TypeBase (E.DimDecl VName) () -> InternaliseM Int
internalisedTypeSize :: StructType -> InternaliseM Int
internalisedTypeSize = ([TypeBase ExtShape Uniqueness] -> Int)
-> InternaliseM [TypeBase ExtShape Uniqueness] -> InternaliseM Int
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [TypeBase ExtShape Uniqueness] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length (InternaliseM [TypeBase ExtShape Uniqueness] -> InternaliseM Int)
-> (StructType -> InternaliseM [TypeBase ExtShape Uniqueness])
-> StructType
-> InternaliseM Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. StructType -> InternaliseM [TypeBase ExtShape Uniqueness]
internaliseType
internalisePrimType :: E.PrimType -> I.PrimType
internalisePrimType :: PrimType -> PrimType
internalisePrimType (E.Signed IntType
t) = IntType -> PrimType
I.IntType IntType
t
internalisePrimType (E.Unsigned IntType
t) = IntType -> PrimType
I.IntType IntType
t
internalisePrimType (E.FloatType FloatType
t) = FloatType -> PrimType
I.FloatType FloatType
t
internalisePrimType PrimType
E.Bool = PrimType
I.Bool
internalisePrimValue :: E.PrimValue -> I.PrimValue
internalisePrimValue :: PrimValue -> PrimValue
internalisePrimValue (E.SignedValue IntValue
v) = IntValue -> PrimValue
I.IntValue IntValue
v
internalisePrimValue (E.UnsignedValue IntValue
v) = IntValue -> PrimValue
I.IntValue IntValue
v
internalisePrimValue (E.FloatValue FloatValue
v) = FloatValue -> PrimValue
I.FloatValue FloatValue
v
internalisePrimValue (E.BoolValue Bool
b) = Bool -> PrimValue
I.BoolValue Bool
b