[Git][ghc/ghc][wip/inconsistent-flags] Add -Winconsistent-flags warning

Matthew Pickering (@mpickering) gitlab at gitlab.haskell.org
Fri Sep 8 11:46:50 UTC 2023



Matthew Pickering pushed to branch wip/inconsistent-flags at Glasgow Haskell Compiler / GHC


Commits:
3ca1e3e3 by Matthew Pickering at 2023-09-08T12:46:32+01: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,7 +692,8 @@ 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_WarnInconsistentFlags                       -- Since 9.8
    deriving (Eq, Ord, Show, Enum)
 
 -- | Return the names of a WarningFlag
@@ -803,7 +804,8 @@ 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_WarnInconsistentFlags                       -> "inconsistent-flags" :| []
 
 -- -----------------------------------------------------------------------------
 -- Standard sets of warning options
@@ -942,7 +944,8 @@ standardWarnings -- see Note [Documenting warning flags]
         Opt_WarnUnicodeBidirectionalFormatCharacters,
         Opt_WarnGADTMonoLocalBinds,
         Opt_WarnLoopySuperclassSolve,
-        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,6 +78,7 @@ 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:`-Winconsistent-flags`
 
 .. ghc-flag:: -W
     :shortdesc: enable normal warnings
@@ -2460,7 +2461,7 @@ of ``-W(no-)*``.
     :reverse: -Wno-role-annotations-signatures
     :category:
 
-    :since: 9.8
+    :since: 9.8.1
     :default: off
 
     .. index::
@@ -2482,7 +2483,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
@@ -2499,9 +2500,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
@@ -2531,4 +2529,22 @@ sanity, not yours.)
         import A
 
      When :ghc-flag:`-Wincomplete-export-warnings` is enabled, GHC warns about exports
-     that are not deprecating a name that is deprecated with another export in that module.
\ No newline at end of file
+     that are not deprecating a name that is deprecated with another export in that module.
+
+.. 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/3ca1e3e3fc93b536a709c0091fb1e60055e88f9a

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/3ca1e3e3fc93b536a709c0091fb1e60055e88f9a
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/20230908/6f713ba9/attachment-0001.html>


More information about the ghc-commits mailing list