From e9c0537cfbf7b47c64f592f529e402358b66ca7f Mon Sep 17 00:00:00 2001 From: Vladislav Zavialov Date: Sat, 14 Jan 2023 14:41:39 +0300 Subject: Enable -Wstar-is-type by default (#22759) Following the plan in GHC Proposal #143 "Remove the * kind syntax", which states: In the next release (or 3 years in), enable -fwarn-star-is-type by default. The "next release" happens to be 9.6.1 I also moved the T21583 test case from should_fail to should_compile, because the only reason it was failing was -Werror=compat in our test suite configuration. --- compiler/GHC/Driver/Flags.hs | 3 +- compiler/GHC/Tc/Errors/Types.hs | 2 +- docs/users_guide/9.6.1-notes.rst | 2 + docs/users_guide/using-warnings.rst | 5 +- testsuite/tests/ghci/scripts/ghci024.stdout | 1 - .../tests/ghci/scripts/ghci024.stdout-mingw32 | 1 - testsuite/tests/typecheck/should_compile/T21583.hs | 92 ++++++++++++++++++++++ .../tests/typecheck/should_compile/T21583.stderr | 15 ++++ testsuite/tests/typecheck/should_compile/all.T | 1 + testsuite/tests/typecheck/should_fail/T21583.hs | 90 --------------------- .../tests/typecheck/should_fail/T21583.stderr | 27 ------- testsuite/tests/typecheck/should_fail/all.T | 1 - testsuite/tests/warnings/should_compile/T22759.hs | 4 + .../tests/warnings/should_compile/T22759.stderr | 6 ++ testsuite/tests/warnings/should_compile/all.T | 1 + testsuite/tests/wcompat-warnings/Template.hs | 6 -- .../wcompat-warnings/WCompatWarningsOn.stderr | 12 +-- 17 files changed, 127 insertions(+), 142 deletions(-) create mode 100644 testsuite/tests/typecheck/should_compile/T21583.hs create mode 100644 testsuite/tests/typecheck/should_compile/T21583.stderr delete mode 100644 testsuite/tests/typecheck/should_fail/T21583.hs delete mode 100644 testsuite/tests/typecheck/should_fail/T21583.stderr create mode 100644 testsuite/tests/warnings/should_compile/T22759.hs create mode 100644 testsuite/tests/warnings/should_compile/T22759.stderr diff --git a/compiler/GHC/Driver/Flags.hs b/compiler/GHC/Driver/Flags.hs index 4f656041df..634718ae7e 100644 --- a/compiler/GHC/Driver/Flags.hs +++ b/compiler/GHC/Driver/Flags.hs @@ -822,6 +822,7 @@ standardWarnings -- see Note [Documenting warning flags] Opt_WarnUnrecognisedWarningFlags, Opt_WarnSimplifiableClassConstraints, Opt_WarnStarBinder, + Opt_WarnStarIsType, Opt_WarnInaccessibleCode, Opt_WarnSpaceAfterBang, Opt_WarnNonCanonicalMonadInstances, @@ -863,7 +864,6 @@ minusWallOpts Opt_WarnMissingPatternSynonymSignatures, Opt_WarnUnusedRecordWildcards, Opt_WarnRedundantRecordWildcards, - Opt_WarnStarIsType, Opt_WarnIncompleteUniPatterns, Opt_WarnIncompletePatternsRecUpd ] @@ -881,7 +881,6 @@ minusWcompatOpts :: [WarningFlag] minusWcompatOpts = [ Opt_WarnSemigroup , Opt_WarnNonCanonicalMonoidInstances - , Opt_WarnStarIsType , Opt_WarnCompatUnqualifiedImports , Opt_WarnTypeEqualityOutOfScope ] diff --git a/compiler/GHC/Tc/Errors/Types.hs b/compiler/GHC/Tc/Errors/Types.hs index 65701f9fee..add396957c 100644 --- a/compiler/GHC/Tc/Errors/Types.hs +++ b/compiler/GHC/Tc/Errors/Types.hs @@ -2578,7 +2578,7 @@ data TcRnMessage where testsuite/tests/typecheck/should_compile/tc078 testsuite/tests/typecheck/should_compile/tc161 testsuite/tests/typecheck/should_fail/T5051 - testsuite/tests/typecheck/should_fail/T21583 + testsuite/tests/typecheck/should_compile/T21583 testsuite/tests/backpack/should_compile/bkp47 testsuite/tests/backpack/should_fail/bkpfail25 testsuite/tests/parser/should_compile/T2245 diff --git a/docs/users_guide/9.6.1-notes.rst b/docs/users_guide/9.6.1-notes.rst index 9fd0ca2d75..5105a3ece7 100644 --- a/docs/users_guide/9.6.1-notes.rst +++ b/docs/users_guide/9.6.1-notes.rst @@ -96,6 +96,8 @@ Compiler - The :ghc-flag:`-Woperator-whitespace` warning no longer ignores constructor symbols (operators starting with ``:``). +- The :ghc-flag:`-Wstar-is-type` warning is now enabled by default. + - Added a new warning :ghc-flag:`-Wterm-variable-capture` that helps to make code compatible with the future extension ``RequiredTypeArguments``. diff --git a/docs/users_guide/using-warnings.rst b/docs/users_guide/using-warnings.rst index c99c51043f..4a6e1ab817 100644 --- a/docs/users_guide/using-warnings.rst +++ b/docs/users_guide/using-warnings.rst @@ -60,6 +60,7 @@ To reverse ``-Werror``, which makes all warnings into errors, use ``-Wwarn``. * :ghc-flag:`-Wunrecognised-warning-flags` * :ghc-flag:`-Winaccessible-code` * :ghc-flag:`-Wstar-binder` + * :ghc-flag:`-Wstar-is-type` * :ghc-flag:`-Woperator-whitespace-ext-conflict` * :ghc-flag:`-Wambiguous-fields` * :ghc-flag:`-Wunicode-bidirectional-format-characters` @@ -160,7 +161,6 @@ The following flags are simple ways to select standard "packages" of warnings: * :ghc-flag:`-Wsemigroup` * :ghc-flag:`-Wnoncanonical-monoid-instances` - * :ghc-flag:`-Wstar-is-type` * :ghc-flag:`-Wcompat-unqualified-imports` * :ghc-flag:`-Wtype-equality-out-of-scope` @@ -1505,9 +1505,6 @@ of ``-W(no-)*``. breaking change takes place. The recommended fix is to replace ``*`` with ``Type`` imported from ``Data.Kind``. - 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:: -Wstar-binder :shortdesc: warn about binding the ``(*)`` type operator despite :extension:`StarIsType` diff --git a/testsuite/tests/ghci/scripts/ghci024.stdout b/testsuite/tests/ghci/scripts/ghci024.stdout index c7ddba4f62..ea2b56d35d 100644 --- a/testsuite/tests/ghci/scripts/ghci024.stdout +++ b/testsuite/tests/ghci/scripts/ghci024.stdout @@ -16,7 +16,6 @@ other dynamic, non-language, flag settings: -fprefer-byte-code warning settings: -Wsemigroup - -Wstar-is-type -Wcompat-unqualified-imports -Wtype-equality-out-of-scope ~~~~~~~~~~ Testing :set -a diff --git a/testsuite/tests/ghci/scripts/ghci024.stdout-mingw32 b/testsuite/tests/ghci/scripts/ghci024.stdout-mingw32 index 7dea29c218..e5e54a12b0 100644 --- a/testsuite/tests/ghci/scripts/ghci024.stdout-mingw32 +++ b/testsuite/tests/ghci/scripts/ghci024.stdout-mingw32 @@ -15,7 +15,6 @@ other dynamic, non-language, flag settings: -fprefer-byte-code warning settings: -Wsemigroup - -Wstar-is-type -Wcompat-unqualified-imports -Wtype-equality-out-of-scope ~~~~~~~~~~ Testing :set -a diff --git a/testsuite/tests/typecheck/should_compile/T21583.hs b/testsuite/tests/typecheck/should_compile/T21583.hs new file mode 100644 index 0000000000..7146e1de03 --- /dev/null +++ b/testsuite/tests/typecheck/should_compile/T21583.hs @@ -0,0 +1,92 @@ +{-# LANGUAGE LambdaCase #-} +{-# LANGUAGE DeriveTraversable #-} +{-# LANGUAGE TypeFamilies #-} +{-# LANGUAGE PatternSynonyms #-} +{-# LANGUAGE FlexibleContexts #-} +module Telomare.Possible where + +import Data.Kind (Type) + +data PartExprF f + = ZeroSF + deriving (Eq, Ord, Show, Functor, Foldable, Traversable) + +newtype EnhancedExpr f = EnhancedExpr {unEnhanceExpr :: SplitFunctor f PartExprF (EnhancedExpr f)} -- deriving (Eq, Show) + +type family Base t :: Type -> Type + +type instance Base (EnhancedExpr f) = SplitFunctor f PartExprF + +class Functor (Base t) => Recursive t where + project :: t -> Base t t + +instance Functor f => Recursive (EnhancedExpr f) where + project = unEnhanceExpr + +class Functor (Base t) => Corecursive t where + embed :: Base t t -> t + +instance Functor f => Corecursive (EnhancedExpr f) where + embed = EnhancedExpr + +type SimpleExpr = EnhancedExpr VoidF +type BasicBase f = SplitFunctor f PartExprF +type SuperBase f = BasicBase (SplitFunctor f SuperPositionF) +type AbortBase f = SuperBase (SplitFunctor f AbortableF) +type UnsizedBase = AbortBase UnsizedRecursionF + +pattern UnsizedFW :: UnsizedRecursionF a -> UnsizedBase a +pattern UnsizedFW x = SplitFunctor (Left (SplitFunctor (Left (SplitFunctor (Left x))))) +pattern BasicExpr :: PartExprF (EnhancedExpr f) -> EnhancedExpr f +pattern BasicExpr x = EnhancedExpr (SplitFunctor (Right x)) +pattern UnsizedWrap :: UnsizedRecursionF UnsizedExpr -> UnsizedExpr +pattern UnsizedWrap x = EnhancedExpr (UnsizedFW x) + +data VoidF f + deriving (Functor, Foldable, Traversable) + +data SuperPositionF f + = AnyPF + deriving (Eq, Ord, Show, Functor, Foldable, Traversable) + +data AbortableF f + = AbortF + deriving (Eq, Ord, Show, Functor, Foldable, Traversable) + +newtype SplitFunctor g f x = SplitFunctor { unSplitF :: Either (g x) (f x) } deriving (Eq, Show) + +instance (Functor f, Functor g) => Functor (SplitFunctor g f) where + +instance (Foldable f, Foldable g) => Foldable (SplitFunctor g f) where + +instance (Traversable f, Traversable g) => Traversable (SplitFunctor g f) where + +type SuperExpr f = EnhancedExpr (SplitFunctor f SuperPositionF) + +type AbortExpr f = SuperExpr (SplitFunctor f AbortableF) + +type BreakExtras = () + +data UnsizedRecursionF f + = UnsizedRecursionF BreakExtras f + | UnsizedBarrierF f + deriving (Eq, Ord, Show, Functor, Foldable, Traversable) + +type UnsizedExpr = AbortExpr UnsizedRecursionF + +cata :: Recursive t => (Base t a -> a) -> t -> a +cata = undefined + +sizeTerm :: UnsizedExpr -> Maybe (AbortExpr VoidF) +sizeTerm term = + let sizingTerm = eval term + eval :: UnsizedExpr -> UnsizedExpr + eval = undefined + setSizes sizes = cata $ \case + UnsizedFW (UnsizedRecursionF be env) -> BasicExpr ZeroSF + clean = undefined + hoist = undefined + maybeSized = pure sizingTerm + in hoist clean <$> maybeSized + + diff --git a/testsuite/tests/typecheck/should_compile/T21583.stderr b/testsuite/tests/typecheck/should_compile/T21583.stderr new file mode 100644 index 0000000000..b05cadf933 --- /dev/null +++ b/testsuite/tests/typecheck/should_compile/T21583.stderr @@ -0,0 +1,15 @@ + +T21583.hs:58:10: warning: [GHC-06201] [-Wmissing-methods (in -Wdefault)] + • No explicit implementation for + ‘fmap’ + • In the instance declaration for ‘Functor (SplitFunctor g f)’ + +T21583.hs:60:10: warning: [GHC-06201] [-Wmissing-methods (in -Wdefault)] + • No explicit implementation for + either ‘foldMap’ or ‘foldr’ + • In the instance declaration for ‘Foldable (SplitFunctor g f)’ + +T21583.hs:62:10: warning: [GHC-06201] [-Wmissing-methods (in -Wdefault)] + • No explicit implementation for + either ‘traverse’ or ‘sequenceA’ + • In the instance declaration for ‘Traversable (SplitFunctor g f)’ diff --git a/testsuite/tests/typecheck/should_compile/all.T b/testsuite/tests/typecheck/should_compile/all.T index 0a1edfa866..fc5ce4936b 100644 --- a/testsuite/tests/typecheck/should_compile/all.T +++ b/testsuite/tests/typecheck/should_compile/all.T @@ -825,6 +825,7 @@ test('T21328', normal, compile, ['']) test('T21516', normal, compile, ['']) test('T21519', normal, compile, ['']) test('T21519a', normal, compile, ['']) +test('T21583', normal, compile, ['']) test('T2595', normal, compile, ['']) test('T3632', normal, compile, ['']) test('T10808', normal, compile, ['']) diff --git a/testsuite/tests/typecheck/should_fail/T21583.hs b/testsuite/tests/typecheck/should_fail/T21583.hs deleted file mode 100644 index 5b7873dce6..0000000000 --- a/testsuite/tests/typecheck/should_fail/T21583.hs +++ /dev/null @@ -1,90 +0,0 @@ -{-# LANGUAGE LambdaCase #-} -{-# LANGUAGE DeriveTraversable #-} -{-# LANGUAGE TypeFamilies #-} -{-# LANGUAGE PatternSynonyms #-} -{-# LANGUAGE FlexibleContexts #-} -module Telomare.Possible where - -data PartExprF f - = ZeroSF - deriving (Eq, Ord, Show, Functor, Foldable, Traversable) - -newtype EnhancedExpr f = EnhancedExpr {unEnhanceExpr :: SplitFunctor f PartExprF (EnhancedExpr f)} -- deriving (Eq, Show) - -type family Base t :: * -> * - -type instance Base (EnhancedExpr f) = SplitFunctor f PartExprF - -class Functor (Base t) => Recursive t where - project :: t -> Base t t - -instance Functor f => Recursive (EnhancedExpr f) where - project = unEnhanceExpr - -class Functor (Base t) => Corecursive t where - embed :: Base t t -> t - -instance Functor f => Corecursive (EnhancedExpr f) where - embed = EnhancedExpr - -type SimpleExpr = EnhancedExpr VoidF -type BasicBase f = SplitFunctor f PartExprF -type SuperBase f = BasicBase (SplitFunctor f SuperPositionF) -type AbortBase f = SuperBase (SplitFunctor f AbortableF) -type UnsizedBase = AbortBase UnsizedRecursionF - -pattern UnsizedFW :: UnsizedRecursionF a -> UnsizedBase a -pattern UnsizedFW x = SplitFunctor (Left (SplitFunctor (Left (SplitFunctor (Left x))))) -pattern BasicExpr :: PartExprF (EnhancedExpr f) -> EnhancedExpr f -pattern BasicExpr x = EnhancedExpr (SplitFunctor (Right x)) -pattern UnsizedWrap :: UnsizedRecursionF UnsizedExpr -> UnsizedExpr -pattern UnsizedWrap x = EnhancedExpr (UnsizedFW x) - -data VoidF f - deriving (Functor, Foldable, Traversable) - -data SuperPositionF f - = AnyPF - deriving (Eq, Ord, Show, Functor, Foldable, Traversable) - -data AbortableF f - = AbortF - deriving (Eq, Ord, Show, Functor, Foldable, Traversable) - -newtype SplitFunctor g f x = SplitFunctor { unSplitF :: Either (g x) (f x) } deriving (Eq, Show) - -instance (Functor f, Functor g) => Functor (SplitFunctor g f) where - -instance (Foldable f, Foldable g) => Foldable (SplitFunctor g f) where - -instance (Traversable f, Traversable g) => Traversable (SplitFunctor g f) where - -type SuperExpr f = EnhancedExpr (SplitFunctor f SuperPositionF) - -type AbortExpr f = SuperExpr (SplitFunctor f AbortableF) - -type BreakExtras = () - -data UnsizedRecursionF f - = UnsizedRecursionF BreakExtras f - | UnsizedBarrierF f - deriving (Eq, Ord, Show, Functor, Foldable, Traversable) - -type UnsizedExpr = AbortExpr UnsizedRecursionF - -cata :: Recursive t => (Base t a -> a) -> t -> a -cata = undefined - -sizeTerm :: UnsizedExpr -> Maybe (AbortExpr VoidF) -sizeTerm term = - let sizingTerm = eval term - eval :: UnsizedExpr -> UnsizedExpr - eval = undefined - setSizes sizes = cata $ \case - UnsizedFW (UnsizedRecursionF be env) -> BasicExpr ZeroSF - clean = undefined - hoist = undefined - maybeSized = pure sizingTerm - in hoist clean <$> maybeSized - - diff --git a/testsuite/tests/typecheck/should_fail/T21583.stderr b/testsuite/tests/typecheck/should_fail/T21583.stderr deleted file mode 100644 index 04aa3d938d..0000000000 --- a/testsuite/tests/typecheck/should_fail/T21583.stderr +++ /dev/null @@ -1,27 +0,0 @@ - -T21583.hs:14:23: error: [GHC-39567] [-Wstar-is-type (in -Wall, -Wcompat), Werror=star-is-type] - Using ‘*’ (or its Unicode variant) to mean ‘Data.Kind.Type’ - relies on the StarIsType extension, which will become - deprecated in the future. - Suggested fix: Use ‘Type’ from ‘Data.Kind’ instead. - -T21583.hs:14:28: error: [GHC-39567] [-Wstar-is-type (in -Wall, -Wcompat), Werror=star-is-type] - Using ‘*’ (or its Unicode variant) to mean ‘Data.Kind.Type’ - relies on the StarIsType extension, which will become - deprecated in the future. - Suggested fix: Use ‘Type’ from ‘Data.Kind’ instead. - -T21583.hs:56:10: warning: [GHC-06201] [-Wmissing-methods (in -Wdefault)] - • No explicit implementation for - ‘fmap’ - • In the instance declaration for ‘Functor (SplitFunctor g f)’ - -T21583.hs:58:10: warning: [GHC-06201] [-Wmissing-methods (in -Wdefault)] - • No explicit implementation for - either ‘foldMap’ or ‘foldr’ - • In the instance declaration for ‘Foldable (SplitFunctor g f)’ - -T21583.hs:60:10: warning: [GHC-06201] [-Wmissing-methods (in -Wdefault)] - • No explicit implementation for - either ‘traverse’ or ‘sequenceA’ - • In the instance declaration for ‘Traversable (SplitFunctor g f)’ diff --git a/testsuite/tests/typecheck/should_fail/all.T b/testsuite/tests/typecheck/should_fail/all.T index bfb7b311a0..5224a58aa6 100644 --- a/testsuite/tests/typecheck/should_fail/all.T +++ b/testsuite/tests/typecheck/should_fail/all.T @@ -660,7 +660,6 @@ test('T20768_fail', normal, compile_fail, ['']) test('T21327', normal, compile_fail, ['']) test('T21338', normal, compile_fail, ['']) test('T21158', normal, compile_fail, ['']) -test('T21583', normal, compile_fail, ['']) test('MissingDefaultMethodBinding', normal, compile_fail, ['']) test('T21447', normal, compile_fail, ['']) test('T21530a', normal, compile_fail, ['']) diff --git a/testsuite/tests/warnings/should_compile/T22759.hs b/testsuite/tests/warnings/should_compile/T22759.hs new file mode 100644 index 0000000000..7834eeeb1e --- /dev/null +++ b/testsuite/tests/warnings/should_compile/T22759.hs @@ -0,0 +1,4 @@ +module T22759 where + +b :: (Bool :: *) +b = True \ No newline at end of file diff --git a/testsuite/tests/warnings/should_compile/T22759.stderr b/testsuite/tests/warnings/should_compile/T22759.stderr new file mode 100644 index 0000000000..deb0842a47 --- /dev/null +++ b/testsuite/tests/warnings/should_compile/T22759.stderr @@ -0,0 +1,6 @@ + +T22759.hs:3:15: warning: [GHC-39567] [-Wstar-is-type (in -Wdefault)] + Using ‘*’ (or its Unicode variant) to mean ‘Data.Kind.Type’ + relies on the StarIsType extension, which will become + deprecated in the future. + Suggested fix: Use ‘Type’ from ‘Data.Kind’ instead. diff --git a/testsuite/tests/warnings/should_compile/all.T b/testsuite/tests/warnings/should_compile/all.T index 40d1ce12f0..3139a042e2 100644 --- a/testsuite/tests/warnings/should_compile/all.T +++ b/testsuite/tests/warnings/should_compile/all.T @@ -53,3 +53,4 @@ test('DerivingTypeable', normal, compile, ['-Wderiving-typeable']) test('T18862a', normal, compile, ['']) test('T18862b', normal, compile, ['']) test('T20312', normal, compile,['-Wall']) +test('T22759', normal, compile, ['']) diff --git a/testsuite/tests/wcompat-warnings/Template.hs b/testsuite/tests/wcompat-warnings/Template.hs index 798eafc787..2a9a11b0c4 100644 --- a/testsuite/tests/wcompat-warnings/Template.hs +++ b/testsuite/tests/wcompat-warnings/Template.hs @@ -1,5 +1,3 @@ -{-# LANGUAGE KindSignatures #-} - module WCompatWarningsOnOff where import qualified Data.Semigroup as Semi @@ -15,7 +13,3 @@ instance Semi.Semigroup S where instance Monoid S where S a `mappend` S b = S (a+b) mempty = S 0 - --- -fwarn-star-is-type -b :: (Bool :: *) -b = True diff --git a/testsuite/tests/wcompat-warnings/WCompatWarningsOn.stderr b/testsuite/tests/wcompat-warnings/WCompatWarningsOn.stderr index a24d18353d..aaf0772b41 100644 --- a/testsuite/tests/wcompat-warnings/WCompatWarningsOn.stderr +++ b/testsuite/tests/wcompat-warnings/WCompatWarningsOn.stderr @@ -1,23 +1,17 @@ -Template.hs:7:1: warning: [-Wsemigroup (in -Wcompat)] +Template.hs:5:1: warning: [-Wsemigroup (in -Wcompat)] Local definition of ‘<>’ clashes with a future Prelude name. This will become an error in a future release. -Template.hs:13:3: warning: [-Wnoncanonical-monoid-instances (in -Wdefault, -Wcompat)] +Template.hs:11:3: warning: [-Wnoncanonical-monoid-instances (in -Wdefault, -Wcompat)] Noncanonical ‘(<>) = mappend’ definition detected in the instance declaration for ‘Semigroup S’. Move definition from ‘mappend’ to ‘(<>)’ See also: https://gitlab.haskell.org/ghc/ghc/-/wikis/proposal/semigroup-monoid -Template.hs:16:3: warning: [-Wnoncanonical-monoid-instances (in -Wdefault, -Wcompat)] +Template.hs:14:3: warning: [-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 ‘(<>)’ Either remove definition for ‘mappend’ (recommended) or define as ‘mappend = (<>)’ See also: https://gitlab.haskell.org/ghc/ghc/-/wikis/proposal/semigroup-monoid - -Template.hs:20:15: warning: [GHC-39567] [-Wstar-is-type (in -Wall, -Wcompat)] - Using ‘*’ (or its Unicode variant) to mean ‘Data.Kind.Type’ - relies on the StarIsType extension, which will become - deprecated in the future. - Suggested fix: Use ‘Type’ from ‘Data.Kind’ instead. -- cgit v1.2.1