Skip to content

Instantly share code, notes, and snippets.

@tfausak
Last active May 24, 2022 12:11
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
A GHC plugin for disabling some warnings.
cabal-version: >= 1.10
name: disable-warnings
version: 0.2022.5.24
build-type: Simple
library
build-depends: base, ghc
default-language: Haskell2010
exposed-modules: DisableWarnings
module DisableWarnings where
import qualified Data.List as List
import qualified GHC.Data.Bag as Bag
import qualified GHC.Data.IOEnv as IOEnv
import qualified GHC.Plugins as Plugins
import qualified GHC.Tc.Types as Tc
import qualified GHC.Types.Error as Error
plugin :: Plugins.Plugin
plugin = Plugins.defaultPlugin
{ Plugins.pluginRecompile = Plugins.purePlugin
, Plugins.typeCheckResultAction = \_ _ _ -> do
env <- IOEnv.getEnv
IOEnv.updMutVarM (Tc.tcl_errs $ Tc.env_lcl env) $ \messages -> do
let
(warnings, errors) = Error.partitionMessages messages
newWarnings = Bag.filterBag shouldKeep warnings
pure . Error.mkMessages $ Bag.unionBags newWarnings errors
pure $ Tc.env_gbl env
}
shouldKeep :: Error.MsgEnvelope Error.DecoratedSDoc -> Bool
shouldKeep msgEnvelope =
let shown = show msgEnvelope
in
case Error.errMsgReason msgEnvelope of
Plugins.Reason Plugins.Opt_WarnDuplicateConstraints ->
notInfixOf "HasCallStack" shown
Plugins.Reason Plugins.Opt_WarnRedundantConstraints ->
notInfixOf "HasCallStack" shown
Plugins.Reason Plugins.Opt_WarnUnusedImports ->
notInfixOf "GHC.Stack" shown
_ -> True
notInfixOf :: Eq a => [a] -> [a] -> Bool
notInfixOf x = not . List.isInfixOf x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment