Safe Haskell | None |
---|
Defines different interpretations of Feldspar programs
- module Feldspar.Core.Interpretation.Typed
- targetSpecialization :: BitWidth n -> ASTF dom a -> ASTF dom a
- class Sharable dom where
- class SizeProp feature where
- sizePropDefault :: Type (DenResult a) => feature a -> Args (WrapFull Info) a -> Size (DenResult a)
- resultType :: Type (DenResult a) => c a -> TypeRep (DenResult a)
- type SourceInfo = String
- data Info a where
- mkInfo :: Type a => Size a -> Info a
- mkInfoTy :: (Show (Size a), Lattice (Size a)) => TypeRep a -> Info a
- infoRange :: Type a => Info a -> RangeSet a
- class LatticeSize1 m where
- viewLiteral :: forall info dom a. (Literal :|| Type) :<: dom => ASTF (Decor info (dom :|| Typeable)) a -> Maybe a
- literal :: (Type a, (Literal :|| Type) :<: dom) => a -> ASTF (dom :|| Typeable) a
- literalDecor :: (Type a, (Literal :|| Type) :<: dom) => a -> ASTF (Decor Info (dom :|| Typeable)) a
- constFold :: (Typed dom, (Literal :|| Type) :<: dom) => SourceInfo -> ASTF (Decor Info (dom :|| Typeable)) a -> a -> ASTF (Decor Info (dom :|| Typeable)) a
- data SomeInfo where
- data SomeType where
- data Env = Env {
- varEnv :: [(VarId, SomeInfo)]
- sourceEnv :: SourceInfo
- data FeldOpts = FeldOpts {}
- data Target
- inTarget :: Target -> FeldOpts -> Bool
- defaultFeldOpts :: FeldOpts
- localVar :: Typeable b => VarId -> Info b -> Opt a -> Opt a
- localSource :: SourceInfo -> Opt a -> Opt a
- type Opt = Reader Env
- class Optimize feature dom where
- optimizeFeat :: (Typeable (DenResult a), OptimizeSuper dom) => FeldOpts -> feature a -> Args (AST (dom :|| Typeable)) a -> Opt (ASTF (Decor Info (dom :|| Typeable)) (DenResult a))
- constructFeatOpt :: Typeable (DenResult a) => FeldOpts -> feature a -> Args (AST (Decor Info (dom :|| Typeable))) a -> Opt (ASTF (Decor Info (dom :|| Typeable)) (DenResult a))
- constructFeatUnOpt :: Typeable (DenResult a) => FeldOpts -> feature a -> Args (AST (Decor Info (dom :|| Typeable))) a -> Opt (ASTF (Decor Info (dom :|| Typeable)) (DenResult a))
- class (AlphaEq dom dom (dom :|| Typeable) [(VarId, VarId)], AlphaEq dom dom (Decor Info (dom :|| Typeable)) [(VarId, VarId)], EvalBind dom, (Literal :|| Type) :<: dom, Typed dom, Render dom, Constrained dom, Optimize dom dom) => OptimizeSuper dom
- constructFeat :: (Typeable (DenResult a), Optimize feature dom) => FeldOpts -> feature a -> Args (AST (Decor Info (dom :|| Typeable))) a -> Opt (ASTF (Decor Info (dom :|| Typeable)) (DenResult a))
- optimizeM :: OptimizeSuper dom => FeldOpts -> ASTF (dom :|| Typeable) a -> Opt (ASTF (Decor Info (dom :|| Typeable)) a)
- optimize :: (Typeable a, OptimizeSuper dom) => FeldOpts -> ASTF (dom :|| Typeable) a -> ASTF (Decor Info (dom :|| Typeable)) a
- constructFeatUnOptDefaultTyp :: (feature :<: dom, SizeProp feature, Typeable (DenResult a), Show (Size (DenResult a)), Lattice (Size (DenResult a))) => FeldOpts -> TypeRep (DenResult a) -> feature a -> Args (AST (Decor Info (dom :|| Typeable))) a -> Opt (ASTF (Decor Info (dom :|| Typeable)) (DenResult a))
- constructFeatUnOptDefault :: (feature :<: dom, SizeProp feature, Type (DenResult a)) => FeldOpts -> feature a -> Args (AST (Decor Info (dom :|| Typeable))) a -> Opt (ASTF (Decor Info (dom :|| Typeable)) (DenResult a))
- optimizeFeatDefault :: (Optimize feature dom, Typeable (DenResult a), OptimizeSuper dom) => FeldOpts -> feature a -> Args (AST (dom :|| Typeable)) a -> Opt (ASTF (Decor Info (dom :|| Typeable)) (DenResult a))
- prjF :: Project (sub :|| Type) sup => sup sig -> Maybe ((sub :|| Type) sig)
- c' :: Type (DenResult sig) => feature sig -> (feature :|| Type) sig
- class Monotonic feature where
- monotonicInc :: feature a -> Args (AST (Decor Info (dom :|| Typeable))) a -> [ASTF (Decor Info (dom :|| Typeable)) (DenResult a)]
- monotonicDec :: feature a -> Args (AST (Decor Info (dom :|| Typeable))) a -> [ASTF (Decor Info (dom :|| Typeable)) (DenResult a)]
- viewMonotonicInc :: Monotonic dom => ASTF (Decor Info (dom :|| Typeable)) a -> [ASTF (Decor Info (dom :|| Typeable)) a]
- viewMonotonicDec :: Monotonic dom => ASTF (Decor Info (dom :|| Typeable)) a -> [ASTF (Decor Info (dom :|| Typeable)) a]
Documentation
targetSpecialization :: BitWidth n -> ASTF dom a -> ASTF dom aSource
Specialize the program for a target platform with the given native bit width
class Sharable dom whereSource
Indication whether a symbol is sharable or not
Sharable Empty | |
Sharable Literal | |
Sharable Tuple | |
Sharable Select | |
Sharable Condition | |
Sharable Variable | |
Sharable Let | |
Sharable Lambda | |
Sharable COMPLEX | |
Sharable ORD | |
Sharable EQ | |
Sharable Logic | |
Sharable BITS | |
Sharable INTEGRAL | |
Sharable Error | |
Sharable FLOATING | |
Sharable NUM | |
Sharable FRACTIONAL | |
Sharable NoInline | |
Sharable REALFLOAT | |
Sharable Trace | |
Sharable FFI | |
Sharable Save | |
Sharable Array | |
Sharable FUTURE | |
Sharable Mutable | |
Sharable Switch | |
Sharable Conversion | |
Sharable MutableReference | |
Sharable Loop | |
Sharable MutableArray | |
Sharable MutableToPure | |
Sharable ParFeature | |
Sharable PropSize | |
Sharable (MONAD Par) | |
Sharable (MONAD Mut) | |
Sharable (ConditionM m) | |
Sharable (LoopM m) | |
(Sharable sub1, Sharable sub2) => Sharable (:+: sub1 sub2) | |
Sharable sym => Sharable (:|| sym pred) | |
Sharable dom => Sharable (Decor Info dom) | |
Sharable (Decor SourceInfo1 Identity) | |
Sharable sym => Sharable (SubConstr2 c sym p1 p2) |
class SizeProp feature whereSource
Forwards size propagation
sizeProp :: feature a -> Args (WrapFull Info) a -> Size (DenResult a)Source
Size propagation for a symbol given a list of argument sizes
SizeProp Identity | |
SizeProp Let | |
SizeProp Mutable | |
SizeProp MutableReference | |
SizeProp MutableArray | |
SizeProp MutableToPure | |
SizeProp ParFeature | |
SizeProp (MONAD Par) | |
SizeProp (MONAD Mut) | |
LatticeSize1 m => SizeProp (ConditionM m) | |
SizeProp (LoopM m) | |
SizeProp (:|| (Decor SourceInfo1 Identity) Type) | |
SizeProp (:|| Literal Type) | |
SizeProp (:|| Tuple Type) | |
SizeProp (:|| Select Type) | |
SizeProp (:|| Condition Type) | |
SizeProp (:|| COMPLEX Type) | |
SizeProp (:|| ORD Type) | |
SizeProp (:|| EQ Type) | |
SizeProp (:|| Logic Type) | |
SizeProp (:|| BITS Type) | |
SizeProp (:|| INTEGRAL Type) | |
SizeProp (:|| Error Type) | |
SizeProp (:|| FLOATING Type) | |
SizeProp (:|| NUM Type) | |
SizeProp (:|| FRACTIONAL Type) | |
SizeProp (:|| NoInline Type) | |
SizeProp (:|| REALFLOAT Type) | |
SizeProp (:|| Trace Type) | |
SizeProp (:|| FFI Type) | |
SizeProp (:|| Save Type) | |
SizeProp (:|| Array Type) | |
SizeProp (:|| FUTURE Type) | |
SizeProp (:|| Switch Type) | |
SizeProp (:|| Conversion Type) | |
SizeProp (:|| Loop Type) | |
SizeProp (:|| PropSize Type) |
sizePropDefault :: Type (DenResult a) => feature a -> Args (WrapFull Info) a -> Size (DenResult a)Source
Convenient default implementation of sizeProp
resultType :: Type (DenResult a) => c a -> TypeRep (DenResult a)Source
Compute a type representation of a symbol's result type
type SourceInfo = StringSource
Information about the source code of an expression
Type and size information of a Feldspar program
class LatticeSize1 m whereSource
This class is used to allow constructs to be abstract in the monad. Its
purpose is similar to that of MonadType
.
viewLiteral :: forall info dom a. (Literal :|| Type) :<: dom => ASTF (Decor info (dom :|| Typeable)) a -> Maybe aSource
It the expression is a literal, its value is returned, otherwise Nothing
literal :: (Type a, (Literal :|| Type) :<: dom) => a -> ASTF (dom :|| Typeable) aSource
Construct a Literal
literalDecor :: (Type a, (Literal :|| Type) :<: dom) => a -> ASTF (Decor Info (dom :|| Typeable)) aSource
Construct a Literal
decorated with Info
constFold :: (Typed dom, (Literal :|| Type) :<: dom) => SourceInfo -> ASTF (Decor Info (dom :|| Typeable)) a -> a -> ASTF (Decor Info (dom :|| Typeable)) aSource
Replaces an expression with a literal if the type permits, otherwise returns the expression unchanged.
A record with options for explicit passing in rewrite rules.
defaultFeldOpts :: FeldOptsSource
Default options.
localVar :: Typeable b => VarId -> Info b -> Opt a -> Opt aSource
Insert a variable into the environment
localSource :: SourceInfo -> Opt a -> Opt aSource
Change the SourceInfo
environment
class Optimize feature dom whereSource
Basic optimization of a feature
This optimization is similar to Optimize
, but it also performs size
inference. Size inference has to be done simultaneously with other
optimizations in order to avoid iterating the phases. (Size information may
help optimization and optimization may help size inference.)
optimizeFeat :: (Typeable (DenResult a), OptimizeSuper dom) => FeldOpts -> feature a -> Args (AST (dom :|| Typeable)) a -> Opt (ASTF (Decor Info (dom :|| Typeable)) (DenResult a))Source
Top-down and bottom-up optimization of a feature
constructFeatOpt :: Typeable (DenResult a) => FeldOpts -> feature a -> Args (AST (Decor Info (dom :|| Typeable))) a -> Opt (ASTF (Decor Info (dom :|| Typeable)) (DenResult a))Source
Optimized construction of an expression from a symbol and its optimized arguments
Note: This function should normally not be called directly. Instead, use
constructFeat
which has more accurate propagation of Info
.
constructFeatUnOpt :: Typeable (DenResult a) => FeldOpts -> feature a -> Args (AST (Decor Info (dom :|| Typeable))) a -> Opt (ASTF (Decor Info (dom :|| Typeable)) (DenResult a))Source
Unoptimized construction of an expression from a symbol and its optimized arguments
Optimize Empty dom | |
(:<: Let dom, :<: (:|| Variable Type) dom, :<: (CLambda Type) dom, OptimizeSuper dom) => Optimize Let dom | |
(:<: Mutable dom, :<: (MONAD Mut) dom, OptimizeSuper dom) => Optimize Mutable dom | |
(:<: MutableReference dom, :<: (MONAD Mut) dom, Project (CLambda Type) dom, Project (:|| Variable Type) dom, OptimizeSuper dom) => Optimize MutableReference dom | |
(:<: MutableArray dom, Optimize dom dom) => Optimize MutableArray dom | |
(:<: MutableToPure dom, Optimize dom dom) => Optimize MutableToPure dom | |
(:<: (MONAD Par) dom, :<: ParFeature dom, Optimize dom dom) => Optimize ParFeature dom | |
(:<: (MONAD Par) dom, :<: (:|| Variable Type) dom, :<: (CLambda Type) dom, :<: Let dom, OptimizeSuper dom) => Optimize (MONAD Par) dom | |
(:<: (MONAD Mut) dom, :<: (:|| Variable Type) dom, :<: (CLambda Type) dom, :<: Let dom, OptimizeSuper dom) => Optimize (MONAD Mut) dom | |
(:<: (ConditionM m) dom, :<: (:|| Logic Type) dom, OptimizeSuper dom, LatticeSize1 m) => Optimize (ConditionM m) dom | |
(:<: (CLambda Type) dom, OptimizeSuper dom) => Optimize (CLambda Type) dom | |
(:<: (LoopM Mut) dom, :<: (:|| Variable Type) dom, :<: (CLambda Type) dom, :<: (MONAD Mut) dom, :<: MutableReference dom, :<: Let dom, Optimize (CLambda Type) dom, Optimize (MONAD Mut) dom, Optimize dom dom) => Optimize (LoopM Mut) dom | |
(Optimize sub1 dom, Optimize sub2 dom) => Optimize (:+: sub1 sub2) dom | |
(:<: (:|| (Decor SourceInfo1 Identity) Type) dom, Optimize dom dom) => Optimize (:|| (Decor SourceInfo1 Identity) Type) dom | |
(:<: (:|| Literal Type) dom, OptimizeSuper dom) => Optimize (:|| Literal Type) dom | |
(:<: (:|| Tuple Type) dom, :<: (:|| Select Type) dom, OptimizeSuper dom) => Optimize (:|| Tuple Type) dom | |
(:<: (:|| Select Type) dom, :<: (CLambda Type) dom, :<: (:|| Tuple Type) dom, :<: Let dom, :<: (:|| Variable Type) dom, OptimizeSuper dom) => Optimize (:|| Select Type) dom | |
(:<: (:|| Condition Type) dom, :<: (:|| Logic Type) dom, :<: (:|| EQ Type) dom, :<: (:|| ORD Type) dom, :<: (:|| Variable Type) dom, :<: (CLambda Type) dom, Monotonic dom, OptimizeSuper dom) => Optimize (:|| Condition Type) dom | |
(:<: (:|| Variable Type) dom, OptimizeSuper dom) => Optimize (:|| Variable Type) dom | |
(:<: (:|| COMPLEX Type) dom, OptimizeSuper dom) => Optimize (:|| COMPLEX Type) dom | |
(:<: (:|| ORD Type) dom, Monotonic dom, OptimizeSuper dom) => Optimize (:|| ORD Type) dom | |
(:<: (:|| EQ Type) dom, OptimizeSuper dom) => Optimize (:|| EQ Type) dom | |
(:<: (:|| Logic Type) dom, :<: (:|| EQ Type) dom, :<: (:|| ORD Type) dom, Monotonic dom, OptimizeSuper dom) => Optimize (:|| Logic Type) dom | |
(:<: (:|| BITS Type) dom, :<: (:|| Logic Type) dom, :<: (:|| EQ Type) dom, :<: (:|| ORD Type) dom, Monotonic dom, OptimizeSuper dom) => Optimize (:|| BITS Type) dom | |
(:<: (:|| INTEGRAL Type) dom, :<: (:|| BITS Type) dom, :<: (:|| EQ Type) dom, :<: (:|| ORD Type) dom, :<: (:|| COMPLEX Type) dom, :<: (:|| Condition Type) dom, :<: (:|| Logic Type) dom, Monotonic dom, OptimizeSuper dom, Optimize (:|| Condition Type) dom) => Optimize (:|| INTEGRAL Type) dom | |
(:<: (:|| Error Type) dom, Optimize dom dom) => Optimize (:|| Error Type) dom | |
(:<: (:|| FLOATING Type) dom, OptimizeSuper dom) => Optimize (:|| FLOATING Type) dom | |
(:<: (:|| NUM Type) dom, :<: (:|| Literal Type) dom, :<: (:|| INTEGRAL Type) dom, :<: (:|| COMPLEX Type) dom, OptimizeSuper dom) => Optimize (:|| NUM Type) dom | |
(:<: (:|| FRACTIONAL Type) dom, :<: (:|| NUM Type) dom, OptimizeSuper dom) => Optimize (:|| FRACTIONAL Type) dom | |
(:<: (:|| NoInline Type) dom, OptimizeSuper dom) => Optimize (:|| NoInline Type) dom | |
(:<: (:|| REALFLOAT Type) dom, OptimizeSuper dom) => Optimize (:|| REALFLOAT Type) dom | |
(:<: (:|| Trace Type) dom, OptimizeSuper dom) => Optimize (:|| Trace Type) dom | |
(:<: (:|| FFI Type) dom, OptimizeSuper dom) => Optimize (:|| FFI Type) dom | |
(:<: (:|| Save Type) dom, OptimizeSuper dom) => Optimize (:|| Save Type) dom | |
(:<: (:|| Array Type) dom, :<: (:|| NUM Type) dom, :<: Let dom, :<: (:|| ORD Type) dom, :<: (:|| INTEGRAL Type) dom, :<: (:|| COMPLEX Type) dom, :<: (:|| Variable Type) dom, :<: (CLambda Type) dom, OptimizeSuper dom) => Optimize (:|| Array Type) dom | |
(:<: (:|| FUTURE Type) dom, OptimizeSuper dom) => Optimize (:|| FUTURE Type) dom | |
(:<: (:|| Switch Type) dom, :<: (:|| EQ Type) dom, :<: (:|| Condition Type) dom, OptimizeSuper dom) => Optimize (:|| Switch Type) dom | |
(:<: (:|| Conversion Type) dom, OptimizeSuper dom) => Optimize (:|| Conversion Type) dom | |
(:<: (:|| Literal Type) dom, :<: (:|| Loop Type) dom, :<: (:|| Variable Type) dom, :<: (CLambda Type) dom, :<: Let dom, OptimizeSuper dom) => Optimize (:|| Loop Type) dom | |
(:<: (:|| PropSize Type) dom, OptimizeSuper dom) => Optimize (:|| PropSize Type) dom |
class (AlphaEq dom dom (dom :|| Typeable) [(VarId, VarId)], AlphaEq dom dom (Decor Info (dom :|| Typeable)) [(VarId, VarId)], EvalBind dom, (Literal :|| Type) :<: dom, Typed dom, Render dom, Constrained dom, Optimize dom dom) => OptimizeSuper dom Source
constructFeat :: (Typeable (DenResult a), Optimize feature dom) => FeldOpts -> feature a -> Args (AST (Decor Info (dom :|| Typeable))) a -> Opt (ASTF (Decor Info (dom :|| Typeable)) (DenResult a))Source
Optimized construction of an expression from a symbol and its optimized arguments
optimizeM :: OptimizeSuper dom => FeldOpts -> ASTF (dom :|| Typeable) a -> Opt (ASTF (Decor Info (dom :|| Typeable)) a)Source
Optimization of an expression
In addition to running optimizeFeat
, this function performs constant
folding on all closed expressions, provided that the type permits making a
literal.
optimize :: (Typeable a, OptimizeSuper dom) => FeldOpts -> ASTF (dom :|| Typeable) a -> ASTF (Decor Info (dom :|| Typeable)) aSource
Optimization of an expression. This function runs optimizeM
and extracts
the result.
constructFeatUnOptDefaultTyp :: (feature :<: dom, SizeProp feature, Typeable (DenResult a), Show (Size (DenResult a)), Lattice (Size (DenResult a))) => FeldOpts -> TypeRep (DenResult a) -> feature a -> Args (AST (Decor Info (dom :|| Typeable))) a -> Opt (ASTF (Decor Info (dom :|| Typeable)) (DenResult a))Source
Convenient default implementation of constructFeatUnOpt
. Uses sizeProp
to propagate size.
constructFeatUnOptDefault :: (feature :<: dom, SizeProp feature, Type (DenResult a)) => FeldOpts -> feature a -> Args (AST (Decor Info (dom :|| Typeable))) a -> Opt (ASTF (Decor Info (dom :|| Typeable)) (DenResult a))Source
Like constructFeatUnOptDefaultTyp
but without an explicit TypeRep
optimizeFeatDefault :: (Optimize feature dom, Typeable (DenResult a), OptimizeSuper dom) => FeldOpts -> feature a -> Args (AST (dom :|| Typeable)) a -> Opt (ASTF (Decor Info (dom :|| Typeable)) (DenResult a))Source
Convenient default implementation of optimizeFeat
class Monotonic feature whereSource
The Monotonic
class represents (weak) monotonicity
monotonicInc :: feature a -> Args (AST (Decor Info (dom :|| Typeable))) a -> [ASTF (Decor Info (dom :|| Typeable)) (DenResult a)]Source
Return the arguments for which the symbol is monotonic increasing
forAll a. [a] = monotonicInc (f a) ==> f a >= a
monotonicDec :: feature a -> Args (AST (Decor Info (dom :|| Typeable))) a -> [ASTF (Decor Info (dom :|| Typeable)) (DenResult a)]Source
Return the arguments for which the symbol is monotonic decreasing
forAll a. [a] = monotonicDec (f a) ==> f a <= a
Monotonic Empty | |
Monotonic Literal | |
Monotonic Tuple | |
Monotonic Select | |
Monotonic Identity | |
Monotonic Condition | |
Monotonic Variable | |
Monotonic Let | |
Monotonic Lambda | |
Monotonic COMPLEX | |
Monotonic ORD | |
Monotonic EQ | |
Monotonic Logic | |
Monotonic BITS | |
Monotonic INTEGRAL | |
Monotonic Error | |
Monotonic FLOATING | |
Monotonic NUM | |
Monotonic FRACTIONAL | |
Monotonic NoInline | |
Monotonic REALFLOAT | |
Monotonic Trace | |
Monotonic FFI | |
Monotonic Save | |
Monotonic Array | |
Monotonic FUTURE | |
Monotonic Mutable | |
Monotonic Switch | |
Monotonic Conversion | |
Monotonic MutableReference | |
Monotonic Loop | |
Monotonic MutableArray | |
Monotonic MutableToPure | |
Monotonic ParFeature | |
Monotonic PropSize | |
Monotonic (MONAD Par) | |
Monotonic (MONAD Mut) | |
Monotonic (ConditionM m) | |
Monotonic (LoopM m) | |
(Monotonic sub1, Monotonic sub2) => Monotonic (:+: sub1 sub2) | |
Monotonic sym => Monotonic (:|| sym pred) | |
Monotonic dom => Monotonic (Decor Info dom) | |
Monotonic (Decor SourceInfo1 Identity) | |
Monotonic sym => Monotonic (SubConstr2 c sym p1 p2) |