GHC core plugin supporting the derive-storable package.

Latest on Hackage:

This package is not currently in any snapshots. If you're interested in using it, we recommend adding it to Stackage Nightly. Doing so will make builds more reliable, and allow to host generated Haddocks.

MIT licensed by Mateusz Kłoczko


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.


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


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


Revision history for generic-storable-plugin -- 2018-03-20

  • Bump to 8.4 -- 2017-11-04

  • Support for GHC 8.2.*.
  • Added benchmarks. -- 2017-01-08

  • Added tests.
  • Added TravisCI builds. -- 2016-09-11

  • Changed generic-storable to derive-storable in
  • Added to the package -- 2016-09-08

  • First version. Released on an unsuspecting world.
Depends on 4 packages:
Used by 1 package:
comments powered byDisqus