{-# LANGUAGE CPP #-}

module GHC.NotExport.Plugin (plugin) where

#if MIN_VERSION_ghc(9,0,0)
import GHC.Driver.Plugins
import GHC.Types.Avail
import GHC.Types.Name
import GHC.Tc.Types
import GHC.Utils.Outputable
#else
import GhcPlugins
import Plugins
import TcRnTypes
import Avail
#endif

import Data.List (isPrefixOf)

plugin :: Plugin
plugin :: Plugin
plugin =
  Plugin
defaultPlugin
    { typeCheckResultAction :: [CommandLineOption] -> ModSummary -> TcGblEnv -> TcM TcGblEnv
typeCheckResultAction = forall {m :: * -> *} {p} {p}.
Monad m =>
p -> p -> TcGblEnv -> m TcGblEnv
notExportPlugins,
      pluginRecompile :: [CommandLineOption] -> IO PluginRecompile
pluginRecompile = [CommandLineOption] -> IO PluginRecompile
purePlugin
    }

notExportPlugins :: p -> p -> TcGblEnv -> m TcGblEnv
notExportPlugins p
cmdOptions p
modSummary TcGblEnv
env = do
  let updated_tcg_exports :: [AvailInfo]
updated_tcg_exports = forall a. (a -> Bool) -> [a] -> [a]
filter (\AvailInfo
v -> Bool -> Bool
not (forall a. Eq a => [a] -> [a] -> Bool
isPrefixOf CommandLineOption
"inline_c_ffi" ((SDoc -> CommandLineOption
showSDocUnsafe forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Outputable a => a -> SDoc
ppr forall b c a. (b -> c) -> (a -> b) -> a -> c
. Name -> OccName
nameOccName forall b c a. (b -> c) -> (a -> b) -> a -> c
. AvailInfo -> Name
availName) AvailInfo
v))) forall a b. (a -> b) -> a -> b
$ TcGblEnv -> [AvailInfo]
tcg_exports TcGblEnv
env
  forall (m :: * -> *) a. Monad m => a -> m a
return TcGblEnv
env {tcg_exports :: [AvailInfo]
tcg_exports = [AvailInfo]
updated_tcg_exports}