Commit 2206fa8c authored by quchen's avatar quchen Committed by Herbert Valerio Riedel

Add `-W(no-)xxx` aliases for `-f(no-)warn-xxx` flags

This also updates the user's guide to refer to the `-W`-based warning
flags by default.

Quoting the release note entry:

| Warnings can now be controlled with `-W(no-)...` flags in addition to
| the old `-f(no-)warn...` ones. This was done as the first part of a
| rewrite of the warning system to provide better control over warnings,
| better warning messages, and more common syntax compared to other
| compilers. The old `-fwarn...`-based warning flags will remain
| functional for the forseeable future.

This is part of
https://ghc.haskell.org/wiki/Design/Warnings
and addresses #11218

Reviewed By: hvr, bgamari

Differential Revision: https://phabricator.haskell.org/D1613
parent 3a48e6ef
...@@ -48,7 +48,8 @@ module DynFlags ( ...@@ -48,7 +48,8 @@ module DynFlags (
PkgConfRef(..), PkgConfRef(..),
Option(..), showOpt, Option(..), showOpt,
DynLibLoader(..), DynLibLoader(..),
fFlags, fWarningFlags, fLangFlags, xFlags, fFlags, fLangFlags, xFlags,
wWarningFlags,
dynFlagDependencies, dynFlagDependencies,
tablesNextToCode, mkTablesNextToCode, tablesNextToCode, mkTablesNextToCode,
SigOf, getSigOf, SigOf, getSigOf,
...@@ -503,7 +504,7 @@ data WarningFlag = ...@@ -503,7 +504,7 @@ data WarningFlag =
| Opt_WarnUnusedPatternBinds | Opt_WarnUnusedPatternBinds
| Opt_WarnUnusedImports | Opt_WarnUnusedImports
| Opt_WarnUnusedMatches | Opt_WarnUnusedMatches
| Opt_WarnContextQuantification -- remove in 8.2 | Opt_WarnContextQuantification -- remove in 8.2
| Opt_WarnWarningsDeprecations | Opt_WarnWarningsDeprecations
| Opt_WarnDeprecatedFlags | Opt_WarnDeprecatedFlags
| Opt_WarnAMP -- Introduced in GHC 7.8, obsolete since 7.10 | Opt_WarnAMP -- Introduced in GHC 7.8, obsolete since 7.10
...@@ -2610,8 +2611,10 @@ dynamic_flags = [ ...@@ -2610,8 +2611,10 @@ dynamic_flags = [
, defFlag "fno-glasgow-exts" , defFlag "fno-glasgow-exts"
(NoArg (do disableGlasgowExts (NoArg (do disableGlasgowExts
deprecate "Use individual extensions instead")) deprecate "Use individual extensions instead"))
, defFlag "fwarn-unused-binds" (NoArg enableUnusedBinds) , defFlag "Wunused-binds" (NoArg enableUnusedBinds)
, defFlag "fno-warn-unused-binds" (NoArg disableUnusedBinds) , defFlag "Wno-unused-binds" (NoArg disableUnusedBinds)
, defHiddenFlag "fwarn-unused-binds" (NoArg enableUnusedBinds)
, defHiddenFlag "fno-warn-unused-binds" (NoArg disableUnusedBinds)
------ Safe Haskell flags ------------------------------------------- ------ Safe Haskell flags -------------------------------------------
, defFlag "fpackage-trust" (NoArg setPackageTrust) , defFlag "fpackage-trust" (NoArg setPackageTrust)
...@@ -2622,20 +2625,22 @@ dynamic_flags = [ ...@@ -2622,20 +2625,22 @@ dynamic_flags = [
------ Debugging flags ---------------------------------------------- ------ Debugging flags ----------------------------------------------
, defGhcFlag "g" (OptIntSuffix setDebugLevel) , defGhcFlag "g" (OptIntSuffix setDebugLevel)
] ]
++ map (mkFlag turnOn "" setGeneralFlag ) negatableFlags ++ map (mkFlag turnOn "" setGeneralFlag ) negatableFlags
++ map (mkFlag turnOff "no-" unSetGeneralFlag) negatableFlags ++ map (mkFlag turnOff "no-" unSetGeneralFlag ) negatableFlags
++ map (mkFlag turnOn "d" setGeneralFlag ) dFlags ++ map (mkFlag turnOn "d" setGeneralFlag ) dFlags
++ map (mkFlag turnOff "dno-" unSetGeneralFlag) dFlags ++ map (mkFlag turnOff "dno-" unSetGeneralFlag ) dFlags
++ map (mkFlag turnOn "f" setGeneralFlag ) fFlags ++ map (mkFlag turnOn "f" setGeneralFlag ) fFlags
++ map (mkFlag turnOff "fno-" unSetGeneralFlag) fFlags ++ map (mkFlag turnOff "fno-" unSetGeneralFlag ) fFlags
++ map (mkFlag turnOn "f" setWarningFlag ) fWarningFlags ++ map (mkFlag turnOn "W" setWarningFlag ) wWarningFlags
++ map (mkFlag turnOff "fno-" unSetWarningFlag) fWarningFlags ++ map (mkFlag turnOff "Wno-" unSetWarningFlag ) wWarningFlags
++ map (mkFlag turnOn "f" setExtensionFlag ) fLangFlags ++ map (mkFlag turnOn "fwarn-" setWarningFlag . hideFlag) wWarningFlags
++ map (mkFlag turnOff "fno-" unSetExtensionFlag) fLangFlags ++ map (mkFlag turnOff "fno-warn-" unSetWarningFlag . hideFlag) wWarningFlags
++ map (mkFlag turnOn "X" setExtensionFlag ) xFlags ++ map (mkFlag turnOn "f" setExtensionFlag ) fLangFlags
++ map (mkFlag turnOff "XNo" unSetExtensionFlag) xFlags ++ map (mkFlag turnOff "fno-" unSetExtensionFlag) fLangFlags
++ map (mkFlag turnOn "X" setLanguage) languageFlags ++ map (mkFlag turnOn "X" setExtensionFlag ) xFlags
++ map (mkFlag turnOn "X" setSafeHaskell) safeHaskellFlags ++ map (mkFlag turnOff "XNo" unSetExtensionFlag) xFlags
++ map (mkFlag turnOn "X" setLanguage ) languageFlags
++ map (mkFlag turnOn "X" setSafeHaskell ) safeHaskellFlags
++ [ defFlag "XGenerics" ++ [ defFlag "XGenerics"
(NoArg (deprecate $ (NoArg (deprecate $
"it does nothing; look into -XDefaultSignatures " ++ "it does nothing; look into -XDefaultSignatures " ++
...@@ -2740,6 +2745,13 @@ flagHiddenSpec name flag = flagHiddenSpec' name flag nop ...@@ -2740,6 +2745,13 @@ flagHiddenSpec name flag = flagHiddenSpec' name flag nop
flagHiddenSpec' :: String -> flag -> (TurnOnFlag -> DynP ()) -> FlagSpec flag flagHiddenSpec' :: String -> flag -> (TurnOnFlag -> DynP ()) -> FlagSpec flag
flagHiddenSpec' name flag act = FlagSpec name flag act HiddenFlag flagHiddenSpec' name flag act = FlagSpec name flag act HiddenFlag
-- | Hide a 'FlagSpec' from being displayed in @--show-options@.
--
-- This is for example useful for flags that are obsolete, but should not
-- (yet) be deprecated for compatibility reasons.
hideFlag :: FlagSpec a -> FlagSpec a
hideFlag fs = fs { flagSpecGhcMode = HiddenFlag }
mkFlag :: TurnOnFlag -- ^ True <=> it should be turned on mkFlag :: TurnOnFlag -- ^ True <=> it should be turned on
-> String -- ^ The flag prefix -> String -- ^ The flag prefix
-> (flag -> DynP ()) -- ^ What to do when the flag is found -> (flag -> DynP ()) -- ^ What to do when the flag is found
...@@ -2765,80 +2777,80 @@ useInstead flag turn_on ...@@ -2765,80 +2777,80 @@ useInstead flag turn_on
nop :: TurnOnFlag -> DynP () nop :: TurnOnFlag -> DynP ()
nop _ = return () nop _ = return ()
-- | These @-f\<blah\>@ flags can all be reversed with @-fno-\<blah\>@ -- | These @-W\<blah\>@ flags can all be reversed with @-Wno-\<blah\>@
fWarningFlags :: [FlagSpec WarningFlag] wWarningFlags :: [FlagSpec WarningFlag]
fWarningFlags = [ wWarningFlags = [
-- See Note [Updating flag description in the User's Guide] -- See Note [Updating flag description in the User's Guide]
-- See Note [Supporting CLI completion] -- See Note [Supporting CLI completion]
-- Please keep the list of flags below sorted alphabetically -- Please keep the list of flags below sorted alphabetically
flagSpec "warn-alternative-layout-rule-transitional" flagSpec "alternative-layout-rule-transitional"
Opt_WarnAlternativeLayoutRuleTransitional, Opt_WarnAlternativeLayoutRuleTransitional,
flagSpec' "warn-amp" Opt_WarnAMP flagSpec' "amp" Opt_WarnAMP
(\_ -> deprecate "it has no effect"), (\_ -> deprecate "it has no effect"),
flagSpec' "warn-auto-orphans" Opt_WarnAutoOrphans flagSpec' "auto-orphans" Opt_WarnAutoOrphans
(\_ -> deprecate "it has no effect"), (\_ -> deprecate "it has no effect"),
flagSpec "warn-deferred-type-errors" Opt_WarnDeferredTypeErrors, flagSpec "deferred-type-errors" Opt_WarnDeferredTypeErrors,
flagSpec "warn-deprecations" Opt_WarnWarningsDeprecations, flagSpec "deprecations" Opt_WarnWarningsDeprecations,
flagSpec "warn-deprecated-flags" Opt_WarnDeprecatedFlags, flagSpec "deprecated-flags" Opt_WarnDeprecatedFlags,
flagSpec "warn-deriving-typeable" Opt_WarnDerivingTypeable, flagSpec "deriving-typeable" Opt_WarnDerivingTypeable,
flagSpec "warn-dodgy-exports" Opt_WarnDodgyExports, flagSpec "dodgy-exports" Opt_WarnDodgyExports,
flagSpec "warn-dodgy-foreign-imports" Opt_WarnDodgyForeignImports, flagSpec "dodgy-foreign-imports" Opt_WarnDodgyForeignImports,
flagSpec "warn-dodgy-imports" Opt_WarnDodgyImports, flagSpec "dodgy-imports" Opt_WarnDodgyImports,
flagSpec "warn-empty-enumerations" Opt_WarnEmptyEnumerations, flagSpec "empty-enumerations" Opt_WarnEmptyEnumerations,
flagSpec' "warn-context-quantification" Opt_WarnContextQuantification flagSpec' "context-quantification" Opt_WarnContextQuantification
(\_ -> deprecate "it is subsumed by an error message that cannot be disabled"), (\_ -> deprecate "it is subsumed by an error message that cannot be disabled"),
flagSpec' "warn-duplicate-constraints" Opt_WarnDuplicateConstraints flagSpec' "duplicate-constraints" Opt_WarnDuplicateConstraints
(\_ -> deprecate "it is subsumed by -fwarn-redundant-constraints"), (\_ -> deprecate "it is subsumed by -Wredundant-constraints"),
flagSpec "warn-redundant-constraints" Opt_WarnRedundantConstraints, flagSpec "redundant-constraints" Opt_WarnRedundantConstraints,
flagSpec "warn-duplicate-exports" Opt_WarnDuplicateExports, flagSpec "duplicate-exports" Opt_WarnDuplicateExports,
flagSpec "warn-hi-shadowing" Opt_WarnHiShadows, flagSpec "hi-shadowing" Opt_WarnHiShadows,
flagSpec "warn-implicit-prelude" Opt_WarnImplicitPrelude, flagSpec "implicit-prelude" Opt_WarnImplicitPrelude,
flagSpec "warn-incomplete-patterns" Opt_WarnIncompletePatterns, flagSpec "incomplete-patterns" Opt_WarnIncompletePatterns,
flagSpec "warn-incomplete-record-updates" Opt_WarnIncompletePatternsRecUpd, flagSpec "incomplete-record-updates" Opt_WarnIncompletePatternsRecUpd,
flagSpec "warn-incomplete-uni-patterns" Opt_WarnIncompleteUniPatterns, flagSpec "incomplete-uni-patterns" Opt_WarnIncompleteUniPatterns,
flagSpec "warn-inline-rule-shadowing" Opt_WarnInlineRuleShadowing, flagSpec "inline-rule-shadowing" Opt_WarnInlineRuleShadowing,
flagSpec "warn-identities" Opt_WarnIdentities, flagSpec "identities" Opt_WarnIdentities,
flagSpec "warn-missing-fields" Opt_WarnMissingFields, flagSpec "missing-fields" Opt_WarnMissingFields,
flagSpec "warn-missing-import-lists" Opt_WarnMissingImportList, flagSpec "missing-import-lists" Opt_WarnMissingImportList,
flagSpec "warn-missing-local-sigs" Opt_WarnMissingLocalSigs, flagSpec "missing-local-sigs" Opt_WarnMissingLocalSigs,
flagSpec "warn-missing-methods" Opt_WarnMissingMethods, flagSpec "missing-methods" Opt_WarnMissingMethods,
flagSpec "warn-missing-monadfail-instance" Opt_WarnMissingMonadFailInstance, flagSpec "missing-monadfail-instance" Opt_WarnMissingMonadFailInstance,
flagSpec "warn-semigroup" Opt_WarnSemigroup, flagSpec "semigroup" Opt_WarnSemigroup,
flagSpec "warn-missing-signatures" Opt_WarnMissingSigs, flagSpec "missing-signatures" Opt_WarnMissingSigs,
flagSpec "warn-missing-exported-sigs" Opt_WarnMissingExportedSigs, flagSpec "missing-exported-sigs" Opt_WarnMissingExportedSigs,
flagSpec "warn-monomorphism-restriction" Opt_WarnMonomorphism, flagSpec "monomorphism-restriction" Opt_WarnMonomorphism,
flagSpec "warn-name-shadowing" Opt_WarnNameShadowing, flagSpec "name-shadowing" Opt_WarnNameShadowing,
flagSpec "warn-noncanonical-monad-instances" flagSpec "noncanonical-monad-instances"
Opt_WarnNonCanonicalMonadInstances, Opt_WarnNonCanonicalMonadInstances,
flagSpec "warn-noncanonical-monoid-instances" flagSpec "noncanonical-monoid-instances"
Opt_WarnNonCanonicalMonoidInstances, Opt_WarnNonCanonicalMonoidInstances,
flagSpec "warn-orphans" Opt_WarnOrphans, flagSpec "orphans" Opt_WarnOrphans,
flagSpec "warn-overflowed-literals" Opt_WarnOverflowedLiterals, flagSpec "overflowed-literals" Opt_WarnOverflowedLiterals,
flagSpec "warn-overlapping-patterns" Opt_WarnOverlappingPatterns, flagSpec "overlapping-patterns" Opt_WarnOverlappingPatterns,
flagSpec "warn-missed-specialisations" Opt_WarnMissedSpecs, flagSpec "missed-specialisations" Opt_WarnMissedSpecs,
flagSpec "warn-all-missed-specialisations" Opt_WarnAllMissedSpecs, flagSpec "all-missed-specialisations" Opt_WarnAllMissedSpecs,
flagSpec' "warn-safe" Opt_WarnSafe setWarnSafe, flagSpec' "safe" Opt_WarnSafe setWarnSafe,
flagSpec "warn-trustworthy-safe" Opt_WarnTrustworthySafe, flagSpec "trustworthy-safe" Opt_WarnTrustworthySafe,
flagSpec "warn-tabs" Opt_WarnTabs, flagSpec "tabs" Opt_WarnTabs,
flagSpec "warn-type-defaults" Opt_WarnTypeDefaults, flagSpec "type-defaults" Opt_WarnTypeDefaults,
flagSpec "warn-typed-holes" Opt_WarnTypedHoles, flagSpec "typed-holes" Opt_WarnTypedHoles,
flagSpec "warn-partial-type-signatures" Opt_WarnPartialTypeSignatures, flagSpec "partial-type-signatures" Opt_WarnPartialTypeSignatures,
flagSpec "warn-unrecognised-pragmas" Opt_WarnUnrecognisedPragmas, flagSpec "unrecognised-pragmas" Opt_WarnUnrecognisedPragmas,
flagSpec' "warn-unsafe" Opt_WarnUnsafe setWarnUnsafe, flagSpec' "unsafe" Opt_WarnUnsafe setWarnUnsafe,
flagSpec "warn-unsupported-calling-conventions" flagSpec "unsupported-calling-conventions"
Opt_WarnUnsupportedCallingConventions, Opt_WarnUnsupportedCallingConventions,
flagSpec "warn-unsupported-llvm-version" Opt_WarnUnsupportedLlvmVersion, flagSpec "unsupported-llvm-version" Opt_WarnUnsupportedLlvmVersion,
flagSpec "warn-unticked-promoted-constructors" flagSpec "unticked-promoted-constructors"
Opt_WarnUntickedPromotedConstructors, Opt_WarnUntickedPromotedConstructors,
flagSpec "warn-unused-do-bind" Opt_WarnUnusedDoBind, flagSpec "unused-do-bind" Opt_WarnUnusedDoBind,
flagSpec "warn-unused-imports" Opt_WarnUnusedImports, flagSpec "unused-imports" Opt_WarnUnusedImports,
flagSpec "warn-unused-local-binds" Opt_WarnUnusedLocalBinds, flagSpec "unused-local-binds" Opt_WarnUnusedLocalBinds,
flagSpec "warn-unused-matches" Opt_WarnUnusedMatches, flagSpec "unused-matches" Opt_WarnUnusedMatches,
flagSpec "warn-unused-pattern-binds" Opt_WarnUnusedPatternBinds, flagSpec "unused-pattern-binds" Opt_WarnUnusedPatternBinds,
flagSpec "warn-unused-top-binds" Opt_WarnUnusedTopBinds, flagSpec "unused-top-binds" Opt_WarnUnusedTopBinds,
flagSpec "warn-warnings-deprecations" Opt_WarnWarningsDeprecations, flagSpec "warnings-deprecations" Opt_WarnWarningsDeprecations,
flagSpec "warn-wrong-do-bind" Opt_WarnWrongDoBind, flagSpec "wrong-do-bind" Opt_WarnWrongDoBind,
flagSpec "warn-missing-pat-syn-sigs" Opt_WarnMissingPatSynSigs] flagSpec "missing-pat-syn-sigs" Opt_WarnMissingPatSynSigs]
-- | These @-\<blah\>@ flags can all be reversed with @-no-\<blah\>@ -- | These @-\<blah\>@ flags can all be reversed with @-no-\<blah\>@
negatableFlags :: [FlagSpec GeneralFlag] negatableFlags :: [FlagSpec GeneralFlag]
...@@ -3405,7 +3417,7 @@ enableUnusedBinds = mapM_ setWarningFlag unusedBindsFlags ...@@ -3405,7 +3417,7 @@ enableUnusedBinds = mapM_ setWarningFlag unusedBindsFlags
disableUnusedBinds :: DynP () disableUnusedBinds :: DynP ()
disableUnusedBinds = mapM_ unSetWarningFlag unusedBindsFlags disableUnusedBinds = mapM_ unSetWarningFlag unusedBindsFlags
-- Things you get with -fwarn-unused-binds -- Things you get with -Wunused-binds
unusedBindsFlags :: [WarningFlag] unusedBindsFlags :: [WarningFlag]
unusedBindsFlags = [ Opt_WarnUnusedTopBinds unusedBindsFlags = [ Opt_WarnUnusedTopBinds
, Opt_WarnUnusedLocalBinds , Opt_WarnUnusedLocalBinds
......
...@@ -270,8 +270,8 @@ ioMsgMaybe' ioA = do ...@@ -270,8 +270,8 @@ ioMsgMaybe' ioA = do
#ifdef GHCI #ifdef GHCI
hscTcRnLookupRdrName :: HscEnv -> Located RdrName -> IO [Name] hscTcRnLookupRdrName :: HscEnv -> Located RdrName -> IO [Name]
hscTcRnLookupRdrName hsc_env0 rdr_name hscTcRnLookupRdrName hsc_env0 rdr_name
= runInteractiveHsc hsc_env0 $ = runInteractiveHsc hsc_env0 $
do { hsc_env <- getHscEnv do { hsc_env <- getHscEnv
; ioMsgMaybe $ tcRnLookupRdrName hsc_env rdr_name } ; ioMsgMaybe $ tcRnLookupRdrName hsc_env rdr_name }
#endif #endif
...@@ -809,8 +809,8 @@ hscFileFrontEnd mod_summary = do ...@@ -809,8 +809,8 @@ hscFileFrontEnd mod_summary = do
-- --
-- It used to be that we only did safe inference on modules that had no Safe -- It used to be that we only did safe inference on modules that had no Safe
-- Haskell flags, but now we perform safe inference on all modules as we want -- Haskell flags, but now we perform safe inference on all modules as we want
-- to allow users to set the `-fwarn-safe`, `-fwarn-unsafe` and -- to allow users to set the `-Wsafe`, `-Wunsafe` and
-- `-fwarn-trustworthy-safe` flags on Trustworthy and Unsafe modules so that a -- `-Wtrustworthy-safe` flags on Trustworthy and Unsafe modules so that a
-- user can ensure their assumptions are correct and see reasons for why a -- user can ensure their assumptions are correct and see reasons for why a
-- module is safe or unsafe. -- module is safe or unsafe.
-- --
......
...@@ -182,7 +182,7 @@ execStmt stmt ExecOptions{..} = do ...@@ -182,7 +182,7 @@ execStmt stmt ExecOptions{..} = do
-- wait on this when a computation is running -- wait on this when a computation is running
statusMVar <- liftIO $ newEmptyMVar statusMVar <- liftIO $ newEmptyMVar
-- Turn off -fwarn-unused-local-binds when running a statement, to hide -- Turn off -Wunused-local-binds when running a statement, to hide
-- warnings about the implicit bindings we introduce. -- warnings about the implicit bindings we introduce.
let ic = hsc_IC hsc_env -- use the interactive dflags let ic = hsc_IC hsc_env -- use the interactive dflags
idflags' = ic_dflags ic `wopt_unset` Opt_WarnUnusedLocalBinds idflags' = ic_dflags ic `wopt_unset` Opt_WarnUnusedLocalBinds
......
...@@ -178,7 +178,7 @@ data NameMaker ...@@ -178,7 +178,7 @@ data NameMaker
= LamMk -- Lambdas = LamMk -- Lambdas
Bool -- True <=> report unused bindings Bool -- True <=> report unused bindings
-- (even if True, the warning only comes out -- (even if True, the warning only comes out
-- if -fwarn-unused-matches is on) -- if -Wunused-matches is on)
| LetMk -- Let bindings, incl top level | LetMk -- Let bindings, incl top level
-- Do *not* check for unused bindings -- Do *not* check for unused bindings
......
...@@ -491,7 +491,7 @@ warnMissingAT :: Name -> TcM () ...@@ -491,7 +491,7 @@ warnMissingAT :: Name -> TcM ()
warnMissingAT name warnMissingAT name
= do { warn <- woptM Opt_WarnMissingMethods = do { warn <- woptM Opt_WarnMissingMethods
; traceTc "warn" (ppr name <+> ppr warn) ; traceTc "warn" (ppr name <+> ppr warn)
; warnTc warn -- Warn only if -fwarn-missing-methods ; warnTc warn -- Warn only if -Wmissing-methods
(ptext (sLit "No explicit") <+> text "associated type" (ptext (sLit "No explicit") <+> text "associated type"
<+> ptext (sLit "or default declaration for ") <+> ptext (sLit "or default declaration for ")
<+> quotes (ppr name)) } <+> quotes (ppr name)) }
...@@ -443,7 +443,7 @@ Consider this (see Trac #1954): ...@@ -443,7 +443,7 @@ Consider this (see Trac #1954):
module Bug(P) where module Bug(P) where
newtype P a = MkP (IO a) deriving Monad newtype P a = MkP (IO a) deriving Monad
If you compile with -fwarn-unused-binds you do not expect the warning If you compile with -Wunused-binds you do not expect the warning
"Defined but not used: data consructor MkP". Yet the newtype deriving "Defined but not used: data consructor MkP". Yet the newtype deriving
code does not explicitly mention MkP, but it should behave as if you code does not explicitly mention MkP, but it should behave as if you
had written had written
......
...@@ -259,7 +259,7 @@ data ReportErrCtxt ...@@ -259,7 +259,7 @@ data ReportErrCtxt
, cec_expr_holes :: HoleChoice -- Holes in expressions , cec_expr_holes :: HoleChoice -- Holes in expressions
, cec_type_holes :: HoleChoice -- Holes in types , cec_type_holes :: HoleChoice -- Holes in types
, cec_warn_redundant :: Bool -- True <=> -fwarn-redundant-constraints , cec_warn_redundant :: Bool -- True <=> -Wredundant-constraints
, cec_suppress :: Bool -- True <=> More important errors have occurred, , cec_suppress :: Bool -- True <=> More important errors have occurred,
-- so create bindings if need be, but -- so create bindings if need be, but
...@@ -590,7 +590,7 @@ maybeReportHoleError ctxt ct err ...@@ -590,7 +590,7 @@ maybeReportHoleError ctxt ct err
-- Otherwise this is a typed hole in an expression -- Otherwise this is a typed hole in an expression
| otherwise | otherwise
= -- If deferring, report a warning only if -fwarn-typed-holds is on = -- If deferring, report a warning only if -Wtyped-holds is on
case cec_expr_holes ctxt of case cec_expr_holes ctxt of
HoleError -> reportError err HoleError -> reportError err
HoleWarn -> reportWarning err HoleWarn -> reportWarning err
......
...@@ -340,7 +340,7 @@ How is this implemented? It's complicated! So we'll step through it all: ...@@ -340,7 +340,7 @@ How is this implemented? It's complicated! So we'll step through it all:
compilation should fail. These are handled as normal constraint resolution compilation should fail. These are handled as normal constraint resolution
failures from here-on (see step 6). failures from here-on (see step 6).
Otherwise, we may be inferring safety (or using `-fwarn-unsafe`), and Otherwise, we may be inferring safety (or using `-Wunsafe`), and
compilation should succeed, but print warnings and/or mark the compiled module compilation should succeed, but print warnings and/or mark the compiled module
as `-XUnsafe`. In this case, we call `insertSafeOverlapFailureTcS` which adds as `-XUnsafe`. In this case, we call `insertSafeOverlapFailureTcS` which adds
the unsafe (but resolved!) constraint to the `inert_safehask` field of the unsafe (but resolved!) constraint to the `inert_safehask` field of
...@@ -350,7 +350,7 @@ How is this implemented? It's complicated! So we'll step through it all: ...@@ -350,7 +350,7 @@ How is this implemented? It's complicated! So we'll step through it all:
constraint resolution. Once finished, we call `getSafeOverlapFailures` to constraint resolution. Once finished, we call `getSafeOverlapFailures` to
retrieve the list of overlapping instances that were successfully resolved, retrieve the list of overlapping instances that were successfully resolved,
but unsafe. Remember, this is only applicable for generating warnings but unsafe. Remember, this is only applicable for generating warnings
(`-fwarn-unsafe`) or inferring a module unsafe. `-XSafe` and `-XTrustworthy` (`-Wunsafe`) or inferring a module unsafe. `-XSafe` and `-XTrustworthy`
cause compilation failure by not resolving the unsafe constraint at all. cause compilation failure by not resolving the unsafe constraint at all.
`simpl_top` returns a list of unresolved constraints (all types), and resolved `simpl_top` returns a list of unresolved constraints (all types), and resolved
(but unsafe) resolved dictionary constraints. (but unsafe) resolved dictionary constraints.
......
...@@ -160,6 +160,13 @@ Language ...@@ -160,6 +160,13 @@ Language
Compiler Compiler
~~~~~~~~ ~~~~~~~~
- Warnings can now be controlled with ``-W(no-)...`` flags in addition to
the old ``-f(no-)warn...`` ones. This was done as the first part of a
rewrite of the warning system to provide better control over warnings,
better warning messages, and more common syntax compared to other
compilers. The old ``-f``-based warning flags will remain functional for
the forseeable future.
- Added the option ``-dth-dec-file``. This dumps out a .th.hs file of - Added the option ``-dth-dec-file``. This dumps out a .th.hs file of
all Template Haskell declarations in a corresponding .hs file. The all Template Haskell declarations in a corresponding .hs file. The
idea is that application developers can check this into their idea is that application developers can check this into their
...@@ -184,14 +191,14 @@ Compiler ...@@ -184,14 +191,14 @@ Compiler
Enabling ``-fworker-wrapper`` while strictness analysis is disabled (by Enabling ``-fworker-wrapper`` while strictness analysis is disabled (by
``-fno-strictness``) has no effect. ``-fno-strictness``) has no effect.
- Added the options ``-fwarn-missed-specialisations`` and - Added the options ``-Wmissed-specialisations`` and
``-fwarn-all-missed-specialisations``. When enabled, the simplifier will ``-Wall-missed-specialisations``. When enabled, the simplifier will
produce a warning when a overloaded imported function cannot be produce a warning when a overloaded imported function cannot be
specialised (typically due to a missing ``INLINEABLE`` pragma). This specialised (typically due to a missing ``INLINEABLE`` pragma). This
is intended to alert users to cases where they apply ``INLINEABLE`` but is intended to alert users to cases where they apply ``INLINEABLE`` but
may not get the speed-up they expect. may not get the speed-up they expect.
- Added the option ``-fwarn-noncanonical-monad-instances`` which helps - Added the option ``-Wnoncanonical-monad-instances`` which helps
detect noncanonical ``Applicative``/``Monad`` instance definitions. detect noncanonical ``Applicative``/``Monad`` instance definitions.
See flag description in :ref:`options-sanity` for more details. See flag description in :ref:`options-sanity` for more details.
...@@ -204,19 +211,19 @@ Compiler ...@@ -204,19 +211,19 @@ Compiler
allows library authors eager to make their code future compatible to adapt allows library authors eager to make their code future compatible to adapt
to new features before they even generate warnings. to new features before they even generate warnings.
- Added the ``-fwarn-missing-monadfail-instance`` flag. When enabled, this - Added the ``-Wmissing-monadfail-instance`` flag. When enabled, this
will issue a warning if a failable pattern is used in a context that does 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 not have a ``MonadFail`` constraint. This flag represents phase 1 of the
`MonadFail Proposal (MFP) `MonadFail Proposal (MFP)
<https://prime.haskell.org/wiki/Libraries/Proposals/MonadFail>`__. <https://prime.haskell.org/wiki/Libraries/Proposals/MonadFail>`__.
- Added the ``-fwarn-semigroup`` flag. When enabled, this - Added the ``-Wsemigroup`` flag. When enabled, this
will issue a warning if a type is an instance of ``Monoid`` but not will issue a warning if a type is an instance of ``Monoid`` but not
``Semigroup``, and when a custom definition ``(<>)`` is made. Fixing these ``Semigroup``, and when a custom definition ``(<>)`` is made. Fixing these
warnings makes sure the definition of ``Semigroup`` as a superclass of warnings makes sure the definition of ``Semigroup`` as a superclass of
``Monoid`` does not break any code. ``Monoid`` does not break any code.
- Added the ``-fwarn-missing-pat-syn-sigs`` flag. When enabled, this will issue - Added the ``-Wmissing-pat-syn-sigs`` flag. When enabled, this will issue
a warning when a pattern synonym definition doesn't have a type signature. a warning when a pattern synonym definition doesn't have a type signature.
It is turned off by default but enabled by ``-Wall``. It is turned off by default but enabled by ``-Wall``.
......
...@@ -1372,7 +1372,7 @@ breakpoint. Note: GHC considers the TAB character to have a width of 1, ...@@ -1372,7 +1372,7 @@ breakpoint. Note: GHC considers the TAB character to have a width of 1,
wherever it occurs; in other words it counts characters, rather than wherever it occurs; in other words it counts characters, rather than
columns. This matches what some editors do, and doesn't match others. columns. This matches what some editors do, and doesn't match others.
The best advice is to avoid tab characters in your source code The best advice is to avoid tab characters in your source code
altogether (see ``-fwarn-tabs`` in :ref:`options-sanity`). altogether (see ``-Wtabs`` in :ref:`options-sanity`).
If the module is omitted, then the most recently-loaded module is used. If the module is omitted, then the most recently-loaded module is used.
...@@ -2697,11 +2697,11 @@ Setting GHC command-line options in GHCi ...@@ -2697,11 +2697,11 @@ Setting GHC command-line options in GHCi
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Normal GHC command-line options may also be set using ``:set``. For Normal GHC command-line options may also be set using ``:set``. For
example, to turn on ``-fwarn-missing-signatures``, you would say: example, to turn on ``-Wmissing-signatures``, you would say:
:: ::
Prelude> :set -fwarn-missing-signatures Prelude> :set -Wmissing-signatures
Any GHC command-line option that is designated as dynamic (see the table Any GHC command-line option that is designated as dynamic (see the table
in :ref:`flag-reference`), may be set using ``:set``. To unset an in :ref:`flag-reference`), may be set using ``:set``. To unset an
...@@ -2712,7 +2712,7 @@ option, you can set the reverse option: ...@@ -2712,7 +2712,7 @@ option, you can set the reverse option:
:: ::
Prelude> :set -fno-warn-incomplete-patterns -XNoMultiParamTypeClasses Prelude> :set -Wno-incomplete-patterns -XNoMultiParamTypeClasses
:ref:`flag-reference` lists the reverse for each option where :ref:`flag-reference` lists the reverse for each option where
applicable. applicable.
......
...@@ -2029,7 +2029,7 @@ example, consider these two candidate definitions of ``absurd``: ...@@ -2029,7 +2029,7 @@ example, consider these two candidate definitions of ``absurd``:
We much prefer (B). Why? Because GHC can figure out that We much prefer (B). Why? Because GHC can figure out that
``(True :~: False)`` is an empty type. So (B) has no partiality and GHC ``(True :~: False)`` is an empty type. So (B) has no partiality and GHC
should be able to compile with ``-fwarn-incomplete-patterns``. (Though should be able to compile with ``-Wincomplete-patterns``. (Though
the pattern match checking is not yet clever enough to do that.) On the the pattern match checking is not yet clever enough to do that.) On the
other hand (A) looks dangerous, and GHC doesn't check to make sure that, other hand (A) looks dangerous, and GHC doesn't check to make sure that,
in fact, the function can never get called. in fact, the function can never get called.
...@@ -2156,7 +2156,7 @@ interests of supporting backward compatibility; for example, a newer ...@@ -2156,7 +2156,7 @@ interests of supporting backward compatibility; for example, a newer
version of ``A`` might export ``g``, and you want ``B`` to work in version of ``A`` might export ``g``, and you want ``B`` to work in
either case. either case.
The warning ``-fwarn-dodgy-imports``, which is off by default but The warning ``-Wdodgy-imports``, which is off by default but
included with ``-W``, warns if you hide something that the imported included with ``-W``, warns if you hide something that the imported
module does not export. module does not export.
...@@ -4494,7 +4494,7 @@ methods. ...@@ -4494,7 +4494,7 @@ methods.
This is This is
mostly useful in classes whose `minimal set <#minimal-pragma>`__ is mostly useful in classes whose `minimal set <#minimal-pragma>`__ is
empty, and especially when writing empty, and especially when writing
`generic functions <#generic-programming>`__. `generic functions <#generic-programming>`__.
As an example, consider a simple pretty-printer class ``SPretty``, which outputs As an example, consider a simple pretty-printer class ``SPretty``, which outputs
pretty strings: :: pretty strings: ::
...@@ -8510,7 +8510,7 @@ example: ...@@ -8510,7 +8510,7 @@ example:
newtype Swizzle' = MkSwizzle' (Ord a => [a] -> [a]) newtype Swizzle' = MkSwizzle' (Ord a => [a] -> [a])
As of GHC 7.10, this is deprecated. The As of GHC 7.10, this is deprecated. The
``-fwarn-context-quantification`` flag detects this situation and issues ``-Wcontext-quantification`` flag detects this situation and issues
a warning. In GHC 8.0 this flag was deprecated and declarations such as a warning. In GHC 8.0 this flag was deprecated and declarations such as
``MkSwizzle'`` will cause an out-of-scope error. ``MkSwizzle'`` will cause an out-of-scope error.
...@@ -9264,7 +9264,7 @@ in a partial type signature, informing the programmer of the inferred ...@@ -9264,7 +9264,7 @@ in a partial type signature, informing the programmer of the inferred
type. When the ``-XPartialTypeSignatures`` flag is enabled, the type. When the ``-XPartialTypeSignatures`` flag is enabled, the
type-checker will accept the inferred type for each hole, generating type-checker will accept the inferred type for each hole, generating
warnings instead of errors. Additionally, these warnings can be silenced warnings instead of errors. Additionally, these warnings can be silenced
with the ``-fno-warn-partial-type-signatures`` flag. with the ``-Wno-partial-type-signatures`` flag.
.. _pts-syntax: .. _pts-syntax:
...@@ -9563,7 +9563,7 @@ Enabling deferring of type errors ...@@ -9563,7 +9563,7 @@ Enabling deferring of type errors
The flag ``-fdefer-type-errors`` controls whether type errors are The flag ``-fdefer-type-errors`` controls whether type errors are
deferred to runtime. Type errors will still be emitted as warnings, but deferred to runtime. Type errors will still be emitted as warnings, but
will not prevent compilation. You can use will not prevent compilation. You can use
``-fno-warn-deferred-type-errors`` to suppress these warnings. ``-Wno-deferred-type-errors`` to suppress these warnings.
This flag implies the ``-fdefer-typed-holes`` flag, which enables this This flag implies the ``-fdefer-typed-holes`` flag, which enables this
behaviour for `typed holes <#typed-holes>`__. Should you so wish, it is behaviour for `typed holes <#typed-holes>`__. Should you so wish, it is
...@@ -11250,7 +11250,7 @@ library in which one module gathers together and re-exports the exports ...@@ -11250,7 +11250,7 @@ library in which one module gathers together and re-exports the exports
of several others. of several others.
You can suppress the warnings with the flag You can suppress the warnings with the flag
``-fno-warn-warnings-deprecations``. ``-Wno-warnings-deprecations``.
.. _minimal-pragma: .. _minimal-pragma:
...@@ -11296,10 +11296,10 @@ If no ``MINIMAL`` pragma is given in the class declaration, it is just as if ...@@ -11296,10 +11296,10 @@ If no ``MINIMAL`` pragma is given in the class declaration, it is just as if
a pragma ``{-# MINIMAL op1, op2, ..., opn #-}`` was given, where the a pragma ``{-# MINIMAL op1, op2, ..., opn #-}`` was given, where the
``opi`` are the</