[Git][ghc/ghc][wip/T24267] Turn -Wtype-equality-out-of-scope on by default

Krzysztof Gogolewski (@monoidal) gitlab at gitlab.haskell.org
Mon Dec 18 18:16:01 UTC 2023



Krzysztof Gogolewski pushed to branch wip/T24267 at Glasgow Haskell Compiler / GHC


Commits:
b404e610 by Krzysztof Gogolewski at 2023-12-18T19:15:30+01:00
Turn -Wtype-equality-out-of-scope on by default

Also remove -Wnoncanonical-{monoid,monad}-instances from -Wcompat,
since they are enabled by default. Refresh wcompat-warnings/ test
with new -Wcompat warnings.

Part of #24267

- - - - -


10 changed files:

- compiler/GHC/Driver/Flags.hs
- docs/users_guide/using-warnings.rst
- testsuite/tests/ghci/scripts/ghci024.stdout
- testsuite/tests/warnings/should_compile/T18862b.hs
- testsuite/tests/warnings/should_compile/T18862b.stderr
- + testsuite/tests/warnings/should_compile/WarnNoncanonical.hs
- + testsuite/tests/warnings/should_compile/WarnNoncanonical.stderr
- testsuite/tests/warnings/should_compile/all.T
- testsuite/tests/wcompat-warnings/Template.hs
- testsuite/tests/wcompat-warnings/WCompatWarningsOn.stderr


Changes:

=====================================
compiler/GHC/Driver/Flags.hs
=====================================
@@ -952,7 +952,8 @@ standardWarnings -- see Note [Documenting warning flags]
         Opt_WarnBadlyStagedTypes,
         Opt_WarnTypeEqualityRequiresOperators,
         Opt_WarnInconsistentFlags,
-        Opt_WarnDataKindsTC
+        Opt_WarnDataKindsTC,
+        Opt_WarnTypeEqualityOutOfScope
       ]
 
 -- | Things you get with -W
@@ -1002,10 +1003,7 @@ minusWeverythingOpts = [ toEnum 0 .. ]
 minusWcompatOpts :: [WarningFlag]
 minusWcompatOpts
     = [ Opt_WarnSemigroup
-      , Opt_WarnNonCanonicalMonoidInstances
-      , Opt_WarnNonCanonicalMonadInstances
       , Opt_WarnCompatUnqualifiedImports
-      , Opt_WarnTypeEqualityOutOfScope
       , Opt_WarnImplicitRhsQuantification
       , Opt_WarnDeprecatedTypeAbstractions
       ]


=====================================
docs/users_guide/using-warnings.rst
=====================================
@@ -78,8 +78,12 @@ 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:`-Wtype-equality-out-of-scope`
         * :ghc-flag:`-Wbadly-staged-types`
         * :ghc-flag:`-Winconsistent-flags`
+        * :ghc-flag:`-Wnoncanonical-monoid-instances`
+        * :ghc-flag:`-Wnoncanonical-monad-instances`
+        * :ghc-flag:`-Wdata-kinds-tc`
 
 .. ghc-flag:: -W
     :shortdesc: enable normal warnings
@@ -166,10 +170,7 @@ as ``-Wno-...`` for every individual warning in the group.
         :columns: 3
 
         * :ghc-flag:`-Wsemigroup`
-        * :ghc-flag:`-Wnoncanonical-monoid-instances`
-        * :ghc-flag:`-Wnoncanonical-monad-instances`
         * :ghc-flag:`-Wcompat-unqualified-imports`
-        * :ghc-flag:`-Wtype-equality-out-of-scope`
         * :ghc-flag:`-Wimplicit-rhs-quantification`
         * :ghc-flag:`-Wdeprecated-type-abstractions`
 
@@ -591,8 +592,6 @@ of ``-W(no-)*``.
      * Warn if ``pure`` is defined backwards (i.e. ``pure = return``).
      * Warn if ``(*>)`` is defined backwards (i.e. ``(*>) = (>>)``).
 
-    This warning is  part of the :ghc-flag:`-Wcompat` option group.
-
 .. ghc-flag:: -Wnoncanonical-monadfail-instances
     :shortdesc: *(deprecated)*
         warn when ``Monad`` or ``MonadFail`` instances have
