Commit 6d147939 authored by quchen's avatar quchen Committed by Ben Gamari

Add -Wcompat warning flag group

Reviewers: hvr, austin, thomie, bgamari

Reviewed By: hvr, austin, thomie, bgamari

Subscribers: thomie

Differential Revision: https://phabricator.haskell.org/D1495

GHC Trac Issues: #11000
parent c05fddde
......@@ -2570,13 +2570,15 @@ dynamic_flags = [
, defGhcFlag "mavx512pf" (noArg (\d -> d{ avx512pf = True }))
------ Warning opts -------------------------------------------------
, defFlag "W" (NoArg (mapM_ setWarningFlag minusWOpts))
, defFlag "Werror" (NoArg (setGeneralFlag Opt_WarnIsError))
, defFlag "Wwarn" (NoArg (unSetGeneralFlag Opt_WarnIsError))
, defFlag "Wall" (NoArg (mapM_ setWarningFlag minusWallOpts))
, defFlag "Wnot" (NoArg (do upd (\dfs -> dfs {warningFlags = IntSet.empty})
deprecate "Use -w instead"))
, defFlag "w" (NoArg (upd (\dfs -> dfs {warningFlags = IntSet.empty})))
, defFlag "W" (NoArg (mapM_ setWarningFlag minusWOpts))
, defFlag "Werror" (NoArg (setGeneralFlag Opt_WarnIsError))
, defFlag "Wwarn" (NoArg (unSetGeneralFlag Opt_WarnIsError))
, defFlag "Wcompat" (NoArg (mapM_ setWarningFlag minusWcompatOpts))
, defFlag "Wno-compat" (NoArg (mapM_ unSetWarningFlag minusWcompatOpts))
, defFlag "Wall" (NoArg (mapM_ setWarningFlag minusWallOpts))
, defFlag "Wnot" (NoArg (do upd (\dfs -> dfs {warningFlags = IntSet.empty})
deprecate "Use -w instead"))
, defFlag "w" (NoArg (upd (\dfs -> dfs {warningFlags = IntSet.empty})))
------ Plugin flags ------------------------------------------------
, defGhcFlag "fplugin-opt" (hasArg addPluginModuleNameOption)
......@@ -3416,6 +3418,7 @@ optLevelFlags -- see Note [Documenting optimisation flags]
--
-- * docs/users_guide/using.xml
-- | Warnings enabled unless specified otherwise
standardWarnings :: [WarningFlag]
standardWarnings -- see Note [Documenting warning flags]
= [ Opt_WarnOverlappingPatterns,
......@@ -3441,8 +3444,8 @@ standardWarnings -- see Note [Documenting warning flags]
Opt_WarnTabs
]
-- | Things you get with -W
minusWOpts :: [WarningFlag]
-- Things you get with -W
minusWOpts
= standardWarnings ++
[ Opt_WarnUnusedTopBinds,
......@@ -3455,8 +3458,8 @@ minusWOpts
Opt_WarnDodgyImports
]
-- | Things you get with -Wall
minusWallOpts :: [WarningFlag]
-- Things you get with -Wall
minusWallOpts
= minusWOpts ++
[ Opt_WarnTypeDefaults,
......@@ -3469,6 +3472,16 @@ minusWallOpts
Opt_WarnUntickedPromotedConstructors
]
-- | Things you get with -Wcompat.
--
-- This is intended to group together warnings that will be enabled by default
-- at some point in the future, so that library authors eager to make their
-- code future compatible to fix issues before they even generate warnings.
minusWcompatOpts :: [WarningFlag]
minusWcompatOpts
= [ Opt_WarnMissingMonadFailInstance
]
enableUnusedBinds :: DynP ()
enableUnusedBinds = mapM_ setWarningFlag unusedBindsFlags
......
......@@ -152,6 +152,17 @@ Compiler
- When printing an out-of-scope error message, GHC will give helpful advice if
the error might be caused by too restrictive imports.
- Added the ``-Wcompat`` warning group, along with its opposite
``-Wno-compat``. Turns on warnings that will be enabled by default in the
future, but remain off in normal compilations for the time being. This
allows library authors eager to make their code future compatible to adapt
to new features before they even generate warnings.
- Added the ``-fwarn-missing-monadfail-instance`` flag. When enabled, this
will issue a warning if a failable pattern is used in a context that does
not have a ``MonadFail`` constraint. This flag represents phase 1 of the
MonadFail proposal (MFP).
GHCi
~~~~
......
......@@ -45,6 +45,23 @@ standard “packages” of warnings:
``-fwarn-missing-exported-sigs``, ``-fwarn-missing-import-lists``
and ``-fwarn-identities``.
``-Wcompat``
.. index::
single: -Wcompat
Turns on warnings that will be enabled by default in the future, but remain
off in normal compilations for the time being. This allows library authors
eager to make their code future compatible to adapt to new features before
they even generate warnings.
This currently enables only ``-fwarn-missing-monadfail-instance``.
``-Wno-compat``
.. index::
single: -Wno-compat
Disables all warnings enabled by ``-Wcompat``.
``-w``
.. index::
single: -w
......@@ -223,8 +240,9 @@ command line.
Warn when a failable pattern is used in a do-block that does not have a
``MonadFail`` instance.
This option is off by default, but will be switched on in a future GHC
release, as part of the MFP (MonadFail Proposal).
Being part of the ``-Wcompat`` option group, this warning is off by
default, but will be switched on in a future GHC release, as part of
the MFP (MonadFail Proposal).
``-fwarn-deprecated-flags``
.. index::
......
-- Test purpose:
-- Ensure that not using -Wcompat does not enable its warnings
-- {-# OPTIONS_GHC -Wcompat #-}
-- {-# OPTIONS_GHC -Wno-compat #-}
module WCompatWarningsNotOn where
monadFail :: Monad m => m a
monadFail = do
Just _ <- undefined
undefined
-- Test purpose:
-- Ensure that using -Wno-compat does not switch on warnings
-- {-# OPTIONS_GHC -Wcompat #-}
{-# OPTIONS_GHC -Wno-compat #-}
module WCompatWarningsOff where
monadFail :: Monad m => m a
monadFail = do
Just _ <- undefined
undefined
-- Test purpose:
-- Ensure that -Wcompat switches on the right warnings
{-# OPTIONS_GHC -Wcompat #-}
-- {-# OPTIONS_GHC -Wno-compat #-}
module WCompatWarningsOn where
monadFail :: Monad m => m a
monadFail = do
Just _ <- undefined
undefined
WCompatWarningsOn.hs:11:5: warning:
Could not deduce (MonadFail m)
arising from the failable pattern ‘Just _’
(this will become an error a future GHC release)
from the context: Monad m
bound by the type signature for:
monadFail :: Monad m => m a
at WCompatWarningsOn.hs:9:14-27
Possible fix:
add (MonadFail m) to the context of
the type signature for:
monadFail :: Monad m => m a
In a stmt of a 'do' block: Just _ <- undefined
In the expression:
do { Just _ <- undefined;
undefined }
In an equation for ‘monadFail’:
monadFail
= do { Just _ <- undefined;
undefined }
-- Test purpose:
-- Ensure that -Wno-compat disables a previously set -Wcompat
{-# OPTIONS_GHC -Wcompat #-}
{-# OPTIONS_GHC -Wno-compat #-}
module WCompatWarningsOnOff where
monadFail :: Monad m => m a
monadFail = do
Just _ <- undefined
undefined
test('WCompatWarningsOn', normal, compile, [''])
test('WCompatWarningsOff', normal, compile, [''])
test('WCompatWarningsNotOn', normal, compile, [''])
test('WCompatWarningsOnOff', normal, compile, [''])
......@@ -19,6 +19,13 @@ warningsOptions =
, flagType = DynamicFlag
, flagReverse = "-w"
}
, flag { flagName = "-Wcompat"
, flagDescription =
"enable future compatibility warnings " ++
"(details in :ref:`options-sanity`)"
, flagType = DynamicFlag
, flagReverse = "-Wno-compat"
}
, flag { flagName = "-Werror"
, flagDescription = "make warnings fatal"
, flagType = DynamicFlag
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment