derive-storable-plugin: GHC core plugin supporting the derive-storable package.

This is a package candidate release! Here you can preview how this package release will appear once published to the main package index (which can be accomplished via the 'maintain' link below). Please note that once a package has been published to the main package index it cannot be undone! Please consult the package uploading documentation for more information.

[maintain]

The package helps derive-storable package in forcing compile time evaluation of sizes, alignments and offsets.


[Skip to ReadMe]

Properties

Versions0.1.0.0, 0.1.0.1, 0.1.0.2, 0.2.0.0, 0.2.1.0, 0.2.2.0, 0.2.2.0
Change logChangeLog.md
Dependenciesbase (>=4.9 && <4.13), derive-storable (>=0.1.1 && <0.2), ghc (>=8.0 && <8.7), ghci (>=8.0 && <8.7) [details]
LicenseMIT
AuthorMateusz Kłoczko
Maintainermateusz.p.kloczko@gmail.com
CategoryForeign
Home pagehttps://www.github.com/mkloczko/derive-storable-plugin/
Source repositoryhead: git clone https://www.github.com/mkloczko/derive-storable-plugin/
UploadedSat Sep 29 05:44:25 UTC 2018 by mkloczko

Modules

[Index]

Downloads

Maintainers' corner

For package maintainers and hackage trustees


Readme for derive-storable-plugin-0.2.2.0

[back to package description]

Introduction

Build Status

The goal of derive-storable-plugin is to support the derive-storable package. It introduces optimisations to GStorable methods derived using GHC.Generics at core-to-core passes.

Usage

Just add a -fplugin=Foreign.Storable.Generic.Plugin flag and you're set. You might also want to pass a verbosity flag -vX, where X is either 0,1 or 2. By default the verbosity flag is set to -v1.

{-# LANGUAGE DeriveGeneric, DeriveAnyClass #-}
{-# OPTIONS_GHC -fplugin=Foreign.Storable.Generic.Plugin #-}
{-# OPTIONS_GHC -fplugin-opt=Foreign.Storable.Generic.Plugin:-v1 #-} 
module Main where

import GHC.Generics

import Foreign.Storable.Generic
import Foreign.Ptr
import Foreign.Marshal.Alloc

data Point = Point {
    x :: Float,
    y :: Float
    } deriving (Show, Read, Generic, GStorable)

main = do
    let val = Point 0.0 10.0
    ptr <- malloc :: IO (Ptr Point)
    putStrLn "Created a ptr with value of"
    print =<< peek ptr
    poke ptr val
    putStrLn "And now the value of ptr is:"
    print =<< peek ptr

Benchmarks

The plugin was benchmarked using derive-storable-benchmark package. The benchark measures handwritten Storable instances, raw GStorable instances and optimised-by-plugin GStorable instances. The code was compiled with -O1 optimisation flag. Benchmarks