# fusion-plugin: GHC plugin to make stream fusion more predictable.

[ bsd3, development, library ] [ Propose Tags ]

This plugin provides the programmer with a way to annotate certain types using a Fuse pragma from the fusion-plugin-types package. 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.

This plugin was primarily motivated by streamly but it can be used in general.

Versions [faq] 0.1.0, 0.1.1, 0.2.0 CHANGELOG.md base (>=4.0 && <5.0), fusion-plugin-types (==0.1.*), ghc (>=7.10.3 && <=8.8.2), syb (==0.7.*) [details] BSD-3-Clause (c) 2019 Composewell Technologies Pranay Sashank pranaysashank@composewell.com Development https://github.com/composewell/fusion-plugin https://github.com/composewell/fusion-plugin/issues head: git clone https://github.com/composewell/fusion-plugin by pranaysashank at Wed Feb 19 08:54:25 UTC 2020 NixOS:0.2.0 306 total (128 in the last 30 days) 2.0 (votes: 1) [estimated by Bayesian average] λ λ λ Docs available Last success reported on 2020-02-19

## Modules

[Index] [Quick Jump]

#### Maintainer's Corner

For package maintainers and hackage trustees

[back to package description]

# fusion-plugin

## Motivation

The goal of stream fusion is to eliminate constructors of internal state used in a stream. For example, in case of streamly streams, the constructors of Step type, Yield, Skip and 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.

## Solution

This plugin provides the programmer with a way to annotate certain types using a Fuse pragma from the fusion-plugin-types package. 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 build-depends and pass the following to your ghc-options: ghc-options: -O2 -fplugin=Fusion.Plugin