{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE PatternGuards #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE ViewPatterns #-}
{-# OPTIONS_HADDOCK hide #-}
module Data.Array.Accelerate.Trafo.Substitution (
inline, inlineVars, compose,
subTop, subAtop,
(:>), Sink(..), SinkExp(..), weakenVars,
(:?>), strengthen, strengthenE,
RebuildAcc, Rebuildable(..), RebuildableAcc,
RebuildableExp(..), rebuildWeakenVar, rebuildLHS,
OpenAccFun(..), OpenAccExp(..),
isIdentity, isIdentityIndexing, extractExpVars,
bindingIsTrivial,
) where
import Data.Array.Accelerate.AST
import Data.Array.Accelerate.AST.LeftHandSide
import Data.Array.Accelerate.AST.Var
import Data.Array.Accelerate.AST.Idx
import Data.Array.Accelerate.AST.Environment
import Data.Array.Accelerate.Analysis.Match
import Data.Array.Accelerate.Error
import Data.Array.Accelerate.Representation.Type
import Data.Array.Accelerate.Representation.Array
import qualified Data.Array.Accelerate.Debug.Stats as Stats
import Data.Kind
import Control.Applicative hiding ( Const )
import Control.Monad
import Prelude hiding ( exp, seq )
infixr `compose`
lhsFullVars :: forall s a env1 env2. LeftHandSide s a env1 env2 -> Maybe (Vars s env2 a)
lhsFullVars :: LeftHandSide s a env1 env2 -> Maybe (Vars s env2 a)
lhsFullVars = ((env1 :> env2, Vars s env2 a) -> Vars s env2 a)
-> Maybe (env1 :> env2, Vars s env2 a) -> Maybe (Vars s env2 a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (env1 :> env2, Vars s env2 a) -> Vars s env2 a
forall a b. (a, b) -> b
snd (Maybe (env1 :> env2, Vars s env2 a) -> Maybe (Vars s env2 a))
-> (LeftHandSide s a env1 env2
-> Maybe (env1 :> env2, Vars s env2 a))
-> LeftHandSide s a env1 env2
-> Maybe (Vars s env2 a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (env2 :> env2)
-> LeftHandSide s a env1 env2
-> Maybe (env1 :> env2, Vars s env2 a)
forall env env' b.
(env' :> env2)
-> LeftHandSide s b env env' -> Maybe (env :> env2, Vars s env2 b)
go env2 :> env2
forall env. env :> env
weakenId
where
go :: forall env env' b. (env' :> env2) -> LeftHandSide s b env env' -> Maybe (env :> env2, Vars s env2 b)
go :: (env' :> env2)
-> LeftHandSide s b env env' -> Maybe (env :> env2, Vars s env2 b)
go env' :> env2
k (LeftHandSideWildcard TupR s b
TupRunit) = (env' :> env2, TupR (Var s env2) ())
-> Maybe (env' :> env2, TupR (Var s env2) ())
forall a. a -> Maybe a
Just (env' :> env2
k, TupR (Var s env2) ()
forall (s :: * -> *). TupR s ()
TupRunit)
go env' :> env2
k (LeftHandSideSingle s b
s) = (env :> env2, Vars s env2 b) -> Maybe (env :> env2, Vars s env2 b)
forall a. a -> Maybe a
Just ((env :> env2, Vars s env2 b)
-> Maybe (env :> env2, Vars s env2 b))
-> (env :> env2, Vars s env2 b)
-> Maybe (env :> env2, Vars s env2 b)
forall a b. (a -> b) -> a -> b
$ (((env, b) :> env2) -> env :> env2
forall env t env'. ((env, t) :> env') -> env :> env'
weakenSucc (((env, b) :> env2) -> env :> env2)
-> ((env, b) :> env2) -> env :> env2
forall a b. (a -> b) -> a -> b
$ env' :> env2
(env, b) :> env2
k, Var s env2 b -> Vars s env2 b
forall (s :: * -> *) a. s a -> TupR s a
TupRsingle (Var s env2 b -> Vars s env2 b) -> Var s env2 b -> Vars s env2 b
forall a b. (a -> b) -> a -> b
$ s b -> Idx env2 b -> Var s env2 b
forall (s :: * -> *) env t. s t -> Idx env t -> Var s env t
Var s b
s (Idx env2 b -> Var s env2 b) -> Idx env2 b -> Var s env2 b
forall a b. (a -> b) -> a -> b
$ env' :> env2
k (env' :> env2) -> Idx env' b -> Idx env2 b
forall env env'.
(env :> env') -> forall t'. Idx env t' -> Idx env' t'
>:> Idx env' b
forall env t. Idx (env, t) t
ZeroIdx)
go env' :> env2
k (LeftHandSidePair LeftHandSide s v1 env env'
l1 LeftHandSide s v2 env' env'
l2)
| Just (env' :> env2
k', Vars s env2 v2
v2) <- (env' :> env2)
-> LeftHandSide s v2 env' env'
-> Maybe (env' :> env2, Vars s env2 v2)
forall env env' b.
(env' :> env2)
-> LeftHandSide s b env env' -> Maybe (env :> env2, Vars s env2 b)
go env' :> env2
k LeftHandSide s v2 env' env'
l2
, Just (env :> env2
k'', Vars s env2 v1
v1) <- (env' :> env2)
-> LeftHandSide s v1 env env'
-> Maybe (env :> env2, Vars s env2 v1)
forall env env' b.
(env' :> env2)
-> LeftHandSide s b env env' -> Maybe (env :> env2, Vars s env2 b)
go env' :> env2
k' LeftHandSide s v1 env env'
l1 = (env :> env2, TupR (Var s env2) (v1, v2))
-> Maybe (env :> env2, TupR (Var s env2) (v1, v2))
forall a. a -> Maybe a
Just (env :> env2
k'', Vars s env2 v1 -> Vars s env2 v2 -> TupR (Var s env2) (v1, v2)
forall (s :: * -> *) a b. TupR s a -> TupR s b -> TupR s (a, b)
TupRpair Vars s env2 v1
v1 Vars s env2 v2
v2)
go env' :> env2
_ LeftHandSide s b env env'
_ = Maybe (env :> env2, Vars s env2 b)
forall a. Maybe a
Nothing
bindingIsTrivial :: LeftHandSide s a env1 env2 -> Vars s env2 b -> Maybe (a :~: b)
bindingIsTrivial :: LeftHandSide s a env1 env2 -> Vars s env2 b -> Maybe (a :~: b)
bindingIsTrivial LeftHandSide s a env1 env2
lhs Vars s env2 b
vars
| Just Vars s env2 a
lhsVars <- LeftHandSide s a env1 env2 -> Maybe (Vars s env2 a)
forall (s :: * -> *) a env1 env2.
LeftHandSide s a env1 env2 -> Maybe (Vars s env2 a)
lhsFullVars LeftHandSide s a env1 env2
lhs
, Just b :~: a
Refl <- Vars s env2 b -> Vars s env2 a -> Maybe (b :~: a)
forall (s :: * -> *) env t1 t2.
Vars s env t1 -> Vars s env t2 -> Maybe (t1 :~: t2)
matchVars Vars s env2 b
vars Vars s env2 a
lhsVars
= (a :~: a) -> Maybe (a :~: a)
forall a. a -> Maybe a
Just a :~: a
forall k (a :: k). a :~: a
Refl
bindingIsTrivial LeftHandSide s a env1 env2
_ Vars s env2 b
_ = Maybe (a :~: b)
forall a. Maybe a
Nothing
isIdentity :: OpenFun env aenv (a -> b) -> Maybe (a :~: b)
isIdentity :: OpenFun env aenv (a -> b) -> Maybe (a :~: b)
isIdentity (Lam ELeftHandSide a env env'
lhs (Body (OpenExp env' aenv t -> Maybe (ExpVars env' t)
forall env aenv a. OpenExp env aenv a -> Maybe (ExpVars env a)
extractExpVars -> Just ExpVars env' t
vars))) = ELeftHandSide a env env' -> ExpVars env' t -> Maybe (a :~: t)
forall (s :: * -> *) a env1 env2 b.
LeftHandSide s a env1 env2 -> Vars s env2 b -> Maybe (a :~: b)
bindingIsTrivial ELeftHandSide a env env'
lhs ExpVars env' t
vars
isIdentity OpenFun env aenv (a -> b)
_ = Maybe (a :~: b)
forall a. Maybe a
Nothing
isIdentityIndexing :: OpenFun env aenv (a -> b) -> Maybe (ArrayVar aenv (Array a b))
isIdentityIndexing :: OpenFun env aenv (a -> b) -> Maybe (ArrayVar aenv (Array a b))
isIdentityIndexing (Lam ELeftHandSide a env env'
lhs (Body OpenExp env' aenv t
body))
| Index ArrayVar aenv (Array dim t)
avar OpenExp env' aenv dim
ix <- OpenExp env' aenv t
body
, Just ExpVars env' dim
vars <- OpenExp env' aenv dim -> Maybe (ExpVars env' dim)
forall env aenv a. OpenExp env aenv a -> Maybe (ExpVars env a)
extractExpVars OpenExp env' aenv dim
ix
, Just a :~: dim
Refl <- ELeftHandSide a env env' -> ExpVars env' dim -> Maybe (a :~: dim)
forall (s :: * -> *) a env1 env2 b.
LeftHandSide s a env1 env2 -> Vars s env2 b -> Maybe (a :~: b)
bindingIsTrivial ELeftHandSide a env env'
lhs ExpVars env' dim
vars
= ArrayVar aenv (Array dim t) -> Maybe (ArrayVar aenv (Array dim t))
forall a. a -> Maybe a
Just ArrayVar aenv (Array dim t)
avar
isIdentityIndexing OpenFun env aenv (a -> b)
_ = Maybe (ArrayVar aenv (Array a b))
forall a. Maybe a
Nothing
inline :: OpenExp (env, s) aenv t
-> OpenExp env aenv s
-> OpenExp env aenv t
inline :: OpenExp (env, s) aenv t -> OpenExp env aenv s -> OpenExp env aenv t
inline OpenExp (env, s) aenv t
f OpenExp env aenv s
g = Text -> OpenExp env aenv t -> OpenExp env aenv t
forall a. Text -> a -> a
Stats.substitution Text
"inline" (OpenExp env aenv t -> OpenExp env aenv t)
-> OpenExp env aenv t -> OpenExp env aenv t
forall a b. (a -> b) -> a -> b
$ (forall e'. ExpVar (env, s) e' -> OpenExp env aenv e')
-> OpenExp (env, s) aenv t -> OpenExp env aenv t
forall (f :: * -> * -> * -> *) (fe :: * -> * -> * -> *) env env'
aenv e.
(RebuildableExp f, SyntacticExp fe) =>
(forall e'. ExpVar env e' -> fe env' aenv e')
-> f env aenv e -> f env' aenv e
rebuildE (OpenExp env aenv s -> ExpVar (env, s) e' -> OpenExp env aenv e'
forall env aenv s t.
OpenExp env aenv s -> ExpVar (env, s) t -> OpenExp env aenv t
subTop OpenExp env aenv s
g) OpenExp (env, s) aenv t
f
inlineVars :: forall env env' aenv t1 t2.
ELeftHandSide t1 env env'
-> OpenExp env' aenv t2
-> OpenExp env aenv t1
-> Maybe (OpenExp env aenv t2)
inlineVars :: ELeftHandSide t1 env env'
-> OpenExp env' aenv t2
-> OpenExp env aenv t1
-> Maybe (OpenExp env aenv t2)
inlineVars ELeftHandSide t1 env env'
lhsBound OpenExp env' aenv t2
expr OpenExp env aenv t1
bound
| Just Vars ScalarType env' t1
vars <- ELeftHandSide t1 env env' -> Maybe (Vars ScalarType env' t1)
forall (s :: * -> *) a env1 env2.
LeftHandSide s a env1 env2 -> Maybe (Vars s env2 a)
lhsFullVars ELeftHandSide t1 env env'
lhsBound = (env' :?> env)
-> (env :> env)
-> Vars ScalarType env' t1
-> OpenExp env' aenv t2
-> Maybe (OpenExp env aenv t2)
forall env1 env2 t.
(env1 :?> env2)
-> (env :> env2)
-> ExpVars env1 t1
-> OpenExp env1 aenv t
-> Maybe (OpenExp env2 aenv t)
substitute (ELeftHandSide t1 env env' -> env' :?> env
forall (s :: * -> *) t env1 env2.
LeftHandSide s t env1 env2 -> env2 :?> env1
strengthenWithLHS ELeftHandSide t1 env env'
lhsBound) env :> env
forall env. env :> env
weakenId Vars ScalarType env' t1
vars OpenExp env' aenv t2
expr
where
substitute
:: forall env1 env2 t.
env1 :?> env2
-> env :> env2
-> ExpVars env1 t1
-> OpenExp env1 aenv t
-> Maybe (OpenExp env2 aenv t)
substitute :: (env1 :?> env2)
-> (env :> env2)
-> ExpVars env1 t1
-> OpenExp env1 aenv t
-> Maybe (OpenExp env2 aenv t)
substitute env1 :?> env2
_ env :> env2
k2 ExpVars env1 t1
vars (OpenExp env1 aenv t -> Maybe (ExpVars env1 t)
forall env aenv a. OpenExp env aenv a -> Maybe (ExpVars env a)
extractExpVars -> Just ExpVars env1 t
vars')
| Just t1 :~: t
Refl <- ExpVars env1 t1 -> ExpVars env1 t -> Maybe (t1 :~: t)
forall (s :: * -> *) env t1 t2.
Vars s env t1 -> Vars s env t2 -> Maybe (t1 :~: t2)
matchVars ExpVars env1 t1
vars ExpVars env1 t
vars' = OpenExp env2 aenv t1 -> Maybe (OpenExp env2 aenv t1)
forall a. a -> Maybe a
Just (OpenExp env2 aenv t1 -> Maybe (OpenExp env2 aenv t1))
-> OpenExp env2 aenv t1 -> Maybe (OpenExp env2 aenv t1)
forall a b. (a -> b) -> a -> b
$ (env :> env2) -> OpenExp env aenv t1 -> OpenExp env2 aenv t1
forall (f :: * -> * -> * -> *) env env' aenv t.
SinkExp f =>
(env :> env') -> f env aenv t -> f env' aenv t
weakenE env :> env2
k2 OpenExp env aenv t1
bound
substitute env1 :?> env2
k1 env :> env2
k2 ExpVars env1 t1
vars OpenExp env1 aenv t
topExp = case OpenExp env1 aenv t
topExp of
Let ELeftHandSide bnd_t env1 env'
lhs OpenExp env1 aenv bnd_t
e1 OpenExp env' aenv t
e2
| Exists LeftHandSide ScalarType bnd_t env2 a
lhs' <- ELeftHandSide bnd_t env1 env'
-> Exists (LeftHandSide ScalarType bnd_t env2)
forall (s :: * -> *) t aenv1 aenv1' aenv2.
LeftHandSide s t aenv1 aenv1' -> Exists (LeftHandSide s t aenv2)
rebuildLHS ELeftHandSide bnd_t env1 env'
lhs
-> LeftHandSide ScalarType bnd_t env2 a
-> OpenExp env2 aenv bnd_t
-> OpenExp a aenv t
-> OpenExp env2 aenv t
forall bnd_t env env' aenv body_t.
ELeftHandSide bnd_t env env'
-> OpenExp env aenv bnd_t
-> OpenExp env' aenv body_t
-> OpenExp env aenv body_t
Let LeftHandSide ScalarType bnd_t env2 a
lhs' (OpenExp env2 aenv bnd_t
-> OpenExp a aenv t -> OpenExp env2 aenv t)
-> Maybe (OpenExp env2 aenv bnd_t)
-> Maybe (OpenExp a aenv t -> OpenExp env2 aenv t)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> OpenExp env1 aenv bnd_t -> Maybe (OpenExp env2 aenv bnd_t)
forall s. OpenExp env1 aenv s -> Maybe (OpenExp env2 aenv s)
travE OpenExp env1 aenv bnd_t
e1 Maybe (OpenExp a aenv t -> OpenExp env2 aenv t)
-> Maybe (OpenExp a aenv t) -> Maybe (OpenExp env2 aenv t)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (env' :?> a)
-> (env :> a)
-> ExpVars env' t1
-> OpenExp env' aenv t
-> Maybe (OpenExp a aenv t)
forall env1 env2 t.
(env1 :?> env2)
-> (env :> env2)
-> ExpVars env1 t1
-> OpenExp env1 aenv t
-> Maybe (OpenExp env2 aenv t)
substitute (ELeftHandSide bnd_t env1 env'
-> LeftHandSide ScalarType bnd_t env2 a
-> (env1 :?> env2)
-> env' :?> a
forall (s :: * -> *) t env1 env2 env1' env2'.
LeftHandSide s t env1 env2
-> LeftHandSide s t env1' env2'
-> (env1 :?> env1')
-> env2 :?> env2'
strengthenAfter ELeftHandSide bnd_t env1 env'
lhs LeftHandSide ScalarType bnd_t env2 a
lhs' env1 :?> env2
k1) (LeftHandSide ScalarType bnd_t env2 a -> env2 :> a
forall (s :: * -> *) t env env'.
LeftHandSide s t env env' -> env :> env'
weakenWithLHS LeftHandSide ScalarType bnd_t env2 a
lhs' (env2 :> a) -> (env :> env2) -> env :> a
forall env2 env3 env1.
(env2 :> env3) -> (env1 :> env2) -> env1 :> env3
.> env :> env2
k2) (ELeftHandSide bnd_t env1 env' -> env1 :> env'
forall (s :: * -> *) t env env'.
LeftHandSide s t env env' -> env :> env'
weakenWithLHS ELeftHandSide bnd_t env1 env'
lhs (env1 :> env') -> ExpVars env1 t1 -> ExpVars env' t1
forall env env' (s :: * -> *) t.
(env :> env') -> Vars s env t -> Vars s env' t
`weakenVars` ExpVars env1 t1
vars) OpenExp env' aenv t
e2
Evar (Var ScalarType t
t Idx env1 t
ix) -> ExpVar env2 t -> OpenExp env2 aenv t
forall env t aenv. ExpVar env t -> OpenExp env aenv t
Evar (ExpVar env2 t -> OpenExp env2 aenv t)
-> (Idx env2 t -> ExpVar env2 t)
-> Idx env2 t
-> OpenExp env2 aenv t
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ScalarType t -> Idx env2 t -> ExpVar env2 t
forall (s :: * -> *) env t. s t -> Idx env t -> Var s env t
Var ScalarType t
t (Idx env2 t -> OpenExp env2 aenv t)
-> Maybe (Idx env2 t) -> Maybe (OpenExp env2 aenv t)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Idx env1 t -> Maybe (Idx env2 t)
env1 :?> env2
k1 Idx env1 t
ix
Foreign TypeR t
tp asm (x -> t)
asm Fun () (x -> t)
f OpenExp env1 aenv x
e1 -> TypeR t
-> asm (x -> t)
-> Fun () (x -> t)
-> OpenExp env2 aenv x
-> OpenExp env2 aenv t
forall (asm :: * -> *) y x env aenv.
Foreign asm =>
TypeR y
-> asm (x -> y)
-> Fun () (x -> y)
-> OpenExp env aenv x
-> OpenExp env aenv y
Foreign TypeR t
tp asm (x -> t)
asm Fun () (x -> t)
f (OpenExp env2 aenv x -> OpenExp env2 aenv t)
-> Maybe (OpenExp env2 aenv x) -> Maybe (OpenExp env2 aenv t)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> OpenExp env1 aenv x -> Maybe (OpenExp env2 aenv x)
forall s. OpenExp env1 aenv s -> Maybe (OpenExp env2 aenv s)
travE OpenExp env1 aenv x
e1
Pair OpenExp env1 aenv t1
e1 OpenExp env1 aenv t2
e2 -> OpenExp env2 aenv t1
-> OpenExp env2 aenv t2 -> OpenExp env2 aenv (t1, t2)
forall env aenv t1 t2.
OpenExp env aenv t1
-> OpenExp env aenv t2 -> OpenExp env aenv (t1, t2)
Pair (OpenExp env2 aenv t1
-> OpenExp env2 aenv t2 -> OpenExp env2 aenv (t1, t2))
-> Maybe (OpenExp env2 aenv t1)
-> Maybe (OpenExp env2 aenv t2 -> OpenExp env2 aenv (t1, t2))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> OpenExp env1 aenv t1 -> Maybe (OpenExp env2 aenv t1)
forall s. OpenExp env1 aenv s -> Maybe (OpenExp env2 aenv s)
travE OpenExp env1 aenv t1
e1 Maybe (OpenExp env2 aenv t2 -> OpenExp env2 aenv (t1, t2))
-> Maybe (OpenExp env2 aenv t2)
-> Maybe (OpenExp env2 aenv (t1, t2))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> OpenExp env1 aenv t2 -> Maybe (OpenExp env2 aenv t2)
forall s. OpenExp env1 aenv s -> Maybe (OpenExp env2 aenv s)
travE OpenExp env1 aenv t2
e2
OpenExp env1 aenv t
Nil -> OpenExp env2 aenv () -> Maybe (OpenExp env2 aenv ())
forall a. a -> Maybe a
Just OpenExp env2 aenv ()
forall env aenv. OpenExp env aenv ()
Nil
VecPack VecR n s tup
vec OpenExp env1 aenv tup
e1 -> VecR n s tup
-> OpenExp env2 aenv tup -> OpenExp env2 aenv (Vec n s)
forall (n :: Nat) s tup env aenv.
KnownNat n =>
VecR n s tup -> OpenExp env aenv tup -> OpenExp env aenv (Vec n s)
VecPack VecR n s tup
vec (OpenExp env2 aenv tup -> OpenExp env2 aenv (Vec n s))
-> Maybe (OpenExp env2 aenv tup)
-> Maybe (OpenExp env2 aenv (Vec n s))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> OpenExp env1 aenv tup -> Maybe (OpenExp env2 aenv tup)
forall s. OpenExp env1 aenv s -> Maybe (OpenExp env2 aenv s)
travE OpenExp env1 aenv tup
e1
VecUnpack VecR n s t
vec OpenExp env1 aenv (Vec n s)
e1 -> VecR n s t -> OpenExp env2 aenv (Vec n s) -> OpenExp env2 aenv t
forall (n :: Nat) s tup env aenv.
KnownNat n =>
VecR n s tup -> OpenExp env aenv (Vec n s) -> OpenExp env aenv tup
VecUnpack VecR n s t
vec (OpenExp env2 aenv (Vec n s) -> OpenExp env2 aenv t)
-> Maybe (OpenExp env2 aenv (Vec n s))
-> Maybe (OpenExp env2 aenv t)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> OpenExp env1 aenv (Vec n s) -> Maybe (OpenExp env2 aenv (Vec n s))
forall s. OpenExp env1 aenv s -> Maybe (OpenExp env2 aenv s)
travE OpenExp env1 aenv (Vec n s)
e1
IndexSlice SliceIndex slix t co sh
si OpenExp env1 aenv slix
e1 OpenExp env1 aenv sh
e2 -> SliceIndex slix t co sh
-> OpenExp env2 aenv slix
-> OpenExp env2 aenv sh
-> OpenExp env2 aenv t
forall slix sl co sh env aenv.
SliceIndex slix sl co sh
-> OpenExp env aenv slix
-> OpenExp env aenv sh
-> OpenExp env aenv sl
IndexSlice SliceIndex slix t co sh
si (OpenExp env2 aenv slix
-> OpenExp env2 aenv sh -> OpenExp env2 aenv t)
-> Maybe (OpenExp env2 aenv slix)
-> Maybe (OpenExp env2 aenv sh -> OpenExp env2 aenv t)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> OpenExp env1 aenv slix -> Maybe (OpenExp env2 aenv slix)
forall s. OpenExp env1 aenv s -> Maybe (OpenExp env2 aenv s)
travE OpenExp env1 aenv slix
e1 Maybe (OpenExp env2 aenv sh -> OpenExp env2 aenv t)
-> Maybe (OpenExp env2 aenv sh) -> Maybe (OpenExp env2 aenv t)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> OpenExp env1 aenv sh -> Maybe (OpenExp env2 aenv sh)
forall s. OpenExp env1 aenv s -> Maybe (OpenExp env2 aenv s)
travE OpenExp env1 aenv sh
e2
IndexFull SliceIndex slix sl co t
si OpenExp env1 aenv slix
e1 OpenExp env1 aenv sl
e2 -> SliceIndex slix sl co t
-> OpenExp env2 aenv slix
-> OpenExp env2 aenv sl
-> OpenExp env2 aenv t
forall slix sl co sh env aenv.
SliceIndex slix sl co sh
-> OpenExp env aenv slix
-> OpenExp env aenv sl
-> OpenExp env aenv sh
IndexFull SliceIndex slix sl co t
si (OpenExp env2 aenv slix
-> OpenExp env2 aenv sl -> OpenExp env2 aenv t)
-> Maybe (OpenExp env2 aenv slix)
-> Maybe (OpenExp env2 aenv sl -> OpenExp env2 aenv t)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> OpenExp env1 aenv slix -> Maybe (OpenExp env2 aenv slix)
forall s. OpenExp env1 aenv s -> Maybe (OpenExp env2 aenv s)
travE OpenExp env1 aenv slix
e1 Maybe (OpenExp env2 aenv sl -> OpenExp env2 aenv t)
-> Maybe (OpenExp env2 aenv sl) -> Maybe (OpenExp env2 aenv t)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> OpenExp env1 aenv sl -> Maybe (OpenExp env2 aenv sl)
forall s. OpenExp env1 aenv s -> Maybe (OpenExp env2 aenv s)
travE OpenExp env1 aenv sl
e2
ToIndex ShapeR sh
shr OpenExp env1 aenv sh
e1 OpenExp env1 aenv sh
e2 -> ShapeR sh
-> OpenExp env2 aenv sh
-> OpenExp env2 aenv sh
-> OpenExp env2 aenv Int
forall sh env aenv.
ShapeR sh
-> OpenExp env aenv sh
-> OpenExp env aenv sh
-> OpenExp env aenv Int
ToIndex ShapeR sh
shr (OpenExp env2 aenv sh
-> OpenExp env2 aenv sh -> OpenExp env2 aenv Int)
-> Maybe (OpenExp env2 aenv sh)
-> Maybe (OpenExp env2 aenv sh -> OpenExp env2 aenv Int)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> OpenExp env1 aenv sh -> Maybe (OpenExp env2 aenv sh)
forall s. OpenExp env1 aenv s -> Maybe (OpenExp env2 aenv s)
travE OpenExp env1 aenv sh
e1 Maybe (OpenExp env2 aenv sh -> OpenExp env2 aenv Int)
-> Maybe (OpenExp env2 aenv sh) -> Maybe (OpenExp env2 aenv Int)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> OpenExp env1 aenv sh -> Maybe (OpenExp env2 aenv sh)
forall s. OpenExp env1 aenv s -> Maybe (OpenExp env2 aenv s)
travE OpenExp env1 aenv sh
e2
FromIndex ShapeR t
shr OpenExp env1 aenv t
e1 OpenExp env1 aenv Int
e2 -> ShapeR t
-> OpenExp env2 aenv t
-> OpenExp env2 aenv Int
-> OpenExp env2 aenv t
forall sh env aenv.
ShapeR sh
-> OpenExp env aenv sh
-> OpenExp env aenv Int
-> OpenExp env aenv sh
FromIndex ShapeR t
shr (OpenExp env2 aenv t
-> OpenExp env2 aenv Int -> OpenExp env2 aenv t)
-> Maybe (OpenExp env2 aenv t)
-> Maybe (OpenExp env2 aenv Int -> OpenExp env2 aenv t)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> OpenExp env1 aenv t -> Maybe (OpenExp env2 aenv t)
forall s. OpenExp env1 aenv s -> Maybe (OpenExp env2 aenv s)
travE OpenExp env1 aenv t
e1 Maybe (OpenExp env2 aenv Int -> OpenExp env2 aenv t)
-> Maybe (OpenExp env2 aenv Int) -> Maybe (OpenExp env2 aenv t)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> OpenExp env1 aenv Int -> Maybe (OpenExp env2 aenv Int)
forall s. OpenExp env1 aenv s -> Maybe (OpenExp env2 aenv s)
travE OpenExp env1 aenv Int
e2
Case OpenExp env1 aenv TAG
e1 [(TAG, OpenExp env1 aenv t)]
rhs Maybe (OpenExp env1 aenv t)
def -> OpenExp env2 aenv TAG
-> [(TAG, OpenExp env2 aenv t)]
-> Maybe (OpenExp env2 aenv t)
-> OpenExp env2 aenv t
forall env aenv b.
OpenExp env aenv TAG
-> [(TAG, OpenExp env aenv b)]
-> Maybe (OpenExp env aenv b)
-> OpenExp env aenv b
Case (OpenExp env2 aenv TAG
-> [(TAG, OpenExp env2 aenv t)]
-> Maybe (OpenExp env2 aenv t)
-> OpenExp env2 aenv t)
-> Maybe (OpenExp env2 aenv TAG)
-> Maybe
([(TAG, OpenExp env2 aenv t)]
-> Maybe (OpenExp env2 aenv t) -> OpenExp env2 aenv t)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> OpenExp env1 aenv TAG -> Maybe (OpenExp env2 aenv TAG)
forall s. OpenExp env1 aenv s -> Maybe (OpenExp env2 aenv s)
travE OpenExp env1 aenv TAG
e1 Maybe
([(TAG, OpenExp env2 aenv t)]
-> Maybe (OpenExp env2 aenv t) -> OpenExp env2 aenv t)
-> Maybe [(TAG, OpenExp env2 aenv t)]
-> Maybe (Maybe (OpenExp env2 aenv t) -> OpenExp env2 aenv t)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((TAG, OpenExp env1 aenv t) -> Maybe (TAG, OpenExp env2 aenv t))
-> [(TAG, OpenExp env1 aenv t)]
-> Maybe [(TAG, OpenExp env2 aenv t)]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (\(TAG
t,OpenExp env1 aenv t
c) -> (TAG
t,) (OpenExp env2 aenv t -> (TAG, OpenExp env2 aenv t))
-> Maybe (OpenExp env2 aenv t) -> Maybe (TAG, OpenExp env2 aenv t)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> OpenExp env1 aenv t -> Maybe (OpenExp env2 aenv t)
forall s. OpenExp env1 aenv s -> Maybe (OpenExp env2 aenv s)
travE OpenExp env1 aenv t
c) [(TAG, OpenExp env1 aenv t)]
rhs Maybe (Maybe (OpenExp env2 aenv t) -> OpenExp env2 aenv t)
-> Maybe (Maybe (OpenExp env2 aenv t))
-> Maybe (OpenExp env2 aenv t)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Maybe (OpenExp env1 aenv t) -> Maybe (Maybe (OpenExp env2 aenv t))
forall s.
Maybe (OpenExp env1 aenv s) -> Maybe (Maybe (OpenExp env2 aenv s))
travMaybeE Maybe (OpenExp env1 aenv t)
def
Cond OpenExp env1 aenv TAG
e1 OpenExp env1 aenv t
e2 OpenExp env1 aenv t
e3 -> OpenExp env2 aenv TAG
-> OpenExp env2 aenv t
-> OpenExp env2 aenv t
-> OpenExp env2 aenv t
forall env aenv t.
OpenExp env aenv TAG
-> OpenExp env aenv t -> OpenExp env aenv t -> OpenExp env aenv t
Cond (OpenExp env2 aenv TAG
-> OpenExp env2 aenv t
-> OpenExp env2 aenv t
-> OpenExp env2 aenv t)
-> Maybe (OpenExp env2 aenv TAG)
-> Maybe
(OpenExp env2 aenv t -> OpenExp env2 aenv t -> OpenExp env2 aenv t)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> OpenExp env1 aenv TAG -> Maybe (OpenExp env2 aenv TAG)
forall s. OpenExp env1 aenv s -> Maybe (OpenExp env2 aenv s)
travE OpenExp env1 aenv TAG
e1 Maybe
(OpenExp env2 aenv t -> OpenExp env2 aenv t -> OpenExp env2 aenv t)
-> Maybe (OpenExp env2 aenv t)
-> Maybe (OpenExp env2 aenv t -> OpenExp env2 aenv t)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> OpenExp env1 aenv t -> Maybe (OpenExp env2 aenv t)
forall s. OpenExp env1 aenv s -> Maybe (OpenExp env2 aenv s)
travE OpenExp env1 aenv t
e2 Maybe (OpenExp env2 aenv t -> OpenExp env2 aenv t)
-> Maybe (OpenExp env2 aenv t) -> Maybe (OpenExp env2 aenv t)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> OpenExp env1 aenv t -> Maybe (OpenExp env2 aenv t)
forall s. OpenExp env1 aenv s -> Maybe (OpenExp env2 aenv s)
travE OpenExp env1 aenv t
e3
While OpenFun env1 aenv (t -> TAG)
f1 OpenFun env1 aenv (t -> t)
f2 OpenExp env1 aenv t
e1 -> OpenFun env2 aenv (t -> TAG)
-> OpenFun env2 aenv (t -> t)
-> OpenExp env2 aenv t
-> OpenExp env2 aenv t
forall env aenv a.
OpenFun env aenv (a -> TAG)
-> OpenFun env aenv (a -> a)
-> OpenExp env aenv a
-> OpenExp env aenv a
While (OpenFun env2 aenv (t -> TAG)
-> OpenFun env2 aenv (t -> t)
-> OpenExp env2 aenv t
-> OpenExp env2 aenv t)
-> Maybe (OpenFun env2 aenv (t -> TAG))
-> Maybe
(OpenFun env2 aenv (t -> t)
-> OpenExp env2 aenv t -> OpenExp env2 aenv t)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> OpenFun env1 aenv (t -> TAG)
-> Maybe (OpenFun env2 aenv (t -> TAG))
forall s. OpenFun env1 aenv s -> Maybe (OpenFun env2 aenv s)
travF OpenFun env1 aenv (t -> TAG)
f1 Maybe
(OpenFun env2 aenv (t -> t)
-> OpenExp env2 aenv t -> OpenExp env2 aenv t)
-> Maybe (OpenFun env2 aenv (t -> t))
-> Maybe (OpenExp env2 aenv t -> OpenExp env2 aenv t)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> OpenFun env1 aenv (t -> t) -> Maybe (OpenFun env2 aenv (t -> t))
forall s. OpenFun env1 aenv s -> Maybe (OpenFun env2 aenv s)
travF OpenFun env1 aenv (t -> t)
f2 Maybe (OpenExp env2 aenv t -> OpenExp env2 aenv t)
-> Maybe (OpenExp env2 aenv t) -> Maybe (OpenExp env2 aenv t)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> OpenExp env1 aenv t -> Maybe (OpenExp env2 aenv t)
forall s. OpenExp env1 aenv s -> Maybe (OpenExp env2 aenv s)
travE OpenExp env1 aenv t
e1
Const ScalarType t
t t
c -> OpenExp env2 aenv t -> Maybe (OpenExp env2 aenv t)
forall a. a -> Maybe a
Just (OpenExp env2 aenv t -> Maybe (OpenExp env2 aenv t))
-> OpenExp env2 aenv t -> Maybe (OpenExp env2 aenv t)
forall a b. (a -> b) -> a -> b
$ ScalarType t -> t -> OpenExp env2 aenv t
forall t env aenv. ScalarType t -> t -> OpenExp env aenv t
Const ScalarType t
t t
c
PrimConst PrimConst t
c -> OpenExp env2 aenv t -> Maybe (OpenExp env2 aenv t)
forall a. a -> Maybe a
Just (OpenExp env2 aenv t -> Maybe (OpenExp env2 aenv t))
-> OpenExp env2 aenv t -> Maybe (OpenExp env2 aenv t)
forall a b. (a -> b) -> a -> b
$ PrimConst t -> OpenExp env2 aenv t
forall t env aenv. PrimConst t -> OpenExp env aenv t
PrimConst PrimConst t
c
PrimApp PrimFun (a -> t)
p OpenExp env1 aenv a
e1 -> PrimFun (a -> t) -> OpenExp env2 aenv a -> OpenExp env2 aenv t
forall a r env aenv.
PrimFun (a -> r) -> OpenExp env aenv a -> OpenExp env aenv r
PrimApp PrimFun (a -> t)
p (OpenExp env2 aenv a -> OpenExp env2 aenv t)
-> Maybe (OpenExp env2 aenv a) -> Maybe (OpenExp env2 aenv t)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> OpenExp env1 aenv a -> Maybe (OpenExp env2 aenv a)
forall s. OpenExp env1 aenv s -> Maybe (OpenExp env2 aenv s)
travE OpenExp env1 aenv a
e1
Index ArrayVar aenv (Array dim t)
a OpenExp env1 aenv dim
e1 -> ArrayVar aenv (Array dim t)
-> OpenExp env2 aenv dim -> OpenExp env2 aenv t
forall aenv dim t env.
ArrayVar aenv (Array dim t)
-> OpenExp env aenv dim -> OpenExp env aenv t
Index ArrayVar aenv (Array dim t)
a (OpenExp env2 aenv dim -> OpenExp env2 aenv t)
-> Maybe (OpenExp env2 aenv dim) -> Maybe (OpenExp env2 aenv t)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> OpenExp env1 aenv dim -> Maybe (OpenExp env2 aenv dim)
forall s. OpenExp env1 aenv s -> Maybe (OpenExp env2 aenv s)
travE OpenExp env1 aenv dim
e1
LinearIndex ArrayVar aenv (Array dim t)
a OpenExp env1 aenv Int
e1 -> ArrayVar aenv (Array dim t)
-> OpenExp env2 aenv Int -> OpenExp env2 aenv t
forall aenv dim t env.
ArrayVar aenv (Array dim t)
-> OpenExp env aenv Int -> OpenExp env aenv t
LinearIndex ArrayVar aenv (Array dim t)
a (OpenExp env2 aenv Int -> OpenExp env2 aenv t)
-> Maybe (OpenExp env2 aenv Int) -> Maybe (OpenExp env2 aenv t)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> OpenExp env1 aenv Int -> Maybe (OpenExp env2 aenv Int)
forall s. OpenExp env1 aenv s -> Maybe (OpenExp env2 aenv s)
travE OpenExp env1 aenv Int
e1
Shape ArrayVar aenv (Array t e)
a -> OpenExp env2 aenv t -> Maybe (OpenExp env2 aenv t)
forall a. a -> Maybe a
Just (OpenExp env2 aenv t -> Maybe (OpenExp env2 aenv t))
-> OpenExp env2 aenv t -> Maybe (OpenExp env2 aenv t)
forall a b. (a -> b) -> a -> b
$ ArrayVar aenv (Array t e) -> OpenExp env2 aenv t
forall aenv dim e env.
ArrayVar aenv (Array dim e) -> OpenExp env aenv dim
Shape ArrayVar aenv (Array t e)
a
ShapeSize ShapeR dim
shr OpenExp env1 aenv dim
e1 -> ShapeR dim -> OpenExp env2 aenv dim -> OpenExp env2 aenv Int
forall dim env aenv.
ShapeR dim -> OpenExp env aenv dim -> OpenExp env aenv Int
ShapeSize ShapeR dim
shr (OpenExp env2 aenv dim -> OpenExp env2 aenv Int)
-> Maybe (OpenExp env2 aenv dim) -> Maybe (OpenExp env2 aenv Int)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> OpenExp env1 aenv dim -> Maybe (OpenExp env2 aenv dim)
forall s. OpenExp env1 aenv s -> Maybe (OpenExp env2 aenv s)
travE OpenExp env1 aenv dim
e1
Undef ScalarType t
t -> OpenExp env2 aenv t -> Maybe (OpenExp env2 aenv t)
forall a. a -> Maybe a
Just (OpenExp env2 aenv t -> Maybe (OpenExp env2 aenv t))
-> OpenExp env2 aenv t -> Maybe (OpenExp env2 aenv t)
forall a b. (a -> b) -> a -> b
$ ScalarType t -> OpenExp env2 aenv t
forall t env aenv. ScalarType t -> OpenExp env aenv t
Undef ScalarType t
t
Coerce ScalarType a
t1 ScalarType t
t2 OpenExp env1 aenv a
e1 -> ScalarType a
-> ScalarType t -> OpenExp env2 aenv a -> OpenExp env2 aenv t
forall a b env aenv.
BitSizeEq a b =>
ScalarType a
-> ScalarType b -> OpenExp env aenv a -> OpenExp env aenv b
Coerce ScalarType a
t1 ScalarType t
t2 (OpenExp env2 aenv a -> OpenExp env2 aenv t)
-> Maybe (OpenExp env2 aenv a) -> Maybe (OpenExp env2 aenv t)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> OpenExp env1 aenv a -> Maybe (OpenExp env2 aenv a)
forall s. OpenExp env1 aenv s -> Maybe (OpenExp env2 aenv s)
travE OpenExp env1 aenv a
e1
where
travE :: OpenExp env1 aenv s -> Maybe (OpenExp env2 aenv s)
travE :: OpenExp env1 aenv s -> Maybe (OpenExp env2 aenv s)
travE = (env1 :?> env2)
-> (env :> env2)
-> ExpVars env1 t1
-> OpenExp env1 aenv s
-> Maybe (OpenExp env2 aenv s)
forall env1 env2 t.
(env1 :?> env2)
-> (env :> env2)
-> ExpVars env1 t1
-> OpenExp env1 aenv t
-> Maybe (OpenExp env2 aenv t)
substitute env1 :?> env2
k1 env :> env2
k2 ExpVars env1 t1
vars
travF :: OpenFun env1 aenv s -> Maybe (OpenFun env2 aenv s)
travF :: OpenFun env1 aenv s -> Maybe (OpenFun env2 aenv s)
travF = (env1 :?> env2)
-> (env :> env2)
-> ExpVars env1 t1
-> OpenFun env1 aenv s
-> Maybe (OpenFun env2 aenv s)
forall env1 env2 t.
(env1 :?> env2)
-> (env :> env2)
-> ExpVars env1 t1
-> OpenFun env1 aenv t
-> Maybe (OpenFun env2 aenv t)
substituteF env1 :?> env2
k1 env :> env2
k2 ExpVars env1 t1
vars
travMaybeE :: Maybe (OpenExp env1 aenv s) -> Maybe (Maybe (OpenExp env2 aenv s))
travMaybeE :: Maybe (OpenExp env1 aenv s) -> Maybe (Maybe (OpenExp env2 aenv s))
travMaybeE Maybe (OpenExp env1 aenv s)
Nothing = Maybe (OpenExp env2 aenv s) -> Maybe (Maybe (OpenExp env2 aenv s))
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe (OpenExp env2 aenv s)
forall a. Maybe a
Nothing
travMaybeE (Just OpenExp env1 aenv s
x) = OpenExp env2 aenv s -> Maybe (OpenExp env2 aenv s)
forall a. a -> Maybe a
Just (OpenExp env2 aenv s -> Maybe (OpenExp env2 aenv s))
-> Maybe (OpenExp env2 aenv s)
-> Maybe (Maybe (OpenExp env2 aenv s))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> OpenExp env1 aenv s -> Maybe (OpenExp env2 aenv s)
forall s. OpenExp env1 aenv s -> Maybe (OpenExp env2 aenv s)
travE OpenExp env1 aenv s
x
substituteF :: forall env1 env2 t.
env1 :?> env2
-> env :> env2
-> ExpVars env1 t1
-> OpenFun env1 aenv t
-> Maybe (OpenFun env2 aenv t)
substituteF :: (env1 :?> env2)
-> (env :> env2)
-> ExpVars env1 t1
-> OpenFun env1 aenv t
-> Maybe (OpenFun env2 aenv t)
substituteF env1 :?> env2
k1 env :> env2
k2 ExpVars env1 t1
vars (Body OpenExp env1 aenv t
e) = OpenExp env2 aenv t -> OpenFun env2 aenv t
forall env aenv t. OpenExp env aenv t -> OpenFun env aenv t
Body (OpenExp env2 aenv t -> OpenFun env2 aenv t)
-> Maybe (OpenExp env2 aenv t) -> Maybe (OpenFun env2 aenv t)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (env1 :?> env2)
-> (env :> env2)
-> ExpVars env1 t1
-> OpenExp env1 aenv t
-> Maybe (OpenExp env2 aenv t)
forall env1 env2 t.
(env1 :?> env2)
-> (env :> env2)
-> ExpVars env1 t1
-> OpenExp env1 aenv t
-> Maybe (OpenExp env2 aenv t)
substitute env1 :?> env2
k1 env :> env2
k2 ExpVars env1 t1
vars OpenExp env1 aenv t
e
substituteF env1 :?> env2
k1 env :> env2
k2 ExpVars env1 t1
vars (Lam ELeftHandSide a env1 env'
lhs OpenFun env' aenv t
f)
| Exists LeftHandSide ScalarType a env2 a
lhs' <- ELeftHandSide a env1 env'
-> Exists (LeftHandSide ScalarType a env2)
forall (s :: * -> *) t aenv1 aenv1' aenv2.
LeftHandSide s t aenv1 aenv1' -> Exists (LeftHandSide s t aenv2)
rebuildLHS ELeftHandSide a env1 env'
lhs = LeftHandSide ScalarType a env2 a
-> OpenFun a aenv t -> OpenFun env2 aenv (a -> t)
forall a env env' aenv t.
ELeftHandSide a env env'
-> OpenFun env' aenv t -> OpenFun env aenv (a -> t)
Lam LeftHandSide ScalarType a env2 a
lhs' (OpenFun a aenv t -> OpenFun env2 aenv (a -> t))
-> Maybe (OpenFun a aenv t) -> Maybe (OpenFun env2 aenv (a -> t))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (env' :?> a)
-> (env :> a)
-> ExpVars env' t1
-> OpenFun env' aenv t
-> Maybe (OpenFun a aenv t)
forall env1 env2 t.
(env1 :?> env2)
-> (env :> env2)
-> ExpVars env1 t1
-> OpenFun env1 aenv t
-> Maybe (OpenFun env2 aenv t)
substituteF (ELeftHandSide a env1 env'
-> LeftHandSide ScalarType a env2 a
-> (env1 :?> env2)
-> env' :?> a
forall (s :: * -> *) t env1 env2 env1' env2'.
LeftHandSide s t env1 env2
-> LeftHandSide s t env1' env2'
-> (env1 :?> env1')
-> env2 :?> env2'
strengthenAfter ELeftHandSide a env1 env'
lhs LeftHandSide ScalarType a env2 a
lhs' env1 :?> env2
k1) (LeftHandSide ScalarType a env2 a -> env2 :> a
forall (s :: * -> *) t env env'.
LeftHandSide s t env env' -> env :> env'
weakenWithLHS LeftHandSide ScalarType a env2 a
lhs' (env2 :> a) -> (env :> env2) -> env :> a
forall env2 env3 env1.
(env2 :> env3) -> (env1 :> env2) -> env1 :> env3
.> env :> env2
k2) (ELeftHandSide a env1 env' -> env1 :> env'
forall (s :: * -> *) t env env'.
LeftHandSide s t env env' -> env :> env'
weakenWithLHS ELeftHandSide a env1 env'
lhs (env1 :> env') -> ExpVars env1 t1 -> ExpVars env' t1
forall env env' (s :: * -> *) t.
(env :> env') -> Vars s env t -> Vars s env' t
`weakenVars` ExpVars env1 t1
vars) OpenFun env' aenv t
f
inlineVars ELeftHandSide t1 env env'
_ OpenExp env' aenv t2
_ OpenExp env aenv t1
_ = Maybe (OpenExp env aenv t2)
forall a. Maybe a
Nothing
compose :: HasCallStack
=> OpenFun env aenv (b -> c)
-> OpenFun env aenv (a -> b)
-> OpenFun env aenv (a -> c)
compose :: OpenFun env aenv (b -> c)
-> OpenFun env aenv (a -> b) -> OpenFun env aenv (a -> c)
compose f :: OpenFun env aenv (b -> c)
f@(Lam ELeftHandSide a env env'
lhsB (Body OpenExp env' aenv t
c)) g :: OpenFun env aenv (a -> b)
g@(Lam ELeftHandSide a env env'
lhsA (Body OpenExp env' aenv t
b))
| Text -> Bool -> Bool
forall a. Text -> a -> a
Stats.substitution Text
"compose" Bool
False = OpenFun env aenv (a -> c)
forall a. HasCallStack => a
undefined
| Just b :~: c
Refl <- OpenFun env aenv (b -> c) -> Maybe (b :~: c)
forall env aenv a b. OpenFun env aenv (a -> b) -> Maybe (a :~: b)
isIdentity OpenFun env aenv (b -> c)
f = OpenFun env aenv (a -> b)
OpenFun env aenv (a -> c)
g
| Just a :~: b
Refl <- OpenFun env aenv (a -> b) -> Maybe (a :~: b)
forall env aenv a b. OpenFun env aenv (a -> b) -> Maybe (a :~: b)
isIdentity OpenFun env aenv (a -> b)
g = OpenFun env aenv (b -> c)
OpenFun env aenv (a -> c)
f
| Exists LeftHandSide ScalarType a env' a
lhsB' <- ELeftHandSide a env env' -> Exists (LeftHandSide ScalarType a env')
forall (s :: * -> *) t aenv1 aenv1' aenv2.
LeftHandSide s t aenv1 aenv1' -> Exists (LeftHandSide s t aenv2)
rebuildLHS ELeftHandSide a env env'
lhsB
= ELeftHandSide a env env'
-> OpenFun env' aenv t -> OpenFun env aenv (a -> t)
forall a env env' aenv t.
ELeftHandSide a env env'
-> OpenFun env' aenv t -> OpenFun env aenv (a -> t)
Lam ELeftHandSide a env env'
lhsA
(OpenFun env' aenv t -> OpenFun env aenv (a -> t))
-> OpenFun env' aenv t -> OpenFun env aenv (a -> t)
forall a b. (a -> b) -> a -> b
$ OpenExp env' aenv t -> OpenFun env' aenv t
forall env aenv t. OpenExp env aenv t -> OpenFun env aenv t
Body
(OpenExp env' aenv t -> OpenFun env' aenv t)
-> OpenExp env' aenv t -> OpenFun env' aenv t
forall a b. (a -> b) -> a -> b
$ LeftHandSide ScalarType a env' a
-> OpenExp env' aenv a -> OpenExp a aenv t -> OpenExp env' aenv t
forall bnd_t env env' aenv body_t.
ELeftHandSide bnd_t env env'
-> OpenExp env aenv bnd_t
-> OpenExp env' aenv body_t
-> OpenExp env aenv body_t
Let LeftHandSide ScalarType a env' a
lhsB' OpenExp env' aenv a
OpenExp env' aenv t
b
(OpenExp a aenv t -> OpenExp env' aenv t)
-> OpenExp a aenv t -> OpenExp env' aenv t
forall a b. (a -> b) -> a -> b
$ (env' :> a) -> OpenExp env' aenv t -> OpenExp a aenv t
forall (f :: * -> * -> * -> *) env env' aenv t.
SinkExp f =>
(env :> env') -> f env aenv t -> f env' aenv t
weakenE (ELeftHandSide a env env'
-> LeftHandSide ScalarType a env' a -> (env :> env') -> env' :> a
forall (s :: * -> *) t env1 env1' env2 env2'.
HasCallStack =>
LeftHandSide s t env1 env1'
-> LeftHandSide s t env2 env2' -> (env1 :> env2) -> env1' :> env2'
sinkWithLHS ELeftHandSide a env env'
lhsB LeftHandSide ScalarType a env' a
lhsB' ((env :> env') -> env' :> a) -> (env :> env') -> env' :> a
forall a b. (a -> b) -> a -> b
$ ELeftHandSide a env env' -> env :> env'
forall (s :: * -> *) t env env'.
LeftHandSide s t env env' -> env :> env'
weakenWithLHS ELeftHandSide a env env'
lhsA) OpenExp env' aenv t
c
compose OpenFun env aenv (b -> c)
_
OpenFun env aenv (a -> b)
_ = [Char] -> OpenFun env aenv (a -> c)
forall a. HasCallStack => [Char] -> a
error [Char]
"compose: impossible evaluation"
subTop :: OpenExp env aenv s -> ExpVar (env, s) t -> OpenExp env aenv t
subTop :: OpenExp env aenv s -> ExpVar (env, s) t -> OpenExp env aenv t
subTop OpenExp env aenv s
s (Var ScalarType t
_ Idx (env, s) t
ZeroIdx ) = OpenExp env aenv s
OpenExp env aenv t
s
subTop OpenExp env aenv s
_ (Var ScalarType t
tp (SuccIdx Idx env t
ix)) = ExpVar env t -> OpenExp env aenv t
forall env t aenv. ExpVar env t -> OpenExp env aenv t
Evar (ExpVar env t -> OpenExp env aenv t)
-> ExpVar env t -> OpenExp env aenv t
forall a b. (a -> b) -> a -> b
$ ScalarType t -> Idx env t -> ExpVar env t
forall (s :: * -> *) env t. s t -> Idx env t -> Var s env t
Var ScalarType t
tp Idx env t
ix
subAtop :: PreOpenAcc acc aenv t -> ArrayVar (aenv, t) (Array sh2 e2) -> PreOpenAcc acc aenv (Array sh2 e2)
subAtop :: PreOpenAcc acc aenv t
-> ArrayVar (aenv, t) (Array sh2 e2)
-> PreOpenAcc acc aenv (Array sh2 e2)
subAtop PreOpenAcc acc aenv t
t (Var ArrayR (Array sh2 e2)
_ Idx (aenv, t) (Array sh2 e2)
ZeroIdx ) = PreOpenAcc acc aenv t
PreOpenAcc acc aenv (Array sh2 e2)
t
subAtop PreOpenAcc acc aenv t
_ (Var ArrayR (Array sh2 e2)
repr (SuccIdx Idx env (Array sh2 e2)
idx)) = ArrayVar env (Array sh2 e2) -> PreOpenAcc acc env (Array sh2 e2)
forall aenv sh e (acc :: * -> * -> *).
ArrayVar aenv (Array sh e) -> PreOpenAcc acc aenv (Array sh e)
Avar (ArrayVar env (Array sh2 e2) -> PreOpenAcc acc env (Array sh2 e2))
-> ArrayVar env (Array sh2 e2) -> PreOpenAcc acc env (Array sh2 e2)
forall a b. (a -> b) -> a -> b
$ ArrayR (Array sh2 e2)
-> Idx env (Array sh2 e2) -> ArrayVar env (Array sh2 e2)
forall (s :: * -> *) env t. s t -> Idx env t -> Var s env t
Var ArrayR (Array sh2 e2)
repr Idx env (Array sh2 e2)
idx
data Identity a = Identity { Identity a -> a
runIdentity :: a }
instance Functor Identity where
{-# INLINE fmap #-}
fmap :: (a -> b) -> Identity a -> Identity b
fmap a -> b
f (Identity a
a) = b -> Identity b
forall a. a -> Identity a
Identity (a -> b
f a
a)
instance Applicative Identity where
{-# INLINE (<*>) #-}
{-# INLINE pure #-}
Identity a -> b
f <*> :: Identity (a -> b) -> Identity a -> Identity b
<*> Identity a
a = b -> Identity b
forall a. a -> Identity a
Identity (a -> b
f a
a)
pure :: a -> Identity a
pure a
a = a -> Identity a
forall a. a -> Identity a
Identity a
a
class Rebuildable f where
{-# MINIMAL rebuildPartial #-}
type AccClo f :: Type -> Type -> Type
rebuildPartial :: (Applicative f', SyntacticAcc fa)
=> (forall sh e. ArrayVar aenv (Array sh e) -> f' (fa (AccClo f) aenv' (Array sh e)))
-> f aenv a
-> f' (f aenv' a)
{-# INLINEABLE rebuildA #-}
rebuildA :: (SyntacticAcc fa)
=> (forall sh e. ArrayVar aenv (Array sh e) -> fa (AccClo f) aenv' (Array sh e))
-> f aenv a
-> f aenv' a
rebuildA forall sh e.
ArrayVar aenv (Array sh e) -> fa (AccClo f) aenv' (Array sh e)
av = Identity (f aenv' a) -> f aenv' a
forall a. Identity a -> a
runIdentity (Identity (f aenv' a) -> f aenv' a)
-> (f aenv a -> Identity (f aenv' a)) -> f aenv a -> f aenv' a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall sh e.
ArrayVar aenv (Array sh e)
-> Identity (fa (AccClo f) aenv' (Array sh e)))
-> f aenv a -> Identity (f aenv' a)
forall (f :: * -> * -> *) (f' :: * -> *)
(fa :: (* -> * -> *) -> * -> * -> *) aenv aenv' a.
(Rebuildable f, Applicative f', SyntacticAcc fa) =>
(forall sh e.
ArrayVar aenv (Array sh e)
-> f' (fa (AccClo f) aenv' (Array sh e)))
-> f aenv a -> f' (f aenv' a)
rebuildPartial (fa (AccClo f) aenv' (Array sh e)
-> Identity (fa (AccClo f) aenv' (Array sh e))
forall a. a -> Identity a
Identity (fa (AccClo f) aenv' (Array sh e)
-> Identity (fa (AccClo f) aenv' (Array sh e)))
-> (ArrayVar aenv (Array sh e) -> fa (AccClo f) aenv' (Array sh e))
-> ArrayVar aenv (Array sh e)
-> Identity (fa (AccClo f) aenv' (Array sh e))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ArrayVar aenv (Array sh e) -> fa (AccClo f) aenv' (Array sh e)
forall sh e.
ArrayVar aenv (Array sh e) -> fa (AccClo f) aenv' (Array sh e)
av)
class RebuildableExp f where
{-# MINIMAL rebuildPartialE #-}
rebuildPartialE :: (Applicative f', SyntacticExp fe)
=> (forall e'. ExpVar env e' -> f' (fe env' aenv e'))
-> f env aenv e
-> f' (f env' aenv e)
{-# INLINEABLE rebuildE #-}
rebuildE :: SyntacticExp fe
=> (forall e'. ExpVar env e' -> fe env' aenv e')
-> f env aenv e
-> f env' aenv e
rebuildE forall e'. ExpVar env e' -> fe env' aenv e'
v = Identity (f env' aenv e) -> f env' aenv e
forall a. Identity a -> a
runIdentity (Identity (f env' aenv e) -> f env' aenv e)
-> (f env aenv e -> Identity (f env' aenv e))
-> f env aenv e
-> f env' aenv e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall e'. ExpVar env e' -> Identity (fe env' aenv e'))
-> f env aenv e -> Identity (f env' aenv e)
forall (f :: * -> * -> * -> *) (f' :: * -> *)
(fe :: * -> * -> * -> *) env env' aenv e.
(RebuildableExp f, Applicative f', SyntacticExp fe) =>
(forall e'. ExpVar env e' -> f' (fe env' aenv e'))
-> f env aenv e -> f' (f env' aenv e)
rebuildPartialE (fe env' aenv e' -> Identity (fe env' aenv e')
forall a. a -> Identity a
Identity (fe env' aenv e' -> Identity (fe env' aenv e'))
-> (ExpVar env e' -> fe env' aenv e')
-> ExpVar env e'
-> Identity (fe env' aenv e')
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ExpVar env e' -> fe env' aenv e'
forall e'. ExpVar env e' -> fe env' aenv e'
v)
type RebuildableAcc acc = (Rebuildable acc, AccClo acc ~ acc)
data OpenAccExp (acc :: Type -> Type -> Type) env aenv a where
OpenAccExp :: { OpenAccExp acc env aenv a -> OpenExp env aenv a
unOpenAccExp :: OpenExp env aenv a } -> OpenAccExp acc env aenv a
data OpenAccFun (acc :: Type -> Type -> Type) env aenv a where
OpenAccFun :: { OpenAccFun acc env aenv a -> OpenFun env aenv a
unOpenAccFun :: OpenFun env aenv a } -> OpenAccFun acc env aenv a
instance Rebuildable (OpenAccExp acc env) where
type AccClo (OpenAccExp acc env) = acc
{-# INLINEABLE rebuildPartial #-}
rebuildPartial :: (forall sh e.
ArrayVar aenv (Array sh e)
-> f' (fa (AccClo (OpenAccExp acc env)) aenv' (Array sh e)))
-> OpenAccExp acc env aenv a -> f' (OpenAccExp acc env aenv' a)
rebuildPartial forall sh e.
ArrayVar aenv (Array sh e)
-> f' (fa (AccClo (OpenAccExp acc env)) aenv' (Array sh e))
v (OpenAccExp OpenExp env aenv a
e) = OpenExp env aenv' a -> OpenAccExp acc env aenv' a
forall env aenv a (acc :: * -> * -> *).
OpenExp env aenv a -> OpenAccExp acc env aenv a
OpenAccExp (OpenExp env aenv' a -> OpenAccExp acc env aenv' a)
-> f' (OpenExp env aenv' a) -> f' (OpenAccExp acc env aenv' a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text -> f' (OpenExp env aenv' a) -> f' (OpenExp env aenv' a)
forall a. Text -> a -> a
Stats.substitution Text
"rebuild" (RebuildEvar f' IdxE env env aenv'
-> ReindexAvar f' aenv aenv'
-> OpenExp env aenv a
-> f' (OpenExp env aenv' a)
forall (f :: * -> *) (fe :: * -> * -> * -> *) env env' aenv' aenv
t.
(HasCallStack, Applicative f, SyntacticExp fe) =>
RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> OpenExp env aenv t
-> f (OpenExp env' aenv' t)
rebuildOpenExp (IdxE env aenv' t' -> f' (IdxE env aenv' t')
forall (f :: * -> *) a. Applicative f => a -> f a
pure (IdxE env aenv' t' -> f' (IdxE env aenv' t'))
-> (ExpVar env t' -> IdxE env aenv' t')
-> ExpVar env t'
-> f' (IdxE env aenv' t')
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ExpVar env t' -> IdxE env aenv' t'
forall env aenv t. ExpVar env t -> IdxE env aenv t
IE) (RebuildAvar f' fa acc aenv aenv' -> ReindexAvar f' aenv aenv'
forall (f :: * -> *) (fa :: (* -> * -> *) -> * -> * -> *)
(acc :: * -> * -> *) aenv aenv'.
(HasCallStack, Applicative f, SyntacticAcc fa) =>
RebuildAvar f fa acc aenv aenv' -> ReindexAvar f aenv aenv'
reindexAvar RebuildAvar f' fa acc aenv aenv'
forall sh e.
ArrayVar aenv (Array sh e)
-> f' (fa (AccClo (OpenAccExp acc env)) aenv' (Array sh e))
v) OpenExp env aenv a
e)
instance Rebuildable (OpenAccFun acc env) where
type AccClo (OpenAccFun acc env) = acc
{-# INLINEABLE rebuildPartial #-}
rebuildPartial :: (forall sh e.
ArrayVar aenv (Array sh e)
-> f' (fa (AccClo (OpenAccFun acc env)) aenv' (Array sh e)))
-> OpenAccFun acc env aenv a -> f' (OpenAccFun acc env aenv' a)
rebuildPartial forall sh e.
ArrayVar aenv (Array sh e)
-> f' (fa (AccClo (OpenAccFun acc env)) aenv' (Array sh e))
v (OpenAccFun OpenFun env aenv a
f) = OpenFun env aenv' a -> OpenAccFun acc env aenv' a
forall env aenv a (acc :: * -> * -> *).
OpenFun env aenv a -> OpenAccFun acc env aenv a
OpenAccFun (OpenFun env aenv' a -> OpenAccFun acc env aenv' a)
-> f' (OpenFun env aenv' a) -> f' (OpenAccFun acc env aenv' a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text -> f' (OpenFun env aenv' a) -> f' (OpenFun env aenv' a)
forall a. Text -> a -> a
Stats.substitution Text
"rebuild" (RebuildEvar f' IdxE env env aenv'
-> ReindexAvar f' aenv aenv'
-> OpenFun env aenv a
-> f' (OpenFun env aenv' a)
forall (f :: * -> *) (fe :: * -> * -> * -> *) env env' aenv' aenv
t.
(HasCallStack, Applicative f, SyntacticExp fe) =>
RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> OpenFun env aenv t
-> f (OpenFun env' aenv' t)
rebuildFun (IdxE env aenv' t' -> f' (IdxE env aenv' t')
forall (f :: * -> *) a. Applicative f => a -> f a
pure (IdxE env aenv' t' -> f' (IdxE env aenv' t'))
-> (ExpVar env t' -> IdxE env aenv' t')
-> ExpVar env t'
-> f' (IdxE env aenv' t')
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ExpVar env t' -> IdxE env aenv' t'
forall env aenv t. ExpVar env t -> IdxE env aenv t
IE) (RebuildAvar f' fa acc aenv aenv' -> ReindexAvar f' aenv aenv'
forall (f :: * -> *) (fa :: (* -> * -> *) -> * -> * -> *)
(acc :: * -> * -> *) aenv aenv'.
(HasCallStack, Applicative f, SyntacticAcc fa) =>
RebuildAvar f fa acc aenv aenv' -> ReindexAvar f aenv aenv'
reindexAvar RebuildAvar f' fa acc aenv aenv'
forall sh e.
ArrayVar aenv (Array sh e)
-> f' (fa (AccClo (OpenAccFun acc env)) aenv' (Array sh e))
v) OpenFun env aenv a
f)
instance RebuildableAcc acc => Rebuildable (PreOpenAcc acc) where
type AccClo (PreOpenAcc acc) = acc
{-# INLINEABLE rebuildPartial #-}
rebuildPartial :: (forall sh e.
ArrayVar aenv (Array sh e)
-> f' (fa (AccClo (PreOpenAcc acc)) aenv' (Array sh e)))
-> PreOpenAcc acc aenv a -> f' (PreOpenAcc acc aenv' a)
rebuildPartial forall sh e.
ArrayVar aenv (Array sh e)
-> f' (fa (AccClo (PreOpenAcc acc)) aenv' (Array sh e))
x = Text
-> (PreOpenAcc acc aenv a -> f' (PreOpenAcc acc aenv' a))
-> PreOpenAcc acc aenv a
-> f' (PreOpenAcc acc aenv' a)
forall a. Text -> a -> a
Stats.substitution Text
"rebuild" ((PreOpenAcc acc aenv a -> f' (PreOpenAcc acc aenv' a))
-> PreOpenAcc acc aenv a -> f' (PreOpenAcc acc aenv' a))
-> (PreOpenAcc acc aenv a -> f' (PreOpenAcc acc aenv' a))
-> PreOpenAcc acc aenv a
-> f' (PreOpenAcc acc aenv' a)
forall a b. (a -> b) -> a -> b
$ RebuildAcc acc
-> RebuildAvar f' fa acc aenv aenv'
-> PreOpenAcc acc aenv a
-> f' (PreOpenAcc acc aenv' a)
forall (f :: * -> *) (fa :: (* -> * -> *) -> * -> * -> *)
(acc :: * -> * -> *) aenv aenv' t.
(HasCallStack, Applicative f, SyntacticAcc fa) =>
RebuildAcc acc
-> RebuildAvar f fa acc aenv aenv'
-> PreOpenAcc acc aenv t
-> f (PreOpenAcc acc aenv' t)
rebuildPreOpenAcc RebuildAcc acc
forall (f :: * -> * -> *) (f' :: * -> *)
(fa :: (* -> * -> *) -> * -> * -> *) aenv aenv' a.
(Rebuildable f, Applicative f', SyntacticAcc fa) =>
(forall sh e.
ArrayVar aenv (Array sh e)
-> f' (fa (AccClo f) aenv' (Array sh e)))
-> f aenv a -> f' (f aenv' a)
rebuildPartial RebuildAvar f' fa acc aenv aenv'
forall sh e.
ArrayVar aenv (Array sh e)
-> f' (fa (AccClo (PreOpenAcc acc)) aenv' (Array sh e))
x
instance RebuildableAcc acc => Rebuildable (PreOpenAfun acc) where
type AccClo (PreOpenAfun acc) = acc
{-# INLINEABLE rebuildPartial #-}
rebuildPartial :: (forall sh e.
ArrayVar aenv (Array sh e)
-> f' (fa (AccClo (PreOpenAfun acc)) aenv' (Array sh e)))
-> PreOpenAfun acc aenv a -> f' (PreOpenAfun acc aenv' a)
rebuildPartial forall sh e.
ArrayVar aenv (Array sh e)
-> f' (fa (AccClo (PreOpenAfun acc)) aenv' (Array sh e))
x = Text
-> (PreOpenAfun acc aenv a -> f' (PreOpenAfun acc aenv' a))
-> PreOpenAfun acc aenv a
-> f' (PreOpenAfun acc aenv' a)
forall a. Text -> a -> a
Stats.substitution Text
"rebuild" ((PreOpenAfun acc aenv a -> f' (PreOpenAfun acc aenv' a))
-> PreOpenAfun acc aenv a -> f' (PreOpenAfun acc aenv' a))
-> (PreOpenAfun acc aenv a -> f' (PreOpenAfun acc aenv' a))
-> PreOpenAfun acc aenv a
-> f' (PreOpenAfun acc aenv' a)
forall a b. (a -> b) -> a -> b
$ RebuildAcc acc
-> RebuildAvar f' fa acc aenv aenv'
-> PreOpenAfun acc aenv a
-> f' (PreOpenAfun acc aenv' a)
forall (f :: * -> *) (fa :: (* -> * -> *) -> * -> * -> *)
(acc :: * -> * -> *) aenv aenv' t.
(HasCallStack, Applicative f, SyntacticAcc fa) =>
RebuildAcc acc
-> RebuildAvar f fa acc aenv aenv'
-> PreOpenAfun acc aenv t
-> f (PreOpenAfun acc aenv' t)
rebuildAfun RebuildAcc acc
forall (f :: * -> * -> *) (f' :: * -> *)
(fa :: (* -> * -> *) -> * -> * -> *) aenv aenv' a.
(Rebuildable f, Applicative f', SyntacticAcc fa) =>
(forall sh e.
ArrayVar aenv (Array sh e)
-> f' (fa (AccClo f) aenv' (Array sh e)))
-> f aenv a -> f' (f aenv' a)
rebuildPartial RebuildAvar f' fa acc aenv aenv'
forall sh e.
ArrayVar aenv (Array sh e)
-> f' (fa (AccClo (PreOpenAfun acc)) aenv' (Array sh e))
x
instance Rebuildable OpenAcc where
type AccClo OpenAcc = OpenAcc
{-# INLINEABLE rebuildPartial #-}
rebuildPartial :: (forall sh e.
ArrayVar aenv (Array sh e)
-> f' (fa (AccClo OpenAcc) aenv' (Array sh e)))
-> OpenAcc aenv a -> f' (OpenAcc aenv' a)
rebuildPartial forall sh e.
ArrayVar aenv (Array sh e)
-> f' (fa (AccClo OpenAcc) aenv' (Array sh e))
x = Text
-> (OpenAcc aenv a -> f' (OpenAcc aenv' a))
-> OpenAcc aenv a
-> f' (OpenAcc aenv' a)
forall a. Text -> a -> a
Stats.substitution Text
"rebuild" ((OpenAcc aenv a -> f' (OpenAcc aenv' a))
-> OpenAcc aenv a -> f' (OpenAcc aenv' a))
-> (OpenAcc aenv a -> f' (OpenAcc aenv' a))
-> OpenAcc aenv a
-> f' (OpenAcc aenv' a)
forall a b. (a -> b) -> a -> b
$ (forall sh e.
ArrayVar aenv (Array sh e) -> f' (fa OpenAcc aenv' (Array sh e)))
-> OpenAcc aenv a -> f' (OpenAcc aenv' a)
forall (f :: * -> *) (fa :: (* -> * -> *) -> * -> * -> *) aenv
aenv' t.
(HasCallStack, Applicative f, SyntacticAcc fa) =>
(forall sh e.
ArrayVar aenv (Array sh e) -> f (fa OpenAcc aenv' (Array sh e)))
-> OpenAcc aenv t -> f (OpenAcc aenv' t)
rebuildOpenAcc forall sh e.
ArrayVar aenv (Array sh e) -> f' (fa OpenAcc aenv' (Array sh e))
forall sh e.
ArrayVar aenv (Array sh e)
-> f' (fa (AccClo OpenAcc) aenv' (Array sh e))
x
instance RebuildableExp OpenExp where
{-# INLINEABLE rebuildPartialE #-}
rebuildPartialE :: (forall e'. ExpVar env e' -> f' (fe env' aenv e'))
-> OpenExp env aenv e -> f' (OpenExp env' aenv e)
rebuildPartialE forall e'. ExpVar env e' -> f' (fe env' aenv e')
v OpenExp env aenv e
x = Text -> f' (OpenExp env' aenv e) -> f' (OpenExp env' aenv e)
forall a. Text -> a -> a
Stats.substitution Text
"rebuild" (f' (OpenExp env' aenv e) -> f' (OpenExp env' aenv e))
-> f' (OpenExp env' aenv e) -> f' (OpenExp env' aenv e)
forall a b. (a -> b) -> a -> b
$ (forall e'. ExpVar env e' -> f' (fe env' aenv e'))
-> ReindexAvar f' aenv aenv
-> OpenExp env aenv e
-> f' (OpenExp env' aenv e)
forall (f :: * -> *) (fe :: * -> * -> * -> *) env env' aenv' aenv
t.
(HasCallStack, Applicative f, SyntacticExp fe) =>
RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> OpenExp env aenv t
-> f (OpenExp env' aenv' t)
rebuildOpenExp forall e'. ExpVar env e' -> f' (fe env' aenv e')
v ((forall sh e.
ArrayVar aenv (Array sh e) -> f' (ArrayVar aenv (Array sh e)))
-> ReindexAvar f' aenv aenv
forall (f :: * -> *) aenv aenv'.
(forall sh e.
ArrayVar aenv (Array sh e) -> f (ArrayVar aenv' (Array sh e)))
-> ReindexAvar f aenv aenv'
ReindexAvar forall sh e.
ArrayVar aenv (Array sh e) -> f' (ArrayVar aenv (Array sh e))
forall (f :: * -> *) a. Applicative f => a -> f a
pure) OpenExp env aenv e
x
instance RebuildableExp OpenFun where
{-# INLINEABLE rebuildPartialE #-}
rebuildPartialE :: (forall e'. ExpVar env e' -> f' (fe env' aenv e'))
-> OpenFun env aenv e -> f' (OpenFun env' aenv e)
rebuildPartialE forall e'. ExpVar env e' -> f' (fe env' aenv e')
v OpenFun env aenv e
x = Text -> f' (OpenFun env' aenv e) -> f' (OpenFun env' aenv e)
forall a. Text -> a -> a
Stats.substitution Text
"rebuild" (f' (OpenFun env' aenv e) -> f' (OpenFun env' aenv e))
-> f' (OpenFun env' aenv e) -> f' (OpenFun env' aenv e)
forall a b. (a -> b) -> a -> b
$ (forall e'. ExpVar env e' -> f' (fe env' aenv e'))
-> ReindexAvar f' aenv aenv
-> OpenFun env aenv e
-> f' (OpenFun env' aenv e)
forall (f :: * -> *) (fe :: * -> * -> * -> *) env env' aenv' aenv
t.
(HasCallStack, Applicative f, SyntacticExp fe) =>
RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> OpenFun env aenv t
-> f (OpenFun env' aenv' t)
rebuildFun forall e'. ExpVar env e' -> f' (fe env' aenv e')
v ((forall sh e.
ArrayVar aenv (Array sh e) -> f' (ArrayVar aenv (Array sh e)))
-> ReindexAvar f' aenv aenv
forall (f :: * -> *) aenv aenv'.
(forall sh e.
ArrayVar aenv (Array sh e) -> f (ArrayVar aenv' (Array sh e)))
-> ReindexAvar f aenv aenv'
ReindexAvar forall sh e.
ArrayVar aenv (Array sh e) -> f' (ArrayVar aenv (Array sh e))
forall (f :: * -> *) a. Applicative f => a -> f a
pure) OpenFun env aenv e
x
class Sink f where
weaken :: env :> env' -> f env t -> f env' t
instance Sink Idx where
{-# INLINEABLE weaken #-}
weaken :: (env :> env') -> Idx env t -> Idx env' t
weaken = (env :> env') -> Idx env t -> Idx env' t
forall env env'.
(env :> env') -> forall t'. Idx env t' -> Idx env' t'
(>:>)
instance Sink (Var s) where
{-# INLINEABLE weaken #-}
weaken :: (env :> env') -> Var s env t -> Var s env' t
weaken env :> env'
k (Var s t
s Idx env t
ix) = s t -> Idx env' t -> Var s env' t
forall (s :: * -> *) env t. s t -> Idx env t -> Var s env t
Var s t
s (env :> env'
k (env :> env') -> Idx env t -> Idx env' t
forall env env'.
(env :> env') -> forall t'. Idx env t' -> Idx env' t'
>:> Idx env t
ix)
weakenVars :: env :> env' -> Vars s env t -> Vars s env' t
weakenVars :: (env :> env') -> Vars s env t -> Vars s env' t
weakenVars env :> env'
_ Vars s env t
TupRunit = Vars s env' t
forall (s :: * -> *). TupR s ()
TupRunit
weakenVars env :> env'
k (TupRsingle Var s env t
v) = Var s env' t -> Vars s env' t
forall (s :: * -> *) a. s a -> TupR s a
TupRsingle (Var s env' t -> Vars s env' t) -> Var s env' t -> Vars s env' t
forall a b. (a -> b) -> a -> b
$ (env :> env') -> Var s env t -> Var s env' t
forall (f :: * -> * -> *) env env' t.
Sink f =>
(env :> env') -> f env t -> f env' t
weaken env :> env'
k Var s env t
v
weakenVars env :> env'
k (TupRpair TupR (Var s env) a
v TupR (Var s env) b
w) = TupR (Var s env') a
-> TupR (Var s env') b -> TupR (Var s env') (a, b)
forall (s :: * -> *) a b. TupR s a -> TupR s b -> TupR s (a, b)
TupRpair ((env :> env') -> TupR (Var s env) a -> TupR (Var s env') a
forall env env' (s :: * -> *) t.
(env :> env') -> Vars s env t -> Vars s env' t
weakenVars env :> env'
k TupR (Var s env) a
v) ((env :> env') -> TupR (Var s env) b -> TupR (Var s env') b
forall env env' (s :: * -> *) t.
(env :> env') -> Vars s env t -> Vars s env' t
weakenVars env :> env'
k TupR (Var s env) b
w)
rebuildWeakenVar :: env :> env' -> ArrayVar env (Array sh e) -> PreOpenAcc acc env' (Array sh e)
rebuildWeakenVar :: (env :> env')
-> ArrayVar env (Array sh e) -> PreOpenAcc acc env' (Array sh e)
rebuildWeakenVar env :> env'
k (Var ArrayR (Array sh e)
s Idx env (Array sh e)
idx) = ArrayVar env' (Array sh e) -> PreOpenAcc acc env' (Array sh e)
forall aenv sh e (acc :: * -> * -> *).
ArrayVar aenv (Array sh e) -> PreOpenAcc acc aenv (Array sh e)
Avar (ArrayVar env' (Array sh e) -> PreOpenAcc acc env' (Array sh e))
-> ArrayVar env' (Array sh e) -> PreOpenAcc acc env' (Array sh e)
forall a b. (a -> b) -> a -> b
$ ArrayR (Array sh e)
-> Idx env' (Array sh e) -> ArrayVar env' (Array sh e)
forall (s :: * -> *) env t. s t -> Idx env t -> Var s env t
Var ArrayR (Array sh e)
s (Idx env' (Array sh e) -> ArrayVar env' (Array sh e))
-> Idx env' (Array sh e) -> ArrayVar env' (Array sh e)
forall a b. (a -> b) -> a -> b
$ env :> env'
k (env :> env') -> Idx env (Array sh e) -> Idx env' (Array sh e)
forall env env'.
(env :> env') -> forall t'. Idx env t' -> Idx env' t'
>:> Idx env (Array sh e)
idx
rebuildWeakenEvar :: env :> env' -> ExpVar env t -> OpenExp env' aenv t
rebuildWeakenEvar :: (env :> env') -> ExpVar env t -> OpenExp env' aenv t
rebuildWeakenEvar env :> env'
k (Var ScalarType t
s Idx env t
idx) = ExpVar env' t -> OpenExp env' aenv t
forall env t aenv. ExpVar env t -> OpenExp env aenv t
Evar (ExpVar env' t -> OpenExp env' aenv t)
-> ExpVar env' t -> OpenExp env' aenv t
forall a b. (a -> b) -> a -> b
$ ScalarType t -> Idx env' t -> ExpVar env' t
forall (s :: * -> *) env t. s t -> Idx env t -> Var s env t
Var ScalarType t
s (Idx env' t -> ExpVar env' t) -> Idx env' t -> ExpVar env' t
forall a b. (a -> b) -> a -> b
$ env :> env'
k (env :> env') -> Idx env t -> Idx env' t
forall env env'.
(env :> env') -> forall t'. Idx env t' -> Idx env' t'
>:> Idx env t
idx
instance RebuildableAcc acc => Sink (PreOpenAcc acc) where
{-# INLINEABLE weaken #-}
weaken :: (env :> env') -> PreOpenAcc acc env t -> PreOpenAcc acc env' t
weaken env :> env'
k = Text -> PreOpenAcc acc env' t -> PreOpenAcc acc env' t
forall a. Text -> a -> a
Stats.substitution Text
"weaken" (PreOpenAcc acc env' t -> PreOpenAcc acc env' t)
-> (PreOpenAcc acc env t -> PreOpenAcc acc env' t)
-> PreOpenAcc acc env t
-> PreOpenAcc acc env' t
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall sh e.
ArrayVar env (Array sh e)
-> PreOpenAcc (AccClo (PreOpenAcc acc)) env' (Array sh e))
-> PreOpenAcc acc env t -> PreOpenAcc acc env' t
forall (f :: * -> * -> *) (fa :: (* -> * -> *) -> * -> * -> *) aenv
aenv' a.
(Rebuildable f, SyntacticAcc fa) =>
(forall sh e.
ArrayVar aenv (Array sh e) -> fa (AccClo f) aenv' (Array sh e))
-> f aenv a -> f aenv' a
rebuildA ((env :> env')
-> Var ArrayR env (Array sh e) -> PreOpenAcc acc env' (Array sh e)
forall env env' sh e (acc :: * -> * -> *).
(env :> env')
-> ArrayVar env (Array sh e) -> PreOpenAcc acc env' (Array sh e)
rebuildWeakenVar env :> env'
k)
instance RebuildableAcc acc => Sink (PreOpenAfun acc) where
{-# INLINEABLE weaken #-}
weaken :: (env :> env') -> PreOpenAfun acc env t -> PreOpenAfun acc env' t
weaken env :> env'
k = Text -> PreOpenAfun acc env' t -> PreOpenAfun acc env' t
forall a. Text -> a -> a
Stats.substitution Text
"weaken" (PreOpenAfun acc env' t -> PreOpenAfun acc env' t)
-> (PreOpenAfun acc env t -> PreOpenAfun acc env' t)
-> PreOpenAfun acc env t
-> PreOpenAfun acc env' t
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall sh e.
ArrayVar env (Array sh e)
-> PreOpenAcc (AccClo (PreOpenAfun acc)) env' (Array sh e))
-> PreOpenAfun acc env t -> PreOpenAfun acc env' t
forall (f :: * -> * -> *) (fa :: (* -> * -> *) -> * -> * -> *) aenv
aenv' a.
(Rebuildable f, SyntacticAcc fa) =>
(forall sh e.
ArrayVar aenv (Array sh e) -> fa (AccClo f) aenv' (Array sh e))
-> f aenv a -> f aenv' a
rebuildA ((env :> env')
-> Var ArrayR env (Array sh e) -> PreOpenAcc acc env' (Array sh e)
forall env env' sh e (acc :: * -> * -> *).
(env :> env')
-> ArrayVar env (Array sh e) -> PreOpenAcc acc env' (Array sh e)
rebuildWeakenVar env :> env'
k)
instance Sink (OpenExp env) where
{-# INLINEABLE weaken #-}
weaken :: (env :> env') -> OpenExp env env t -> OpenExp env env' t
weaken env :> env'
k = Text -> OpenExp env env' t -> OpenExp env env' t
forall a. Text -> a -> a
Stats.substitution Text
"weaken" (OpenExp env env' t -> OpenExp env env' t)
-> (OpenExp env env t -> OpenExp env env' t)
-> OpenExp env env t
-> OpenExp env env' t
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Identity (OpenExp env env' t) -> OpenExp env env' t
forall a. Identity a -> a
runIdentity (Identity (OpenExp env env' t) -> OpenExp env env' t)
-> (OpenExp env env t -> Identity (OpenExp env env' t))
-> OpenExp env env t
-> OpenExp env env' t
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RebuildEvar Identity OpenExp env env env'
-> ReindexAvar Identity env env'
-> OpenExp env env t
-> Identity (OpenExp env env' t)
forall (f :: * -> *) (fe :: * -> * -> * -> *) env env' aenv' aenv
t.
(HasCallStack, Applicative f, SyntacticExp fe) =>
RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> OpenExp env aenv t
-> f (OpenExp env' aenv' t)
rebuildOpenExp (OpenExp env env' t' -> Identity (OpenExp env env' t')
forall a. a -> Identity a
Identity (OpenExp env env' t' -> Identity (OpenExp env env' t'))
-> (ExpVar env t' -> OpenExp env env' t')
-> ExpVar env t'
-> Identity (OpenExp env env' t')
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ExpVar env t' -> OpenExp env env' t'
forall env t aenv. ExpVar env t -> OpenExp env aenv t
Evar) ((forall sh e.
ArrayVar env (Array sh e) -> Identity (ArrayVar env' (Array sh e)))
-> ReindexAvar Identity env env'
forall (f :: * -> *) aenv aenv'.
(forall sh e.
ArrayVar aenv (Array sh e) -> f (ArrayVar aenv' (Array sh e)))
-> ReindexAvar f aenv aenv'
ReindexAvar (Var ArrayR env' (Array sh e)
-> Identity (Var ArrayR env' (Array sh e))
forall a. a -> Identity a
Identity (Var ArrayR env' (Array sh e)
-> Identity (Var ArrayR env' (Array sh e)))
-> (Var ArrayR env (Array sh e) -> Var ArrayR env' (Array sh e))
-> Var ArrayR env (Array sh e)
-> Identity (Var ArrayR env' (Array sh e))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (env :> env')
-> Var ArrayR env (Array sh e) -> Var ArrayR env' (Array sh e)
forall (f :: * -> * -> *) env env' t.
Sink f =>
(env :> env') -> f env t -> f env' t
weaken env :> env'
k))
instance Sink (OpenFun env) where
{-# INLINEABLE weaken #-}
weaken :: (env :> env') -> OpenFun env env t -> OpenFun env env' t
weaken env :> env'
k = Text -> OpenFun env env' t -> OpenFun env env' t
forall a. Text -> a -> a
Stats.substitution Text
"weaken" (OpenFun env env' t -> OpenFun env env' t)
-> (OpenFun env env t -> OpenFun env env' t)
-> OpenFun env env t
-> OpenFun env env' t
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Identity (OpenFun env env' t) -> OpenFun env env' t
forall a. Identity a -> a
runIdentity (Identity (OpenFun env env' t) -> OpenFun env env' t)
-> (OpenFun env env t -> Identity (OpenFun env env' t))
-> OpenFun env env t
-> OpenFun env env' t
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RebuildEvar Identity OpenExp env env env'
-> ReindexAvar Identity env env'
-> OpenFun env env t
-> Identity (OpenFun env env' t)
forall (f :: * -> *) (fe :: * -> * -> * -> *) env env' aenv' aenv
t.
(HasCallStack, Applicative f, SyntacticExp fe) =>
RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> OpenFun env aenv t
-> f (OpenFun env' aenv' t)
rebuildFun (OpenExp env env' t' -> Identity (OpenExp env env' t')
forall a. a -> Identity a
Identity (OpenExp env env' t' -> Identity (OpenExp env env' t'))
-> (ExpVar env t' -> OpenExp env env' t')
-> ExpVar env t'
-> Identity (OpenExp env env' t')
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ExpVar env t' -> OpenExp env env' t'
forall env t aenv. ExpVar env t -> OpenExp env aenv t
Evar) ((forall sh e.
ArrayVar env (Array sh e) -> Identity (ArrayVar env' (Array sh e)))
-> ReindexAvar Identity env env'
forall (f :: * -> *) aenv aenv'.
(forall sh e.
ArrayVar aenv (Array sh e) -> f (ArrayVar aenv' (Array sh e)))
-> ReindexAvar f aenv aenv'
ReindexAvar (Var ArrayR env' (Array sh e)
-> Identity (Var ArrayR env' (Array sh e))
forall a. a -> Identity a
Identity (Var ArrayR env' (Array sh e)
-> Identity (Var ArrayR env' (Array sh e)))
-> (Var ArrayR env (Array sh e) -> Var ArrayR env' (Array sh e))
-> Var ArrayR env (Array sh e)
-> Identity (Var ArrayR env' (Array sh e))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (env :> env')
-> Var ArrayR env (Array sh e) -> Var ArrayR env' (Array sh e)
forall (f :: * -> * -> *) env env' t.
Sink f =>
(env :> env') -> f env t -> f env' t
weaken env :> env'
k))
instance Sink Boundary where
{-# INLINEABLE weaken #-}
weaken :: (env :> env') -> Boundary env t -> Boundary env' t
weaken env :> env'
k Boundary env t
bndy =
case Boundary env t
bndy of
Boundary env t
Clamp -> Boundary env' t
forall aenv t. Boundary aenv t
Clamp
Boundary env t
Mirror -> Boundary env' t
forall aenv t. Boundary aenv t
Mirror
Boundary env t
Wrap -> Boundary env' t
forall aenv t. Boundary aenv t
Wrap
Constant e
c -> e -> Boundary env' (Array sh e)
forall e aenv sh. e -> Boundary aenv (Array sh e)
Constant e
c
Function Fun env (sh -> e)
f -> Fun env' (sh -> e) -> Boundary env' (Array sh e)
forall aenv sh e. Fun aenv (sh -> e) -> Boundary aenv (Array sh e)
Function ((env :> env') -> Fun env (sh -> e) -> Fun env' (sh -> e)
forall (f :: * -> * -> *) env env' t.
Sink f =>
(env :> env') -> f env t -> f env' t
weaken env :> env'
k Fun env (sh -> e)
f)
instance Sink OpenAcc where
{-# INLINEABLE weaken #-}
weaken :: (env :> env') -> OpenAcc env t -> OpenAcc env' t
weaken env :> env'
k = Text -> OpenAcc env' t -> OpenAcc env' t
forall a. Text -> a -> a
Stats.substitution Text
"weaken" (OpenAcc env' t -> OpenAcc env' t)
-> (OpenAcc env t -> OpenAcc env' t)
-> OpenAcc env t
-> OpenAcc env' t
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall sh e.
ArrayVar env (Array sh e)
-> PreOpenAcc (AccClo OpenAcc) env' (Array sh e))
-> OpenAcc env t -> OpenAcc env' t
forall (f :: * -> * -> *) (fa :: (* -> * -> *) -> * -> * -> *) aenv
aenv' a.
(Rebuildable f, SyntacticAcc fa) =>
(forall sh e.
ArrayVar aenv (Array sh e) -> fa (AccClo f) aenv' (Array sh e))
-> f aenv a -> f aenv' a
rebuildA ((env :> env')
-> Var ArrayR env (Array sh e)
-> PreOpenAcc OpenAcc env' (Array sh e)
forall env env' sh e (acc :: * -> * -> *).
(env :> env')
-> ArrayVar env (Array sh e) -> PreOpenAcc acc env' (Array sh e)
rebuildWeakenVar env :> env'
k)
class SinkExp f where
weakenE :: env :> env' -> f env aenv t -> f env' aenv t
instance SinkExp OpenExp where
{-# INLINEABLE weakenE #-}
weakenE :: (env :> env') -> OpenExp env aenv t -> OpenExp env' aenv t
weakenE env :> env'
v = Text -> OpenExp env' aenv t -> OpenExp env' aenv t
forall a. Text -> a -> a
Stats.substitution Text
"weakenE" (OpenExp env' aenv t -> OpenExp env' aenv t)
-> (OpenExp env aenv t -> OpenExp env' aenv t)
-> OpenExp env aenv t
-> OpenExp env' aenv t
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall e'. ExpVar env e' -> OpenExp env' aenv e')
-> OpenExp env aenv t -> OpenExp env' aenv t
forall (f :: * -> * -> * -> *) (fe :: * -> * -> * -> *) env env'
aenv e.
(RebuildableExp f, SyntacticExp fe) =>
(forall e'. ExpVar env e' -> fe env' aenv e')
-> f env aenv e -> f env' aenv e
rebuildE ((env :> env') -> ExpVar env e' -> OpenExp env' aenv e'
forall env env' t aenv.
(env :> env') -> ExpVar env t -> OpenExp env' aenv t
rebuildWeakenEvar env :> env'
v)
instance SinkExp OpenFun where
{-# INLINEABLE weakenE #-}
weakenE :: (env :> env') -> OpenFun env aenv t -> OpenFun env' aenv t
weakenE env :> env'
v = Text -> OpenFun env' aenv t -> OpenFun env' aenv t
forall a. Text -> a -> a
Stats.substitution Text
"weakenE" (OpenFun env' aenv t -> OpenFun env' aenv t)
-> (OpenFun env aenv t -> OpenFun env' aenv t)
-> OpenFun env aenv t
-> OpenFun env' aenv t
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall e'. ExpVar env e' -> OpenExp env' aenv e')
-> OpenFun env aenv t -> OpenFun env' aenv t
forall (f :: * -> * -> * -> *) (fe :: * -> * -> * -> *) env env'
aenv e.
(RebuildableExp f, SyntacticExp fe) =>
(forall e'. ExpVar env e' -> fe env' aenv e')
-> f env aenv e -> f env' aenv e
rebuildE ((env :> env') -> ExpVar env e' -> OpenExp env' aenv e'
forall env env' t aenv.
(env :> env') -> ExpVar env t -> OpenExp env' aenv t
rebuildWeakenEvar env :> env'
v)
type env :?> env' = forall t'. Idx env t' -> Maybe (Idx env' t')
{-# INLINEABLE strengthen #-}
strengthen :: forall f env env' t. Rebuildable f => env :?> env' -> f env t -> Maybe (f env' t)
strengthen :: (env :?> env') -> f env t -> Maybe (f env' t)
strengthen env :?> env'
k f env t
x = Text -> Maybe (f env' t) -> Maybe (f env' t)
forall a. Text -> a -> a
Stats.substitution Text
"strengthen" (Maybe (f env' t) -> Maybe (f env' t))
-> Maybe (f env' t) -> Maybe (f env' t)
forall a b. (a -> b) -> a -> b
$ (forall sh e.
ArrayVar env (Array sh e)
-> Maybe (IdxA (AccClo f) env' (Array sh e)))
-> f env t -> Maybe (f env' t)
forall (f :: * -> * -> *) (f' :: * -> *)
(fa :: (* -> * -> *) -> * -> * -> *) aenv aenv' a.
(Rebuildable f, Applicative f', SyntacticAcc fa) =>
(forall sh e.
ArrayVar aenv (Array sh e)
-> f' (fa (AccClo f) aenv' (Array sh e)))
-> f aenv a -> f' (f aenv' a)
rebuildPartial @f @Maybe @IdxA (\(Var ArrayR (Array sh e)
s Idx env (Array sh e)
ix) -> (Idx env' (Array sh e) -> IdxA (AccClo f) env' (Array sh e))
-> Maybe (Idx env' (Array sh e))
-> Maybe (IdxA (AccClo f) env' (Array sh e))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (ArrayVar env' (Array sh e) -> IdxA (AccClo f) env' (Array sh e)
forall (acc :: * -> * -> *) aenv t.
ArrayVar aenv t -> IdxA acc aenv t
IA (ArrayVar env' (Array sh e) -> IdxA (AccClo f) env' (Array sh e))
-> (Idx env' (Array sh e) -> ArrayVar env' (Array sh e))
-> Idx env' (Array sh e)
-> IdxA (AccClo f) env' (Array sh e)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ArrayR (Array sh e)
-> Idx env' (Array sh e) -> ArrayVar env' (Array sh e)
forall (s :: * -> *) env t. s t -> Idx env t -> Var s env t
Var ArrayR (Array sh e)
s) (Maybe (Idx env' (Array sh e))
-> Maybe (IdxA (AccClo f) env' (Array sh e)))
-> Maybe (Idx env' (Array sh e))
-> Maybe (IdxA (AccClo f) env' (Array sh e))
forall a b. (a -> b) -> a -> b
$ Idx env (Array sh e) -> Maybe (Idx env' (Array sh e))
env :?> env'
k Idx env (Array sh e)
ix) f env t
x
{-# INLINEABLE strengthenE #-}
strengthenE :: forall f env env' aenv t. RebuildableExp f => env :?> env' -> f env aenv t -> Maybe (f env' aenv t)
strengthenE :: (env :?> env') -> f env aenv t -> Maybe (f env' aenv t)
strengthenE env :?> env'
k f env aenv t
x = Text -> Maybe (f env' aenv t) -> Maybe (f env' aenv t)
forall a. Text -> a -> a
Stats.substitution Text
"strengthenE" (Maybe (f env' aenv t) -> Maybe (f env' aenv t))
-> Maybe (f env' aenv t) -> Maybe (f env' aenv t)
forall a b. (a -> b) -> a -> b
$ (forall e'. ExpVar env e' -> Maybe (IdxE env' aenv e'))
-> f env aenv t -> Maybe (f env' aenv t)
forall (f :: * -> * -> * -> *) (f' :: * -> *)
(fe :: * -> * -> * -> *) env env' aenv e.
(RebuildableExp f, Applicative f', SyntacticExp fe) =>
(forall e'. ExpVar env e' -> f' (fe env' aenv e'))
-> f env aenv e -> f' (f env' aenv e)
rebuildPartialE @f @Maybe @IdxE (\(Var ScalarType e'
tp Idx env e'
ix) -> (Idx env' e' -> IdxE env' aenv e')
-> Maybe (Idx env' e') -> Maybe (IdxE env' aenv e')
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (ExpVar env' e' -> IdxE env' aenv e'
forall env aenv t. ExpVar env t -> IdxE env aenv t
IE (ExpVar env' e' -> IdxE env' aenv e')
-> (Idx env' e' -> ExpVar env' e')
-> Idx env' e'
-> IdxE env' aenv e'
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ScalarType e' -> Idx env' e' -> ExpVar env' e'
forall (s :: * -> *) env t. s t -> Idx env t -> Var s env t
Var ScalarType e'
tp) (Maybe (Idx env' e') -> Maybe (IdxE env' aenv e'))
-> Maybe (Idx env' e') -> Maybe (IdxE env' aenv e')
forall a b. (a -> b) -> a -> b
$ Idx env e' -> Maybe (Idx env' e')
env :?> env'
k Idx env e'
ix) f env aenv t
x
strengthenWithLHS :: LeftHandSide s t env1 env2 -> env2 :?> env1
strengthenWithLHS :: LeftHandSide s t env1 env2 -> env2 :?> env1
strengthenWithLHS (LeftHandSideWildcard TupR s t
_) = Idx env2 t' -> Maybe (Idx env1 t')
forall a. a -> Maybe a
Just
strengthenWithLHS (LeftHandSideSingle s t
_) = \Idx env2 t'
ix -> case Idx env2 t'
ix of
Idx env2 t'
ZeroIdx -> Maybe (Idx env1 t')
forall a. Maybe a
Nothing
SuccIdx Idx env t'
i -> Idx env t' -> Maybe (Idx env t')
forall a. a -> Maybe a
Just Idx env t'
i
strengthenWithLHS (LeftHandSidePair LeftHandSide s v1 env1 env'
l1 LeftHandSide s v2 env' env2
l2) = LeftHandSide s v2 env' env2 -> env2 :?> env'
forall (s :: * -> *) t env1 env2.
LeftHandSide s t env1 env2 -> env2 :?> env1
strengthenWithLHS LeftHandSide s v2 env' env2
l2 (Idx env2 t' -> Maybe (Idx env' t'))
-> (Idx env' t' -> Maybe (Idx env1 t'))
-> Idx env2 t'
-> Maybe (Idx env1 t')
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> LeftHandSide s v1 env1 env' -> env' :?> env1
forall (s :: * -> *) t env1 env2.
LeftHandSide s t env1 env2 -> env2 :?> env1
strengthenWithLHS LeftHandSide s v1 env1 env'
l1
strengthenAfter :: LeftHandSide s t env1 env2 -> LeftHandSide s t env1' env2' -> env1 :?> env1' -> env2 :?> env2'
strengthenAfter :: LeftHandSide s t env1 env2
-> LeftHandSide s t env1' env2'
-> (env1 :?> env1')
-> env2 :?> env2'
strengthenAfter (LeftHandSideWildcard TupR s t
_) (LeftHandSideWildcard TupR s t
_) env1 :?> env1'
k = Idx env2 t' -> Maybe (Idx env2' t')
env1 :?> env1'
k
strengthenAfter (LeftHandSideSingle s t
_) (LeftHandSideSingle s t
_) env1 :?> env1'
k = \Idx env2 t'
ix -> case Idx env2 t'
ix of
Idx env2 t'
ZeroIdx -> Idx (env1', t') t' -> Maybe (Idx (env1', t') t')
forall a. a -> Maybe a
Just Idx (env1', t') t'
forall env t. Idx (env, t) t
ZeroIdx
SuccIdx Idx env t'
i -> Idx env1' t' -> Idx (env1', t) t'
forall env t s. Idx env t -> Idx (env, s) t
SuccIdx (Idx env1' t' -> Idx (env1', t) t')
-> Maybe (Idx env1' t') -> Maybe (Idx (env1', t) t')
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Idx env1 t' -> Maybe (Idx env1' t')
env1 :?> env1'
k Idx env1 t'
Idx env t'
i
strengthenAfter (LeftHandSidePair LeftHandSide s v1 env1 env'
l1 LeftHandSide s v2 env' env2
l2) (LeftHandSidePair LeftHandSide s v1 env1' env'
l1' LeftHandSide s v2 env' env2'
l2') env1 :?> env1'
k =
LeftHandSide s v2 env' env2
-> LeftHandSide s v2 env' env2'
-> (env' :?> env')
-> env2 :?> env2'
forall (s :: * -> *) t env1 env2 env1' env2'.
LeftHandSide s t env1 env2
-> LeftHandSide s t env1' env2'
-> (env1 :?> env1')
-> env2 :?> env2'
strengthenAfter LeftHandSide s v2 env' env2
l2 LeftHandSide s v2 env' env2'
LeftHandSide s v2 env' env2'
l2' ((env' :?> env') -> env2 :?> env2')
-> (env' :?> env') -> env2 :?> env2'
forall a b. (a -> b) -> a -> b
$ LeftHandSide s v1 env1 env'
-> LeftHandSide s v1 env1' env'
-> (env1 :?> env1')
-> env' :?> env'
forall (s :: * -> *) t env1 env2 env1' env2'.
LeftHandSide s t env1 env2
-> LeftHandSide s t env1' env2'
-> (env1 :?> env1')
-> env2 :?> env2'
strengthenAfter LeftHandSide s v1 env1 env'
l1 LeftHandSide s v1 env1' env'
LeftHandSide s v1 env1' env'
l1' env1 :?> env1'
k
strengthenAfter LeftHandSide s t env1 env2
_ LeftHandSide s t env1' env2'
_ env1 :?> env1'
_ = [Char] -> Idx env2 t' -> Maybe (Idx env2' t')
forall a. HasCallStack => [Char] -> a
error [Char]
"Substitution.strengthenAfter: left hand sides do not match"
class SyntacticExp f where
varIn :: ExpVar env t -> f env aenv t
expOut :: f env aenv t -> OpenExp env aenv t
weakenExp :: f env aenv t -> f (env, s) aenv t
newtype IdxE env aenv t = IE { IdxE env aenv t -> ExpVar env t
unIE :: ExpVar env t }
instance SyntacticExp IdxE where
varIn :: ExpVar env t -> IdxE env aenv t
varIn = ExpVar env t -> IdxE env aenv t
forall env aenv t. ExpVar env t -> IdxE env aenv t
IE
expOut :: IdxE env aenv t -> OpenExp env aenv t
expOut = ExpVar env t -> OpenExp env aenv t
forall env t aenv. ExpVar env t -> OpenExp env aenv t
Evar (ExpVar env t -> OpenExp env aenv t)
-> (IdxE env aenv t -> ExpVar env t)
-> IdxE env aenv t
-> OpenExp env aenv t
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IdxE env aenv t -> ExpVar env t
forall env aenv t. IdxE env aenv t -> ExpVar env t
unIE
weakenExp :: IdxE env aenv t -> IdxE (env, s) aenv t
weakenExp (IE (Var ScalarType t
tp Idx env t
ix)) = ExpVar (env, s) t -> IdxE (env, s) aenv t
forall env aenv t. ExpVar env t -> IdxE env aenv t
IE (ExpVar (env, s) t -> IdxE (env, s) aenv t)
-> ExpVar (env, s) t -> IdxE (env, s) aenv t
forall a b. (a -> b) -> a -> b
$ ScalarType t -> Idx (env, s) t -> ExpVar (env, s) t
forall (s :: * -> *) env t. s t -> Idx env t -> Var s env t
Var ScalarType t
tp (Idx (env, s) t -> ExpVar (env, s) t)
-> Idx (env, s) t -> ExpVar (env, s) t
forall a b. (a -> b) -> a -> b
$ Idx env t -> Idx (env, s) t
forall env t s. Idx env t -> Idx (env, s) t
SuccIdx Idx env t
ix
instance SyntacticExp OpenExp where
varIn :: ExpVar env t -> OpenExp env aenv t
varIn = ExpVar env t -> OpenExp env aenv t
forall env t aenv. ExpVar env t -> OpenExp env aenv t
Evar
expOut :: OpenExp env aenv t -> OpenExp env aenv t
expOut = OpenExp env aenv t -> OpenExp env aenv t
forall a. a -> a
id
weakenExp :: OpenExp env aenv t -> OpenExp (env, s) aenv t
weakenExp = Identity (OpenExp (env, s) aenv t) -> OpenExp (env, s) aenv t
forall a. Identity a -> a
runIdentity (Identity (OpenExp (env, s) aenv t) -> OpenExp (env, s) aenv t)
-> (OpenExp env aenv t -> Identity (OpenExp (env, s) aenv t))
-> OpenExp env aenv t
-> OpenExp (env, s) aenv t
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RebuildEvar Identity IdxE env (env, s) aenv
-> ReindexAvar Identity aenv aenv
-> OpenExp env aenv t
-> Identity (OpenExp (env, s) aenv t)
forall (f :: * -> *) (fe :: * -> * -> * -> *) env env' aenv' aenv
t.
(HasCallStack, Applicative f, SyntacticExp fe) =>
RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> OpenExp env aenv t
-> f (OpenExp env' aenv' t)
rebuildOpenExp (IdxE (env, s) aenv t' -> Identity (IdxE (env, s) aenv t')
forall a. a -> Identity a
Identity (IdxE (env, s) aenv t' -> Identity (IdxE (env, s) aenv t'))
-> (ExpVar env t' -> IdxE (env, s) aenv t')
-> ExpVar env t'
-> Identity (IdxE (env, s) aenv t')
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IdxE env aenv t' -> IdxE (env, s) aenv t'
forall (f :: * -> * -> * -> *) env aenv t s.
SyntacticExp f =>
f env aenv t -> f (env, s) aenv t
weakenExp (IdxE env aenv t' -> IdxE (env, s) aenv t')
-> (ExpVar env t' -> IdxE env aenv t')
-> ExpVar env t'
-> IdxE (env, s) aenv t'
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ExpVar env t' -> IdxE env aenv t'
forall env aenv t. ExpVar env t -> IdxE env aenv t
IE) ((forall sh e.
ArrayVar aenv (Array sh e)
-> Identity (ArrayVar aenv (Array sh e)))
-> ReindexAvar Identity aenv aenv
forall (f :: * -> *) aenv aenv'.
(forall sh e.
ArrayVar aenv (Array sh e) -> f (ArrayVar aenv' (Array sh e)))
-> ReindexAvar f aenv aenv'
ReindexAvar forall a. a -> Identity a
forall sh e.
ArrayVar aenv (Array sh e) -> Identity (ArrayVar aenv (Array sh e))
Identity)
{-# INLINEABLE shiftE #-}
shiftE
:: (Applicative f, SyntacticExp fe)
=> RebuildEvar f fe env env' aenv
-> RebuildEvar f fe (env, s) (env', s) aenv
shiftE :: RebuildEvar f fe env env' aenv
-> RebuildEvar f fe (env, s) (env', s) aenv
shiftE RebuildEvar f fe env env' aenv
_ (Var ScalarType t'
tp Idx (env, s) t'
ZeroIdx) = fe (env', t') aenv t' -> f (fe (env', t') aenv t')
forall (f :: * -> *) a. Applicative f => a -> f a
pure (fe (env', t') aenv t' -> f (fe (env', t') aenv t'))
-> fe (env', t') aenv t' -> f (fe (env', t') aenv t')
forall a b. (a -> b) -> a -> b
$ ExpVar (env', t') t' -> fe (env', t') aenv t'
forall (f :: * -> * -> * -> *) env t aenv.
SyntacticExp f =>
ExpVar env t -> f env aenv t
varIn (ScalarType t' -> Idx (env', t') t' -> ExpVar (env', t') t'
forall (s :: * -> *) env t. s t -> Idx env t -> Var s env t
Var ScalarType t'
tp Idx (env', t') t'
forall env t. Idx (env, t) t
ZeroIdx)
shiftE RebuildEvar f fe env env' aenv
v (Var ScalarType t'
tp (SuccIdx Idx env t'
ix)) = fe env' aenv t' -> fe (env', s) aenv t'
forall (f :: * -> * -> * -> *) env aenv t s.
SyntacticExp f =>
f env aenv t -> f (env, s) aenv t
weakenExp (fe env' aenv t' -> fe (env', s) aenv t')
-> f (fe env' aenv t') -> f (fe (env', s) aenv t')
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ExpVar env t' -> f (fe env' aenv t')
RebuildEvar f fe env env' aenv
v (ScalarType t' -> Idx env t' -> Var ScalarType env t'
forall (s :: * -> *) env t. s t -> Idx env t -> Var s env t
Var ScalarType t'
tp Idx env t'
ix)
{-# INLINEABLE shiftE' #-}
shiftE'
:: (Applicative f, SyntacticExp fa)
=> ELeftHandSide t env1 env1'
-> ELeftHandSide t env2 env2'
-> RebuildEvar f fa env1 env2 aenv
-> RebuildEvar f fa env1' env2' aenv
shiftE' :: ELeftHandSide t env1 env1'
-> ELeftHandSide t env2 env2'
-> RebuildEvar f fa env1 env2 aenv
-> RebuildEvar f fa env1' env2' aenv
shiftE' (LeftHandSideWildcard TupR ScalarType t
_) (LeftHandSideWildcard TupR ScalarType t
_) RebuildEvar f fa env1 env2 aenv
v = Var ScalarType env1' t' -> f (fa env2' aenv t')
RebuildEvar f fa env1 env2 aenv
v
shiftE' (LeftHandSideSingle ScalarType t
_) (LeftHandSideSingle ScalarType t
_) RebuildEvar f fa env1 env2 aenv
v = RebuildEvar f fa env1 env2 aenv
-> RebuildEvar f fa (env1, t) (env2, t) aenv
forall (f :: * -> *) (fe :: * -> * -> * -> *) env env' aenv s.
(Applicative f, SyntacticExp fe) =>
RebuildEvar f fe env env' aenv
-> RebuildEvar f fe (env, s) (env', s) aenv
shiftE RebuildEvar f fa env1 env2 aenv
v
shiftE' (LeftHandSidePair LeftHandSide ScalarType v1 env1 env'
a1 LeftHandSide ScalarType v2 env' env1'
b1) (LeftHandSidePair LeftHandSide ScalarType v1 env2 env'
a2 LeftHandSide ScalarType v2 env' env2'
b2) RebuildEvar f fa env1 env2 aenv
v = LeftHandSide ScalarType v2 env' env1'
-> ELeftHandSide v2 env' env2'
-> RebuildEvar f fa env' env' aenv
-> RebuildEvar f fa env1' env2' aenv
forall (f :: * -> *) (fa :: * -> * -> * -> *) t env1 env1' env2
env2' aenv.
(Applicative f, SyntacticExp fa) =>
ELeftHandSide t env1 env1'
-> ELeftHandSide t env2 env2'
-> RebuildEvar f fa env1 env2 aenv
-> RebuildEvar f fa env1' env2' aenv
shiftE' LeftHandSide ScalarType v2 env' env1'
b1 ELeftHandSide v2 env' env2'
LeftHandSide ScalarType v2 env' env2'
b2 (RebuildEvar f fa env' env' aenv
-> RebuildEvar f fa env1' env2' aenv)
-> RebuildEvar f fa env' env' aenv
-> RebuildEvar f fa env1' env2' aenv
forall a b. (a -> b) -> a -> b
$ LeftHandSide ScalarType v1 env1 env'
-> ELeftHandSide v1 env2 env'
-> RebuildEvar f fa env1 env2 aenv
-> RebuildEvar f fa env' env' aenv
forall (f :: * -> *) (fa :: * -> * -> * -> *) t env1 env1' env2
env2' aenv.
(Applicative f, SyntacticExp fa) =>
ELeftHandSide t env1 env1'
-> ELeftHandSide t env2 env2'
-> RebuildEvar f fa env1 env2 aenv
-> RebuildEvar f fa env1' env2' aenv
shiftE' LeftHandSide ScalarType v1 env1 env'
a1 ELeftHandSide v1 env2 env'
LeftHandSide ScalarType v1 env2 env'
a2 RebuildEvar f fa env1 env2 aenv
v
shiftE' ELeftHandSide t env1 env1'
_ ELeftHandSide t env2 env2'
_ RebuildEvar f fa env1 env2 aenv
_ = [Char] -> Var ScalarType env1' t' -> f (fa env2' aenv t')
forall a. HasCallStack => [Char] -> a
error [Char]
"Substitution: left hand sides do not match"
{-# INLINEABLE rebuildMaybeExp #-}
rebuildMaybeExp
:: (HasCallStack, Applicative f, SyntacticExp fe)
=> RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> Maybe (OpenExp env aenv t)
-> f (Maybe (OpenExp env' aenv' t))
rebuildMaybeExp :: RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> Maybe (OpenExp env aenv t)
-> f (Maybe (OpenExp env' aenv' t))
rebuildMaybeExp RebuildEvar f fe env env' aenv'
_ ReindexAvar f aenv aenv'
_ Maybe (OpenExp env aenv t)
Nothing = Maybe (OpenExp env' aenv' t) -> f (Maybe (OpenExp env' aenv' t))
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe (OpenExp env' aenv' t)
forall a. Maybe a
Nothing
rebuildMaybeExp RebuildEvar f fe env env' aenv'
v ReindexAvar f aenv aenv'
av (Just OpenExp env aenv t
x) = OpenExp env' aenv' t -> Maybe (OpenExp env' aenv' t)
forall a. a -> Maybe a
Just (OpenExp env' aenv' t -> Maybe (OpenExp env' aenv' t))
-> f (OpenExp env' aenv' t) -> f (Maybe (OpenExp env' aenv' t))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> OpenExp env aenv t
-> f (OpenExp env' aenv' t)
forall (f :: * -> *) (fe :: * -> * -> * -> *) env env' aenv' aenv
t.
(HasCallStack, Applicative f, SyntacticExp fe) =>
RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> OpenExp env aenv t
-> f (OpenExp env' aenv' t)
rebuildOpenExp RebuildEvar f fe env env' aenv'
v ReindexAvar f aenv aenv'
av OpenExp env aenv t
x
{-# INLINEABLE rebuildOpenExp #-}
rebuildOpenExp
:: (HasCallStack, Applicative f, SyntacticExp fe)
=> RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> OpenExp env aenv t
-> f (OpenExp env' aenv' t)
rebuildOpenExp :: RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> OpenExp env aenv t
-> f (OpenExp env' aenv' t)
rebuildOpenExp RebuildEvar f fe env env' aenv'
v av :: ReindexAvar f aenv aenv'
av@(ReindexAvar forall sh e.
ArrayVar aenv (Array sh e) -> f (ArrayVar aenv' (Array sh e))
reindex) OpenExp env aenv t
exp =
case OpenExp env aenv t
exp of
Const ScalarType t
t t
c -> OpenExp env' aenv' t -> f (OpenExp env' aenv' t)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (OpenExp env' aenv' t -> f (OpenExp env' aenv' t))
-> OpenExp env' aenv' t -> f (OpenExp env' aenv' t)
forall a b. (a -> b) -> a -> b
$ ScalarType t -> t -> OpenExp env' aenv' t
forall t env aenv. ScalarType t -> t -> OpenExp env aenv t
Const ScalarType t
t t
c
PrimConst PrimConst t
c -> OpenExp env' aenv' t -> f (OpenExp env' aenv' t)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (OpenExp env' aenv' t -> f (OpenExp env' aenv' t))
-> OpenExp env' aenv' t -> f (OpenExp env' aenv' t)
forall a b. (a -> b) -> a -> b
$ PrimConst t -> OpenExp env' aenv' t
forall t env aenv. PrimConst t -> OpenExp env aenv t
PrimConst PrimConst t
c
Undef ScalarType t
t -> OpenExp env' aenv' t -> f (OpenExp env' aenv' t)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (OpenExp env' aenv' t -> f (OpenExp env' aenv' t))
-> OpenExp env' aenv' t -> f (OpenExp env' aenv' t)
forall a b. (a -> b) -> a -> b
$ ScalarType t -> OpenExp env' aenv' t
forall t env aenv. ScalarType t -> OpenExp env aenv t
Undef ScalarType t
t
Evar ExpVar env t
var -> fe env' aenv' t -> OpenExp env' aenv' t
forall (f :: * -> * -> * -> *) env aenv t.
SyntacticExp f =>
f env aenv t -> OpenExp env aenv t
expOut (fe env' aenv' t -> OpenExp env' aenv' t)
-> f (fe env' aenv' t) -> f (OpenExp env' aenv' t)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ExpVar env t -> f (fe env' aenv' t)
RebuildEvar f fe env env' aenv'
v ExpVar env t
var
Let ELeftHandSide bnd_t env env'
lhs OpenExp env aenv bnd_t
a OpenExp env' aenv t
b
| Exists LeftHandSide ScalarType bnd_t env' a
lhs' <- ELeftHandSide bnd_t env env'
-> Exists (LeftHandSide ScalarType bnd_t env')
forall (s :: * -> *) t aenv1 aenv1' aenv2.
LeftHandSide s t aenv1 aenv1' -> Exists (LeftHandSide s t aenv2)
rebuildLHS ELeftHandSide bnd_t env env'
lhs
-> LeftHandSide ScalarType bnd_t env' a
-> OpenExp env' aenv' bnd_t
-> OpenExp a aenv' t
-> OpenExp env' aenv' t
forall bnd_t env env' aenv body_t.
ELeftHandSide bnd_t env env'
-> OpenExp env aenv bnd_t
-> OpenExp env' aenv body_t
-> OpenExp env aenv body_t
Let LeftHandSide ScalarType bnd_t env' a
lhs' (OpenExp env' aenv' bnd_t
-> OpenExp a aenv' t -> OpenExp env' aenv' t)
-> f (OpenExp env' aenv' bnd_t)
-> f (OpenExp a aenv' t -> OpenExp env' aenv' t)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> OpenExp env aenv bnd_t
-> f (OpenExp env' aenv' bnd_t)
forall (f :: * -> *) (fe :: * -> * -> * -> *) env env' aenv' aenv
t.
(HasCallStack, Applicative f, SyntacticExp fe) =>
RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> OpenExp env aenv t
-> f (OpenExp env' aenv' t)
rebuildOpenExp RebuildEvar f fe env env' aenv'
v ReindexAvar f aenv aenv'
av OpenExp env aenv bnd_t
a f (OpenExp a aenv' t -> OpenExp env' aenv' t)
-> f (OpenExp a aenv' t) -> f (OpenExp env' aenv' t)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> RebuildEvar f fe env' a aenv'
-> ReindexAvar f aenv aenv'
-> OpenExp env' aenv t
-> f (OpenExp a aenv' t)
forall (f :: * -> *) (fe :: * -> * -> * -> *) env env' aenv' aenv
t.
(HasCallStack, Applicative f, SyntacticExp fe) =>
RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> OpenExp env aenv t
-> f (OpenExp env' aenv' t)
rebuildOpenExp (ELeftHandSide bnd_t env env'
-> LeftHandSide ScalarType bnd_t env' a
-> RebuildEvar f fe env env' aenv'
-> RebuildEvar f fe env' a aenv'
forall (f :: * -> *) (fa :: * -> * -> * -> *) t env1 env1' env2
env2' aenv.
(Applicative f, SyntacticExp fa) =>
ELeftHandSide t env1 env1'
-> ELeftHandSide t env2 env2'
-> RebuildEvar f fa env1 env2 aenv
-> RebuildEvar f fa env1' env2' aenv
shiftE' ELeftHandSide bnd_t env env'
lhs LeftHandSide ScalarType bnd_t env' a
lhs' RebuildEvar f fe env env' aenv'
v) ReindexAvar f aenv aenv'
av OpenExp env' aenv t
b
Pair OpenExp env aenv t1
e1 OpenExp env aenv t2
e2 -> OpenExp env' aenv' t1
-> OpenExp env' aenv' t2 -> OpenExp env' aenv' (t1, t2)
forall env aenv t1 t2.
OpenExp env aenv t1
-> OpenExp env aenv t2 -> OpenExp env aenv (t1, t2)
Pair (OpenExp env' aenv' t1
-> OpenExp env' aenv' t2 -> OpenExp env' aenv' (t1, t2))
-> f (OpenExp env' aenv' t1)
-> f (OpenExp env' aenv' t2 -> OpenExp env' aenv' (t1, t2))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> OpenExp env aenv t1
-> f (OpenExp env' aenv' t1)
forall (f :: * -> *) (fe :: * -> * -> * -> *) env env' aenv' aenv
t.
(HasCallStack, Applicative f, SyntacticExp fe) =>
RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> OpenExp env aenv t
-> f (OpenExp env' aenv' t)
rebuildOpenExp RebuildEvar f fe env env' aenv'
v ReindexAvar f aenv aenv'
av OpenExp env aenv t1
e1 f (OpenExp env' aenv' t2 -> OpenExp env' aenv' (t1, t2))
-> f (OpenExp env' aenv' t2) -> f (OpenExp env' aenv' (t1, t2))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> OpenExp env aenv t2
-> f (OpenExp env' aenv' t2)
forall (f :: * -> *) (fe :: * -> * -> * -> *) env env' aenv' aenv
t.
(HasCallStack, Applicative f, SyntacticExp fe) =>
RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> OpenExp env aenv t
-> f (OpenExp env' aenv' t)
rebuildOpenExp RebuildEvar f fe env env' aenv'
v ReindexAvar f aenv aenv'
av OpenExp env aenv t2
e2
OpenExp env aenv t
Nil -> OpenExp env' aenv' () -> f (OpenExp env' aenv' ())
forall (f :: * -> *) a. Applicative f => a -> f a
pure OpenExp env' aenv' ()
forall env aenv. OpenExp env aenv ()
Nil
VecPack VecR n s tup
vec OpenExp env aenv tup
e -> VecR n s tup
-> OpenExp env' aenv' tup -> OpenExp env' aenv' (Vec n s)
forall (n :: Nat) s tup env aenv.
KnownNat n =>
VecR n s tup -> OpenExp env aenv tup -> OpenExp env aenv (Vec n s)
VecPack VecR n s tup
vec (OpenExp env' aenv' tup -> OpenExp env' aenv' (Vec n s))
-> f (OpenExp env' aenv' tup) -> f (OpenExp env' aenv' (Vec n s))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> OpenExp env aenv tup
-> f (OpenExp env' aenv' tup)
forall (f :: * -> *) (fe :: * -> * -> * -> *) env env' aenv' aenv
t.
(HasCallStack, Applicative f, SyntacticExp fe) =>
RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> OpenExp env aenv t
-> f (OpenExp env' aenv' t)
rebuildOpenExp RebuildEvar f fe env env' aenv'
v ReindexAvar f aenv aenv'
av OpenExp env aenv tup
e
VecUnpack VecR n s t
vec OpenExp env aenv (Vec n s)
e -> VecR n s t -> OpenExp env' aenv' (Vec n s) -> OpenExp env' aenv' t
forall (n :: Nat) s tup env aenv.
KnownNat n =>
VecR n s tup -> OpenExp env aenv (Vec n s) -> OpenExp env aenv tup
VecUnpack VecR n s t
vec (OpenExp env' aenv' (Vec n s) -> OpenExp env' aenv' t)
-> f (OpenExp env' aenv' (Vec n s)) -> f (OpenExp env' aenv' t)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> OpenExp env aenv (Vec n s)
-> f (OpenExp env' aenv' (Vec n s))
forall (f :: * -> *) (fe :: * -> * -> * -> *) env env' aenv' aenv
t.
(HasCallStack, Applicative f, SyntacticExp fe) =>
RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> OpenExp env aenv t
-> f (OpenExp env' aenv' t)
rebuildOpenExp RebuildEvar f fe env env' aenv'
v ReindexAvar f aenv aenv'
av OpenExp env aenv (Vec n s)
e
IndexSlice SliceIndex slix t co sh
x OpenExp env aenv slix
ix OpenExp env aenv sh
sh -> SliceIndex slix t co sh
-> OpenExp env' aenv' slix
-> OpenExp env' aenv' sh
-> OpenExp env' aenv' t
forall slix sl co sh env aenv.
SliceIndex slix sl co sh
-> OpenExp env aenv slix
-> OpenExp env aenv sh
-> OpenExp env aenv sl
IndexSlice SliceIndex slix t co sh
x (OpenExp env' aenv' slix
-> OpenExp env' aenv' sh -> OpenExp env' aenv' t)
-> f (OpenExp env' aenv' slix)
-> f (OpenExp env' aenv' sh -> OpenExp env' aenv' t)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> OpenExp env aenv slix
-> f (OpenExp env' aenv' slix)
forall (f :: * -> *) (fe :: * -> * -> * -> *) env env' aenv' aenv
t.
(HasCallStack, Applicative f, SyntacticExp fe) =>
RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> OpenExp env aenv t
-> f (OpenExp env' aenv' t)
rebuildOpenExp RebuildEvar f fe env env' aenv'
v ReindexAvar f aenv aenv'
av OpenExp env aenv slix
ix f (OpenExp env' aenv' sh -> OpenExp env' aenv' t)
-> f (OpenExp env' aenv' sh) -> f (OpenExp env' aenv' t)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> OpenExp env aenv sh
-> f (OpenExp env' aenv' sh)
forall (f :: * -> *) (fe :: * -> * -> * -> *) env env' aenv' aenv
t.
(HasCallStack, Applicative f, SyntacticExp fe) =>
RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> OpenExp env aenv t
-> f (OpenExp env' aenv' t)
rebuildOpenExp RebuildEvar f fe env env' aenv'
v ReindexAvar f aenv aenv'
av OpenExp env aenv sh
sh
IndexFull SliceIndex slix sl co t
x OpenExp env aenv slix
ix OpenExp env aenv sl
sl -> SliceIndex slix sl co t
-> OpenExp env' aenv' slix
-> OpenExp env' aenv' sl
-> OpenExp env' aenv' t
forall slix sl co sh env aenv.
SliceIndex slix sl co sh
-> OpenExp env aenv slix
-> OpenExp env aenv sl
-> OpenExp env aenv sh
IndexFull SliceIndex slix sl co t
x (OpenExp env' aenv' slix
-> OpenExp env' aenv' sl -> OpenExp env' aenv' t)
-> f (OpenExp env' aenv' slix)
-> f (OpenExp env' aenv' sl -> OpenExp env' aenv' t)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> OpenExp env aenv slix
-> f (OpenExp env' aenv' slix)
forall (f :: * -> *) (fe :: * -> * -> * -> *) env env' aenv' aenv
t.
(HasCallStack, Applicative f, SyntacticExp fe) =>
RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> OpenExp env aenv t
-> f (OpenExp env' aenv' t)
rebuildOpenExp RebuildEvar f fe env env' aenv'
v ReindexAvar f aenv aenv'
av OpenExp env aenv slix
ix f (OpenExp env' aenv' sl -> OpenExp env' aenv' t)
-> f (OpenExp env' aenv' sl) -> f (OpenExp env' aenv' t)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> OpenExp env aenv sl
-> f (OpenExp env' aenv' sl)
forall (f :: * -> *) (fe :: * -> * -> * -> *) env env' aenv' aenv
t.
(HasCallStack, Applicative f, SyntacticExp fe) =>
RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> OpenExp env aenv t
-> f (OpenExp env' aenv' t)
rebuildOpenExp RebuildEvar f fe env env' aenv'
v ReindexAvar f aenv aenv'
av OpenExp env aenv sl
sl
ToIndex ShapeR sh
shr OpenExp env aenv sh
sh OpenExp env aenv sh
ix -> ShapeR sh
-> OpenExp env' aenv' sh
-> OpenExp env' aenv' sh
-> OpenExp env' aenv' Int
forall sh env aenv.
ShapeR sh
-> OpenExp env aenv sh
-> OpenExp env aenv sh
-> OpenExp env aenv Int
ToIndex ShapeR sh
shr (OpenExp env' aenv' sh
-> OpenExp env' aenv' sh -> OpenExp env' aenv' Int)
-> f (OpenExp env' aenv' sh)
-> f (OpenExp env' aenv' sh -> OpenExp env' aenv' Int)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> OpenExp env aenv sh
-> f (OpenExp env' aenv' sh)
forall (f :: * -> *) (fe :: * -> * -> * -> *) env env' aenv' aenv
t.
(HasCallStack, Applicative f, SyntacticExp fe) =>
RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> OpenExp env aenv t
-> f (OpenExp env' aenv' t)
rebuildOpenExp RebuildEvar f fe env env' aenv'
v ReindexAvar f aenv aenv'
av OpenExp env aenv sh
sh f (OpenExp env' aenv' sh -> OpenExp env' aenv' Int)
-> f (OpenExp env' aenv' sh) -> f (OpenExp env' aenv' Int)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> OpenExp env aenv sh
-> f (OpenExp env' aenv' sh)
forall (f :: * -> *) (fe :: * -> * -> * -> *) env env' aenv' aenv
t.
(HasCallStack, Applicative f, SyntacticExp fe) =>
RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> OpenExp env aenv t
-> f (OpenExp env' aenv' t)
rebuildOpenExp RebuildEvar f fe env env' aenv'
v ReindexAvar f aenv aenv'
av OpenExp env aenv sh
ix
FromIndex ShapeR t
shr OpenExp env aenv t
sh OpenExp env aenv Int
ix -> ShapeR t
-> OpenExp env' aenv' t
-> OpenExp env' aenv' Int
-> OpenExp env' aenv' t
forall sh env aenv.
ShapeR sh
-> OpenExp env aenv sh
-> OpenExp env aenv Int
-> OpenExp env aenv sh
FromIndex ShapeR t
shr (OpenExp env' aenv' t
-> OpenExp env' aenv' Int -> OpenExp env' aenv' t)
-> f (OpenExp env' aenv' t)
-> f (OpenExp env' aenv' Int -> OpenExp env' aenv' t)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> OpenExp env aenv t
-> f (OpenExp env' aenv' t)
forall (f :: * -> *) (fe :: * -> * -> * -> *) env env' aenv' aenv
t.
(HasCallStack, Applicative f, SyntacticExp fe) =>
RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> OpenExp env aenv t
-> f (OpenExp env' aenv' t)
rebuildOpenExp RebuildEvar f fe env env' aenv'
v ReindexAvar f aenv aenv'
av OpenExp env aenv t
sh f (OpenExp env' aenv' Int -> OpenExp env' aenv' t)
-> f (OpenExp env' aenv' Int) -> f (OpenExp env' aenv' t)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> OpenExp env aenv Int
-> f (OpenExp env' aenv' Int)
forall (f :: * -> *) (fe :: * -> * -> * -> *) env env' aenv' aenv
t.
(HasCallStack, Applicative f, SyntacticExp fe) =>
RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> OpenExp env aenv t
-> f (OpenExp env' aenv' t)
rebuildOpenExp RebuildEvar f fe env env' aenv'
v ReindexAvar f aenv aenv'
av OpenExp env aenv Int
ix
Case OpenExp env aenv TAG
e [(TAG, OpenExp env aenv t)]
rhs Maybe (OpenExp env aenv t)
def -> OpenExp env' aenv' TAG
-> [(TAG, OpenExp env' aenv' t)]
-> Maybe (OpenExp env' aenv' t)
-> OpenExp env' aenv' t
forall env aenv b.
OpenExp env aenv TAG
-> [(TAG, OpenExp env aenv b)]
-> Maybe (OpenExp env aenv b)
-> OpenExp env aenv b
Case (OpenExp env' aenv' TAG
-> [(TAG, OpenExp env' aenv' t)]
-> Maybe (OpenExp env' aenv' t)
-> OpenExp env' aenv' t)
-> f (OpenExp env' aenv' TAG)
-> f ([(TAG, OpenExp env' aenv' t)]
-> Maybe (OpenExp env' aenv' t) -> OpenExp env' aenv' t)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> OpenExp env aenv TAG
-> f (OpenExp env' aenv' TAG)
forall (f :: * -> *) (fe :: * -> * -> * -> *) env env' aenv' aenv
t.
(HasCallStack, Applicative f, SyntacticExp fe) =>
RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> OpenExp env aenv t
-> f (OpenExp env' aenv' t)
rebuildOpenExp RebuildEvar f fe env env' aenv'
v ReindexAvar f aenv aenv'
av OpenExp env aenv TAG
e f ([(TAG, OpenExp env' aenv' t)]
-> Maybe (OpenExp env' aenv' t) -> OpenExp env' aenv' t)
-> f [(TAG, OpenExp env' aenv' t)]
-> f (Maybe (OpenExp env' aenv' t) -> OpenExp env' aenv' t)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> [f (TAG, OpenExp env' aenv' t)] -> f [(TAG, OpenExp env' aenv' t)]
forall (t :: * -> *) (f :: * -> *) a.
(Traversable t, Applicative f) =>
t (f a) -> f (t a)
sequenceA [ (TAG
t,) (OpenExp env' aenv' t -> (TAG, OpenExp env' aenv' t))
-> f (OpenExp env' aenv' t) -> f (TAG, OpenExp env' aenv' t)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> OpenExp env aenv t
-> f (OpenExp env' aenv' t)
forall (f :: * -> *) (fe :: * -> * -> * -> *) env env' aenv' aenv
t.
(HasCallStack, Applicative f, SyntacticExp fe) =>
RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> OpenExp env aenv t
-> f (OpenExp env' aenv' t)
rebuildOpenExp RebuildEvar f fe env env' aenv'
v ReindexAvar f aenv aenv'
av OpenExp env aenv t
c | (TAG
t,OpenExp env aenv t
c) <- [(TAG, OpenExp env aenv t)]
rhs ] f (Maybe (OpenExp env' aenv' t) -> OpenExp env' aenv' t)
-> f (Maybe (OpenExp env' aenv' t)) -> f (OpenExp env' aenv' t)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> Maybe (OpenExp env aenv t)
-> f (Maybe (OpenExp env' aenv' t))
forall (f :: * -> *) (fe :: * -> * -> * -> *) env env' aenv' aenv
t.
(HasCallStack, Applicative f, SyntacticExp fe) =>
RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> Maybe (OpenExp env aenv t)
-> f (Maybe (OpenExp env' aenv' t))
rebuildMaybeExp RebuildEvar f fe env env' aenv'
v ReindexAvar f aenv aenv'
av Maybe (OpenExp env aenv t)
def
Cond OpenExp env aenv TAG
p OpenExp env aenv t
t OpenExp env aenv t
e -> OpenExp env' aenv' TAG
-> OpenExp env' aenv' t
-> OpenExp env' aenv' t
-> OpenExp env' aenv' t
forall env aenv t.
OpenExp env aenv TAG
-> OpenExp env aenv t -> OpenExp env aenv t -> OpenExp env aenv t
Cond (OpenExp env' aenv' TAG
-> OpenExp env' aenv' t
-> OpenExp env' aenv' t
-> OpenExp env' aenv' t)
-> f (OpenExp env' aenv' TAG)
-> f (OpenExp env' aenv' t
-> OpenExp env' aenv' t -> OpenExp env' aenv' t)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> OpenExp env aenv TAG
-> f (OpenExp env' aenv' TAG)
forall (f :: * -> *) (fe :: * -> * -> * -> *) env env' aenv' aenv
t.
(HasCallStack, Applicative f, SyntacticExp fe) =>
RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> OpenExp env aenv t
-> f (OpenExp env' aenv' t)
rebuildOpenExp RebuildEvar f fe env env' aenv'
v ReindexAvar f aenv aenv'
av OpenExp env aenv TAG
p f (OpenExp env' aenv' t
-> OpenExp env' aenv' t -> OpenExp env' aenv' t)
-> f (OpenExp env' aenv' t)
-> f (OpenExp env' aenv' t -> OpenExp env' aenv' t)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> OpenExp env aenv t
-> f (OpenExp env' aenv' t)
forall (f :: * -> *) (fe :: * -> * -> * -> *) env env' aenv' aenv
t.
(HasCallStack, Applicative f, SyntacticExp fe) =>
RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> OpenExp env aenv t
-> f (OpenExp env' aenv' t)
rebuildOpenExp RebuildEvar f fe env env' aenv'
v ReindexAvar f aenv aenv'
av OpenExp env aenv t
t f (OpenExp env' aenv' t -> OpenExp env' aenv' t)
-> f (OpenExp env' aenv' t) -> f (OpenExp env' aenv' t)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> OpenExp env aenv t
-> f (OpenExp env' aenv' t)
forall (f :: * -> *) (fe :: * -> * -> * -> *) env env' aenv' aenv
t.
(HasCallStack, Applicative f, SyntacticExp fe) =>
RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> OpenExp env aenv t
-> f (OpenExp env' aenv' t)
rebuildOpenExp RebuildEvar f fe env env' aenv'
v ReindexAvar f aenv aenv'
av OpenExp env aenv t
e
While OpenFun env aenv (t -> TAG)
p OpenFun env aenv (t -> t)
f OpenExp env aenv t
x -> OpenFun env' aenv' (t -> TAG)
-> OpenFun env' aenv' (t -> t)
-> OpenExp env' aenv' t
-> OpenExp env' aenv' t
forall env aenv a.
OpenFun env aenv (a -> TAG)
-> OpenFun env aenv (a -> a)
-> OpenExp env aenv a
-> OpenExp env aenv a
While (OpenFun env' aenv' (t -> TAG)
-> OpenFun env' aenv' (t -> t)
-> OpenExp env' aenv' t
-> OpenExp env' aenv' t)
-> f (OpenFun env' aenv' (t -> TAG))
-> f (OpenFun env' aenv' (t -> t)
-> OpenExp env' aenv' t -> OpenExp env' aenv' t)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> OpenFun env aenv (t -> TAG)
-> f (OpenFun env' aenv' (t -> TAG))
forall (f :: * -> *) (fe :: * -> * -> * -> *) env env' aenv' aenv
t.
(HasCallStack, Applicative f, SyntacticExp fe) =>
RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> OpenFun env aenv t
-> f (OpenFun env' aenv' t)
rebuildFun RebuildEvar f fe env env' aenv'
v ReindexAvar f aenv aenv'
av OpenFun env aenv (t -> TAG)
p f (OpenFun env' aenv' (t -> t)
-> OpenExp env' aenv' t -> OpenExp env' aenv' t)
-> f (OpenFun env' aenv' (t -> t))
-> f (OpenExp env' aenv' t -> OpenExp env' aenv' t)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> OpenFun env aenv (t -> t)
-> f (OpenFun env' aenv' (t -> t))
forall (f :: * -> *) (fe :: * -> * -> * -> *) env env' aenv' aenv
t.
(HasCallStack, Applicative f, SyntacticExp fe) =>
RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> OpenFun env aenv t
-> f (OpenFun env' aenv' t)
rebuildFun RebuildEvar f fe env env' aenv'
v ReindexAvar f aenv aenv'
av OpenFun env aenv (t -> t)
f f (OpenExp env' aenv' t -> OpenExp env' aenv' t)
-> f (OpenExp env' aenv' t) -> f (OpenExp env' aenv' t)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> OpenExp env aenv t
-> f (OpenExp env' aenv' t)
forall (f :: * -> *) (fe :: * -> * -> * -> *) env env' aenv' aenv
t.
(HasCallStack, Applicative f, SyntacticExp fe) =>
RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> OpenExp env aenv t
-> f (OpenExp env' aenv' t)
rebuildOpenExp RebuildEvar f fe env env' aenv'
v ReindexAvar f aenv aenv'
av OpenExp env aenv t
x
PrimApp PrimFun (a -> t)
f OpenExp env aenv a
x -> PrimFun (a -> t) -> OpenExp env' aenv' a -> OpenExp env' aenv' t
forall a r env aenv.
PrimFun (a -> r) -> OpenExp env aenv a -> OpenExp env aenv r
PrimApp PrimFun (a -> t)
f (OpenExp env' aenv' a -> OpenExp env' aenv' t)
-> f (OpenExp env' aenv' a) -> f (OpenExp env' aenv' t)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> OpenExp env aenv a
-> f (OpenExp env' aenv' a)
forall (f :: * -> *) (fe :: * -> * -> * -> *) env env' aenv' aenv
t.
(HasCallStack, Applicative f, SyntacticExp fe) =>
RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> OpenExp env aenv t
-> f (OpenExp env' aenv' t)
rebuildOpenExp RebuildEvar f fe env env' aenv'
v ReindexAvar f aenv aenv'
av OpenExp env aenv a
x
Index ArrayVar aenv (Array dim t)
a OpenExp env aenv dim
sh -> ArrayVar aenv' (Array dim t)
-> OpenExp env' aenv' dim -> OpenExp env' aenv' t
forall aenv dim t env.
ArrayVar aenv (Array dim t)
-> OpenExp env aenv dim -> OpenExp env aenv t
Index (ArrayVar aenv' (Array dim t)
-> OpenExp env' aenv' dim -> OpenExp env' aenv' t)
-> f (ArrayVar aenv' (Array dim t))
-> f (OpenExp env' aenv' dim -> OpenExp env' aenv' t)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ArrayVar aenv (Array dim t) -> f (ArrayVar aenv' (Array dim t))
forall sh e.
ArrayVar aenv (Array sh e) -> f (ArrayVar aenv' (Array sh e))
reindex ArrayVar aenv (Array dim t)
a f (OpenExp env' aenv' dim -> OpenExp env' aenv' t)
-> f (OpenExp env' aenv' dim) -> f (OpenExp env' aenv' t)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> OpenExp env aenv dim
-> f (OpenExp env' aenv' dim)
forall (f :: * -> *) (fe :: * -> * -> * -> *) env env' aenv' aenv
t.
(HasCallStack, Applicative f, SyntacticExp fe) =>
RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> OpenExp env aenv t
-> f (OpenExp env' aenv' t)
rebuildOpenExp RebuildEvar f fe env env' aenv'
v ReindexAvar f aenv aenv'
av OpenExp env aenv dim
sh
LinearIndex ArrayVar aenv (Array dim t)
a OpenExp env aenv Int
i -> ArrayVar aenv' (Array dim t)
-> OpenExp env' aenv' Int -> OpenExp env' aenv' t
forall aenv dim t env.
ArrayVar aenv (Array dim t)
-> OpenExp env aenv Int -> OpenExp env aenv t
LinearIndex (ArrayVar aenv' (Array dim t)
-> OpenExp env' aenv' Int -> OpenExp env' aenv' t)
-> f (ArrayVar aenv' (Array dim t))
-> f (OpenExp env' aenv' Int -> OpenExp env' aenv' t)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ArrayVar aenv (Array dim t) -> f (ArrayVar aenv' (Array dim t))
forall sh e.
ArrayVar aenv (Array sh e) -> f (ArrayVar aenv' (Array sh e))
reindex ArrayVar aenv (Array dim t)
a f (OpenExp env' aenv' Int -> OpenExp env' aenv' t)
-> f (OpenExp env' aenv' Int) -> f (OpenExp env' aenv' t)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> OpenExp env aenv Int
-> f (OpenExp env' aenv' Int)
forall (f :: * -> *) (fe :: * -> * -> * -> *) env env' aenv' aenv
t.
(HasCallStack, Applicative f, SyntacticExp fe) =>
RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> OpenExp env aenv t
-> f (OpenExp env' aenv' t)
rebuildOpenExp RebuildEvar f fe env env' aenv'
v ReindexAvar f aenv aenv'
av OpenExp env aenv Int
i
Shape ArrayVar aenv (Array t e)
a -> ArrayVar aenv' (Array t e) -> OpenExp env' aenv' t
forall aenv dim e env.
ArrayVar aenv (Array dim e) -> OpenExp env aenv dim
Shape (ArrayVar aenv' (Array t e) -> OpenExp env' aenv' t)
-> f (ArrayVar aenv' (Array t e)) -> f (OpenExp env' aenv' t)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ArrayVar aenv (Array t e) -> f (ArrayVar aenv' (Array t e))
forall sh e.
ArrayVar aenv (Array sh e) -> f (ArrayVar aenv' (Array sh e))
reindex ArrayVar aenv (Array t e)
a
ShapeSize ShapeR dim
shr OpenExp env aenv dim
sh -> ShapeR dim -> OpenExp env' aenv' dim -> OpenExp env' aenv' Int
forall dim env aenv.
ShapeR dim -> OpenExp env aenv dim -> OpenExp env aenv Int
ShapeSize ShapeR dim
shr (OpenExp env' aenv' dim -> OpenExp env' aenv' Int)
-> f (OpenExp env' aenv' dim) -> f (OpenExp env' aenv' Int)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> OpenExp env aenv dim
-> f (OpenExp env' aenv' dim)
forall (f :: * -> *) (fe :: * -> * -> * -> *) env env' aenv' aenv
t.
(HasCallStack, Applicative f, SyntacticExp fe) =>
RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> OpenExp env aenv t
-> f (OpenExp env' aenv' t)
rebuildOpenExp RebuildEvar f fe env env' aenv'
v ReindexAvar f aenv aenv'
av OpenExp env aenv dim
sh
Foreign TypeR t
tp asm (x -> t)
ff Fun () (x -> t)
f OpenExp env aenv x
e -> TypeR t
-> asm (x -> t)
-> Fun () (x -> t)
-> OpenExp env' aenv' x
-> OpenExp env' aenv' t
forall (asm :: * -> *) y x env aenv.
Foreign asm =>
TypeR y
-> asm (x -> y)
-> Fun () (x -> y)
-> OpenExp env aenv x
-> OpenExp env aenv y
Foreign TypeR t
tp asm (x -> t)
ff Fun () (x -> t)
f (OpenExp env' aenv' x -> OpenExp env' aenv' t)
-> f (OpenExp env' aenv' x) -> f (OpenExp env' aenv' t)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> OpenExp env aenv x
-> f (OpenExp env' aenv' x)
forall (f :: * -> *) (fe :: * -> * -> * -> *) env env' aenv' aenv
t.
(HasCallStack, Applicative f, SyntacticExp fe) =>
RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> OpenExp env aenv t
-> f (OpenExp env' aenv' t)
rebuildOpenExp RebuildEvar f fe env env' aenv'
v ReindexAvar f aenv aenv'
av OpenExp env aenv x
e
Coerce ScalarType a
t1 ScalarType t
t2 OpenExp env aenv a
e -> ScalarType a
-> ScalarType t -> OpenExp env' aenv' a -> OpenExp env' aenv' t
forall a b env aenv.
BitSizeEq a b =>
ScalarType a
-> ScalarType b -> OpenExp env aenv a -> OpenExp env aenv b
Coerce ScalarType a
t1 ScalarType t
t2 (OpenExp env' aenv' a -> OpenExp env' aenv' t)
-> f (OpenExp env' aenv' a) -> f (OpenExp env' aenv' t)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> OpenExp env aenv a
-> f (OpenExp env' aenv' a)
forall (f :: * -> *) (fe :: * -> * -> * -> *) env env' aenv' aenv
t.
(HasCallStack, Applicative f, SyntacticExp fe) =>
RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> OpenExp env aenv t
-> f (OpenExp env' aenv' t)
rebuildOpenExp RebuildEvar f fe env env' aenv'
v ReindexAvar f aenv aenv'
av OpenExp env aenv a
e
{-# INLINEABLE rebuildFun #-}
rebuildFun
:: (HasCallStack, Applicative f, SyntacticExp fe)
=> RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> OpenFun env aenv t
-> f (OpenFun env' aenv' t)
rebuildFun :: RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> OpenFun env aenv t
-> f (OpenFun env' aenv' t)
rebuildFun RebuildEvar f fe env env' aenv'
v ReindexAvar f aenv aenv'
av OpenFun env aenv t
fun =
case OpenFun env aenv t
fun of
Body OpenExp env aenv t
e -> OpenExp env' aenv' t -> OpenFun env' aenv' t
forall env aenv t. OpenExp env aenv t -> OpenFun env aenv t
Body (OpenExp env' aenv' t -> OpenFun env' aenv' t)
-> f (OpenExp env' aenv' t) -> f (OpenFun env' aenv' t)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> OpenExp env aenv t
-> f (OpenExp env' aenv' t)
forall (f :: * -> *) (fe :: * -> * -> * -> *) env env' aenv' aenv
t.
(HasCallStack, Applicative f, SyntacticExp fe) =>
RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> OpenExp env aenv t
-> f (OpenExp env' aenv' t)
rebuildOpenExp RebuildEvar f fe env env' aenv'
v ReindexAvar f aenv aenv'
av OpenExp env aenv t
e
Lam ELeftHandSide a env env'
lhs OpenFun env' aenv t
f
| Exists LeftHandSide ScalarType a env' a
lhs' <- ELeftHandSide a env env' -> Exists (LeftHandSide ScalarType a env')
forall (s :: * -> *) t aenv1 aenv1' aenv2.
LeftHandSide s t aenv1 aenv1' -> Exists (LeftHandSide s t aenv2)
rebuildLHS ELeftHandSide a env env'
lhs
-> LeftHandSide ScalarType a env' a
-> OpenFun a aenv' t -> OpenFun env' aenv' (a -> t)
forall a env env' aenv t.
ELeftHandSide a env env'
-> OpenFun env' aenv t -> OpenFun env aenv (a -> t)
Lam LeftHandSide ScalarType a env' a
lhs' (OpenFun a aenv' t -> OpenFun env' aenv' (a -> t))
-> f (OpenFun a aenv' t) -> f (OpenFun env' aenv' (a -> t))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> RebuildEvar f fe env' a aenv'
-> ReindexAvar f aenv aenv'
-> OpenFun env' aenv t
-> f (OpenFun a aenv' t)
forall (f :: * -> *) (fe :: * -> * -> * -> *) env env' aenv' aenv
t.
(HasCallStack, Applicative f, SyntacticExp fe) =>
RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> OpenFun env aenv t
-> f (OpenFun env' aenv' t)
rebuildFun (ELeftHandSide a env env'
-> LeftHandSide ScalarType a env' a
-> RebuildEvar f fe env env' aenv'
-> RebuildEvar f fe env' a aenv'
forall (f :: * -> *) (fa :: * -> * -> * -> *) t env1 env1' env2
env2' aenv.
(Applicative f, SyntacticExp fa) =>
ELeftHandSide t env1 env1'
-> ELeftHandSide t env2 env2'
-> RebuildEvar f fa env1 env2 aenv
-> RebuildEvar f fa env1' env2' aenv
shiftE' ELeftHandSide a env env'
lhs LeftHandSide ScalarType a env' a
lhs' RebuildEvar f fe env env' aenv'
v) ReindexAvar f aenv aenv'
av OpenFun env' aenv t
f
type RebuildAcc acc =
forall aenv aenv' f fa a. (HasCallStack, Applicative f, SyntacticAcc fa)
=> RebuildAvar f fa acc aenv aenv'
-> acc aenv a
-> f (acc aenv' a)
newtype IdxA (acc :: Type -> Type -> Type) aenv t = IA { IdxA acc aenv t -> ArrayVar aenv t
unIA :: ArrayVar aenv t }
class SyntacticAcc f where
avarIn :: ArrayVar aenv (Array sh e) -> f acc aenv (Array sh e)
accOut :: f acc aenv (Array sh e) -> PreOpenAcc acc aenv (Array sh e)
weakenAcc :: RebuildAcc acc -> f acc aenv (Array sh e) -> f acc (aenv, s) (Array sh e)
instance SyntacticAcc IdxA where
avarIn :: ArrayVar aenv (Array sh e) -> IdxA acc aenv (Array sh e)
avarIn = ArrayVar aenv (Array sh e) -> IdxA acc aenv (Array sh e)
forall (acc :: * -> * -> *) aenv t.
ArrayVar aenv t -> IdxA acc aenv t
IA
accOut :: IdxA acc aenv (Array sh e) -> PreOpenAcc acc aenv (Array sh e)
accOut = ArrayVar aenv (Array sh e) -> PreOpenAcc acc aenv (Array sh e)
forall aenv sh e (acc :: * -> * -> *).
ArrayVar aenv (Array sh e) -> PreOpenAcc acc aenv (Array sh e)
Avar (ArrayVar aenv (Array sh e) -> PreOpenAcc acc aenv (Array sh e))
-> (IdxA acc aenv (Array sh e) -> ArrayVar aenv (Array sh e))
-> IdxA acc aenv (Array sh e)
-> PreOpenAcc acc aenv (Array sh e)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IdxA acc aenv (Array sh e) -> ArrayVar aenv (Array sh e)
forall (acc :: * -> * -> *) aenv t.
IdxA acc aenv t -> ArrayVar aenv t
unIA
weakenAcc :: RebuildAcc acc
-> IdxA acc aenv (Array sh e) -> IdxA acc (aenv, s) (Array sh e)
weakenAcc RebuildAcc acc
_ (IA (Var ArrayR (Array sh e)
s Idx aenv (Array sh e)
idx)) = ArrayVar (aenv, s) (Array sh e) -> IdxA acc (aenv, s) (Array sh e)
forall (acc :: * -> * -> *) aenv t.
ArrayVar aenv t -> IdxA acc aenv t
IA (ArrayVar (aenv, s) (Array sh e)
-> IdxA acc (aenv, s) (Array sh e))
-> ArrayVar (aenv, s) (Array sh e)
-> IdxA acc (aenv, s) (Array sh e)
forall a b. (a -> b) -> a -> b
$ ArrayR (Array sh e)
-> Idx (aenv, s) (Array sh e) -> ArrayVar (aenv, s) (Array sh e)
forall (s :: * -> *) env t. s t -> Idx env t -> Var s env t
Var ArrayR (Array sh e)
s (Idx (aenv, s) (Array sh e) -> ArrayVar (aenv, s) (Array sh e))
-> Idx (aenv, s) (Array sh e) -> ArrayVar (aenv, s) (Array sh e)
forall a b. (a -> b) -> a -> b
$ Idx aenv (Array sh e) -> Idx (aenv, s) (Array sh e)
forall env t s. Idx env t -> Idx (env, s) t
SuccIdx Idx aenv (Array sh e)
idx
instance SyntacticAcc PreOpenAcc where
avarIn :: ArrayVar aenv (Array sh e) -> PreOpenAcc acc aenv (Array sh e)
avarIn = ArrayVar aenv (Array sh e) -> PreOpenAcc acc aenv (Array sh e)
forall aenv sh e (acc :: * -> * -> *).
ArrayVar aenv (Array sh e) -> PreOpenAcc acc aenv (Array sh e)
Avar
accOut :: PreOpenAcc acc aenv (Array sh e)
-> PreOpenAcc acc aenv (Array sh e)
accOut = PreOpenAcc acc aenv (Array sh e)
-> PreOpenAcc acc aenv (Array sh e)
forall a. a -> a
id
weakenAcc :: RebuildAcc acc
-> PreOpenAcc acc aenv (Array sh e)
-> PreOpenAcc acc (aenv, s) (Array sh e)
weakenAcc RebuildAcc acc
k = Identity (PreOpenAcc acc (aenv, s) (Array sh e))
-> PreOpenAcc acc (aenv, s) (Array sh e)
forall a. Identity a -> a
runIdentity (Identity (PreOpenAcc acc (aenv, s) (Array sh e))
-> PreOpenAcc acc (aenv, s) (Array sh e))
-> (PreOpenAcc acc aenv (Array sh e)
-> Identity (PreOpenAcc acc (aenv, s) (Array sh e)))
-> PreOpenAcc acc aenv (Array sh e)
-> PreOpenAcc acc (aenv, s) (Array sh e)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RebuildAcc acc
-> RebuildAvar Identity IdxA acc aenv (aenv, s)
-> PreOpenAcc acc aenv (Array sh e)
-> Identity (PreOpenAcc acc (aenv, s) (Array sh e))
forall (f :: * -> *) (fa :: (* -> * -> *) -> * -> * -> *)
(acc :: * -> * -> *) aenv aenv' t.
(HasCallStack, Applicative f, SyntacticAcc fa) =>
RebuildAcc acc
-> RebuildAvar f fa acc aenv aenv'
-> PreOpenAcc acc aenv t
-> f (PreOpenAcc acc aenv' t)
rebuildPreOpenAcc RebuildAcc acc
k (IdxA acc (aenv, s) (Array sh e)
-> Identity (IdxA acc (aenv, s) (Array sh e))
forall a. a -> Identity a
Identity (IdxA acc (aenv, s) (Array sh e)
-> Identity (IdxA acc (aenv, s) (Array sh e)))
-> (ArrayVar aenv (Array sh e) -> IdxA acc (aenv, s) (Array sh e))
-> ArrayVar aenv (Array sh e)
-> Identity (IdxA acc (aenv, s) (Array sh e))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RebuildAcc acc
-> IdxA acc aenv (Array sh e) -> IdxA acc (aenv, s) (Array sh e)
forall (f :: (* -> * -> *) -> * -> * -> *) (acc :: * -> * -> *)
aenv sh e s.
SyntacticAcc f =>
RebuildAcc acc
-> f acc aenv (Array sh e) -> f acc (aenv, s) (Array sh e)
weakenAcc RebuildAcc acc
k (IdxA acc aenv (Array sh e) -> IdxA acc (aenv, s) (Array sh e))
-> (ArrayVar aenv (Array sh e) -> IdxA acc aenv (Array sh e))
-> ArrayVar aenv (Array sh e)
-> IdxA acc (aenv, s) (Array sh e)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ArrayVar aenv (Array sh e) -> IdxA acc aenv (Array sh e)
forall (acc :: * -> * -> *) aenv t.
ArrayVar aenv t -> IdxA acc aenv t
IA)
type RebuildAvar f (fa :: (Type -> Type -> Type) -> Type -> Type -> Type) acc aenv aenv'
= forall sh e. ArrayVar aenv (Array sh e) -> f (fa acc aenv' (Array sh e))
type RebuildEvar f fe env env' aenv' =
forall t'. ExpVar env t' -> f (fe env' aenv' t')
newtype ReindexAvar f aenv aenv' =
ReindexAvar (forall sh e. ArrayVar aenv (Array sh e) -> f (ArrayVar aenv' (Array sh e)))
reindexAvar
:: forall f fa acc aenv aenv'.
(HasCallStack, Applicative f, SyntacticAcc fa)
=> RebuildAvar f fa acc aenv aenv'
-> ReindexAvar f aenv aenv'
reindexAvar :: RebuildAvar f fa acc aenv aenv' -> ReindexAvar f aenv aenv'
reindexAvar RebuildAvar f fa acc aenv aenv'
v = (forall sh e.
ArrayVar aenv (Array sh e) -> f (ArrayVar aenv' (Array sh e)))
-> ReindexAvar f aenv aenv'
forall (f :: * -> *) aenv aenv'.
(forall sh e.
ArrayVar aenv (Array sh e) -> f (ArrayVar aenv' (Array sh e)))
-> ReindexAvar f aenv aenv'
ReindexAvar forall sh e.
ArrayVar aenv (Array sh e) -> f (ArrayVar aenv' (Array sh e))
f where
f :: forall sh e. ArrayVar aenv (Array sh e) -> f (ArrayVar aenv' (Array sh e))
f :: ArrayVar aenv (Array sh e) -> f (ArrayVar aenv' (Array sh e))
f ArrayVar aenv (Array sh e)
var = fa acc aenv' (Array sh e) -> ArrayVar aenv' (Array sh e)
forall sh e.
fa acc aenv' (Array sh e) -> ArrayVar aenv' (Array sh e)
g (fa acc aenv' (Array sh e) -> ArrayVar aenv' (Array sh e))
-> f (fa acc aenv' (Array sh e)) -> f (ArrayVar aenv' (Array sh e))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ArrayVar aenv (Array sh e) -> f (fa acc aenv' (Array sh e))
RebuildAvar f fa acc aenv aenv'
v ArrayVar aenv (Array sh e)
var
g :: fa acc aenv' (Array sh e) -> ArrayVar aenv' (Array sh e)
g :: fa acc aenv' (Array sh e) -> ArrayVar aenv' (Array sh e)
g fa acc aenv' (Array sh e)
fa = case fa acc aenv' (Array sh e) -> PreOpenAcc acc aenv' (Array sh e)
forall (f :: (* -> * -> *) -> * -> * -> *) (acc :: * -> * -> *)
aenv sh e.
SyntacticAcc f =>
f acc aenv (Array sh e) -> PreOpenAcc acc aenv (Array sh e)
accOut fa acc aenv' (Array sh e)
fa of
Avar ArrayVar aenv' (Array sh e)
var' -> ArrayVar aenv' (Array sh e)
ArrayVar aenv' (Array sh e)
var'
PreOpenAcc acc aenv' (Array sh e)
_ -> [Char] -> ArrayVar aenv' (Array sh e)
forall a. HasCallStack => [Char] -> a
internalError [Char]
"An Avar which was used in an Exp was mapped to an array term other than Avar. This mapping is invalid as an Exp can only contain array variables."
{-# INLINEABLE shiftA #-}
shiftA
:: (HasCallStack, Applicative f, SyntacticAcc fa)
=> RebuildAcc acc
-> RebuildAvar f fa acc aenv aenv'
-> ArrayVar (aenv, s) (Array sh e)
-> f (fa acc (aenv', s) (Array sh e))
shiftA :: RebuildAcc acc
-> RebuildAvar f fa acc aenv aenv'
-> ArrayVar (aenv, s) (Array sh e)
-> f (fa acc (aenv', s) (Array sh e))
shiftA RebuildAcc acc
_ RebuildAvar f fa acc aenv aenv'
_ (Var ArrayR (Array sh e)
s Idx (aenv, s) (Array sh e)
ZeroIdx) = fa acc (aenv', Array sh e) (Array sh e)
-> f (fa acc (aenv', Array sh e) (Array sh e))
forall (f :: * -> *) a. Applicative f => a -> f a
pure (fa acc (aenv', Array sh e) (Array sh e)
-> f (fa acc (aenv', Array sh e) (Array sh e)))
-> fa acc (aenv', Array sh e) (Array sh e)
-> f (fa acc (aenv', Array sh e) (Array sh e))
forall a b. (a -> b) -> a -> b
$ ArrayVar (aenv', Array sh e) (Array sh e)
-> fa acc (aenv', Array sh e) (Array sh e)
forall (f :: (* -> * -> *) -> * -> * -> *) aenv sh e
(acc :: * -> * -> *).
SyntacticAcc f =>
ArrayVar aenv (Array sh e) -> f acc aenv (Array sh e)
avarIn (ArrayVar (aenv', Array sh e) (Array sh e)
-> fa acc (aenv', Array sh e) (Array sh e))
-> ArrayVar (aenv', Array sh e) (Array sh e)
-> fa acc (aenv', Array sh e) (Array sh e)
forall a b. (a -> b) -> a -> b
$ ArrayR (Array sh e)
-> Idx (aenv', Array sh e) (Array sh e)
-> ArrayVar (aenv', Array sh e) (Array sh e)
forall (s :: * -> *) env t. s t -> Idx env t -> Var s env t
Var ArrayR (Array sh e)
s Idx (aenv', Array sh e) (Array sh e)
forall env t. Idx (env, t) t
ZeroIdx
shiftA RebuildAcc acc
k RebuildAvar f fa acc aenv aenv'
v (Var ArrayR (Array sh e)
s (SuccIdx Idx env (Array sh e)
ix)) = RebuildAcc acc
-> fa acc aenv' (Array sh e) -> fa acc (aenv', s) (Array sh e)
forall (f :: (* -> * -> *) -> * -> * -> *) (acc :: * -> * -> *)
aenv sh e s.
SyntacticAcc f =>
RebuildAcc acc
-> f acc aenv (Array sh e) -> f acc (aenv, s) (Array sh e)
weakenAcc RebuildAcc acc
k (fa acc aenv' (Array sh e) -> fa acc (aenv', s) (Array sh e))
-> f (fa acc aenv' (Array sh e))
-> f (fa acc (aenv', s) (Array sh e))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ArrayVar aenv (Array sh e) -> f (fa acc aenv' (Array sh e))
RebuildAvar f fa acc aenv aenv'
v (ArrayR (Array sh e)
-> Idx env (Array sh e) -> Var ArrayR env (Array sh e)
forall (s :: * -> *) env t. s t -> Idx env t -> Var s env t
Var ArrayR (Array sh e)
s Idx env (Array sh e)
ix)
shiftA'
:: (HasCallStack, Applicative f, SyntacticAcc fa)
=> ALeftHandSide t aenv1 aenv1'
-> ALeftHandSide t aenv2 aenv2'
-> RebuildAcc acc
-> RebuildAvar f fa acc aenv1 aenv2
-> RebuildAvar f fa acc aenv1' aenv2'
shiftA' :: ALeftHandSide t aenv1 aenv1'
-> ALeftHandSide t aenv2 aenv2'
-> RebuildAcc acc
-> RebuildAvar f fa acc aenv1 aenv2
-> RebuildAvar f fa acc aenv1' aenv2'
shiftA' (LeftHandSideWildcard TupR ArrayR t
_) (LeftHandSideWildcard TupR ArrayR t
_) RebuildAcc acc
_ RebuildAvar f fa acc aenv1 aenv2
v = Var ArrayR aenv1' (Array sh e) -> f (fa acc aenv2' (Array sh e))
RebuildAvar f fa acc aenv1 aenv2
v
shiftA' (LeftHandSideSingle ArrayR t
_) (LeftHandSideSingle ArrayR t
_) RebuildAcc acc
k RebuildAvar f fa acc aenv1 aenv2
v = RebuildAcc acc
-> RebuildAvar f fa acc aenv1 aenv2
-> ArrayVar (aenv1, t) (Array sh e)
-> f (fa acc (aenv2, t) (Array sh e))
forall (f :: * -> *) (fa :: (* -> * -> *) -> * -> * -> *)
(acc :: * -> * -> *) aenv aenv' s sh e.
(HasCallStack, Applicative f, SyntacticAcc fa) =>
RebuildAcc acc
-> RebuildAvar f fa acc aenv aenv'
-> ArrayVar (aenv, s) (Array sh e)
-> f (fa acc (aenv', s) (Array sh e))
shiftA RebuildAcc acc
k RebuildAvar f fa acc aenv1 aenv2
v
shiftA' (LeftHandSidePair LeftHandSide ArrayR v1 aenv1 env'
a1 LeftHandSide ArrayR v2 env' aenv1'
b1) (LeftHandSidePair LeftHandSide ArrayR v1 aenv2 env'
a2 LeftHandSide ArrayR v2 env' aenv2'
b2) RebuildAcc acc
k RebuildAvar f fa acc aenv1 aenv2
v = LeftHandSide ArrayR v2 env' aenv1'
-> ALeftHandSide v2 env' aenv2'
-> RebuildAcc acc
-> RebuildAvar f fa acc env' env'
-> RebuildAvar f fa acc aenv1' aenv2'
forall (f :: * -> *) (fa :: (* -> * -> *) -> * -> * -> *) t aenv1
aenv1' aenv2 aenv2' (acc :: * -> * -> *).
(HasCallStack, Applicative f, SyntacticAcc fa) =>
ALeftHandSide t aenv1 aenv1'
-> ALeftHandSide t aenv2 aenv2'
-> RebuildAcc acc
-> RebuildAvar f fa acc aenv1 aenv2
-> RebuildAvar f fa acc aenv1' aenv2'
shiftA' LeftHandSide ArrayR v2 env' aenv1'
b1 ALeftHandSide v2 env' aenv2'
LeftHandSide ArrayR v2 env' aenv2'
b2 RebuildAcc acc
k (RebuildAvar f fa acc env' env'
-> RebuildAvar f fa acc aenv1' aenv2')
-> RebuildAvar f fa acc env' env'
-> RebuildAvar f fa acc aenv1' aenv2'
forall a b. (a -> b) -> a -> b
$ LeftHandSide ArrayR v1 aenv1 env'
-> ALeftHandSide v1 aenv2 env'
-> RebuildAcc acc
-> RebuildAvar f fa acc aenv1 aenv2
-> RebuildAvar f fa acc env' env'
forall (f :: * -> *) (fa :: (* -> * -> *) -> * -> * -> *) t aenv1
aenv1' aenv2 aenv2' (acc :: * -> * -> *).
(HasCallStack, Applicative f, SyntacticAcc fa) =>
ALeftHandSide t aenv1 aenv1'
-> ALeftHandSide t aenv2 aenv2'
-> RebuildAcc acc
-> RebuildAvar f fa acc aenv1 aenv2
-> RebuildAvar f fa acc aenv1' aenv2'
shiftA' LeftHandSide ArrayR v1 aenv1 env'
a1 ALeftHandSide v1 aenv2 env'
LeftHandSide ArrayR v1 aenv2 env'
a2 RebuildAcc acc
k RebuildAvar f fa acc aenv1 aenv2
v
shiftA' ALeftHandSide t aenv1 aenv1'
_ ALeftHandSide t aenv2 aenv2'
_ RebuildAcc acc
_ RebuildAvar f fa acc aenv1 aenv2
_ = [Char]
-> Var ArrayR aenv1' (Array sh e) -> f (fa acc aenv2' (Array sh e))
forall a. HasCallStack => [Char] -> a
internalError [Char]
"left hand sides do not match"
{-# INLINEABLE rebuildOpenAcc #-}
rebuildOpenAcc
:: (HasCallStack, Applicative f, SyntacticAcc fa)
=> (forall sh e. ArrayVar aenv (Array sh e) -> f (fa OpenAcc aenv' (Array sh e)))
-> OpenAcc aenv t
-> f (OpenAcc aenv' t)
rebuildOpenAcc :: (forall sh e.
ArrayVar aenv (Array sh e) -> f (fa OpenAcc aenv' (Array sh e)))
-> OpenAcc aenv t -> f (OpenAcc aenv' t)
rebuildOpenAcc forall sh e.
ArrayVar aenv (Array sh e) -> f (fa OpenAcc aenv' (Array sh e))
av (OpenAcc PreOpenAcc OpenAcc aenv t
acc) = PreOpenAcc OpenAcc aenv' t -> OpenAcc aenv' t
forall aenv t. PreOpenAcc OpenAcc aenv t -> OpenAcc aenv t
OpenAcc (PreOpenAcc OpenAcc aenv' t -> OpenAcc aenv' t)
-> f (PreOpenAcc OpenAcc aenv' t) -> f (OpenAcc aenv' t)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> RebuildAcc OpenAcc
-> (forall sh e.
ArrayVar aenv (Array sh e) -> f (fa OpenAcc aenv' (Array sh e)))
-> PreOpenAcc OpenAcc aenv t
-> f (PreOpenAcc OpenAcc aenv' t)
forall (f :: * -> *) (fa :: (* -> * -> *) -> * -> * -> *)
(acc :: * -> * -> *) aenv aenv' t.
(HasCallStack, Applicative f, SyntacticAcc fa) =>
RebuildAcc acc
-> RebuildAvar f fa acc aenv aenv'
-> PreOpenAcc acc aenv t
-> f (PreOpenAcc acc aenv' t)
rebuildPreOpenAcc RebuildAcc OpenAcc
forall (f :: * -> *) (fa :: (* -> * -> *) -> * -> * -> *) aenv
aenv' t.
(HasCallStack, Applicative f, SyntacticAcc fa) =>
(forall sh e.
ArrayVar aenv (Array sh e) -> f (fa OpenAcc aenv' (Array sh e)))
-> OpenAcc aenv t -> f (OpenAcc aenv' t)
rebuildOpenAcc forall sh e.
ArrayVar aenv (Array sh e) -> f (fa OpenAcc aenv' (Array sh e))
av PreOpenAcc OpenAcc aenv t
acc
{-# INLINEABLE rebuildPreOpenAcc #-}
rebuildPreOpenAcc
:: (HasCallStack, Applicative f, SyntacticAcc fa)
=> RebuildAcc acc
-> RebuildAvar f fa acc aenv aenv'
-> PreOpenAcc acc aenv t
-> f (PreOpenAcc acc aenv' t)
rebuildPreOpenAcc :: RebuildAcc acc
-> RebuildAvar f fa acc aenv aenv'
-> PreOpenAcc acc aenv t
-> f (PreOpenAcc acc aenv' t)
rebuildPreOpenAcc RebuildAcc acc
k RebuildAvar f fa acc aenv aenv'
av PreOpenAcc acc aenv t
acc =
case PreOpenAcc acc aenv t
acc of
Use ArrayR (Array sh e)
repr Array sh e
a -> PreOpenAcc acc aenv' (Array sh e)
-> f (PreOpenAcc acc aenv' (Array sh e))
forall (f :: * -> *) a. Applicative f => a -> f a
pure (PreOpenAcc acc aenv' (Array sh e)
-> f (PreOpenAcc acc aenv' (Array sh e)))
-> PreOpenAcc acc aenv' (Array sh e)
-> f (PreOpenAcc acc aenv' (Array sh e))
forall a b. (a -> b) -> a -> b
$ ArrayR (Array sh e)
-> Array sh e -> PreOpenAcc acc aenv' (Array sh e)
forall sh e (acc :: * -> * -> *) aenv.
ArrayR (Array sh e)
-> Array sh e -> PreOpenAcc acc aenv (Array sh e)
Use ArrayR (Array sh e)
repr Array sh e
a
Alet ALeftHandSide bndArrs aenv aenv'
lhs acc aenv bndArrs
a acc aenv' t
b -> RebuildAcc acc
-> RebuildAvar f fa acc aenv aenv'
-> ALeftHandSide bndArrs aenv aenv'
-> acc aenv bndArrs
-> acc aenv' t
-> f (PreOpenAcc acc aenv' t)
forall (f :: * -> *) (fa :: (* -> * -> *) -> * -> * -> *)
(acc :: * -> * -> *) aenv1 aenv1' aenv2 bndArrs arrs.
(HasCallStack, Applicative f, SyntacticAcc fa) =>
RebuildAcc acc
-> RebuildAvar f fa acc aenv1 aenv2
-> ALeftHandSide bndArrs aenv1 aenv1'
-> acc aenv1 bndArrs
-> acc aenv1' arrs
-> f (PreOpenAcc acc aenv2 arrs)
rebuildAlet RebuildAcc acc
k RebuildAvar f fa acc aenv aenv'
av ALeftHandSide bndArrs aenv aenv'
lhs acc aenv bndArrs
a acc aenv' t
b
Avar ArrayVar aenv (Array sh e)
ix -> fa acc aenv' (Array sh e) -> PreOpenAcc acc aenv' (Array sh e)
forall (f :: (* -> * -> *) -> * -> * -> *) (acc :: * -> * -> *)
aenv sh e.
SyntacticAcc f =>
f acc aenv (Array sh e) -> PreOpenAcc acc aenv (Array sh e)
accOut (fa acc aenv' (Array sh e) -> PreOpenAcc acc aenv' (Array sh e))
-> f (fa acc aenv' (Array sh e))
-> f (PreOpenAcc acc aenv' (Array sh e))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ArrayVar aenv (Array sh e) -> f (fa acc aenv' (Array sh e))
RebuildAvar f fa acc aenv aenv'
av ArrayVar aenv (Array sh e)
ix
Apair acc aenv as
as acc aenv bs
bs -> acc aenv' as -> acc aenv' bs -> PreOpenAcc acc aenv' (as, bs)
forall (acc :: * -> * -> *) aenv as bs.
acc aenv as -> acc aenv bs -> PreOpenAcc acc aenv (as, bs)
Apair (acc aenv' as -> acc aenv' bs -> PreOpenAcc acc aenv' (as, bs))
-> f (acc aenv' as)
-> f (acc aenv' bs -> PreOpenAcc acc aenv' (as, bs))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> RebuildAvar f fa acc aenv aenv' -> acc aenv as -> f (acc aenv' as)
RebuildAcc acc
k RebuildAvar f fa acc aenv aenv'
av acc aenv as
as f (acc aenv' bs -> PreOpenAcc acc aenv' (as, bs))
-> f (acc aenv' bs) -> f (PreOpenAcc acc aenv' (as, bs))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> RebuildAvar f fa acc aenv aenv' -> acc aenv bs -> f (acc aenv' bs)
RebuildAcc acc
k RebuildAvar f fa acc aenv aenv'
av acc aenv bs
bs
PreOpenAcc acc aenv t
Anil -> PreOpenAcc acc aenv' () -> f (PreOpenAcc acc aenv' ())
forall (f :: * -> *) a. Applicative f => a -> f a
pure PreOpenAcc acc aenv' ()
forall (acc :: * -> * -> *) aenv. PreOpenAcc acc aenv ()
Anil
Apply ArraysR t
repr PreOpenAfun acc aenv (arrs1 -> t)
f acc aenv arrs1
a -> ArraysR t
-> PreOpenAfun acc aenv' (arrs1 -> t)
-> acc aenv' arrs1
-> PreOpenAcc acc aenv' t
forall arrs2 (acc :: * -> * -> *) aenv arrs1.
ArraysR arrs2
-> PreOpenAfun acc aenv (arrs1 -> arrs2)
-> acc aenv arrs1
-> PreOpenAcc acc aenv arrs2
Apply ArraysR t
repr (PreOpenAfun acc aenv' (arrs1 -> t)
-> acc aenv' arrs1 -> PreOpenAcc acc aenv' t)
-> f (PreOpenAfun acc aenv' (arrs1 -> t))
-> f (acc aenv' arrs1 -> PreOpenAcc acc aenv' t)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> RebuildAcc acc
-> RebuildAvar f fa acc aenv aenv'
-> PreOpenAfun acc aenv (arrs1 -> t)
-> f (PreOpenAfun acc aenv' (arrs1 -> t))
forall (f :: * -> *) (fa :: (* -> * -> *) -> * -> * -> *)
(acc :: * -> * -> *) aenv aenv' t.
(HasCallStack, Applicative f, SyntacticAcc fa) =>
RebuildAcc acc
-> RebuildAvar f fa acc aenv aenv'
-> PreOpenAfun acc aenv t
-> f (PreOpenAfun acc aenv' t)
rebuildAfun RebuildAcc acc
k RebuildAvar f fa acc aenv aenv'
av PreOpenAfun acc aenv (arrs1 -> t)
f f (acc aenv' arrs1 -> PreOpenAcc acc aenv' t)
-> f (acc aenv' arrs1) -> f (PreOpenAcc acc aenv' t)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> RebuildAvar f fa acc aenv aenv'
-> acc aenv arrs1 -> f (acc aenv' arrs1)
RebuildAcc acc
k RebuildAvar f fa acc aenv aenv'
av acc aenv arrs1
a
Acond Exp aenv TAG
p acc aenv t
t acc aenv t
e -> Exp aenv' TAG
-> acc aenv' t -> acc aenv' t -> PreOpenAcc acc aenv' t
forall aenv (acc :: * -> * -> *) arrs.
Exp aenv TAG
-> acc aenv arrs -> acc aenv arrs -> PreOpenAcc acc aenv arrs
Acond (Exp aenv' TAG
-> acc aenv' t -> acc aenv' t -> PreOpenAcc acc aenv' t)
-> f (Exp aenv' TAG)
-> f (acc aenv' t -> acc aenv' t -> PreOpenAcc acc aenv' t)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> RebuildEvar f IdxE () () aenv'
-> ReindexAvar f aenv aenv' -> Exp aenv TAG -> f (Exp aenv' TAG)
forall (f :: * -> *) (fe :: * -> * -> * -> *) env env' aenv' aenv
t.
(HasCallStack, Applicative f, SyntacticExp fe) =>
RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> OpenExp env aenv t
-> f (OpenExp env' aenv' t)
rebuildOpenExp (IdxE () aenv' t' -> f (IdxE () aenv' t')
forall (f :: * -> *) a. Applicative f => a -> f a
pure (IdxE () aenv' t' -> f (IdxE () aenv' t'))
-> (ExpVar () t' -> IdxE () aenv' t')
-> ExpVar () t'
-> f (IdxE () aenv' t')
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ExpVar () t' -> IdxE () aenv' t'
forall env aenv t. ExpVar env t -> IdxE env aenv t
IE) ReindexAvar f aenv aenv'
av' Exp aenv TAG
p f (acc aenv' t -> acc aenv' t -> PreOpenAcc acc aenv' t)
-> f (acc aenv' t) -> f (acc aenv' t -> PreOpenAcc acc aenv' t)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> RebuildAvar f fa acc aenv aenv' -> acc aenv t -> f (acc aenv' t)
RebuildAcc acc
k RebuildAvar f fa acc aenv aenv'
av acc aenv t
t f (acc aenv' t -> PreOpenAcc acc aenv' t)
-> f (acc aenv' t) -> f (PreOpenAcc acc aenv' t)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> RebuildAvar f fa acc aenv aenv' -> acc aenv t -> f (acc aenv' t)
RebuildAcc acc
k RebuildAvar f fa acc aenv aenv'
av acc aenv t
e
Awhile PreOpenAfun acc aenv (t -> Scalar TAG)
p PreOpenAfun acc aenv (t -> t)
f acc aenv t
a -> PreOpenAfun acc aenv' (t -> Scalar TAG)
-> PreOpenAfun acc aenv' (t -> t)
-> acc aenv' t
-> PreOpenAcc acc aenv' t
forall (acc :: * -> * -> *) aenv arrs.
PreOpenAfun acc aenv (arrs -> Scalar TAG)
-> PreOpenAfun acc aenv (arrs -> arrs)
-> acc aenv arrs
-> PreOpenAcc acc aenv arrs
Awhile (PreOpenAfun acc aenv' (t -> Scalar TAG)
-> PreOpenAfun acc aenv' (t -> t)
-> acc aenv' t
-> PreOpenAcc acc aenv' t)
-> f (PreOpenAfun acc aenv' (t -> Scalar TAG))
-> f (PreOpenAfun acc aenv' (t -> t)
-> acc aenv' t -> PreOpenAcc acc aenv' t)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> RebuildAcc acc
-> RebuildAvar f fa acc aenv aenv'
-> PreOpenAfun acc aenv (t -> Scalar TAG)
-> f (PreOpenAfun acc aenv' (t -> Scalar TAG))
forall (f :: * -> *) (fa :: (* -> * -> *) -> * -> * -> *)
(acc :: * -> * -> *) aenv aenv' t.
(HasCallStack, Applicative f, SyntacticAcc fa) =>
RebuildAcc acc
-> RebuildAvar f fa acc aenv aenv'
-> PreOpenAfun acc aenv t
-> f (PreOpenAfun acc aenv' t)
rebuildAfun RebuildAcc acc
k RebuildAvar f fa acc aenv aenv'
av PreOpenAfun acc aenv (t -> Scalar TAG)
p f (PreOpenAfun acc aenv' (t -> t)
-> acc aenv' t -> PreOpenAcc acc aenv' t)
-> f (PreOpenAfun acc aenv' (t -> t))
-> f (acc aenv' t -> PreOpenAcc acc aenv' t)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> RebuildAcc acc
-> RebuildAvar f fa acc aenv aenv'
-> PreOpenAfun acc aenv (t -> t)
-> f (PreOpenAfun acc aenv' (t -> t))
forall (f :: * -> *) (fa :: (* -> * -> *) -> * -> * -> *)
(acc :: * -> * -> *) aenv aenv' t.
(HasCallStack, Applicative f, SyntacticAcc fa) =>
RebuildAcc acc
-> RebuildAvar f fa acc aenv aenv'
-> PreOpenAfun acc aenv t
-> f (PreOpenAfun acc aenv' t)
rebuildAfun RebuildAcc acc
k RebuildAvar f fa acc aenv aenv'
av PreOpenAfun acc aenv (t -> t)
f f (acc aenv' t -> PreOpenAcc acc aenv' t)
-> f (acc aenv' t) -> f (PreOpenAcc acc aenv' t)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> RebuildAvar f fa acc aenv aenv' -> acc aenv t -> f (acc aenv' t)
RebuildAcc acc
k RebuildAvar f fa acc aenv aenv'
av acc aenv t
a
Unit TypeR e
tp Exp aenv e
e -> TypeR e -> Exp aenv' e -> PreOpenAcc acc aenv' (Scalar e)
forall e aenv (acc :: * -> * -> *).
TypeR e -> Exp aenv e -> PreOpenAcc acc aenv (Scalar e)
Unit TypeR e
tp (Exp aenv' e -> PreOpenAcc acc aenv' (Scalar e))
-> f (Exp aenv' e) -> f (PreOpenAcc acc aenv' (Scalar e))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> RebuildEvar f IdxE () () aenv'
-> ReindexAvar f aenv aenv' -> Exp aenv e -> f (Exp aenv' e)
forall (f :: * -> *) (fe :: * -> * -> * -> *) env env' aenv' aenv
t.
(HasCallStack, Applicative f, SyntacticExp fe) =>
RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> OpenExp env aenv t
-> f (OpenExp env' aenv' t)
rebuildOpenExp (IdxE () aenv' t' -> f (IdxE () aenv' t')
forall (f :: * -> *) a. Applicative f => a -> f a
pure (IdxE () aenv' t' -> f (IdxE () aenv' t'))
-> (ExpVar () t' -> IdxE () aenv' t')
-> ExpVar () t'
-> f (IdxE () aenv' t')
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ExpVar () t' -> IdxE () aenv' t'
forall env aenv t. ExpVar env t -> IdxE env aenv t
IE) ReindexAvar f aenv aenv'
av' Exp aenv e
e
Reshape ShapeR sh
shr Exp aenv sh
e acc aenv (Array sh' e)
a -> ShapeR sh
-> Exp aenv' sh
-> acc aenv' (Array sh' e)
-> PreOpenAcc acc aenv' (Array sh e)
forall sh aenv (acc :: * -> * -> *) sh' e.
ShapeR sh
-> Exp aenv sh
-> acc aenv (Array sh' e)
-> PreOpenAcc acc aenv (Array sh e)
Reshape ShapeR sh
shr (Exp aenv' sh
-> acc aenv' (Array sh' e) -> PreOpenAcc acc aenv' (Array sh e))
-> f (Exp aenv' sh)
-> f (acc aenv' (Array sh' e) -> PreOpenAcc acc aenv' (Array sh e))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> RebuildEvar f IdxE () () aenv'
-> ReindexAvar f aenv aenv' -> Exp aenv sh -> f (Exp aenv' sh)
forall (f :: * -> *) (fe :: * -> * -> * -> *) env env' aenv' aenv
t.
(HasCallStack, Applicative f, SyntacticExp fe) =>
RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> OpenExp env aenv t
-> f (OpenExp env' aenv' t)
rebuildOpenExp (IdxE () aenv' t' -> f (IdxE () aenv' t')
forall (f :: * -> *) a. Applicative f => a -> f a
pure (IdxE () aenv' t' -> f (IdxE () aenv' t'))
-> (ExpVar () t' -> IdxE () aenv' t')
-> ExpVar () t'
-> f (IdxE () aenv' t')
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ExpVar () t' -> IdxE () aenv' t'
forall env aenv t. ExpVar env t -> IdxE env aenv t
IE) ReindexAvar f aenv aenv'
av' Exp aenv sh
e f (acc aenv' (Array sh' e) -> PreOpenAcc acc aenv' (Array sh e))
-> f (acc aenv' (Array sh' e))
-> f (PreOpenAcc acc aenv' (Array sh e))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> RebuildAvar f fa acc aenv aenv'
-> acc aenv (Array sh' e) -> f (acc aenv' (Array sh' e))
RebuildAcc acc
k RebuildAvar f fa acc aenv aenv'
av acc aenv (Array sh' e)
a
Generate ArrayR (Array sh e)
repr Exp aenv sh
e Fun aenv (sh -> e)
f -> ArrayR (Array sh e)
-> Exp aenv' sh
-> Fun aenv' (sh -> e)
-> PreOpenAcc acc aenv' (Array sh e)
forall sh e aenv (acc :: * -> * -> *).
ArrayR (Array sh e)
-> Exp aenv sh
-> Fun aenv (sh -> e)
-> PreOpenAcc acc aenv (Array sh e)
Generate ArrayR (Array sh e)
repr (Exp aenv' sh
-> Fun aenv' (sh -> e) -> PreOpenAcc acc aenv' (Array sh e))
-> f (Exp aenv' sh)
-> f (Fun aenv' (sh -> e) -> PreOpenAcc acc aenv' (Array sh e))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> RebuildEvar f IdxE () () aenv'
-> ReindexAvar f aenv aenv' -> Exp aenv sh -> f (Exp aenv' sh)
forall (f :: * -> *) (fe :: * -> * -> * -> *) env env' aenv' aenv
t.
(HasCallStack, Applicative f, SyntacticExp fe) =>
RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> OpenExp env aenv t
-> f (OpenExp env' aenv' t)
rebuildOpenExp (IdxE () aenv' t' -> f (IdxE () aenv' t')
forall (f :: * -> *) a. Applicative f => a -> f a
pure (IdxE () aenv' t' -> f (IdxE () aenv' t'))
-> (ExpVar () t' -> IdxE () aenv' t')
-> ExpVar () t'
-> f (IdxE () aenv' t')
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ExpVar () t' -> IdxE () aenv' t'
forall env aenv t. ExpVar env t -> IdxE env aenv t
IE) ReindexAvar f aenv aenv'
av' Exp aenv sh
e f (Fun aenv' (sh -> e) -> PreOpenAcc acc aenv' (Array sh e))
-> f (Fun aenv' (sh -> e)) -> f (PreOpenAcc acc aenv' (Array sh e))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> RebuildEvar f IdxE () () aenv'
-> ReindexAvar f aenv aenv'
-> Fun aenv (sh -> e)
-> f (Fun aenv' (sh -> e))
forall (f :: * -> *) (fe :: * -> * -> * -> *) env env' aenv' aenv
t.
(HasCallStack, Applicative f, SyntacticExp fe) =>
RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> OpenFun env aenv t
-> f (OpenFun env' aenv' t)
rebuildFun (IdxE () aenv' t' -> f (IdxE () aenv' t')
forall (f :: * -> *) a. Applicative f => a -> f a
pure (IdxE () aenv' t' -> f (IdxE () aenv' t'))
-> (ExpVar () t' -> IdxE () aenv' t')
-> ExpVar () t'
-> f (IdxE () aenv' t')
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ExpVar () t' -> IdxE () aenv' t'
forall env aenv t. ExpVar env t -> IdxE env aenv t
IE) ReindexAvar f aenv aenv'
av' Fun aenv (sh -> e)
f
Transform ArrayR (Array sh' b)
repr Exp aenv sh'
sh Fun aenv (sh' -> sh)
ix Fun aenv (a -> b)
f acc aenv (Array sh a)
a -> ArrayR (Array sh' b)
-> Exp aenv' sh'
-> Fun aenv' (sh' -> sh)
-> Fun aenv' (a -> b)
-> acc aenv' (Array sh a)
-> PreOpenAcc acc aenv' (Array sh' b)
forall sh' b aenv sh a (acc :: * -> * -> *).
ArrayR (Array sh' b)
-> Exp aenv sh'
-> Fun aenv (sh' -> sh)
-> Fun aenv (a -> b)
-> acc aenv (Array sh a)
-> PreOpenAcc acc aenv (Array sh' b)
Transform ArrayR (Array sh' b)
repr (Exp aenv' sh'
-> Fun aenv' (sh' -> sh)
-> Fun aenv' (a -> b)
-> acc aenv' (Array sh a)
-> PreOpenAcc acc aenv' (Array sh' b))
-> f (Exp aenv' sh')
-> f (Fun aenv' (sh' -> sh)
-> Fun aenv' (a -> b)
-> acc aenv' (Array sh a)
-> PreOpenAcc acc aenv' (Array sh' b))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> RebuildEvar f IdxE () () aenv'
-> ReindexAvar f aenv aenv' -> Exp aenv sh' -> f (Exp aenv' sh')
forall (f :: * -> *) (fe :: * -> * -> * -> *) env env' aenv' aenv
t.
(HasCallStack, Applicative f, SyntacticExp fe) =>
RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> OpenExp env aenv t
-> f (OpenExp env' aenv' t)
rebuildOpenExp (IdxE () aenv' t' -> f (IdxE () aenv' t')
forall (f :: * -> *) a. Applicative f => a -> f a
pure (IdxE () aenv' t' -> f (IdxE () aenv' t'))
-> (ExpVar () t' -> IdxE () aenv' t')
-> ExpVar () t'
-> f (IdxE () aenv' t')
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ExpVar () t' -> IdxE () aenv' t'
forall env aenv t. ExpVar env t -> IdxE env aenv t
IE) ReindexAvar f aenv aenv'
av' Exp aenv sh'
sh f (Fun aenv' (sh' -> sh)
-> Fun aenv' (a -> b)
-> acc aenv' (Array sh a)
-> PreOpenAcc acc aenv' (Array sh' b))
-> f (Fun aenv' (sh' -> sh))
-> f (Fun aenv' (a -> b)
-> acc aenv' (Array sh a) -> PreOpenAcc acc aenv' (Array sh' b))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> RebuildEvar f IdxE () () aenv'
-> ReindexAvar f aenv aenv'
-> Fun aenv (sh' -> sh)
-> f (Fun aenv' (sh' -> sh))
forall (f :: * -> *) (fe :: * -> * -> * -> *) env env' aenv' aenv
t.
(HasCallStack, Applicative f, SyntacticExp fe) =>
RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> OpenFun env aenv t
-> f (OpenFun env' aenv' t)
rebuildFun (IdxE () aenv' t' -> f (IdxE () aenv' t')
forall (f :: * -> *) a. Applicative f => a -> f a
pure (IdxE () aenv' t' -> f (IdxE () aenv' t'))
-> (ExpVar () t' -> IdxE () aenv' t')
-> ExpVar () t'
-> f (IdxE () aenv' t')
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ExpVar () t' -> IdxE () aenv' t'
forall env aenv t. ExpVar env t -> IdxE env aenv t
IE) ReindexAvar f aenv aenv'
av' Fun aenv (sh' -> sh)
ix f (Fun aenv' (a -> b)
-> acc aenv' (Array sh a) -> PreOpenAcc acc aenv' (Array sh' b))
-> f (Fun aenv' (a -> b))
-> f (acc aenv' (Array sh a) -> PreOpenAcc acc aenv' (Array sh' b))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> RebuildEvar f IdxE () () aenv'
-> ReindexAvar f aenv aenv'
-> Fun aenv (a -> b)
-> f (Fun aenv' (a -> b))
forall (f :: * -> *) (fe :: * -> * -> * -> *) env env' aenv' aenv
t.
(HasCallStack, Applicative f, SyntacticExp fe) =>
RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> OpenFun env aenv t
-> f (OpenFun env' aenv' t)
rebuildFun (IdxE () aenv' t' -> f (IdxE () aenv' t')
forall (f :: * -> *) a. Applicative f => a -> f a
pure (IdxE () aenv' t' -> f (IdxE () aenv' t'))
-> (ExpVar () t' -> IdxE () aenv' t')
-> ExpVar () t'
-> f (IdxE () aenv' t')
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ExpVar () t' -> IdxE () aenv' t'
forall env aenv t. ExpVar env t -> IdxE env aenv t
IE) ReindexAvar f aenv aenv'
av' Fun aenv (a -> b)
f f (acc aenv' (Array sh a) -> PreOpenAcc acc aenv' (Array sh' b))
-> f (acc aenv' (Array sh a))
-> f (PreOpenAcc acc aenv' (Array sh' b))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> RebuildAvar f fa acc aenv aenv'
-> acc aenv (Array sh a) -> f (acc aenv' (Array sh a))
RebuildAcc acc
k RebuildAvar f fa acc aenv aenv'
av acc aenv (Array sh a)
a
Replicate SliceIndex slix sl co sh
sl Exp aenv slix
slix acc aenv (Array sl e)
a -> SliceIndex slix sl co sh
-> Exp aenv' slix
-> acc aenv' (Array sl e)
-> PreOpenAcc acc aenv' (Array sh e)
forall slix sl co sh aenv (acc :: * -> * -> *) e.
SliceIndex slix sl co sh
-> Exp aenv slix
-> acc aenv (Array sl e)
-> PreOpenAcc acc aenv (Array sh e)
Replicate SliceIndex slix sl co sh
sl (Exp aenv' slix
-> acc aenv' (Array sl e) -> PreOpenAcc acc aenv' (Array sh e))
-> f (Exp aenv' slix)
-> f (acc aenv' (Array sl e) -> PreOpenAcc acc aenv' (Array sh e))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> RebuildEvar f IdxE () () aenv'
-> ReindexAvar f aenv aenv' -> Exp aenv slix -> f (Exp aenv' slix)
forall (f :: * -> *) (fe :: * -> * -> * -> *) env env' aenv' aenv
t.
(HasCallStack, Applicative f, SyntacticExp fe) =>
RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> OpenExp env aenv t
-> f (OpenExp env' aenv' t)
rebuildOpenExp (IdxE () aenv' t' -> f (IdxE () aenv' t')
forall (f :: * -> *) a. Applicative f => a -> f a
pure (IdxE () aenv' t' -> f (IdxE () aenv' t'))
-> (ExpVar () t' -> IdxE () aenv' t')
-> ExpVar () t'
-> f (IdxE () aenv' t')
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ExpVar () t' -> IdxE () aenv' t'
forall env aenv t. ExpVar env t -> IdxE env aenv t
IE) ReindexAvar f aenv aenv'
av' Exp aenv slix
slix f (acc aenv' (Array sl e) -> PreOpenAcc acc aenv' (Array sh e))
-> f (acc aenv' (Array sl e))
-> f (PreOpenAcc acc aenv' (Array sh e))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> RebuildAvar f fa acc aenv aenv'
-> acc aenv (Array sl e) -> f (acc aenv' (Array sl e))
RebuildAcc acc
k RebuildAvar f fa acc aenv aenv'
av acc aenv (Array sl e)
a
Slice SliceIndex slix sl co sh
sl acc aenv (Array sh e)
a Exp aenv slix
slix -> SliceIndex slix sl co sh
-> acc aenv' (Array sh e)
-> Exp aenv' slix
-> PreOpenAcc acc aenv' (Array sl e)
forall slix sl co sh (acc :: * -> * -> *) aenv e.
SliceIndex slix sl co sh
-> acc aenv (Array sh e)
-> Exp aenv slix
-> PreOpenAcc acc aenv (Array sl e)
Slice SliceIndex slix sl co sh
sl (acc aenv' (Array sh e)
-> Exp aenv' slix -> PreOpenAcc acc aenv' (Array sl e))
-> f (acc aenv' (Array sh e))
-> f (Exp aenv' slix -> PreOpenAcc acc aenv' (Array sl e))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> RebuildAvar f fa acc aenv aenv'
-> acc aenv (Array sh e) -> f (acc aenv' (Array sh e))
RebuildAcc acc
k RebuildAvar f fa acc aenv aenv'
av acc aenv (Array sh e)
a f (Exp aenv' slix -> PreOpenAcc acc aenv' (Array sl e))
-> f (Exp aenv' slix) -> f (PreOpenAcc acc aenv' (Array sl e))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> RebuildEvar f IdxE () () aenv'
-> ReindexAvar f aenv aenv' -> Exp aenv slix -> f (Exp aenv' slix)
forall (f :: * -> *) (fe :: * -> * -> * -> *) env env' aenv' aenv
t.
(HasCallStack, Applicative f, SyntacticExp fe) =>
RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> OpenExp env aenv t
-> f (OpenExp env' aenv' t)
rebuildOpenExp (IdxE () aenv' t' -> f (IdxE () aenv' t')
forall (f :: * -> *) a. Applicative f => a -> f a
pure (IdxE () aenv' t' -> f (IdxE () aenv' t'))
-> (ExpVar () t' -> IdxE () aenv' t')
-> ExpVar () t'
-> f (IdxE () aenv' t')
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ExpVar () t' -> IdxE () aenv' t'
forall env aenv t. ExpVar env t -> IdxE env aenv t
IE) ReindexAvar f aenv aenv'
av' Exp aenv slix
slix
Map TypeR e'
tp Fun aenv (e -> e')
f acc aenv (Array sh e)
a -> TypeR e'
-> Fun aenv' (e -> e')
-> acc aenv' (Array sh e)
-> PreOpenAcc acc aenv' (Array sh e')
forall e' aenv e (acc :: * -> * -> *) sh.
TypeR e'
-> Fun aenv (e -> e')
-> acc aenv (Array sh e)
-> PreOpenAcc acc aenv (Array sh e')
Map TypeR e'
tp (Fun aenv' (e -> e')
-> acc aenv' (Array sh e) -> PreOpenAcc acc aenv' (Array sh e'))
-> f (Fun aenv' (e -> e'))
-> f (acc aenv' (Array sh e) -> PreOpenAcc acc aenv' (Array sh e'))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> RebuildEvar f IdxE () () aenv'
-> ReindexAvar f aenv aenv'
-> Fun aenv (e -> e')
-> f (Fun aenv' (e -> e'))
forall (f :: * -> *) (fe :: * -> * -> * -> *) env env' aenv' aenv
t.
(HasCallStack, Applicative f, SyntacticExp fe) =>
RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> OpenFun env aenv t
-> f (OpenFun env' aenv' t)
rebuildFun (IdxE () aenv' t' -> f (IdxE () aenv' t')
forall (f :: * -> *) a. Applicative f => a -> f a
pure (IdxE () aenv' t' -> f (IdxE () aenv' t'))
-> (ExpVar () t' -> IdxE () aenv' t')
-> ExpVar () t'
-> f (IdxE () aenv' t')
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ExpVar () t' -> IdxE () aenv' t'
forall env aenv t. ExpVar env t -> IdxE env aenv t
IE) ReindexAvar f aenv aenv'
av' Fun aenv (e -> e')
f f (acc aenv' (Array sh e) -> PreOpenAcc acc aenv' (Array sh e'))
-> f (acc aenv' (Array sh e))
-> f (PreOpenAcc acc aenv' (Array sh e'))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> RebuildAvar f fa acc aenv aenv'
-> acc aenv (Array sh e) -> f (acc aenv' (Array sh e))
RebuildAcc acc
k RebuildAvar f fa acc aenv aenv'
av acc aenv (Array sh e)
a
ZipWith TypeR e3
tp Fun aenv (e1 -> e2 -> e3)
f acc aenv (Array sh e1)
a1 acc aenv (Array sh e2)
a2 -> TypeR e3
-> Fun aenv' (e1 -> e2 -> e3)
-> acc aenv' (Array sh e1)
-> acc aenv' (Array sh e2)
-> PreOpenAcc acc aenv' (Array sh e3)
forall e3 aenv e1 e2 (acc :: * -> * -> *) sh.
TypeR e3
-> Fun aenv (e1 -> e2 -> e3)
-> acc aenv (Array sh e1)
-> acc aenv (Array sh e2)
-> PreOpenAcc acc aenv (Array sh e3)
ZipWith TypeR e3
tp (Fun aenv' (e1 -> e2 -> e3)
-> acc aenv' (Array sh e1)
-> acc aenv' (Array sh e2)
-> PreOpenAcc acc aenv' (Array sh e3))
-> f (Fun aenv' (e1 -> e2 -> e3))
-> f (acc aenv' (Array sh e1)
-> acc aenv' (Array sh e2) -> PreOpenAcc acc aenv' (Array sh e3))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> RebuildEvar f IdxE () () aenv'
-> ReindexAvar f aenv aenv'
-> Fun aenv (e1 -> e2 -> e3)
-> f (Fun aenv' (e1 -> e2 -> e3))
forall (f :: * -> *) (fe :: * -> * -> * -> *) env env' aenv' aenv
t.
(HasCallStack, Applicative f, SyntacticExp fe) =>
RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> OpenFun env aenv t
-> f (OpenFun env' aenv' t)
rebuildFun (IdxE () aenv' t' -> f (IdxE () aenv' t')
forall (f :: * -> *) a. Applicative f => a -> f a
pure (IdxE () aenv' t' -> f (IdxE () aenv' t'))
-> (ExpVar () t' -> IdxE () aenv' t')
-> ExpVar () t'
-> f (IdxE () aenv' t')
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ExpVar () t' -> IdxE () aenv' t'
forall env aenv t. ExpVar env t -> IdxE env aenv t
IE) ReindexAvar f aenv aenv'
av' Fun aenv (e1 -> e2 -> e3)
f f (acc aenv' (Array sh e1)
-> acc aenv' (Array sh e2) -> PreOpenAcc acc aenv' (Array sh e3))
-> f (acc aenv' (Array sh e1))
-> f (acc aenv' (Array sh e2)
-> PreOpenAcc acc aenv' (Array sh e3))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> RebuildAvar f fa acc aenv aenv'
-> acc aenv (Array sh e1) -> f (acc aenv' (Array sh e1))
RebuildAcc acc
k RebuildAvar f fa acc aenv aenv'
av acc aenv (Array sh e1)
a1 f (acc aenv' (Array sh e2) -> PreOpenAcc acc aenv' (Array sh e3))
-> f (acc aenv' (Array sh e2))
-> f (PreOpenAcc acc aenv' (Array sh e3))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> RebuildAvar f fa acc aenv aenv'
-> acc aenv (Array sh e2) -> f (acc aenv' (Array sh e2))
RebuildAcc acc
k RebuildAvar f fa acc aenv aenv'
av acc aenv (Array sh e2)
a2
Fold Fun aenv (e -> e -> e)
f Maybe (Exp aenv e)
z acc aenv (Array (sh, Int) e)
a -> Fun aenv' (e -> e -> e)
-> Maybe (Exp aenv' e)
-> acc aenv' (Array (sh, Int) e)
-> PreOpenAcc acc aenv' (Array sh e)
forall aenv e (acc :: * -> * -> *) i.
Fun aenv (e -> e -> e)
-> Maybe (Exp aenv e)
-> acc aenv (Array (i, Int) e)
-> PreOpenAcc acc aenv (Array i e)
Fold (Fun aenv' (e -> e -> e)
-> Maybe (Exp aenv' e)
-> acc aenv' (Array (sh, Int) e)
-> PreOpenAcc acc aenv' (Array sh e))
-> f (Fun aenv' (e -> e -> e))
-> f (Maybe (Exp aenv' e)
-> acc aenv' (Array (sh, Int) e)
-> PreOpenAcc acc aenv' (Array sh e))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> RebuildEvar f IdxE () () aenv'
-> ReindexAvar f aenv aenv'
-> Fun aenv (e -> e -> e)
-> f (Fun aenv' (e -> e -> e))
forall (f :: * -> *) (fe :: * -> * -> * -> *) env env' aenv' aenv
t.
(HasCallStack, Applicative f, SyntacticExp fe) =>
RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> OpenFun env aenv t
-> f (OpenFun env' aenv' t)
rebuildFun (IdxE () aenv' t' -> f (IdxE () aenv' t')
forall (f :: * -> *) a. Applicative f => a -> f a
pure (IdxE () aenv' t' -> f (IdxE () aenv' t'))
-> (ExpVar () t' -> IdxE () aenv' t')
-> ExpVar () t'
-> f (IdxE () aenv' t')
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ExpVar () t' -> IdxE () aenv' t'
forall env aenv t. ExpVar env t -> IdxE env aenv t
IE) ReindexAvar f aenv aenv'
av' Fun aenv (e -> e -> e)
f f (Maybe (Exp aenv' e)
-> acc aenv' (Array (sh, Int) e)
-> PreOpenAcc acc aenv' (Array sh e))
-> f (Maybe (Exp aenv' e))
-> f (acc aenv' (Array (sh, Int) e)
-> PreOpenAcc acc aenv' (Array sh e))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> RebuildEvar f IdxE () () aenv'
-> ReindexAvar f aenv aenv'
-> Maybe (Exp aenv e)
-> f (Maybe (Exp aenv' e))
forall (f :: * -> *) (fe :: * -> * -> * -> *) env env' aenv' aenv
t.
(HasCallStack, Applicative f, SyntacticExp fe) =>
RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> Maybe (OpenExp env aenv t)
-> f (Maybe (OpenExp env' aenv' t))
rebuildMaybeExp (IdxE () aenv' t' -> f (IdxE () aenv' t')
forall (f :: * -> *) a. Applicative f => a -> f a
pure (IdxE () aenv' t' -> f (IdxE () aenv' t'))
-> (ExpVar () t' -> IdxE () aenv' t')
-> ExpVar () t'
-> f (IdxE () aenv' t')
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ExpVar () t' -> IdxE () aenv' t'
forall env aenv t. ExpVar env t -> IdxE env aenv t
IE) ReindexAvar f aenv aenv'
av' Maybe (Exp aenv e)
z f (acc aenv' (Array (sh, Int) e)
-> PreOpenAcc acc aenv' (Array sh e))
-> f (acc aenv' (Array (sh, Int) e))
-> f (PreOpenAcc acc aenv' (Array sh e))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> RebuildAvar f fa acc aenv aenv'
-> acc aenv (Array (sh, Int) e)
-> f (acc aenv' (Array (sh, Int) e))
RebuildAcc acc
k RebuildAvar f fa acc aenv aenv'
av acc aenv (Array (sh, Int) e)
a
FoldSeg IntegralType i
itp Fun aenv (e -> e -> e)
f Maybe (Exp aenv e)
z acc aenv (Array (sh, Int) e)
a acc aenv (Segments i)
s -> IntegralType i
-> Fun aenv' (e -> e -> e)
-> Maybe (Exp aenv' e)
-> acc aenv' (Array (sh, Int) e)
-> acc aenv' (Segments i)
-> PreOpenAcc acc aenv' (Array (sh, Int) e)
forall i aenv e (acc :: * -> * -> *) e.
IntegralType i
-> Fun aenv (e -> e -> e)
-> Maybe (Exp aenv e)
-> acc aenv (Array (e, Int) e)
-> acc aenv (Segments i)
-> PreOpenAcc acc aenv (Array (e, Int) e)
FoldSeg IntegralType i
itp (Fun aenv' (e -> e -> e)
-> Maybe (Exp aenv' e)
-> acc aenv' (Array (sh, Int) e)
-> acc aenv' (Segments i)
-> PreOpenAcc acc aenv' (Array (sh, Int) e))
-> f (Fun aenv' (e -> e -> e))
-> f (Maybe (Exp aenv' e)
-> acc aenv' (Array (sh, Int) e)
-> acc aenv' (Segments i)
-> PreOpenAcc acc aenv' (Array (sh, Int) e))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> RebuildEvar f IdxE () () aenv'
-> ReindexAvar f aenv aenv'
-> Fun aenv (e -> e -> e)
-> f (Fun aenv' (e -> e -> e))
forall (f :: * -> *) (fe :: * -> * -> * -> *) env env' aenv' aenv
t.
(HasCallStack, Applicative f, SyntacticExp fe) =>
RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> OpenFun env aenv t
-> f (OpenFun env' aenv' t)
rebuildFun (IdxE () aenv' t' -> f (IdxE () aenv' t')
forall (f :: * -> *) a. Applicative f => a -> f a
pure (IdxE () aenv' t' -> f (IdxE () aenv' t'))
-> (ExpVar () t' -> IdxE () aenv' t')
-> ExpVar () t'
-> f (IdxE () aenv' t')
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ExpVar () t' -> IdxE () aenv' t'
forall env aenv t. ExpVar env t -> IdxE env aenv t
IE) ReindexAvar f aenv aenv'
av' Fun aenv (e -> e -> e)
f f (Maybe (Exp aenv' e)
-> acc aenv' (Array (sh, Int) e)
-> acc aenv' (Segments i)
-> PreOpenAcc acc aenv' (Array (sh, Int) e))
-> f (Maybe (Exp aenv' e))
-> f (acc aenv' (Array (sh, Int) e)
-> acc aenv' (Segments i)
-> PreOpenAcc acc aenv' (Array (sh, Int) e))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> RebuildEvar f IdxE () () aenv'
-> ReindexAvar f aenv aenv'
-> Maybe (Exp aenv e)
-> f (Maybe (Exp aenv' e))
forall (f :: * -> *) (fe :: * -> * -> * -> *) env env' aenv' aenv
t.
(HasCallStack, Applicative f, SyntacticExp fe) =>
RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> Maybe (OpenExp env aenv t)
-> f (Maybe (OpenExp env' aenv' t))
rebuildMaybeExp (IdxE () aenv' t' -> f (IdxE () aenv' t')
forall (f :: * -> *) a. Applicative f => a -> f a
pure (IdxE () aenv' t' -> f (IdxE () aenv' t'))
-> (ExpVar () t' -> IdxE () aenv' t')
-> ExpVar () t'
-> f (IdxE () aenv' t')
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ExpVar () t' -> IdxE () aenv' t'
forall env aenv t. ExpVar env t -> IdxE env aenv t
IE) ReindexAvar f aenv aenv'
av' Maybe (Exp aenv e)
z f (acc aenv' (Array (sh, Int) e)
-> acc aenv' (Segments i)
-> PreOpenAcc acc aenv' (Array (sh, Int) e))
-> f (acc aenv' (Array (sh, Int) e))
-> f (acc aenv' (Segments i)
-> PreOpenAcc acc aenv' (Array (sh, Int) e))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> RebuildAvar f fa acc aenv aenv'
-> acc aenv (Array (sh, Int) e)
-> f (acc aenv' (Array (sh, Int) e))
RebuildAcc acc
k RebuildAvar f fa acc aenv aenv'
av acc aenv (Array (sh, Int) e)
a f (acc aenv' (Segments i)
-> PreOpenAcc acc aenv' (Array (sh, Int) e))
-> f (acc aenv' (Segments i))
-> f (PreOpenAcc acc aenv' (Array (sh, Int) e))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> RebuildAvar f fa acc aenv aenv'
-> acc aenv (Segments i) -> f (acc aenv' (Segments i))
RebuildAcc acc
k RebuildAvar f fa acc aenv aenv'
av acc aenv (Segments i)
s
Scan Direction
d Fun aenv (e -> e -> e)
f Maybe (Exp aenv e)
z acc aenv (Array (sh, Int) e)
a -> Direction
-> Fun aenv' (e -> e -> e)
-> Maybe (Exp aenv' e)
-> acc aenv' (Array (sh, Int) e)
-> PreOpenAcc acc aenv' (Array (sh, Int) e)
forall aenv e (acc :: * -> * -> *) sh.
Direction
-> Fun aenv (e -> e -> e)
-> Maybe (Exp aenv e)
-> acc aenv (Array (sh, Int) e)
-> PreOpenAcc acc aenv (Array (sh, Int) e)
Scan Direction
d (Fun aenv' (e -> e -> e)
-> Maybe (Exp aenv' e)
-> acc aenv' (Array (sh, Int) e)
-> PreOpenAcc acc aenv' (Array (sh, Int) e))
-> f (Fun aenv' (e -> e -> e))
-> f (Maybe (Exp aenv' e)
-> acc aenv' (Array (sh, Int) e)
-> PreOpenAcc acc aenv' (Array (sh, Int) e))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> RebuildEvar f IdxE () () aenv'
-> ReindexAvar f aenv aenv'
-> Fun aenv (e -> e -> e)
-> f (Fun aenv' (e -> e -> e))
forall (f :: * -> *) (fe :: * -> * -> * -> *) env env' aenv' aenv
t.
(HasCallStack, Applicative f, SyntacticExp fe) =>
RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> OpenFun env aenv t
-> f (OpenFun env' aenv' t)
rebuildFun (IdxE () aenv' t' -> f (IdxE () aenv' t')
forall (f :: * -> *) a. Applicative f => a -> f a
pure (IdxE () aenv' t' -> f (IdxE () aenv' t'))
-> (ExpVar () t' -> IdxE () aenv' t')
-> ExpVar () t'
-> f (IdxE () aenv' t')
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ExpVar () t' -> IdxE () aenv' t'
forall env aenv t. ExpVar env t -> IdxE env aenv t
IE) ReindexAvar f aenv aenv'
av' Fun aenv (e -> e -> e)
f f (Maybe (Exp aenv' e)
-> acc aenv' (Array (sh, Int) e)
-> PreOpenAcc acc aenv' (Array (sh, Int) e))
-> f (Maybe (Exp aenv' e))
-> f (acc aenv' (Array (sh, Int) e)
-> PreOpenAcc acc aenv' (Array (sh, Int) e))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> RebuildEvar f IdxE () () aenv'
-> ReindexAvar f aenv aenv'
-> Maybe (Exp aenv e)
-> f (Maybe (Exp aenv' e))
forall (f :: * -> *) (fe :: * -> * -> * -> *) env env' aenv' aenv
t.
(HasCallStack, Applicative f, SyntacticExp fe) =>
RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> Maybe (OpenExp env aenv t)
-> f (Maybe (OpenExp env' aenv' t))
rebuildMaybeExp (IdxE () aenv' t' -> f (IdxE () aenv' t')
forall (f :: * -> *) a. Applicative f => a -> f a
pure (IdxE () aenv' t' -> f (IdxE () aenv' t'))
-> (ExpVar () t' -> IdxE () aenv' t')
-> ExpVar () t'
-> f (IdxE () aenv' t')
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ExpVar () t' -> IdxE () aenv' t'
forall env aenv t. ExpVar env t -> IdxE env aenv t
IE) ReindexAvar f aenv aenv'
av' Maybe (Exp aenv e)
z f (acc aenv' (Array (sh, Int) e)
-> PreOpenAcc acc aenv' (Array (sh, Int) e))
-> f (acc aenv' (Array (sh, Int) e))
-> f (PreOpenAcc acc aenv' (Array (sh, Int) e))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> RebuildAvar f fa acc aenv aenv'
-> acc aenv (Array (sh, Int) e)
-> f (acc aenv' (Array (sh, Int) e))
RebuildAcc acc
k RebuildAvar f fa acc aenv aenv'
av acc aenv (Array (sh, Int) e)
a
Scan' Direction
d Fun aenv (e -> e -> e)
f Exp aenv e
z acc aenv (Array (sh, Int) e)
a -> Direction
-> Fun aenv' (e -> e -> e)
-> Exp aenv' e
-> acc aenv' (Array (sh, Int) e)
-> PreOpenAcc acc aenv' (Array (sh, Int) e, Array sh e)
forall aenv e (acc :: * -> * -> *) sh.
Direction
-> Fun aenv (e -> e -> e)
-> Exp aenv e
-> acc aenv (Array (sh, Int) e)
-> PreOpenAcc acc aenv (Array (sh, Int) e, Array sh e)
Scan' Direction
d (Fun aenv' (e -> e -> e)
-> Exp aenv' e
-> acc aenv' (Array (sh, Int) e)
-> PreOpenAcc acc aenv' (Array (sh, Int) e, Array sh e))
-> f (Fun aenv' (e -> e -> e))
-> f (Exp aenv' e
-> acc aenv' (Array (sh, Int) e)
-> PreOpenAcc acc aenv' (Array (sh, Int) e, Array sh e))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> RebuildEvar f IdxE () () aenv'
-> ReindexAvar f aenv aenv'
-> Fun aenv (e -> e -> e)
-> f (Fun aenv' (e -> e -> e))
forall (f :: * -> *) (fe :: * -> * -> * -> *) env env' aenv' aenv
t.
(HasCallStack, Applicative f, SyntacticExp fe) =>
RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> OpenFun env aenv t
-> f (OpenFun env' aenv' t)
rebuildFun (IdxE () aenv' t' -> f (IdxE () aenv' t')
forall (f :: * -> *) a. Applicative f => a -> f a
pure (IdxE () aenv' t' -> f (IdxE () aenv' t'))
-> (ExpVar () t' -> IdxE () aenv' t')
-> ExpVar () t'
-> f (IdxE () aenv' t')
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ExpVar () t' -> IdxE () aenv' t'
forall env aenv t. ExpVar env t -> IdxE env aenv t
IE) ReindexAvar f aenv aenv'
av' Fun aenv (e -> e -> e)
f f (Exp aenv' e
-> acc aenv' (Array (sh, Int) e)
-> PreOpenAcc acc aenv' (Array (sh, Int) e, Array sh e))
-> f (Exp aenv' e)
-> f (acc aenv' (Array (sh, Int) e)
-> PreOpenAcc acc aenv' (Array (sh, Int) e, Array sh e))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> RebuildEvar f IdxE () () aenv'
-> ReindexAvar f aenv aenv' -> Exp aenv e -> f (Exp aenv' e)
forall (f :: * -> *) (fe :: * -> * -> * -> *) env env' aenv' aenv
t.
(HasCallStack, Applicative f, SyntacticExp fe) =>
RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> OpenExp env aenv t
-> f (OpenExp env' aenv' t)
rebuildOpenExp (IdxE () aenv' t' -> f (IdxE () aenv' t')
forall (f :: * -> *) a. Applicative f => a -> f a
pure (IdxE () aenv' t' -> f (IdxE () aenv' t'))
-> (ExpVar () t' -> IdxE () aenv' t')
-> ExpVar () t'
-> f (IdxE () aenv' t')
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ExpVar () t' -> IdxE () aenv' t'
forall env aenv t. ExpVar env t -> IdxE env aenv t
IE) ReindexAvar f aenv aenv'
av' Exp aenv e
z f (acc aenv' (Array (sh, Int) e)
-> PreOpenAcc acc aenv' (Array (sh, Int) e, Array sh e))
-> f (acc aenv' (Array (sh, Int) e))
-> f (PreOpenAcc acc aenv' (Array (sh, Int) e, Array sh e))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> RebuildAvar f fa acc aenv aenv'
-> acc aenv (Array (sh, Int) e)
-> f (acc aenv' (Array (sh, Int) e))
RebuildAcc acc
k RebuildAvar f fa acc aenv aenv'
av acc aenv (Array (sh, Int) e)
a
Permute Fun aenv (e -> e -> e)
f1 acc aenv (Array sh' e)
a1 Fun aenv (sh -> PrimMaybe sh')
f2 acc aenv (Array sh e)
a2 -> Fun aenv' (e -> e -> e)
-> acc aenv' (Array sh' e)
-> Fun aenv' (sh -> PrimMaybe sh')
-> acc aenv' (Array sh e)
-> PreOpenAcc acc aenv' (Array sh' e)
forall aenv e (acc :: * -> * -> *) sh' sh.
Fun aenv (e -> e -> e)
-> acc aenv (Array sh' e)
-> Fun aenv (sh -> PrimMaybe sh')
-> acc aenv (Array sh e)
-> PreOpenAcc acc aenv (Array sh' e)
Permute (Fun aenv' (e -> e -> e)
-> acc aenv' (Array sh' e)
-> Fun aenv' (sh -> PrimMaybe sh')
-> acc aenv' (Array sh e)
-> PreOpenAcc acc aenv' (Array sh' e))
-> f (Fun aenv' (e -> e -> e))
-> f (acc aenv' (Array sh' e)
-> Fun aenv' (sh -> PrimMaybe sh')
-> acc aenv' (Array sh e)
-> PreOpenAcc acc aenv' (Array sh' e))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> RebuildEvar f IdxE () () aenv'
-> ReindexAvar f aenv aenv'
-> Fun aenv (e -> e -> e)
-> f (Fun aenv' (e -> e -> e))
forall (f :: * -> *) (fe :: * -> * -> * -> *) env env' aenv' aenv
t.
(HasCallStack, Applicative f, SyntacticExp fe) =>
RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> OpenFun env aenv t
-> f (OpenFun env' aenv' t)
rebuildFun (IdxE () aenv' t' -> f (IdxE () aenv' t')
forall (f :: * -> *) a. Applicative f => a -> f a
pure (IdxE () aenv' t' -> f (IdxE () aenv' t'))
-> (ExpVar () t' -> IdxE () aenv' t')
-> ExpVar () t'
-> f (IdxE () aenv' t')
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ExpVar () t' -> IdxE () aenv' t'
forall env aenv t. ExpVar env t -> IdxE env aenv t
IE) ReindexAvar f aenv aenv'
av' Fun aenv (e -> e -> e)
f1 f (acc aenv' (Array sh' e)
-> Fun aenv' (sh -> PrimMaybe sh')
-> acc aenv' (Array sh e)
-> PreOpenAcc acc aenv' (Array sh' e))
-> f (acc aenv' (Array sh' e))
-> f (Fun aenv' (sh -> PrimMaybe sh')
-> acc aenv' (Array sh e) -> PreOpenAcc acc aenv' (Array sh' e))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> RebuildAvar f fa acc aenv aenv'
-> acc aenv (Array sh' e) -> f (acc aenv' (Array sh' e))
RebuildAcc acc
k RebuildAvar f fa acc aenv aenv'
av acc aenv (Array sh' e)
a1 f (Fun aenv' (sh -> PrimMaybe sh')
-> acc aenv' (Array sh e) -> PreOpenAcc acc aenv' (Array sh' e))
-> f (Fun aenv' (sh -> PrimMaybe sh'))
-> f (acc aenv' (Array sh e) -> PreOpenAcc acc aenv' (Array sh' e))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> RebuildEvar f IdxE () () aenv'
-> ReindexAvar f aenv aenv'
-> Fun aenv (sh -> PrimMaybe sh')
-> f (Fun aenv' (sh -> PrimMaybe sh'))
forall (f :: * -> *) (fe :: * -> * -> * -> *) env env' aenv' aenv
t.
(HasCallStack, Applicative f, SyntacticExp fe) =>
RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> OpenFun env aenv t
-> f (OpenFun env' aenv' t)
rebuildFun (IdxE () aenv' t' -> f (IdxE () aenv' t')
forall (f :: * -> *) a. Applicative f => a -> f a
pure (IdxE () aenv' t' -> f (IdxE () aenv' t'))
-> (ExpVar () t' -> IdxE () aenv' t')
-> ExpVar () t'
-> f (IdxE () aenv' t')
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ExpVar () t' -> IdxE () aenv' t'
forall env aenv t. ExpVar env t -> IdxE env aenv t
IE) ReindexAvar f aenv aenv'
av' Fun aenv (sh -> PrimMaybe sh')
f2 f (acc aenv' (Array sh e) -> PreOpenAcc acc aenv' (Array sh' e))
-> f (acc aenv' (Array sh e))
-> f (PreOpenAcc acc aenv' (Array sh' e))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> RebuildAvar f fa acc aenv aenv'
-> acc aenv (Array sh e) -> f (acc aenv' (Array sh e))
RebuildAcc acc
k RebuildAvar f fa acc aenv aenv'
av acc aenv (Array sh e)
a2
Backpermute ShapeR sh'
shr Exp aenv sh'
sh Fun aenv (sh' -> sh)
f acc aenv (Array sh e)
a -> ShapeR sh'
-> Exp aenv' sh'
-> Fun aenv' (sh' -> sh)
-> acc aenv' (Array sh e)
-> PreOpenAcc acc aenv' (Array sh' e)
forall sh' aenv sh (acc :: * -> * -> *) e.
ShapeR sh'
-> Exp aenv sh'
-> Fun aenv (sh' -> sh)
-> acc aenv (Array sh e)
-> PreOpenAcc acc aenv (Array sh' e)
Backpermute ShapeR sh'
shr (Exp aenv' sh'
-> Fun aenv' (sh' -> sh)
-> acc aenv' (Array sh e)
-> PreOpenAcc acc aenv' (Array sh' e))
-> f (Exp aenv' sh')
-> f (Fun aenv' (sh' -> sh)
-> acc aenv' (Array sh e) -> PreOpenAcc acc aenv' (Array sh' e))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> RebuildEvar f IdxE () () aenv'
-> ReindexAvar f aenv aenv' -> Exp aenv sh' -> f (Exp aenv' sh')
forall (f :: * -> *) (fe :: * -> * -> * -> *) env env' aenv' aenv
t.
(HasCallStack, Applicative f, SyntacticExp fe) =>
RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> OpenExp env aenv t
-> f (OpenExp env' aenv' t)
rebuildOpenExp (IdxE () aenv' t' -> f (IdxE () aenv' t')
forall (f :: * -> *) a. Applicative f => a -> f a
pure (IdxE () aenv' t' -> f (IdxE () aenv' t'))
-> (ExpVar () t' -> IdxE () aenv' t')
-> ExpVar () t'
-> f (IdxE () aenv' t')
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ExpVar () t' -> IdxE () aenv' t'
forall env aenv t. ExpVar env t -> IdxE env aenv t
IE) ReindexAvar f aenv aenv'
av' Exp aenv sh'
sh f (Fun aenv' (sh' -> sh)
-> acc aenv' (Array sh e) -> PreOpenAcc acc aenv' (Array sh' e))
-> f (Fun aenv' (sh' -> sh))
-> f (acc aenv' (Array sh e) -> PreOpenAcc acc aenv' (Array sh' e))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> RebuildEvar f IdxE () () aenv'
-> ReindexAvar f aenv aenv'
-> Fun aenv (sh' -> sh)
-> f (Fun aenv' (sh' -> sh))
forall (f :: * -> *) (fe :: * -> * -> * -> *) env env' aenv' aenv
t.
(HasCallStack, Applicative f, SyntacticExp fe) =>
RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> OpenFun env aenv t
-> f (OpenFun env' aenv' t)
rebuildFun (IdxE () aenv' t' -> f (IdxE () aenv' t')
forall (f :: * -> *) a. Applicative f => a -> f a
pure (IdxE () aenv' t' -> f (IdxE () aenv' t'))
-> (ExpVar () t' -> IdxE () aenv' t')
-> ExpVar () t'
-> f (IdxE () aenv' t')
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ExpVar () t' -> IdxE () aenv' t'
forall env aenv t. ExpVar env t -> IdxE env aenv t
IE) ReindexAvar f aenv aenv'
av' Fun aenv (sh' -> sh)
f f (acc aenv' (Array sh e) -> PreOpenAcc acc aenv' (Array sh' e))
-> f (acc aenv' (Array sh e))
-> f (PreOpenAcc acc aenv' (Array sh' e))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> RebuildAvar f fa acc aenv aenv'
-> acc aenv (Array sh e) -> f (acc aenv' (Array sh e))
RebuildAcc acc
k RebuildAvar f fa acc aenv aenv'
av acc aenv (Array sh e)
a
Stencil StencilR sh e stencil
sr TypeR e'
tp Fun aenv (stencil -> e')
f Boundary aenv (Array sh e)
b acc aenv (Array sh e)
a -> StencilR sh e stencil
-> TypeR e'
-> Fun aenv' (stencil -> e')
-> Boundary aenv' (Array sh e)
-> acc aenv' (Array sh e)
-> PreOpenAcc acc aenv' (Array sh e')
forall sh e stencil sh aenv (acc :: * -> * -> *).
StencilR sh e stencil
-> TypeR sh
-> Fun aenv (stencil -> sh)
-> Boundary aenv (Array sh e)
-> acc aenv (Array sh e)
-> PreOpenAcc acc aenv (Array sh sh)
Stencil StencilR sh e stencil
sr TypeR e'
tp (Fun aenv' (stencil -> e')
-> Boundary aenv' (Array sh e)
-> acc aenv' (Array sh e)
-> PreOpenAcc acc aenv' (Array sh e'))
-> f (Fun aenv' (stencil -> e'))
-> f (Boundary aenv' (Array sh e)
-> acc aenv' (Array sh e) -> PreOpenAcc acc aenv' (Array sh e'))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> RebuildEvar f IdxE () () aenv'
-> ReindexAvar f aenv aenv'
-> Fun aenv (stencil -> e')
-> f (Fun aenv' (stencil -> e'))
forall (f :: * -> *) (fe :: * -> * -> * -> *) env env' aenv' aenv
t.
(HasCallStack, Applicative f, SyntacticExp fe) =>
RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> OpenFun env aenv t
-> f (OpenFun env' aenv' t)
rebuildFun (IdxE () aenv' t' -> f (IdxE () aenv' t')
forall (f :: * -> *) a. Applicative f => a -> f a
pure (IdxE () aenv' t' -> f (IdxE () aenv' t'))
-> (ExpVar () t' -> IdxE () aenv' t')
-> ExpVar () t'
-> f (IdxE () aenv' t')
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ExpVar () t' -> IdxE () aenv' t'
forall env aenv t. ExpVar env t -> IdxE env aenv t
IE) ReindexAvar f aenv aenv'
av' Fun aenv (stencil -> e')
f f (Boundary aenv' (Array sh e)
-> acc aenv' (Array sh e) -> PreOpenAcc acc aenv' (Array sh e'))
-> f (Boundary aenv' (Array sh e))
-> f (acc aenv' (Array sh e) -> PreOpenAcc acc aenv' (Array sh e'))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ReindexAvar f aenv aenv'
-> Boundary aenv (Array sh e) -> f (Boundary aenv' (Array sh e))
forall (f :: * -> *) aenv aenv' t.
Applicative f =>
ReindexAvar f aenv aenv' -> Boundary aenv t -> f (Boundary aenv' t)
rebuildBoundary ReindexAvar f aenv aenv'
av' Boundary aenv (Array sh e)
b f (acc aenv' (Array sh e) -> PreOpenAcc acc aenv' (Array sh e'))
-> f (acc aenv' (Array sh e))
-> f (PreOpenAcc acc aenv' (Array sh e'))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> RebuildAvar f fa acc aenv aenv'
-> acc aenv (Array sh e) -> f (acc aenv' (Array sh e))
RebuildAcc acc
k RebuildAvar f fa acc aenv aenv'
av acc aenv (Array sh e)
a
Stencil2 StencilR sh a stencil1
s1 StencilR sh b stencil2
s2 TypeR c
tp Fun aenv (stencil1 -> stencil2 -> c)
f Boundary aenv (Array sh a)
b1 acc aenv (Array sh a)
a1 Boundary aenv (Array sh b)
b2 acc aenv (Array sh b)
a2
-> StencilR sh a stencil1
-> StencilR sh b stencil2
-> TypeR c
-> Fun aenv' (stencil1 -> stencil2 -> c)
-> Boundary aenv' (Array sh a)
-> acc aenv' (Array sh a)
-> Boundary aenv' (Array sh b)
-> acc aenv' (Array sh b)
-> PreOpenAcc acc aenv' (Array sh c)
forall sh a stencil1 b stencil2 c aenv (acc :: * -> * -> *).
StencilR sh a stencil1
-> StencilR sh b stencil2
-> TypeR c
-> Fun aenv (stencil1 -> stencil2 -> c)
-> Boundary aenv (Array sh a)
-> acc aenv (Array sh a)
-> Boundary aenv (Array sh b)
-> acc aenv (Array sh b)
-> PreOpenAcc acc aenv (Array sh c)
Stencil2 StencilR sh a stencil1
s1 StencilR sh b stencil2
s2 TypeR c
tp (Fun aenv' (stencil1 -> stencil2 -> c)
-> Boundary aenv' (Array sh a)
-> acc aenv' (Array sh a)
-> Boundary aenv' (Array sh b)
-> acc aenv' (Array sh b)
-> PreOpenAcc acc aenv' (Array sh c))
-> f (Fun aenv' (stencil1 -> stencil2 -> c))
-> f (Boundary aenv' (Array sh a)
-> acc aenv' (Array sh a)
-> Boundary aenv' (Array sh b)
-> acc aenv' (Array sh b)
-> PreOpenAcc acc aenv' (Array sh c))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> RebuildEvar f IdxE () () aenv'
-> ReindexAvar f aenv aenv'
-> Fun aenv (stencil1 -> stencil2 -> c)
-> f (Fun aenv' (stencil1 -> stencil2 -> c))
forall (f :: * -> *) (fe :: * -> * -> * -> *) env env' aenv' aenv
t.
(HasCallStack, Applicative f, SyntacticExp fe) =>
RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> OpenFun env aenv t
-> f (OpenFun env' aenv' t)
rebuildFun (IdxE () aenv' t' -> f (IdxE () aenv' t')
forall (f :: * -> *) a. Applicative f => a -> f a
pure (IdxE () aenv' t' -> f (IdxE () aenv' t'))
-> (ExpVar () t' -> IdxE () aenv' t')
-> ExpVar () t'
-> f (IdxE () aenv' t')
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ExpVar () t' -> IdxE () aenv' t'
forall env aenv t. ExpVar env t -> IdxE env aenv t
IE) ReindexAvar f aenv aenv'
av' Fun aenv (stencil1 -> stencil2 -> c)
f f (Boundary aenv' (Array sh a)
-> acc aenv' (Array sh a)
-> Boundary aenv' (Array sh b)
-> acc aenv' (Array sh b)
-> PreOpenAcc acc aenv' (Array sh c))
-> f (Boundary aenv' (Array sh a))
-> f (acc aenv' (Array sh a)
-> Boundary aenv' (Array sh b)
-> acc aenv' (Array sh b)
-> PreOpenAcc acc aenv' (Array sh c))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ReindexAvar f aenv aenv'
-> Boundary aenv (Array sh a) -> f (Boundary aenv' (Array sh a))
forall (f :: * -> *) aenv aenv' t.
Applicative f =>
ReindexAvar f aenv aenv' -> Boundary aenv t -> f (Boundary aenv' t)
rebuildBoundary ReindexAvar f aenv aenv'
av' Boundary aenv (Array sh a)
b1 f (acc aenv' (Array sh a)
-> Boundary aenv' (Array sh b)
-> acc aenv' (Array sh b)
-> PreOpenAcc acc aenv' (Array sh c))
-> f (acc aenv' (Array sh a))
-> f (Boundary aenv' (Array sh b)
-> acc aenv' (Array sh b) -> PreOpenAcc acc aenv' (Array sh c))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> RebuildAvar f fa acc aenv aenv'
-> acc aenv (Array sh a) -> f (acc aenv' (Array sh a))
RebuildAcc acc
k RebuildAvar f fa acc aenv aenv'
av acc aenv (Array sh a)
a1 f (Boundary aenv' (Array sh b)
-> acc aenv' (Array sh b) -> PreOpenAcc acc aenv' (Array sh c))
-> f (Boundary aenv' (Array sh b))
-> f (acc aenv' (Array sh b) -> PreOpenAcc acc aenv' (Array sh c))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ReindexAvar f aenv aenv'
-> Boundary aenv (Array sh b) -> f (Boundary aenv' (Array sh b))
forall (f :: * -> *) aenv aenv' t.
Applicative f =>
ReindexAvar f aenv aenv' -> Boundary aenv t -> f (Boundary aenv' t)
rebuildBoundary ReindexAvar f aenv aenv'
av' Boundary aenv (Array sh b)
b2 f (acc aenv' (Array sh b) -> PreOpenAcc acc aenv' (Array sh c))
-> f (acc aenv' (Array sh b))
-> f (PreOpenAcc acc aenv' (Array sh c))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> RebuildAvar f fa acc aenv aenv'
-> acc aenv (Array sh b) -> f (acc aenv' (Array sh b))
RebuildAcc acc
k RebuildAvar f fa acc aenv aenv'
av acc aenv (Array sh b)
a2
Aforeign ArraysR t
repr asm (as -> t)
ff PreAfun acc (as -> t)
afun acc aenv as
as -> ArraysR t
-> asm (as -> t)
-> PreAfun acc (as -> t)
-> acc aenv' as
-> PreOpenAcc acc aenv' t
forall (asm :: * -> *) bs as (acc :: * -> * -> *) aenv.
Foreign asm =>
ArraysR bs
-> asm (as -> bs)
-> PreAfun acc (as -> bs)
-> acc aenv as
-> PreOpenAcc acc aenv bs
Aforeign ArraysR t
repr asm (as -> t)
ff PreAfun acc (as -> t)
afun (acc aenv' as -> PreOpenAcc acc aenv' t)
-> f (acc aenv' as) -> f (PreOpenAcc acc aenv' t)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> RebuildAvar f fa acc aenv aenv' -> acc aenv as -> f (acc aenv' as)
RebuildAcc acc
k RebuildAvar f fa acc aenv aenv'
av acc aenv as
as
where
av' :: ReindexAvar f aenv aenv'
av' = RebuildAvar f fa acc aenv aenv' -> ReindexAvar f aenv aenv'
forall (f :: * -> *) (fa :: (* -> * -> *) -> * -> * -> *)
(acc :: * -> * -> *) aenv aenv'.
(HasCallStack, Applicative f, SyntacticAcc fa) =>
RebuildAvar f fa acc aenv aenv' -> ReindexAvar f aenv aenv'
reindexAvar RebuildAvar f fa acc aenv aenv'
av
{-# INLINEABLE rebuildAfun #-}
rebuildAfun
:: (HasCallStack, Applicative f, SyntacticAcc fa)
=> RebuildAcc acc
-> RebuildAvar f fa acc aenv aenv'
-> PreOpenAfun acc aenv t
-> f (PreOpenAfun acc aenv' t)
rebuildAfun :: RebuildAcc acc
-> RebuildAvar f fa acc aenv aenv'
-> PreOpenAfun acc aenv t
-> f (PreOpenAfun acc aenv' t)
rebuildAfun RebuildAcc acc
k RebuildAvar f fa acc aenv aenv'
av (Abody acc aenv t
b) = acc aenv' t -> PreOpenAfun acc aenv' t
forall (acc :: * -> * -> *) aenv t.
acc aenv t -> PreOpenAfun acc aenv t
Abody (acc aenv' t -> PreOpenAfun acc aenv' t)
-> f (acc aenv' t) -> f (PreOpenAfun acc aenv' t)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> RebuildAvar f fa acc aenv aenv' -> acc aenv t -> f (acc aenv' t)
RebuildAcc acc
k RebuildAvar f fa acc aenv aenv'
av acc aenv t
b
rebuildAfun RebuildAcc acc
k RebuildAvar f fa acc aenv aenv'
av (Alam ALeftHandSide a aenv aenv'
lhs1 PreOpenAfun acc aenv' t
f)
| Exists LeftHandSide ArrayR a aenv' a
lhs2 <- ALeftHandSide a aenv aenv' -> Exists (LeftHandSide ArrayR a aenv')
forall (s :: * -> *) t aenv1 aenv1' aenv2.
LeftHandSide s t aenv1 aenv1' -> Exists (LeftHandSide s t aenv2)
rebuildLHS ALeftHandSide a aenv aenv'
lhs1
= LeftHandSide ArrayR a aenv' a
-> PreOpenAfun acc a t -> PreOpenAfun acc aenv' (a -> t)
forall a aenv aenv' (acc :: * -> * -> *) t.
ALeftHandSide a aenv aenv'
-> PreOpenAfun acc aenv' t -> PreOpenAfun acc aenv (a -> t)
Alam LeftHandSide ArrayR a aenv' a
lhs2 (PreOpenAfun acc a t -> PreOpenAfun acc aenv' (a -> t))
-> f (PreOpenAfun acc a t) -> f (PreOpenAfun acc aenv' (a -> t))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> RebuildAcc acc
-> RebuildAvar f fa acc aenv' a
-> PreOpenAfun acc aenv' t
-> f (PreOpenAfun acc a t)
forall (f :: * -> *) (fa :: (* -> * -> *) -> * -> * -> *)
(acc :: * -> * -> *) aenv aenv' t.
(HasCallStack, Applicative f, SyntacticAcc fa) =>
RebuildAcc acc
-> RebuildAvar f fa acc aenv aenv'
-> PreOpenAfun acc aenv t
-> f (PreOpenAfun acc aenv' t)
rebuildAfun RebuildAcc acc
k (ALeftHandSide a aenv aenv'
-> LeftHandSide ArrayR a aenv' a
-> RebuildAcc acc
-> RebuildAvar f fa acc aenv aenv'
-> RebuildAvar f fa acc aenv' a
forall (f :: * -> *) (fa :: (* -> * -> *) -> * -> * -> *) t aenv1
aenv1' aenv2 aenv2' (acc :: * -> * -> *).
(HasCallStack, Applicative f, SyntacticAcc fa) =>
ALeftHandSide t aenv1 aenv1'
-> ALeftHandSide t aenv2 aenv2'
-> RebuildAcc acc
-> RebuildAvar f fa acc aenv1 aenv2
-> RebuildAvar f fa acc aenv1' aenv2'
shiftA' ALeftHandSide a aenv aenv'
lhs1 LeftHandSide ArrayR a aenv' a
lhs2 RebuildAcc acc
k RebuildAvar f fa acc aenv aenv'
av) PreOpenAfun acc aenv' t
f
rebuildAlet
:: forall f fa acc aenv1 aenv1' aenv2 bndArrs arrs. (HasCallStack, Applicative f, SyntacticAcc fa)
=> RebuildAcc acc
-> RebuildAvar f fa acc aenv1 aenv2
-> ALeftHandSide bndArrs aenv1 aenv1'
-> acc aenv1 bndArrs
-> acc aenv1' arrs
-> f (PreOpenAcc acc aenv2 arrs)
rebuildAlet :: RebuildAcc acc
-> RebuildAvar f fa acc aenv1 aenv2
-> ALeftHandSide bndArrs aenv1 aenv1'
-> acc aenv1 bndArrs
-> acc aenv1' arrs
-> f (PreOpenAcc acc aenv2 arrs)
rebuildAlet RebuildAcc acc
k RebuildAvar f fa acc aenv1 aenv2
av ALeftHandSide bndArrs aenv1 aenv1'
lhs1 acc aenv1 bndArrs
bind1 acc aenv1' arrs
body1
| Exists LeftHandSide ArrayR bndArrs aenv2 a
lhs2 <- ALeftHandSide bndArrs aenv1 aenv1'
-> Exists (LeftHandSide ArrayR bndArrs aenv2)
forall (s :: * -> *) t aenv1 aenv1' aenv2.
LeftHandSide s t aenv1 aenv1' -> Exists (LeftHandSide s t aenv2)
rebuildLHS ALeftHandSide bndArrs aenv1 aenv1'
lhs1
= LeftHandSide ArrayR bndArrs aenv2 a
-> acc aenv2 bndArrs -> acc a arrs -> PreOpenAcc acc aenv2 arrs
forall bndArrs aenv aenv' (acc :: * -> * -> *) bodyArrs.
ALeftHandSide bndArrs aenv aenv'
-> acc aenv bndArrs
-> acc aenv' bodyArrs
-> PreOpenAcc acc aenv bodyArrs
Alet LeftHandSide ArrayR bndArrs aenv2 a
lhs2 (acc aenv2 bndArrs -> acc a arrs -> PreOpenAcc acc aenv2 arrs)
-> f (acc aenv2 bndArrs)
-> f (acc a arrs -> PreOpenAcc acc aenv2 arrs)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> RebuildAvar f fa acc aenv1 aenv2
-> acc aenv1 bndArrs -> f (acc aenv2 bndArrs)
RebuildAcc acc
k RebuildAvar f fa acc aenv1 aenv2
av acc aenv1 bndArrs
bind1 f (acc a arrs -> PreOpenAcc acc aenv2 arrs)
-> f (acc a arrs) -> f (PreOpenAcc acc aenv2 arrs)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> RebuildAvar f fa acc aenv1' a -> acc aenv1' arrs -> f (acc a arrs)
RebuildAcc acc
k (ALeftHandSide bndArrs aenv1 aenv1'
-> LeftHandSide ArrayR bndArrs aenv2 a
-> RebuildAcc acc
-> RebuildAvar f fa acc aenv1 aenv2
-> RebuildAvar f fa acc aenv1' a
forall (f :: * -> *) (fa :: (* -> * -> *) -> * -> * -> *) t aenv1
aenv1' aenv2 aenv2' (acc :: * -> * -> *).
(HasCallStack, Applicative f, SyntacticAcc fa) =>
ALeftHandSide t aenv1 aenv1'
-> ALeftHandSide t aenv2 aenv2'
-> RebuildAcc acc
-> RebuildAvar f fa acc aenv1 aenv2
-> RebuildAvar f fa acc aenv1' aenv2'
shiftA' ALeftHandSide bndArrs aenv1 aenv1'
lhs1 LeftHandSide ArrayR bndArrs aenv2 a
lhs2 RebuildAcc acc
k RebuildAvar f fa acc aenv1 aenv2
av) acc aenv1' arrs
body1
{-# INLINEABLE rebuildLHS #-}
rebuildLHS :: LeftHandSide s t aenv1 aenv1' -> Exists (LeftHandSide s t aenv2)
rebuildLHS :: LeftHandSide s t aenv1 aenv1' -> Exists (LeftHandSide s t aenv2)
rebuildLHS (LeftHandSideWildcard TupR s t
r) = LeftHandSide s t aenv2 aenv2 -> Exists (LeftHandSide s t aenv2)
forall (f :: * -> *) a. f a -> Exists f
Exists (LeftHandSide s t aenv2 aenv2 -> Exists (LeftHandSide s t aenv2))
-> LeftHandSide s t aenv2 aenv2 -> Exists (LeftHandSide s t aenv2)
forall a b. (a -> b) -> a -> b
$ TupR s t -> LeftHandSide s t aenv2 aenv2
forall (s :: * -> *) v env. TupR s v -> LeftHandSide s v env env
LeftHandSideWildcard TupR s t
r
rebuildLHS (LeftHandSideSingle s t
s) = LeftHandSide s t aenv2 (aenv2, t)
-> Exists (LeftHandSide s t aenv2)
forall (f :: * -> *) a. f a -> Exists f
Exists (LeftHandSide s t aenv2 (aenv2, t)
-> Exists (LeftHandSide s t aenv2))
-> LeftHandSide s t aenv2 (aenv2, t)
-> Exists (LeftHandSide s t aenv2)
forall a b. (a -> b) -> a -> b
$ s t -> LeftHandSide s t aenv2 (aenv2, t)
forall (s :: * -> *) v env. s v -> LeftHandSide s v env (env, v)
LeftHandSideSingle s t
s
rebuildLHS (LeftHandSidePair LeftHandSide s v1 aenv1 env'
as LeftHandSide s v2 env' aenv1'
bs)
| Exists LeftHandSide s v1 aenv2 a
as' <- LeftHandSide s v1 aenv1 env' -> Exists (LeftHandSide s v1 aenv2)
forall (s :: * -> *) t aenv1 aenv1' aenv2.
LeftHandSide s t aenv1 aenv1' -> Exists (LeftHandSide s t aenv2)
rebuildLHS LeftHandSide s v1 aenv1 env'
as
, Exists LeftHandSide s v2 a a
bs' <- LeftHandSide s v2 env' aenv1' -> Exists (LeftHandSide s v2 a)
forall (s :: * -> *) t aenv1 aenv1' aenv2.
LeftHandSide s t aenv1 aenv1' -> Exists (LeftHandSide s t aenv2)
rebuildLHS LeftHandSide s v2 env' aenv1'
bs
= LeftHandSide s (v1, v2) aenv2 a
-> Exists (LeftHandSide s (v1, v2) aenv2)
forall (f :: * -> *) a. f a -> Exists f
Exists (LeftHandSide s (v1, v2) aenv2 a
-> Exists (LeftHandSide s (v1, v2) aenv2))
-> LeftHandSide s (v1, v2) aenv2 a
-> Exists (LeftHandSide s (v1, v2) aenv2)
forall a b. (a -> b) -> a -> b
$ LeftHandSide s v1 aenv2 a
-> LeftHandSide s v2 a a -> LeftHandSide s (v1, v2) aenv2 a
forall (s :: * -> *) v1 env env' v2 env''.
LeftHandSide s v1 env env'
-> LeftHandSide s v2 env' env''
-> LeftHandSide s (v1, v2) env env''
LeftHandSidePair LeftHandSide s v1 aenv2 a
as' LeftHandSide s v2 a a
bs'
{-# INLINEABLE rebuildBoundary #-}
rebuildBoundary
:: Applicative f
=> ReindexAvar f aenv aenv'
-> Boundary aenv t
-> f (Boundary aenv' t)
rebuildBoundary :: ReindexAvar f aenv aenv' -> Boundary aenv t -> f (Boundary aenv' t)
rebuildBoundary ReindexAvar f aenv aenv'
av Boundary aenv t
bndy =
case Boundary aenv t
bndy of
Boundary aenv t
Clamp -> Boundary aenv' t -> f (Boundary aenv' t)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Boundary aenv' t
forall aenv t. Boundary aenv t
Clamp
Boundary aenv t
Mirror -> Boundary aenv' t -> f (Boundary aenv' t)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Boundary aenv' t
forall aenv t. Boundary aenv t
Mirror
Boundary aenv t
Wrap -> Boundary aenv' t -> f (Boundary aenv' t)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Boundary aenv' t
forall aenv t. Boundary aenv t
Wrap
Constant e
v -> Boundary aenv' (Array sh e) -> f (Boundary aenv' (Array sh e))
forall (f :: * -> *) a. Applicative f => a -> f a
pure (e -> Boundary aenv' (Array sh e)
forall e aenv sh. e -> Boundary aenv (Array sh e)
Constant e
v)
Function Fun aenv (sh -> e)
f -> Fun aenv' (sh -> e) -> Boundary aenv' (Array sh e)
forall aenv sh e. Fun aenv (sh -> e) -> Boundary aenv (Array sh e)
Function (Fun aenv' (sh -> e) -> Boundary aenv' (Array sh e))
-> f (Fun aenv' (sh -> e)) -> f (Boundary aenv' (Array sh e))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> RebuildEvar f IdxE () () aenv'
-> ReindexAvar f aenv aenv'
-> Fun aenv (sh -> e)
-> f (Fun aenv' (sh -> e))
forall (f :: * -> *) (fe :: * -> * -> * -> *) env env' aenv' aenv
t.
(HasCallStack, Applicative f, SyntacticExp fe) =>
RebuildEvar f fe env env' aenv'
-> ReindexAvar f aenv aenv'
-> OpenFun env aenv t
-> f (OpenFun env' aenv' t)
rebuildFun (IdxE () aenv' t' -> f (IdxE () aenv' t')
forall (f :: * -> *) a. Applicative f => a -> f a
pure (IdxE () aenv' t' -> f (IdxE () aenv' t'))
-> (ExpVar () t' -> IdxE () aenv' t')
-> ExpVar () t'
-> f (IdxE () aenv' t')
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ExpVar () t' -> IdxE () aenv' t'
forall env aenv t. ExpVar env t -> IdxE env aenv t
IE) ReindexAvar f aenv aenv'
av Fun aenv (sh -> e)
f
extractExpVars :: OpenExp env aenv a -> Maybe (ExpVars env a)
OpenExp env aenv a
Nil = TupR (Var ScalarType env) ()
-> Maybe (TupR (Var ScalarType env) ())
forall a. a -> Maybe a
Just TupR (Var ScalarType env) ()
forall (s :: * -> *). TupR s ()
TupRunit
extractExpVars (Pair OpenExp env aenv t1
e1 OpenExp env aenv t2
e2) = TupR (Var ScalarType env) t1
-> TupR (Var ScalarType env) t2
-> TupR (Var ScalarType env) (t1, t2)
forall (s :: * -> *) a b. TupR s a -> TupR s b -> TupR s (a, b)
TupRpair (TupR (Var ScalarType env) t1
-> TupR (Var ScalarType env) t2
-> TupR (Var ScalarType env) (t1, t2))
-> Maybe (TupR (Var ScalarType env) t1)
-> Maybe
(TupR (Var ScalarType env) t2
-> TupR (Var ScalarType env) (t1, t2))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> OpenExp env aenv t1 -> Maybe (TupR (Var ScalarType env) t1)
forall env aenv a. OpenExp env aenv a -> Maybe (ExpVars env a)
extractExpVars OpenExp env aenv t1
e1 Maybe
(TupR (Var ScalarType env) t2
-> TupR (Var ScalarType env) (t1, t2))
-> Maybe (TupR (Var ScalarType env) t2)
-> Maybe (TupR (Var ScalarType env) (t1, t2))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> OpenExp env aenv t2 -> Maybe (TupR (Var ScalarType env) t2)
forall env aenv a. OpenExp env aenv a -> Maybe (ExpVars env a)
extractExpVars OpenExp env aenv t2
e2
extractExpVars (Evar ExpVar env a
v) = ExpVars env a -> Maybe (ExpVars env a)
forall a. a -> Maybe a
Just (ExpVars env a -> Maybe (ExpVars env a))
-> ExpVars env a -> Maybe (ExpVars env a)
forall a b. (a -> b) -> a -> b
$ ExpVar env a -> ExpVars env a
forall (s :: * -> *) a. s a -> TupR s a
TupRsingle ExpVar env a
v
extractExpVars OpenExp env aenv a
_ = Maybe (ExpVars env a)
forall a. Maybe a
Nothing