@@ -636,8 +635,6 @@ of ``-W(no-)*``.
 
      * Warn if ``(<>)`` is defined backwards (i.e. ``(<>) = mappend``).
 
-    This warning is  part of the :ghc-flag:`-Wcompat` option group.
-
 .. ghc-flag:: -Wmissing-monadfail-instances
     :shortdesc: *(deprecated)*
         Warn when a failable pattern is used in a do-block that does
@@ -2379,6 +2376,7 @@ of ``-W(no-)*``.
     :reverse: -Wno-type-equality-out-of-scope
 
     :since: 9.4.1
+    :default: on
 
     In accordance with `GHC Proposal #371
     <https://github.com/ghc-proposals/ghc-proposals/blob/master/proposals/0371-non-magical-eq.md>`__,
@@ -2395,9 +2393,6 @@ of ``-W(no-)*``.
     custom Prelude. In this case, consider updating your custom Prelude to
     re-export ``~`` from ``Data.Type.Equality``.
 
-    Being part of the :ghc-flag:`-Wcompat` option group, this warning is off by
-    default, but will be switched on in a future GHC release.
-
 .. ghc-flag:: -Wtype-equality-requires-operators
     :shortdesc: warn when type equality ``a ~ b`` is used despite being out of scope
     :type: dynamic


=====================================
testsuite/tests/ghci/scripts/ghci024.stdout
=====================================
@@ -18,7 +18,6 @@ other dynamic, non-language, flag settings:
 warning settings:
   -Wsemigroup
   -Wcompat-unqualified-imports
-  -Wtype-equality-out-of-scope
   -Wimplicit-rhs-quantification
   -Wdeprecated-type-abstractions
 ~~~~~~~~~~ Testing :set -a


=====================================
testsuite/tests/warnings/should_compile/T18862b.hs
=====================================
@@ -1,4 +1,4 @@
-{-# OPTIONS -Wcompat -Wno-error=type-equality-out-of-scope #-}
+{-# OPTIONS -Wno-error=type-equality-out-of-scope #-}
 
 module T18862b where
 


=====================================
testsuite/tests/warnings/should_compile/T18862b.stderr
=====================================
@@ -1,5 +1,5 @@
 
-T18862b.hs:7:9: warning: [GHC-12003] [-Wtype-equality-out-of-scope (in -Wcompat)]
+T18862b.hs:7:9: warning: [GHC-12003] [-Wtype-equality-out-of-scope (in -Wdefault)]
     • The ‘~’ operator is out of scope.
       Assuming it to stand for an equality constraint.
     • NB: ‘~’ used to be built-in syntax but now is a regular type operator


=====================================
testsuite/tests/warnings/should_compile/WarnNoncanonical.hs
=====================================
@@ -0,0 +1,30 @@
+module WarnNoncanonical where
+
+import qualified Data.Semigroup as Semi
+
+(<>) = undefined -- Semigroup warnings
+
+-- -fwarn-noncanonical-monoid-instances
+newtype S = S Int
+
+instance Semi.Semigroup S where
+  (<>) = mappend
+
+instance Monoid S where
+  S a `mappend` S b = S (a+b)
+  mempty = S 0
+
+newtype M a = M a
+
+instance Functor M where
+  fmap = undefined
+
+instance Applicative M where
+  liftA2 = undefined
+  pure = return
+  (*>) = (>>)
+
+instance Monad M where
+  return = undefined
+  (>>=) = undefined
+  (>>) = undefined


=====================================
testsuite/tests/warnings/should_compile/WarnNoncanonical.stderr
=====================================
@@ -0,0 +1,45 @@
+
+WarnNoncanonical.hs:11:3: warning: [GHC-50928] [-Wnoncanonical-monoid-instances (in -Wdefault)]
+    Noncanonical ‘(<>) = mappend’ definition detected
+    in the instance declaration for ‘Semigroup S’.
+    Suggested fix:
+      Move definition from ‘mappend’ to ‘(<>)’
+      See also: https://gitlab.haskell.org/ghc/ghc/-/wikis/proposal/semigroup-monoid
+
+WarnNoncanonical.hs:14:3: warning: [GHC-50928] [-Wnoncanonical-monoid-instances (in -Wdefault)]
+    Noncanonical ‘mappend’ definition detected
+    in the instance declaration for ‘Monoid S’.
+    ‘mappend’ will eventually be removed in favour of ‘(<>)’
+    Suggested fix:
+      Either remove definition for ‘mappend’ (recommended) or define as ‘mappend = (<>)’
+      See also: https://gitlab.haskell.org/ghc/ghc/-/wikis/proposal/semigroup-monoid
+
+WarnNoncanonical.hs:24:3: warning: [GHC-22705] [-Wnoncanonical-monad-instances (in -Wdefault)]
+    Noncanonical ‘pure = return’ definition detected
+    in the instance declaration for ‘Applicative M’.
+    Suggested fix:
+      Move definition from ‘return’ to ‘pure’
+      See also: https://gitlab.haskell.org/ghc/ghc/-/wikis/proposal/monad-of-no-return
+
+WarnNoncanonical.hs:25:3: warning: [GHC-22705] [-Wnoncanonical-monad-instances (in -Wdefault)]
+    Noncanonical ‘(*>) = (>>)’ definition detected
+    in the instance declaration for ‘Applicative M’.
+    Suggested fix:
+      Move definition from ‘(>>)’ to ‘(*>)’
+      See also: https://gitlab.haskell.org/ghc/ghc/-/wikis/proposal/monad-of-no-return
+
+WarnNoncanonical.hs:28:3: warning: [GHC-22705] [-Wnoncanonical-monad-instances (in -Wdefault)]
+    Noncanonical ‘return’ definition detected
+    in the instance declaration for ‘Monad M’.
+    ‘return’ will eventually be removed in favour of ‘pure’
+    Suggested fix:
+      Either remove definition for ‘return’ (recommended) or define as ‘return = pure’
+      See also: https://gitlab.haskell.org/ghc/ghc/-/wikis/proposal/monad-of-no-return
+
+WarnNoncanonical.hs:30:3: warning: [GHC-22705] [-Wnoncanonical-monad-instances (in -Wdefault)]
+    Noncanonical ‘(>>)’ definition detected
+    in the instance declaration for ‘Monad M’.
+    ‘(>>)’ will eventually be removed in favour of ‘(*>)’
+    Suggested fix:
+      Either remove definition for ‘(>>)’ (recommended) or define as ‘(>>) = (*>)’
+      See also: https://gitlab.haskell.org/ghc/ghc/-/wikis/proposal/monad-of-no-return


=====================================
testsuite/tests/warnings/should_compile/all.T
=====================================
@@ -68,3 +68,4 @@ test('T22702b', normal, compile, [''])
 test('T22826', normal, compile, [''])
 test('T23573', [extra_files(["T23573.hs", "T23573A.hs", "T23573B.hs"])], multimod_compile, ['T23573', '-v0'])
 test('T23465', normal, compile, ['-ddump-parsed'])
+test('WarnNoncanonical', normal, compile, [''])


=====================================
testsuite/tests/wcompat-warnings/Template.hs
=====================================
@@ -1,30 +1,13 @@
+{-# LANGUAGE DataKinds #-}
 module WCompatWarningsOnOff where
 
-import qualified Data.Semigroup as Semi
+import Data.Proxy
+import GHC.Types
+import Data.List
+import Data.Kind
 
-(<>) = undefined -- Semigroup warnings
+type T1 = 'Nothing :: Maybe a
 
--- -fwarn-noncanonical-monoid-instances
-newtype S = S Int
-
-instance Semi.Semigroup S where
-  (<>) = mappend
-
-instance Monoid S where
-  S a `mappend` S b = S (a+b)
-  mempty = S 0
-
-newtype M a = M a
-
-instance Functor M where
-  fmap = undefined
-
-instance Applicative M where
-  liftA2 = undefined
-  pure = return
-  (*>) = (>>)
-
-instance Monad M where
-  return = undefined
-  (>>=) = undefined
-  (>>) = undefined
+foo :: Maybe a -> Maybe a
+foo (Just @b x) = Just @b x
+foo _ = Nothing


=====================================
testsuite/tests/wcompat-warnings/WCompatWarningsOn.stderr
=====================================
@@ -1,45 +1,15 @@
 
-Template.hs:11:3: warning: [GHC-50928] [-Wnoncanonical-monoid-instances (in -Wdefault, -Wcompat)]
-    Noncanonical ‘(<>) = mappend’ definition detected
-    in the instance declaration for ‘Semigroup S’.
-    Suggested fix:
-      Move definition from ‘mappend’ to ‘(<>)’
-      See also: https://gitlab.haskell.org/ghc/ghc/-/wikis/proposal/semigroup-monoid
-
-Template.hs:14:3: warning: [GHC-50928] [-Wnoncanonical-monoid-instances (in -Wdefault, -Wcompat)]
-    Noncanonical ‘mappend’ definition detected
-    in the instance declaration for ‘Monoid S’.
-    ‘mappend’ will eventually be removed in favour of ‘(<>)’
-    Suggested fix:
-      Either remove definition for ‘mappend’ (recommended) or define as ‘mappend = (<>)’
-      See also: https://gitlab.haskell.org/ghc/ghc/-/wikis/proposal/semigroup-monoid
-
-Template.hs:24:3: warning: [GHC-22705] [-Wnoncanonical-monad-instances (in -Wdefault, -Wcompat)]
-    Noncanonical ‘pure = return’ definition detected
-    in the instance declaration for ‘Applicative M’.
-    Suggested fix:
-      Move definition from ‘return’ to ‘pure’
-      See also: https://gitlab.haskell.org/ghc/ghc/-/wikis/proposal/monad-of-no-return
-
-Template.hs:25:3: warning: [GHC-22705] [-Wnoncanonical-monad-instances (in -Wdefault, -Wcompat)]
-    Noncanonical ‘(*>) = (>>)’ definition detected
-    in the instance declaration for ‘Applicative M’.
-    Suggested fix:
-      Move definition from ‘(>>)’ to ‘(*>)’
-      See also: https://gitlab.haskell.org/ghc/ghc/-/wikis/proposal/monad-of-no-return
-
-Template.hs:28:3: warning: [GHC-22705] [-Wnoncanonical-monad-instances (in -Wdefault, -Wcompat)]
-    Noncanonical ‘return’ definition detected
-    in the instance declaration for ‘Monad M’.
-    ‘return’ will eventually be removed in favour of ‘pure’
-    Suggested fix:
-      Either remove definition for ‘return’ (recommended) or define as ‘return = pure’
-      See also: https://gitlab.haskell.org/ghc/ghc/-/wikis/proposal/monad-of-no-return
-
-Template.hs:30:3: warning: [GHC-22705] [-Wnoncanonical-monad-instances (in -Wdefault, -Wcompat)]
-    Noncanonical ‘(>>)’ definition detected
-    in the instance declaration for ‘Monad M’.
-    ‘(>>)’ will eventually be removed in favour of ‘(*>)’
-    Suggested fix:
-      Either remove definition for ‘(>>)’ (recommended) or define as ‘(>>) = (*>)’
-      See also: https://gitlab.haskell.org/ghc/ghc/-/wikis/proposal/monad-of-no-return
+Template.hs:6:8: warning: [GHC-82347] [-Wcompat-unqualified-imports (in -Wcompat)]
+    To ensure compatibility with future core libraries changes
+    imports to Data.List should be
+    either qualified or have an explicit import list.
+
+Template.hs:9:29: warning: [GHC-16382] [-Wimplicit-rhs-quantification (in -Wcompat)]
+    The variable ‘a’ occurs free on the RHS of the type declaration
+    In the future GHC will no longer implicitly quantify over such variables
+    Suggested fix: Bind ‘a’ on the LHS of the type declaration
+
+Template.hs:12:6: warning: [GHC-69797] [-Wdeprecated-type-abstractions (in -Wcompat)]
+    Type applications in constructor patterns will require
+    the TypeAbstractions extension starting from GHC 9.14.
+    Suggested fix: Perhaps you intended to use TypeAbstractions



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

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/b404e6108d449d54d1caf96b1b1c190da5d1f7a3
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/20231218/d9d154d4/attachment-0001.html>


More information about the ghc-commits mailing list