Giter Site home page Giter Site logo

singleton-optimizer's Introduction

singleton-optimizer GHC plugin

builds.sr.ht status

A GHC plugin that optimizes away the implementation of total singletons

TODO write a more complete readme

Usage

You'll need a development version of Liquid Haskell. If you use cabal new-build, you can find an appropriate source-repository in the cabal.project file.

Add the -fplugin GHC.Plugin.SingletonOptimizer ghc option and mark the singletons to optimize with the annotation OptimizeSingleton.

For example, in your .cabal file:

library somelib
  ghc-options:         -fplugin GHC.Plugin.SingletonOptimizer
  build-depends:       base, singleton-optimizer
  exposed-modules:     YourModule
  hs-source-dirs:      src
  default-language:    Haskell2010

And in your module:

{-# ANN optimizedEquality OptimizeSingleton #-}
optimizedEquality :: SomeWhitelistedType -> SomeType :~: SomeEquivalentType
optimizedEquality = -- some expensive expression that eventually returns a 'Refl'

If Liquid Haskell's termination checker is unable to prove the totality of one of your functions, you can use the UnsafeTotal annotation to manually mark a binding as total.

Current limitations

No intra-module totality checking

Due to limitations in how GHC plugins work, all names referenced by a marked binding have to be either whitelisted or from the same module.

Bytecode compiler can't handle unboxed tuples and sums error

If all the following conditions are satisfied:

  • This plugin is used on a component with multiple modules
  • A module contains a typeclass instance declaration
  • That module gets imported by another module of the same component
  • Optimizations are enabled for that component (-O1 or -O2)

Then compilation will fail with this error

Error: bytecode compiler can't handle unboxed tuples and sums.
  Possibly due to foreign import/export decls in source.
  Workaround: use -fobject-code, or compile this module to .o separately.

This is a limitation of liquidhaskell and of how it calls ghc inside an existing ghc session.

Two possible fixes are:

  • Move the instance declaration to the module where it's used
  • Or separate the modules in two different components

singleton-optimizer's People

Contributors

fgaz avatar robertozunino avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.