[Git][ghc/ghc][master] Add -Winconsistent-flags warning

Marge Bot (@marge-bot) gitlab at gitlab.haskell.org
Wed Sep 13 00:31:28 UTC 2023



Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC


Commits:
21a906c2 by Matthew Pickering at 2023-09-12T17:21:04+02:00
Add -Winconsistent-flags warning

The warning fires when inconsistent command line flags are passed.

For example:

* -dynamic-too and -dynamic
* -dynamic-too on windows
* -O and --interactive
* etc

This is on by default and allows users to control whether the warning is
displayed and whether it should be an error or not.

Fixes #22572

- - - - -


8 changed files:

- compiler/GHC/Driver/Errors/Ppr.hs
- compiler/GHC/Driver/Flags.hs
- docs/users_guide/9.8.1-notes.rst
- docs/users_guide/using-warnings.rst
- testsuite/tests/driver/T20436/T20436.stderr
- testsuite/tests/ghc-api/T10052/T10052.stderr
- testsuite/tests/ghci/should_fail/T10549.stderr
- testsuite/tests/th/T8333.stderr


Changes:

=====================================
compiler/GHC/Driver/Errors/Ppr.hs
=====================================
@@ -294,7 +294,7 @@ instance Diagnostic DriverMessage where
       -> ErrorWithoutFlag
     DriverInterfaceError reason -> diagnosticReason reason
     DriverInconsistentDynFlags {}
-      -> WarningWithoutFlag
+      -> WarningWithFlag Opt_WarnInconsistentFlags
     DriverSafeHaskellIgnoredExtension {}
       -> WarningWithoutFlag
     DriverPackageTrustIgnored {}


=====================================
compiler/GHC/Driver/Flags.hs
=====================================
@@ -692,8 +692,9 @@ data WarningFlag =
    | Opt_WarnMissingRoleAnnotations                  -- Since 9.8
    | Opt_WarnImplicitRhsQuantification               -- Since 9.8
    | Opt_WarnIncompleteExportWarnings                -- Since 9.8
-   | Opt_WarnIncompleteRecordSelectors                  -- Since 9.10
+   | Opt_WarnIncompleteRecordSelectors               -- Since 9.10
    | Opt_WarnBadlyStagedTypes                        -- Since 9.10
+   | Opt_WarnInconsistentFlags                       -- Since 9.8
    deriving (Eq, Ord, Show, Enum)
 
 -- | Return the names of a WarningFlag
@@ -804,8 +805,9 @@ warnFlagNames wflag = case wflag of
   Opt_WarnMissingRoleAnnotations                  -> "missing-role-annotations" :| []
   Opt_WarnImplicitRhsQuantification               -> "implicit-rhs-quantification" :| []
   Opt_WarnIncompleteExportWarnings                -> "incomplete-export-warnings" :| []
-  Opt_WarnIncompleteRecordSelectors                  -> "incomplete-record-selectors" :| []
+  Opt_WarnIncompleteRecordSelectors               -> "incomplete-record-selectors" :| []
   Opt_WarnBadlyStagedTypes                        -> "badly-staged-types" :| []
+  Opt_WarnInconsistentFlags                       -> "inconsistent-flags" :| []
 
 -- -----------------------------------------------------------------------------
 -- Standard sets of warning options
@@ -945,7 +947,8 @@ standardWarnings -- see Note [Documenting warning flags]
         Opt_WarnGADTMonoLocalBinds,
         Opt_WarnLoopySuperclassSolve,
         Opt_WarnBadlyStagedTypes,
-        Opt_WarnTypeEqualityRequiresOperators
+        Opt_WarnTypeEqualityRequiresOperators,
+        Opt_WarnInconsistentFlags
       ]
 
 -- | Things you get with -W


=====================================
docs/users_guide/9.8.1-notes.rst
=====================================
@@ -188,6 +188,10 @@ Compiler
   by default for now whilst we consider more carefully an appropiate fix.
   (See :ghc-ticket:`23469`, :ghc-ticket:`23109`, :ghc-ticket:`21229`, :ghc-ticket:`23445`)
 
+- The warning about incompatible command line flags can now be controlled with the
+  :ghc-flag:`-Winconsistent-flags`. In particular this allows you to silence a warning
+  when using optimisation flags with :ghc-flag:`--interactive` mode.
+
 GHCi
 ~~~~
 


