Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,50 @@ in a different file.
`-fplugin-opt=Fusion.Plugin:verbose=1`: report unfused functions. Verbosity
levels `2`, `3`, `4` can be used for more verbose output.

### Reporting Programmer Annotated Binders

The `verbose=N` report above covers the whole module. To check a single
binding instead, annotate it with `Inspect` from `Fusion.Plugin.Types`
(from the `fusion-plugin-types` package). This works regardless of
`verbose=N` -- an `Inspect` annotated binding is always reported, even when
the plugin is otherwise silent:

```haskell
{-# LANGUAGE TemplateHaskellQuotes #-}

import Fusion.Plugin.Types
(checkFusion, forbid, allow, forbidTypes, allowOnlyTypes)

-- checkFusion: Fuse-annotated types are forbidden by default, with an extra
-- forbid-list and an overriding allow-list.

-- Just enforce the baseline: nothing Fuse-annotated may survive to core.
{-# ANN function1 (checkFusion mempty) #-}
function1 :: ...

-- Also forbid Text even though it isn't Fuse-annotated.
{-# ANN function1a (checkFusion (forbid [''Text])) #-}
function1a :: ...

-- Forbid Text, but explicitly allow ByteString even if it's Fuse-annotated
-- or would otherwise be caught.
{-# ANN function1b (checkFusion (forbid [''Text] <> allow [''ByteString])) #-}
function1b :: ...

-- forbidTypes: blocklist -- only the named types are disallowed, everything
-- else in core is fine.
{-# ANN function2 (forbidTypes [''SomeType]) #-}
function2 :: ...

-- allowOnlyTypes: allowlist -- only the named types may appear, everything
-- else in core fails the check.
{-# ANN function3 (allowOnlyTypes [''Int, ''IO]) #-}
function3 :: ...
```

Type references are TH `Name`s (`''SomeType`), so a typo or a stale
reference to a renamed type is a compile error, not a silently-stale check.

## See also

If you are a library author looking to annotate the types, you need to
Expand Down
19 changes: 10 additions & 9 deletions fusion-plugin.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,17 @@ source-repository head

library
exposed-modules: Fusion.Plugin
build-depends: base >= 4.0 && < 5
, containers >= 0.5.6.2 && < 0.9
, directory >= 1.2.2.0 && < 1.4
, filepath >= 1.4 && < 1.6
, ghc >= 7.10.3 && < 9.15
, syb >= 0.7 && < 0.8
, time >= 1.5 && < 1.16
, transformers >= 0.4 && < 0.7
build-depends: base >= 4.0 && < 5
, containers >= 0.5.6.2 && < 0.9
, directory >= 1.2.2.0 && < 1.4
, filepath >= 1.4 && < 1.6
, ghc >= 7.10.3 && < 9.15
, syb >= 0.7 && < 0.8
, template-haskell
, time >= 1.5 && < 1.16
, transformers >= 0.4 && < 0.7

, fusion-plugin-types >= 0.1 && < 0.2
, fusion-plugin-types >= 0.2 && < 0.3
hs-source-dirs: src
ghc-options: -Wall
if impl(ghc >= 8.0)
Expand Down
Loading
Loading