From 34a04ea171bcc0c676b9d09e71ef0d54fe74b9a1 Mon Sep 17 00:00:00 2001 From: Matthew Pickering <matthewtpickering@gmail.com> Date: Mon, 20 May 2024 09:55:50 +0100 Subject: [PATCH] Add -Wderiving-typeable to -Wall Deriving `Typeable` does nothing, and it hasn't done for a long while. There has also been a warning for a long while which warns you about uselessly deriving it but it wasn't enabled in -Wall. Fixes #24784 --- compiler/GHC/Driver/Flags.hs | 3 +- compiler/GHC/Iface/Ext/Ast.hs | 2 +- compiler/GHC/Iface/Ext/Types.hs | 4 +-- compiler/GHC/JS/JStg/Syntax.hs | 12 ++++---- compiler/GHC/JS/Syntax.hs | 12 ++++---- compiler/GHC/Types/FieldLabel.hs | 4 +-- docs/users_guide/9.12.1-notes.rst | 2 ++ docs/users_guide/using-warnings.rst | 1 + hadrian/src/Settings/Warnings.hs | 28 +++++++++++++++---- .../src/GHC/Internal/JS/Foreign/Callback.hs | 4 +-- .../ghc-internal/src/GHC/Internal/JS/Prim.hs | 4 --- .../should_compile/DerivingTypeable.stderr | 4 +-- .../haddock/haddock-api/src/Haddock/Types.hs | 2 -- 13 files changed, 47 insertions(+), 35 deletions(-) diff --git a/compiler/GHC/Driver/Flags.hs b/compiler/GHC/Driver/Flags.hs index c14acdb60c62..f2cbc92a838d 100644 --- a/compiler/GHC/Driver/Flags.hs +++ b/compiler/GHC/Driver/Flags.hs @@ -1345,7 +1345,8 @@ minusWallOpts Opt_WarnRedundantRecordWildcards, Opt_WarnIncompleteUniPatterns, Opt_WarnIncompletePatternsRecUpd, - Opt_WarnIncompleteExportWarnings + Opt_WarnIncompleteExportWarnings, + Opt_WarnDerivingTypeable ] -- | Things you get with -Weverything, i.e. *all* known warnings flags diff --git a/compiler/GHC/Iface/Ext/Ast.hs b/compiler/GHC/Iface/Ext/Ast.hs index 422fa31ddc2f..1ed1cec133a0 100644 --- a/compiler/GHC/Iface/Ext/Ast.hs +++ b/compiler/GHC/Iface/Ext/Ast.hs @@ -470,7 +470,7 @@ data PScoped a = PS (Maybe Span) Scope -- ^ use site of the pattern Scope -- ^ pattern to the right of a, not including a a - deriving (Typeable, Data) -- Pattern Scope + deriving (Data) -- Pattern Scope {- Note [TyVar Scopes] ~~~~~~~~~~~~~~~~~~~ diff --git a/compiler/GHC/Iface/Ext/Types.hs b/compiler/GHC/Iface/Ext/Types.hs index b8a398465c77..4776035fccc5 100644 --- a/compiler/GHC/Iface/Ext/Types.hs +++ b/compiler/GHC/Iface/Ext/Types.hs @@ -34,7 +34,7 @@ import qualified Data.Array as A import qualified Data.Map as M import qualified Data.Set as S import Data.ByteString ( ByteString ) -import Data.Data ( Typeable, Data ) +import Data.Data ( Data ) import Data.Semigroup ( Semigroup(..) ) import Data.Word ( Word8 ) import Control.Applicative ( (<|>) ) @@ -668,7 +668,7 @@ data Scope = NoScope | LocalScope Span | ModuleScope - deriving (Eq, Ord, Typeable, Data) + deriving (Eq, Ord, Data) instance Outputable Scope where ppr NoScope = text "NoScope" diff --git a/compiler/GHC/JS/JStg/Syntax.hs b/compiler/GHC/JS/JStg/Syntax.hs index 852aebb1ade3..b18d52c817b9 100644 --- a/compiler/GHC/JS/JStg/Syntax.hs +++ b/compiler/GHC/JS/JStg/Syntax.hs @@ -105,7 +105,7 @@ data JStgStat | BreakStat (Maybe JsLabel) -- ^ Break | ContinueStat (Maybe JsLabel) -- ^ Continue | FuncStat !Ident [Ident] JStgStat -- ^ an explicit function definition - deriving (Eq, Typeable, Generic) + deriving (Eq, Generic) -- | A Label used for 'JStgStat', specifically 'BreakStat', 'ContinueStat' and of -- course 'LabelStat' @@ -144,7 +144,7 @@ data JStgExpr | UOpExpr UOp JStgExpr -- ^ Unary Expressions | IfExpr JStgExpr JStgExpr JStgExpr -- ^ If-expression | ApplExpr JStgExpr [JStgExpr] -- ^ Application - deriving (Eq, Typeable, Generic) + deriving (Eq, Generic) instance Outputable JStgExpr where ppr x = case x of @@ -265,7 +265,7 @@ data JVal | JBool Bool -- ^ A Boolean | JHash (UniqMap FastString JStgExpr) -- ^ A JS HashMap: @{"foo": 0}@ | JFunc [Ident] JStgStat -- ^ A function - deriving (Eq, Typeable, Generic) + deriving (Eq, Generic) -------------------------------------------------------------------------------- -- Operators @@ -296,7 +296,7 @@ data Op | LOrOp -- ^ Logical Or: || | InstanceofOp -- ^ @instanceof@ | InOp -- ^ @in@ - deriving (Show, Eq, Ord, Enum, Data, Typeable, Generic) + deriving (Show, Eq, Ord, Enum, Data, Generic) instance NFData Op @@ -315,7 +315,7 @@ data UOp | PostIncOp -- ^ Postfix Increment: @x++@ | PreDecOp -- ^ Prefix Decrement: @--x@ | PostDecOp -- ^ Postfix Decrement: @x--@ - deriving (Show, Eq, Ord, Enum, Data, Typeable, Generic) + deriving (Show, Eq, Ord, Enum, Data, Generic) instance NFData UOp @@ -324,7 +324,7 @@ data AOp = AssignOp -- ^ Vanilla Assignment: = | AddAssignOp -- ^ Addition Assignment: += | SubAssignOp -- ^ Subtraction Assignment: -= - deriving (Show, Eq, Ord, Enum, Data, Typeable, Generic) + deriving (Show, Eq, Ord, Enum, Data, Generic) instance NFData AOp diff --git a/compiler/GHC/JS/Syntax.hs b/compiler/GHC/JS/Syntax.hs index 575eafadcb09..015297915aa9 100644 --- a/compiler/GHC/JS/Syntax.hs +++ b/compiler/GHC/JS/Syntax.hs @@ -129,7 +129,7 @@ data JStat | BreakStat (Maybe JLabel) -- ^ Break | ContinueStat (Maybe JLabel) -- ^ Continue | FuncStat !Ident [Ident] JStat -- ^ an explicit function definition - deriving (Eq, Typeable, Generic) + deriving (Eq, Generic) -- | A Label used for 'JStat', specifically 'BreakStat', 'ContinueStat' and of -- course 'LabelStat' @@ -168,7 +168,7 @@ data JExpr | UOpExpr UOp JExpr -- ^ Unary Expressions | IfExpr JExpr JExpr JExpr -- ^ If-expression | ApplExpr JExpr [JExpr] -- ^ Application - deriving (Eq, Typeable, Generic) + deriving (Eq, Generic) -- * Useful pattern synonyms to ease programming with the deeply embedded JS -- AST. Each pattern wraps @UOp@ and @Op@ into a @JExpr@s to save typing and @@ -274,7 +274,7 @@ data JVal | JBool Bool -- ^ A Boolean | JHash (UniqMap FastString JExpr) -- ^ A JS HashMap: @{"foo": 0}@ | JFunc [Ident] JStat -- ^ A function - deriving (Eq, Typeable, Generic) + deriving (Eq, Generic) -------------------------------------------------------------------------------- @@ -307,7 +307,7 @@ data Op | LOrOp -- ^ Logical Or: || | InstanceofOp -- ^ @instanceof@ | InOp -- ^ @in@ - deriving (Show, Eq, Ord, Enum, Data, Typeable, Generic) + deriving (Show, Eq, Ord, Enum, Data, Generic) instance NFData Op @@ -326,7 +326,7 @@ data UOp | PostIncOp -- ^ Postfix Increment: @x++@ | PreDecOp -- ^ Prefix Decrement: @--x@ | PostDecOp -- ^ Postfix Decrement: @x--@ - deriving (Show, Eq, Ord, Enum, Data, Typeable, Generic) + deriving (Show, Eq, Ord, Enum, Data, Generic) instance NFData UOp @@ -335,7 +335,7 @@ data AOp = AssignOp -- ^ Vanilla Assignment: = | AddAssignOp -- ^ Addition Assignment: += | SubAssignOp -- ^ Subtraction Assignment: -= - deriving (Show, Eq, Ord, Enum, Data, Typeable, Generic) + deriving (Show, Eq, Ord, Enum, Data, Generic) instance NFData AOp diff --git a/compiler/GHC/Types/FieldLabel.hs b/compiler/GHC/Types/FieldLabel.hs index edadf377412c..ca4c7005d2e3 100644 --- a/compiler/GHC/Types/FieldLabel.hs +++ b/compiler/GHC/Types/FieldLabel.hs @@ -99,7 +99,7 @@ instance Uniquable FieldLabelString where data DuplicateRecordFields = DuplicateRecordFields -- ^ Fields may be duplicated in a single module | NoDuplicateRecordFields -- ^ Fields must be unique within a module (the default) - deriving (Show, Eq, Typeable, Data) + deriving (Show, Eq, Data) instance Binary DuplicateRecordFields where put_ bh f = put_ bh (f == DuplicateRecordFields) @@ -118,7 +118,7 @@ instance NFData DuplicateRecordFields where data FieldSelectors = FieldSelectors -- ^ Selector functions are available (the default) | NoFieldSelectors -- ^ Selector functions are not available - deriving (Show, Eq, Typeable, Data) + deriving (Show, Eq, Data) instance Binary FieldSelectors where put_ bh f = put_ bh (f == FieldSelectors) diff --git a/docs/users_guide/9.12.1-notes.rst b/docs/users_guide/9.12.1-notes.rst index 834c8a51a7df..454dc6e68c46 100644 --- a/docs/users_guide/9.12.1-notes.rst +++ b/docs/users_guide/9.12.1-notes.rst @@ -58,6 +58,8 @@ and the migration guide. - A new flag ``-fexpose-overloaded-unfoldings`` has been added providing a lightweight alternative to ``-fexpose-all-unfoldings``. +- :ghc-flag:`-Wderiving-typeable` has been added to :ghc-flag:`-Wall`. + GHCi ~~~~ diff --git a/docs/users_guide/using-warnings.rst b/docs/users_guide/using-warnings.rst index 448dfd431fa9..bc96347efbc2 100644 --- a/docs/users_guide/using-warnings.rst +++ b/docs/users_guide/using-warnings.rst @@ -138,6 +138,7 @@ as ``-Wno-...`` for every individual warning in the group. * :ghc-flag:`-Wunused-do-bind` * :ghc-flag:`-Wunused-record-wildcards` * :ghc-flag:`-Wincomplete-export-warnings` + * :ghc-flag:`-Wderiving-typeable` .. ghc-flag:: -Weverything :shortdesc: enable all warnings supported by GHC diff --git a/hadrian/src/Settings/Warnings.hs b/hadrian/src/Settings/Warnings.hs index 88ec1bec6ea2..552dc62ed3ef 100644 --- a/hadrian/src/Settings/Warnings.hs +++ b/hadrian/src/Settings/Warnings.hs @@ -26,9 +26,17 @@ ghcWarningsArgs = do mconcat [ stage0 ? mconcat [ libraryPackage ? pure [ "-fno-warn-deprecated-flags" ] - , package terminfo ? pure [ "-fno-warn-unused-imports" ] + , package terminfo ? pure [ "-fno-warn-unused-imports", "-Wno-deriving-typeable"] , package transformers ? pure [ "-fno-warn-unused-matches" - , "-fno-warn-unused-imports" ] ] + , "-fno-warn-unused-imports" ] + , package stm ? pure [ "-Wno-deriving-typeable" ] + , package osString ? pure [ "-Wno-deriving-typeable" ] + , package parsec ? pure [ "-Wno-deriving-typeable" ] + , package cabal ? pure [ "-Wno-deriving-typeable" ] + , package cabalSyntax ? pure [ "-Wno-deriving-typeable" ] + , package time ? pure [ "-Wno-deriving-typeable" ] + , package unix ? pure [ "-Wno-deriving-typeable" ] + ] , notStage0 ? mconcat [ libraryPackage ? pure [ "-Wno-deprecated-flags" ] , package ghcInternal ? pure [ "-Wno-trustworthy-safe" ] @@ -51,19 +59,27 @@ ghcWarningsArgs = do , "-Wno-x-partial" , "-Wno-unused-imports" , "-Wno-redundant-constraints" - , "-Wno-simplifiable-class-constraints" ] + , "-Wno-simplifiable-class-constraints" + , "-Wno-deriving-typeable" ] , package pretty ? pure [ "-Wno-unused-imports" ] , package primitive ? pure [ "-Wno-unused-imports" , "-Wno-deprecations" ] , package rts ? pure [ "-Wcpp-undef" ] - , package text ? pure [ "-Wno-deprecations" ] - , package terminfo ? pure [ "-Wno-unused-imports" ] + , package text ? pure [ "-Wno-deprecations", "-Wno-deriving-typeable" ] + , package terminfo ? pure [ "-Wno-unused-imports", "-Wno-deriving-typeable" ] + , package stm ? pure [ "-Wno-deriving-typeable" ] + , package osString ? pure [ "-Wno-deriving-typeable" ] + , package parsec ? pure [ "-Wno-deriving-typeable" ] + , package cabal ? pure [ "-Wno-deriving-typeable" ] + , package cabalSyntax ? pure [ "-Wno-deriving-typeable" ] + , package time ? pure [ "-Wno-deriving-typeable" ] , package transformers ? pure [ "-Wno-unused-matches" , "-Wno-unused-imports" , "-Wno-redundant-constraints" , "-Wno-orphans" ] - , package unix ? pure [ "-Wno-deprecations" ] + , package unix ? pure [ "-Wno-deprecations", "-Wno-deriving-typeable" ] , package win32 ? pure [ "-Wno-trustworthy-safe" , "-Wno-deprecations" -- https://gitlab.haskell.org/ghc/ghc/-/issues/24240 + , "-Wno-deriving-typeable" ] , package xhtml ? pure [ "-Wno-unused-imports" ] ] ] diff --git a/libraries/ghc-internal/src/GHC/Internal/JS/Foreign/Callback.hs b/libraries/ghc-internal/src/GHC/Internal/JS/Foreign/Callback.hs index a31e8909f848..d83a3f8cc9cd 100644 --- a/libraries/ghc-internal/src/GHC/Internal/JS/Foreign/Callback.hs +++ b/libraries/ghc-internal/src/GHC/Internal/JS/Foreign/Callback.hs @@ -23,14 +23,12 @@ import GHC.Internal.JS.Prim import qualified GHC.Internal.Exts as Exts -import GHC.Internal.Data.Typeable - import GHC.Internal.Unsafe.Coerce import GHC.Internal.Base data OnBlocked = ContinueAsync | ThrowWouldBlock deriving (Eq) -newtype Callback a = Callback JSVal deriving Typeable +newtype Callback a = Callback JSVal {- | When you create a callback, the Haskell runtime stores a reference to diff --git a/libraries/ghc-internal/src/GHC/Internal/JS/Prim.hs b/libraries/ghc-internal/src/GHC/Internal/JS/Prim.hs index e7ec274761cf..128fc265640b 100644 --- a/libraries/ghc-internal/src/GHC/Internal/JS/Prim.hs +++ b/libraries/ghc-internal/src/GHC/Internal/JS/Prim.hs @@ -1,6 +1,5 @@ {-# LANGUAGE CPP #-} {-# LANGUAGE MagicHash #-} -{-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE JavaScriptFFI #-} {-# LANGUAGE GHCForeignImportPrim #-} @@ -40,7 +39,6 @@ module GHC.Internal.JS.Prim ( JSVal(..), JSVal# #endif ) where -import GHC.Internal.Data.Typeable (Typeable) import GHC.Internal.Unsafe.Coerce (unsafeCoerce) import GHC.Prim @@ -71,7 +69,6 @@ type JSVal# = Addr# to a JSException -} data JSException = JSException JSVal String - deriving (Typeable) instance Ex.Exception JSException @@ -326,7 +323,6 @@ foreign import javascript unsafe "(($1, $2) => { return $1($2); })" continue asynchronously, it receives this exception. -} data WouldBlockException = WouldBlockException - deriving (Typeable) instance Show WouldBlockException where show _ = "thread would block" diff --git a/testsuite/tests/warnings/should_compile/DerivingTypeable.stderr b/testsuite/tests/warnings/should_compile/DerivingTypeable.stderr index aba784903025..945a19676588 100644 --- a/testsuite/tests/warnings/should_compile/DerivingTypeable.stderr +++ b/testsuite/tests/warnings/should_compile/DerivingTypeable.stderr @@ -1,4 +1,4 @@ - -DerivingTypeable.hs:8:12: warning: [GHC-90584] [-Wderiving-typeable] +DerivingTypeable.hs:8:12: warning: [GHC-90584] [-Wderiving-typeable (in -Wall)] • Deriving ‘Typeable’ has no effect: all types now auto-derive Typeable • In the data declaration for ‘Foo’ + diff --git a/utils/haddock/haddock-api/src/Haddock/Types.hs b/utils/haddock/haddock-api/src/Haddock/Types.hs index 3ccd49cba0fd..2957fc32e13c 100644 --- a/utils/haddock/haddock-api/src/Haddock/Types.hs +++ b/utils/haddock/haddock-api/src/Haddock/Types.hs @@ -50,7 +50,6 @@ import Control.Monad.State.Strict import Data.Data (Data) import Data.Map (Map) import qualified Data.Set as Set -import Data.Typeable (Typeable) import Documentation.Haddock.Types import qualified GHC.Data.Strict as Strict import GHC.Types.Fixity (Fixity (..)) @@ -764,7 +763,6 @@ type Renamer = String -> (NameSpace -> Bool) -> [Name] data HaddockException = HaddockException String | WithContext [String] SomeException - deriving (Typeable) instance Show HaddockException where show (HaddockException str) = str -- GitLab