Skip to content

WIP: Refactor plugins and hooks

Sylvain Henry requested to merge hsyl20/ghc:hsyl20/plugins/family into master
Refactor plugins and hooks


Make Plugin and hooks types abstract. By doing this we can store them in
record fields (Plugin and Hooks) without importing concrete types for
them.

   type family SomePluginType :: Type

   data Plugin = Plugin
     { somePluginType :: Maybe ([CommandLineOption] -> SomePluginType)
     , ...
     }

Doing this makes the compiler more modular because concrete instances
are not necessary to use Plugin and Hooks types: in the example above,
we can fill the plugin field with `Nothing :: Maybe SomePluginType` while
keeping `SomePluginType` abstract.

Most plugin users are expected to import GHC.Plugins which exposes
concrete instances for all of these types. Those users don't gain
anything.

This refactoring is beneficial when we split the compiler into several
components. E.g. it trims 30 modules from `ghc-lib-parser` (cf
CountParserDeps test), a package which contains a subset of GHC's
modules necessary to parse Haskell code.

Merge request reports