{-# LANGUAGE CPP #-}

module Data.Record.Anon.Internal.Plugin (plugin) where

import GHC.TcPlugin.API

import qualified GHC.Plugins

import Data.Record.Anon.Internal.Plugin.TC.NameResolution
import Data.Record.Anon.Internal.Plugin.TC.Rewriter
import Data.Record.Anon.Internal.Plugin.TC.Solver
import Data.Record.Anon.Internal.Plugin.Source

-- | The large-anon plugins
--
-- This consists of two plugins:
--
-- 1. The type checker plugin forms the heart of this package. It solves
--    the various constraints we have on rows, and computes type-level metadata.
-- 2. The source plugin offers syntactic sugar for record construction.
plugin :: GHC.Plugins.Plugin
plugin :: Plugin
plugin = Plugin
GHC.Plugins.defaultPlugin {
      tcPlugin :: TcPlugin
GHC.Plugins.tcPlugin = \[CommandLineOption]
_args -> forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$
        TcPlugin -> TcPlugin
mkTcPlugin TcPlugin
tcPlugin
    , parsedResultAction :: [CommandLineOption]
-> ModSummary -> HsParsedModule -> Hsc HsParsedModule
GHC.Plugins.parsedResultAction = \[CommandLineOption]
args ModSummary
_modSummary ->
        forall {a}. a -> a
ignoreMessages forall a b. (a -> b) -> a -> b
$ [CommandLineOption] -> HsParsedModule -> Hsc HsParsedModule
sourcePlugin [CommandLineOption]
args
    , pluginRecompile :: [CommandLineOption] -> IO PluginRecompile
GHC.Plugins.pluginRecompile =
        [CommandLineOption] -> IO PluginRecompile
GHC.Plugins.purePlugin
    }
  where
#if __GLASGOW_HASKELL__ >= 904
    ignoreMessages f (GHC.Plugins.ParsedResult modl msgs) =
            (\modl' -> GHC.Plugins.ParsedResult modl' msgs) <$> f modl
#else
    ignoreMessages :: a -> a
ignoreMessages = forall {a}. a -> a
id
#endif

tcPlugin :: TcPlugin
tcPlugin :: TcPlugin
tcPlugin = TcPlugin {
      tcPluginInit :: TcPluginM 'Init ResolvedNames
tcPluginInit    = TcPluginM 'Init ResolvedNames
nameResolution
    , tcPluginSolve :: ResolvedNames -> TcPluginSolver
tcPluginSolve   = ResolvedNames -> TcPluginSolver
solve
    , tcPluginRewrite :: ResolvedNames -> UniqFM TyCon TcPluginRewriter
tcPluginRewrite = ResolvedNames -> UniqFM TyCon TcPluginRewriter
rewrite
    , tcPluginStop :: ResolvedNames -> TcPluginM 'Stop ()
tcPluginStop    = forall a b. a -> b -> a
const forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. Monad m => a -> m a
return ()
    }