=====================================
docs/users_guide/using-warnings.rst
=====================================
@@ -78,7 +78,8 @@ as ``-Wno-...`` for every individual warning in the group.
         * :ghc-flag:`-Wforall-identifier`
         * :ghc-flag:`-Wgadt-mono-local-binds`
         * :ghc-flag:`-Wtype-equality-requires-operators`
-        * :ghc-flag:`-Wbadly-staged-types"
+        * :ghc-flag:`-Wbadly-staged-types`
+        * :ghc-flag:`-Winconsistent-flags`
 
 .. ghc-flag:: -W
     :shortdesc: enable normal warnings
@@ -2461,7 +2462,7 @@ of ``-W(no-)*``.
     :reverse: -Wno-role-annotations-signatures
     :category:
 
-    :since: 9.8
+    :since: 9.8.1
     :default: off
 
     .. index::
@@ -2483,7 +2484,7 @@ of ``-W(no-)*``.
     :reverse: -Wno-implicit-rhs-quantification
     :category:
 
-    :since: 9.8
+    :since: 9.8.1
     :default: off
 
     In accordance with `GHC Proposal #425
@@ -2500,9 +2501,6 @@ of ``-W(no-)*``.
 
     This warning detects code that will be affected by this breaking change.
 
-If you're feeling really paranoid, the :ghc-flag:`-dcore-lint` option is a good choice.
-It turns on heavyweight intra-pass sanity-checking within GHC. (It checks GHC's
-sanity, not yours.)
 
 .. ghc-flag:: -Wincomplete-export-warnings
     :shortdesc: warn when some but not all of exports for a name are warned about
@@ -2550,3 +2548,21 @@ sanity, not yours.)
 
     This is badly staged program, and the ``tardy (Proxy @Int)`` won't produce
     a type representation of ``Int``, but rather a local name ``a``.
+
+.. ghc-flag:: -Winconsistent-flags
+    :shortdesc: warn when command line options are inconsistent in some way.
+    :type: dynamic
+    :reverse: -Wno-inconsistent-flags
+
+    :since: 9.8.1
+    :default: on
+
+    Warn when command line options are inconsistent in some way.
+
+    For example, when using GHCi, optimisation flags are ignored and a warning is
+    issued. Another example is :ghc-flag:`-dynamic` is ignored when :ghc-flag:`-dynamic-too`
+    is passed.
+
+If you're feeling really paranoid, the :ghc-flag:`-dcore-lint` option is a good choice.
+It turns on heavyweight intra-pass sanity-checking within GHC. (It checks GHC's
+sanity, not yours.)


=====================================
testsuite/tests/driver/T20436/T20436.stderr
=====================================
@@ -1,3 +1,3 @@
 
-when making flags consistent: warning: [GHC-74335]
+when making flags consistent: warning: [GHC-74335] [-Winconsistent-flags (in -Wdefault)]
     -dynamic-too is ignored when using -dynamic


=====================================
testsuite/tests/ghc-api/T10052/T10052.stderr
=====================================
@@ -1,3 +1,3 @@
 
-when making flags consistent: warning: [GHC-74335]
+when making flags consistent: warning: [GHC-74335] [-Winconsistent-flags]
     Ignoring optimization flags since they are experimental for the byte-code interpreter. Pass -fno-unoptimized-core-for-interpreter to enable this feature.


=====================================
testsuite/tests/ghci/should_fail/T10549.stderr
=====================================
@@ -1,2 +1,3 @@
-when making flags consistent: warning: [GHC-74335]
+
+when making flags consistent: warning: [GHC-74335] [-Winconsistent-flags (in -Wdefault)]
     Ignoring optimization flags since they are experimental for the byte-code interpreter. Pass -fno-unoptimized-core-for-interpreter to enable this feature.


=====================================
testsuite/tests/th/T8333.stderr
=====================================
@@ -1,3 +1,3 @@
 
-when making flags consistent: warning: [GHC-74335]
+when making flags consistent: warning: [GHC-74335] [-Winconsistent-flags (in -Wdefault)]
     Ignoring optimization flags since they are experimental for the byte-code interpreter. Pass -fno-unoptimized-core-for-interpreter to enable this feature.



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/21a906c28da497c2b8390de75270357a7f80e5a7

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/21a906c28da497c2b8390de75270357a7f80e5a7
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20230912/af3815c7/attachment-0001.html>


More information about the ghc-commits mailing list