derive-storable-plugin- GHC core plugin supporting the derive-storable package.
Copyright(c) Mateusz Kłoczko 2016
Safe HaskellNone



The core of compile and substitute optimisations.



compileExpr :: HscEnv -> CoreExpr -> SrcSpan -> IO a Source #

Compile an expression.

tryCompileExpr :: Id -> CoreExpr -> CoreM (Either Error a) Source #

Try to compile an expression. Perhaps return an error.

intToExpr :: Type -> Int -> CoreExpr Source #

Create an expression of form: x -> 16

intSubstitution :: CoreBind -> CoreM (Either Error CoreBind) Source #

For gsizeOf and galignment - calculate the variables.

offsetSubstitution :: CoreBind -> CoreM (Either Error CoreBind) Source #

Try to substitute the offsets.

offsetSubstitutionTree :: [OffsetScope] -> CoreExpr -> CoreM (Either Error CoreExpr) Source #

Substitute the offsets in a tree. All top-level local ids should be alread in place. Now try to compile selected expressions (See note [Offset substitution])

data OffsetScope Source #

Scoped variables for optimising offsets.


Instances details
Outputable OffsetScope Source # 
Instance details

Defined in Foreign.Storable.Generic.Plugin.Internal.Compile

intListExpr :: [Int] -> CoreExpr Source #

Create a list expression from Haskell list.

exprToIntList :: Id -> CoreExpr -> CoreM (Either Error OffsetScope) Source #

Compile expression to list and then write it back to core expr.

isLitOrGlobal :: CoreExpr -> Maybe CoreExpr Source #

Return the expression if it's a literal or global.

inScopeAll :: [OffsetScope] -> CoreExpr -> Maybe CoreExpr Source #

Check whether the given CoreExpr is an id, and if yes - substitute it.

isIndexer :: Id -> Bool Source #

Is an "$w!!" identifier

caseExprIndex :: [OffsetScope] -> CoreExpr -> Maybe CoreExpr Source #

Try to create a compileable version of case expr body. For !! @Int offsets val expressions.

compileGStorableBind :: CoreBind -> CoreM (Either Error CoreBind) Source #

Compile the expression in Core Bind and replace it.

lintBind Source #


:: CoreBind

Core binding to use when returning CompilationError

-> CoreBind

Core binding to check

-> CoreM (Either Error CoreBind)

Success or failure

Lint a binding

replaceIdsBind Source #


:: [CoreBind]

Replace with - for GStorable bindings

-> [CoreBind]

Replace with - for other top-bindings

-> CoreBind

Binding which will have ids replaced.

-> CoreBind

Binding with replaced ids.

Substitutes the localIds inside the bindings with bodies of provided bindings.

compileGroups Source #


:: Flags

Error handling.

-> [[CoreBind]]

Ordered gstorable bindings.

-> [CoreBind]

Non-gstorable bindings, used for replacing ids.

-> CoreM [CoreBind]

The compiled (or not) bindings.

Compile ordered binding.