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

[ foreign, library, mit ] [ Propose Tags ]

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


[Skip to Readme]

Flags

Automatic Flags
NameDescriptionDefault
sumtypes

Use sumtypes within the benchmark and the test.

Disabled

Use -f <flag> to enable a flag, or -f -<flag> to disable that flag. More info

Downloads

Note: This package has metadata revisions in the cabal description newer than included in the tarball. To unpack the package including the revisions, use 'cabal get'.

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

Versions [RSS] 0.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.3.0, 0.2.3.1, 0.2.3.2, 0.2.3.3, 0.2.3.4, 0.2.3.5, 0.2.3.6, 0.2.3.7 (info)
Change log ChangeLog.md
Dependencies base (>=4.9 && <4.15), derive-storable (>=0.1.1 && <0.3), ghc (>=8.0 && <8.11), ghci (>=8.0 && <8.11) [details]
License MIT
Author Mateusz Kłoczko
Maintainer mateusz.p.kloczko@gmail.com
Revised Revision 3 made by mkloczko at 2020-11-28T15:17:10Z
Category Foreign
Home page https://www.github.com/mkloczko/derive-storable-plugin/
Uploaded by mkloczko at 2020-03-23T19:45:03Z
Distributions NixOS:0.2.3.7
Reverse Dependencies 7 direct, 4 indirect [details]
Downloads 5752 total (53 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2020-03-23 [all 1 reports]

Readme for derive-storable-plugin-0.2.3.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