{"id":20761973,"url":"https://github.com/composewell/fusion-plugin","last_synced_at":"2025-04-30T06:28:21.559Z","repository":{"id":42714361,"uuid":"230518106","full_name":"composewell/fusion-plugin","owner":"composewell","description":"GHC plugin to make stream fusion more predictable","archived":false,"fork":false,"pushed_at":"2023-11-01T12:42:53.000Z","size":189,"stargazers_count":16,"open_issues_count":14,"forks_count":1,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-04-25T22:30:27.052Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Haskell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/composewell.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2019-12-27T21:03:49.000Z","updated_at":"2023-01-18T15:59:36.000Z","dependencies_parsed_at":"2023-11-01T13:38:12.779Z","dependency_job_id":null,"html_url":"https://github.com/composewell/fusion-plugin","commit_stats":{"total_commits":108,"total_committers":4,"mean_commits":27.0,"dds":0.4907407407407407,"last_synced_commit":"608ee3b29ca54a52a29f57550847f8fb95022155"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/composewell%2Ffusion-plugin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/composewell%2Ffusion-plugin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/composewell%2Ffusion-plugin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/composewell%2Ffusion-plugin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/composewell","download_url":"https://codeload.github.com/composewell/fusion-plugin/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251653503,"owners_count":21622139,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-17T10:28:20.282Z","updated_at":"2025-04-30T06:28:21.524Z","avatar_url":"https://github.com/composewell.png","language":"Haskell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# fusion-plugin\n\n[![Hackage](https://img.shields.io/hackage/v/fusion-plugin.svg?style=flat)](https://hackage.haskell.org/package/fusion-plugin)\n![](https://github.com/composewell/fusion-plugin/workflows/Haskell%20CI/badge.svg)\n\n\n## Motivation\n\nThe goal of stream fusion is to eliminate constructors of\ninternal state used in a stream. For example, in case of\n[streamly](https://github.com/composewell/streamly) streams, the\nconstructors of `Step` type, `Yield`, `Skip` and `Stop` would get\neliminated by fusion.  Similarly, constructors of any other intermediate\nstate types get eliminated when stream fusion works correctly. See the papers\nin the reference section for more details on stream fusion.\n\nStream fusion depends on the GHC case-of-case transformations\neliminating intermediate constructors.  Case-of-case transformation in\nturn depends on inlining. During core-to-core transformations GHC may\ncreate several internal bindings (e.g. join points) which may not get\ninlined because their size is too big. Even though we know that after\nfusion the resulting code would be smaller and more efficient. The\nprogrammer cannot force inlining of these bindings as there is no way\nfor the programmer to address these bindings at the source level because\nthey are internal, generated during core-to-core transformations. As a result\nstream fusion fails unpredictably depending on whether GHC was able to inline\nthe internal bindings or not.\n\n[See GHC ticket #17075](https://gitlab.haskell.org/ghc/ghc/issues/17075) for\nmore details.\n\n## Solution\n\nThis plugin provides the programmer with a way to annotate certain\ntypes using a `Fuse` pragma from the\n[fusion-plugin-types](https://hackage.haskell.org/package/fusion-plugin-types)\npackage. The programmer would annotate the types that are to be\neliminated by fusion. During the simplifier phase the plugin goes\nthrough the relevant bindings and if one of these types are found\ninside a binding then that binding is marked to be inlined\nirrespective of the size.\n\n## Using the plugin\n\nThis plugin was primarily motivated by\n[streamly](https://github.com/composewell/streamly) but it can be used in\ngeneral.\n\nTo use this plugin, add this package to your `build-depends`\nand pass the following to your ghc-options:\n`ghc-options: -O2 -fplugin=Fusion.Plugin`\n\n### Plugin options\n\nNote: dump-core does not work for GHC-9.0.x, 9.6.x and 9.8.x.\n\n`-fplugin-opt=Fusion.Plugin:dump-core`: dump core after each\ncore-to-core transformation. Output from each transformation is printed\nin a different file.\n\n`-fplugin-opt=Fusion.Plugin:verbose=1`: report unfused functions. Verbosity\nlevels `2`, `3`, `4` can be used for more verbose output.\n\n## See also\n\nIf you are a library author looking to annotate the types, you need to\nuse the\n[fusion-plugin-types](https://hackage.haskell.org/package/fusion-plugin-types)\npackage.\n\n## Contributing\n\nAll contributions are welcome!  The code is available under Apache-2.0\nlicense [on github](https://github.com/composewell/fusion-plugin).  In\ncase you have any questions or suggestions please contact [the\nmaintainers](mailto:streamly@composewell.com).\n\nWe would be happy to see this work getting integrated with GHC as a fix for\n[GHC ticket #17075](https://gitlab.haskell.org/ghc/ghc/issues/17075), any help\nwith that would be appreciated.\n\n## References\n\n* [Stream Fusion: Practical shortcut fusion for coinductive sequence types](https://ora.ox.ac.uk/objects/uuid:b4971f57-2b94-4fdf-a5c0-98d6935a44da)\n* [Stream Fusion From Lists to Streams to Nothing at All](https://www.researchgate.net/publication/221241130_Stream_Fusion_From_Lists_to_Streams_to_Nothing_at_All)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcomposewell%2Ffusion-plugin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcomposewell%2Ffusion-plugin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcomposewell%2Ffusion-plugin/lists"}