GHC plugin to make stream fusion more predictable.
|Version on this page:||0.1.1|
|LTS Haskell 20.23:||0.2.6|
|Stackage Nightly 2023-05-30:||0.2.6|
|Latest on Hackage:||0.2.6|
Module documentation for 0.1.1
The goal of stream fusion is to eliminate constructors of
internal state used in a stream. For example, in case of
streamly streams, the
Stop would get
eliminated by fusion. Similarly, constructors of any other intermediate
state types get eliminated when stream fusion works correctly. See the papers
in the reference section for more details on stream fusion.
Stream fusion depends on the GHC case-of-case transformations eliminating intermediate constructors. Case-of-case transformation in turn depends on inlining. During core-to-core transformations GHC may create several internal bindings (e.g. join points) which may not get inlined because their size is too big. Even though we know that after fusion the resulting code would be smaller and more efficient. The programmer cannot force inlining of these bindings as there is no way for the programmer to address these bindings at the source level because they are internal, generated during core-to-core transformations. As a result stream fusion fails unpredictably depending on whether GHC was able to inline the internal bindings or not.
See GHC ticket #17075 for more details.
This plugin provides the programmer with a way to annotate certain types
Fuse pragma. The programmer would annotate the types that are
to be eliminated by fusion. During the simplifier phase the plugin goes through
the relevant bindings and if one of these types are found inside a binding then
that binding is marked to be inlined irrespective of the size.
Using the plugin
This plugin was primarily motivated by streamly but it can be used in general.
To use this plugin, add this package to your
and pass the following to your ghc-options:
ghc-options: -O2 -fplugin=Fusion.Plugin
All contributions are welcome! The code is available under BSD-3 license on github. In case you have any questions or suggestions please contact Pranay Sashank, the author and maintainer of this plugin.
We would be happy to see this work getting integrated with GHC as a fix for GHC ticket #17075, any help with that would be appreciated.
- Stream Fusion: Practical shortcut fusion for coinductive sequence types
- Stream Fusion From Lists to Streams to Nothing at All
- Now compiles successfully on old GHC versions till 7.10.3.
- Initial release