[Git][ghc/ghc][wip/TTG-No-Orphans] First pass of orphan instance removal.
recursion-ninja pushed to branch wip/TTG-No-Orphans at Glasgow Haskell Compiler / GHC Commits: 13b83052 by Recursion Ninja at 2026-07-10T14:05:05-04:00 First pass of orphan instance removal. This is part of a technical debt removal effort made possible now that seperating out the AST via TTG comes to a close. As the AST in 'L.H.S' has been incrementally separated from the GHC internals, there are many accumulated orphan instance of 'Binary', 'Outputable', 'Uniquable', etc. The orphan instance of data-types from within 'L.H.S' are having thier orphan instances moved to the module which defined the type-class; i.e. moving an orphan 'Binary' instance to 'GHC.Utils.Binary'. Orphan instances resolved (42): | Data-type | Resolved instance(s) | Former orphan module(s) | | -------------------- | -------------------------- | ------------------------- | | Role | Binary, NFData, Outputable | GHC.Core.Coercion.Axiom | | SrcStrictness | Binary, NFData, Outputable | GHC.Core.DataCon | | SrcUnpackedness | Binary, NFData, Outputable | GHC.Core.DataCon | | Fixity | Binary, Outputable | GHC.Hs.Basic | | FixityDirection | Binary, Outputable | GHC.Hs.Basic | | LexicalFixity | Outputable | GHC.Hs.Basic | | CCallTarget | NFData | GHC.Hs.Decls.Foreign | | CType | NFData | GHC.Hs.Decls.Foreign | | Header | NFData | GHC.Hs.Decls.Foreign | | OverlapMode | Binary, NFData | GHC.Hs.Decls.Overlap | | WithHsDocIdentifiers | NFData, Outputable | GHC.Hs.Doc | | HsDocString | NFData, Show | GHC.Hs.DocString | | HsDocStringChunk | Binary, Outputable | GHC.Hs.DocString | | HsDocStringDecorator | Binary, Outputable | GHC.Hs.DocString | | IEWrappedName | Outputable | GHC.Hs.ImpExp | | NamespaceSpecifier | Outputable | GHC.Hs.ImpExp | | FractionalLit | Show | GHC.Hs.Lit | | IntegralLit | Show | GHC.Hs.Lit | | StringLiteral | Show | GHC.Hs.Lit | | ForAllTyFlag | Binary, NFData, Outputable | GHC.Hs.Specificity | | Specificity | Binary, NFData | GHC.Hs.Specificity | | PromotionFlag | Binary, Outputable | GHC.Types.Basic | | FieldLabelString | Outputable, Uniquable | GHC.Types.FieldLabel | | InlinePragma | Binary | GHC.Types.InlinePragma | ------------------------- Metric Decrease: hard_hole_fits ------------------------- Closes #21262, #27469 - - - - - 28 changed files: - compiler/GHC/Core/Coercion/Axiom.hs - compiler/GHC/Core/DataCon.hs - compiler/GHC/Hs/Basic.hs - compiler/GHC/Hs/Decls/Overlap.hs - compiler/GHC/Hs/Doc.hs - compiler/GHC/Hs/DocString.hs - compiler/GHC/Hs/ImpExp.hs - compiler/GHC/Hs/Lit.hs - − compiler/GHC/Hs/Specificity.hs - compiler/GHC/Parser/PostProcess.hs - compiler/GHC/Types/Basic.hs - compiler/GHC/Types/FieldLabel.hs - compiler/GHC/Types/Fixity.hs - compiler/GHC/Types/ForeignCall.hs - compiler/GHC/Types/InlinePragma.hs - compiler/GHC/Types/Unique.hs - compiler/GHC/Types/Var.hs - compiler/GHC/Utils/Binary.hs - compiler/GHC/Utils/Outputable.hs - compiler/Language/Haskell/Syntax/Basic.hs - compiler/Language/Haskell/Syntax/Decls/Foreign.hs - compiler/Language/Haskell/Syntax/Doc.hs - compiler/Language/Haskell/Syntax/Extension.hs - compiler/Language/Haskell/Syntax/ImpExp.hs - compiler/Language/Haskell/Syntax/Lit.hs - compiler/Language/Haskell/Syntax/Specificity.hs - compiler/ghc.cabal.in - testsuite/tests/count-deps/CountDepsParser.stdout Changes: ===================================== compiler/GHC/Core/Coercion/Axiom.hs ===================================== @@ -1,5 +1,3 @@ -{-# OPTIONS_GHC -Wno-orphans #-} -- Outputable - -- (c) The University of Glasgow 2012 -- | Module for coercion axioms, used to represent type family instances @@ -22,7 +20,7 @@ module GHC.Core.Coercion.Axiom ( coAxBranchLHS, coAxBranchRHS, coAxBranchSpan, coAxBranchIncomps, placeHolderIncomps, - Role(..), fsFromRole, + Role(..), CoAxiomRule(..), BuiltInFamRewrite(..), BuiltInFamInjectivity(..), TypeEqn, coAxiomRuleArgRoles, coAxiomRuleRole, @@ -43,7 +41,6 @@ import GHC.Types.Name import GHC.Types.Unique import GHC.Types.Var import GHC.Utils.Misc -import GHC.Utils.Binary import GHC.Utils.Panic import GHC.Data.Pair import GHC.Types.Basic @@ -52,7 +49,6 @@ import GHC.Types.SrcLoc import qualified Data.Data as Data import Data.Array import Data.List ( mapAccumL ) -import Control.DeepSeq {- Note [Coercion axiom branches] @@ -521,44 +517,6 @@ instance Outputable CoAxBranch where , ppUnless (null incomps) $ text "incomps:" <+> vcat (map ppr incomps) ]) -{- -************************************************************************ -* * - Roles -* * -************************************************************************ - -Roles are defined here to avoid circular dependencies. --} - --- These names are slurped into the parser code. Changing these strings --- will change the **surface syntax** that GHC accepts! If you want to --- change only the pretty-printing, do some replumbing. See --- mkRoleAnnotDecl in GHC.Parser.PostProcess -fsFromRole :: Role -> FastString -fsFromRole Nominal = fsLit "nominal" -fsFromRole Representational = fsLit "representational" -fsFromRole Phantom = fsLit "phantom" - -instance Outputable Role where - ppr = ftext . fsFromRole - -instance Binary Role where - put_ bh Nominal = putByte bh 1 - put_ bh Representational = putByte bh 2 - put_ bh Phantom = putByte bh 3 - - get bh = do tag <- getByte bh - case tag of 1 -> return Nominal - 2 -> return Representational - 3 -> return Phantom - _ -> panic ("get Role " ++ show tag) - -instance NFData Role where - rnf Nominal = () - rnf Representational = () - rnf Phantom = () - {- ************************************************************************ * * ===================================== compiler/GHC/Core/DataCon.hs ===================================== @@ -5,8 +5,6 @@ \section[DataCon]{@DataCon@: Data Constructors} -} -{-# OPTIONS_GHC -Wno-orphans #-} -- Outputable, Binary - module GHC.Core.DataCon ( -- * Main data types DataCon, DataConRep(..), @@ -109,7 +107,6 @@ import qualified Data.ByteString.Lazy as LBS import qualified Data.Data as Data import Data.Char import Data.List( find ) -import Control.DeepSeq {- Note [Data constructor representation] @@ -1030,16 +1027,6 @@ instance Outputable HsImplBang where ppr (HsUnpack (Just co)) = text "Unpacked" <> parens (ppr co) ppr (HsStrict b) = text "StrictNotUnpacked" <> parens (ppr b) -instance Outputable SrcStrictness where - ppr SrcLazy = char '~' - ppr SrcStrict = char '!' - ppr NoSrcStrict = empty - -instance Outputable SrcUnpackedness where - ppr SrcUnpack = text "{-# UNPACK #-}" - ppr SrcNoUnpack = text "{-# NOUNPACK #-}" - ppr NoSrcUnpack = empty - instance Outputable StrictnessMark where ppr MarkedStrict = text "!" ppr NotMarkedStrict = empty @@ -1054,40 +1041,6 @@ instance Binary StrictnessMark where 1 -> return MarkedStrict _ -> panic "Invalid binary format" -instance Binary SrcStrictness where - put_ bh SrcLazy = putByte bh 0 - put_ bh SrcStrict = putByte bh 1 - put_ bh NoSrcStrict = putByte bh 2 - - get bh = - do h <- getByte bh - case h of - 0 -> return SrcLazy - 1 -> return SrcStrict - _ -> return NoSrcStrict - -instance Binary SrcUnpackedness where - put_ bh SrcNoUnpack = putByte bh 0 - put_ bh SrcUnpack = putByte bh 1 - put_ bh NoSrcUnpack = putByte bh 2 - - get bh = - do h <- getByte bh - case h of - 0 -> return SrcNoUnpack - 1 -> return SrcUnpack - _ -> return NoSrcUnpack - -instance NFData SrcStrictness where - rnf SrcLazy = () - rnf SrcStrict = () - rnf NoSrcStrict = () - -instance NFData SrcUnpackedness where - rnf SrcNoUnpack = () - rnf SrcUnpack = () - rnf NoSrcUnpack = () - -- | Compare strictness annotations eqHsBang :: HsImplBang -> HsImplBang -> Bool eqHsBang HsLazy HsLazy = True ===================================== compiler/GHC/Hs/Basic.hs ===================================== @@ -1,52 +1,6 @@ -{-# OPTIONS_GHC -Wno-orphans #-} -- Outputable, Binary -{-# LANGUAGE TypeFamilies #-} - -- | Fixity module GHC.Hs.Basic ( module Language.Haskell.Syntax.Basic ) where -import GHC.Prelude - -import GHC.Utils.Outputable -import GHC.Utils.Binary - import Language.Haskell.Syntax.Basic - -instance Outputable LexicalFixity where - ppr Prefix = text "Prefix" - ppr Infix = text "Infix" - -instance Outputable FixityDirection where - ppr InfixL = text "infixl" - ppr InfixR = text "infixr" - ppr InfixN = text "infix" - -instance Outputable Fixity where - ppr (Fixity prec dir) = hcat [ppr dir, space, int prec] - - -instance Binary Fixity where - put_ bh (Fixity aa ab) = do - put_ bh aa - put_ bh ab - get bh = do - aa <- get bh - ab <- get bh - return (Fixity aa ab) - ------------------------- - -instance Binary FixityDirection where - put_ bh InfixL = - putByte bh 0 - put_ bh InfixR = - putByte bh 1 - put_ bh InfixN = - putByte bh 2 - get bh = do - h <- getByte bh - case h of - 0 -> return InfixL - 1 -> return InfixR - _ -> return InfixN ===================================== compiler/GHC/Hs/Decls/Overlap.hs ===================================== @@ -1,12 +1,7 @@ {-# LANGUAGE LambdaCase #-} {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE UndecidableInstances #-} -- XOverlapMode, XXOverlapMode - -{-# OPTIONS_GHC -fno-warn-orphans #-} -{- Necessary for the following instances: - * (type class): Binary OverlapMode - * (type class): NFData OverlapMode --} +{-# OPTIONS_GHC -fno-warn-orphans #-} -- XOverlapMode, XXOverlapMode {- | Data-types describing the overlap annotations for instances as well as @@ -74,34 +69,6 @@ type instance XOverlapMode (GhcPass _) = SourceText type instance XXOverlapMode (GhcPass _) = DataConCantHappen -instance NFData (OverlapMode (GhcPass p)) where - rnf = \case - NoOverlap s -> rnf s - Overlappable s -> rnf s - Overlapping s -> rnf s - Overlaps s -> rnf s - Incoherent s -> rnf s - NonCanonical s -> rnf s - -instance Binary (OverlapMode (GhcPass p)) where - put_ bh = \case - NoOverlap s -> putByte bh 0 >> put_ bh s - Overlaps s -> putByte bh 1 >> put_ bh s - Incoherent s -> putByte bh 2 >> put_ bh s - Overlapping s -> putByte bh 3 >> put_ bh s - Overlappable s -> putByte bh 4 >> put_ bh s - NonCanonical s -> putByte bh 5 >> put_ bh s - - get bh = do - h <- getByte bh - case h of - 0 -> get bh >>= \s -> return $ NoOverlap s - 1 -> get bh >>= \s -> return $ Overlaps s - 2 -> get bh >>= \s -> return $ Incoherent s - 3 -> get bh >>= \s -> return $ Overlapping s - 4 -> get bh >>= \s -> return $ Overlappable s - _ -> get bh >>= \s -> return $ NonCanonical s - pprSafeOverlap :: Bool -> SDoc pprSafeOverlap True = text "[safe]" pprSafeOverlap False = empty ===================================== compiler/GHC/Hs/Doc.hs ===================================== @@ -63,16 +63,6 @@ type instance Anno (WithHsDocIdentifiers (HsDocString (GhcPass pass)) (GhcPass p deriving instance (Data pass, Data (LIdP pass), Data a) => Data (WithHsDocIdentifiers a pass) deriving instance (Eq (LIdP pass), Eq a) => Eq (WithHsDocIdentifiers a pass) -instance (UnXRec pass, NFData (IdP pass), NFData a) => NFData (WithHsDocIdentifiers a pass) where - rnf (WithHsDocIdentifiers d i) = rnf d `seq` rnf (map (unXRec @pass) i) - --- | For compatibility with the existing @-ddump-parsed' output, we only show --- the docstring. --- --- Use 'pprHsDoc' to show `HsDoc`'s internals. -instance Outputable a => Outputable (WithHsDocIdentifiers a pass) where - ppr (WithHsDocIdentifiers s _ids) = ppr s - instance Binary a => Binary (WithHsDocIdentifiers a GhcRn) where put_ bh (WithHsDocIdentifiers s ids) = do put_ bh s ===================================== compiler/GHC/Hs/DocString.hs ===================================== @@ -5,6 +5,8 @@ {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE UndecidableInstances #-} {-# OPTIONS_GHC -Wno-orphans #-} +-- Binary HsDocString +-- Outputable HsDocString module GHC.Hs.DocString ( LHsDocString @@ -44,7 +46,6 @@ import GHC.Hs.Extension.Pass (GhcPass, GhcPs, GhcRn, GhcTc) import Language.Haskell.Syntax.Doc import Language.Haskell.Syntax.Extension -import Control.DeepSeq import Data.Data import Data.List.NonEmpty (NonEmpty(..)) import Data.List (intercalate) @@ -68,25 +69,9 @@ instance (Eq (LHsDocStringChunk pass), XXHsDocString pass ~ DataConCantHappen) = GeneratedDocString _ x == GeneratedDocString _ x' = x == x' _ == _ = False -instance (Show (LHsDocStringChunk pass), XXHsDocString pass ~ DataConCantHappen) => Show (HsDocString pass) where - showsPrec d (MultiLineDocString _ dec xs) = - showParen (d > 10) $ - showString "MultiLineDocString " . showsPrec 11 dec . showChar ' ' . showsPrec 11 xs - showsPrec d (NestedDocString _ dec x) = - showParen (d > 10) $ - showString "NestedDocString " . showsPrec 11 dec . showChar ' ' . showsPrec 11 x - showsPrec d (GeneratedDocString _ x) = - showParen (d > 10) $ - showString "GeneratedDocString " . showsPrec 11 x - instance Outputable (HsDocString (GhcPass p)) where ppr = text . renderHsDocString -instance NFData (HsDocString (GhcPass p)) where - rnf (MultiLineDocString _ a b) = rnf a `seq` rnf b - rnf (NestedDocString _ a b) = rnf a `seq` rnf b - rnf (GeneratedDocString _ a) = rnf a - -- | Annotate a pretty printed thing with its doc. -- The docstring comes after if it is 'HsDocStringPrevious'. -- Otherwise it comes before. @@ -120,37 +105,12 @@ instance Binary (HsDocString (GhcPass p)) where 2 -> GeneratedDocString noExtField <$> get bh t -> fail $ "HsDocString: invalid tag " ++ show t -instance Outputable HsDocStringDecorator where - ppr = text . printDecorator - printDecorator :: HsDocStringDecorator -> String printDecorator HsDocStringNext = "|" printDecorator HsDocStringPrevious = "^" printDecorator (HsDocStringNamed n) = '$':n printDecorator (HsDocStringGroup n) = replicate n '*' -instance Binary HsDocStringDecorator where - put_ bh x = case x of - HsDocStringNext -> putByte bh 0 - HsDocStringPrevious -> putByte bh 1 - HsDocStringNamed n -> putByte bh 2 >> put_ bh n - HsDocStringGroup n -> putByte bh 3 >> put_ bh n - get bh = do - tag <- getByte bh - case tag of - 0 -> pure HsDocStringNext - 1 -> pure HsDocStringPrevious - 2 -> HsDocStringNamed <$> get bh - 3 -> HsDocStringGroup <$> get bh - t -> fail $ "HsDocStringDecorator: invalid tag " ++ show t - -instance Binary HsDocStringChunk where - put_ bh (HsDocStringChunk bs) = put_ bh bs - get bh = HsDocStringChunk <$> get bh - -instance Outputable HsDocStringChunk where - ppr = text . unpackHDSC - mkGeneratedHsDocStringGhc :: String -> HsDocString (GhcPass p) mkGeneratedHsDocStringGhc = mkGeneratedHsDocString noExtField . mkHsDocStringChunk ===================================== compiler/GHC/Hs/ImpExp.hs ===================================== @@ -447,8 +447,3 @@ coveredByNamespaceSpecifier DataNamespaceSpecifier{} = isValNameSpace filterByNamespaceSpecifierGREs :: NamespaceSpecifier (GhcPass p) -> [GlobalRdrElt] -> [GlobalRdrElt] filterByNamespaceSpecifierGREs NoNamespaceSpecifier{} = id filterByNamespaceSpecifierGREs ns_spec = filterByNamespaceGREs (coveredByNamespaceSpecifier ns_spec) - -instance Outputable (NamespaceSpecifier (GhcPass p)) where - ppr NoNamespaceSpecifier{} = empty - ppr TypeNamespaceSpecifier{} = text "type" - ppr DataNamespaceSpecifier{} = text "data" ===================================== compiler/GHC/Hs/Lit.hs ===================================== @@ -505,17 +505,6 @@ instance Outputable (FractionalLit (GhcPass p)) where rat = fl_signi * (base ^^ fl_exp) in pprWithSourceText fl_text $ rational rat --- The 'Show' instance is required for the derived --- 'GHC.Parser.Lexer.Token' instance when DEBUG is enabled. -instance Show (FractionalLit (GhcPass p)) where - show (FL{..}) = unwords - [ show fl_text - , show fl_neg - , show fl_signi - , show fl_exp - , show fl_exp_base - ] - mkFractionalLit :: SourceText -> Bool -> @@ -626,9 +615,6 @@ instance Outputable (IntegralLit (GhcPass p)) where ppr (IL (SourceText src) _ _) = ftext src ppr (IL NoSourceText _ value) = text (show value) -instance Show (IntegralLit (GhcPass p)) where - show (IL{..}) = unwords [ show il_text, show il_neg, show il_value ] - mkIntegralLit :: Integral a => a -> IntegralLit (GhcPass p) mkIntegralLit i = IL { il_text = SourceText (fsLit $ show i_integer) @@ -678,10 +664,6 @@ instance Eq (StringLiteral (GhcPass p)) where instance Outputable (StringLiteral (GhcPass p)) where ppr (StringLiteral{..}) = pprWithSourceText sl_src (doubleQuotes $ ppr sl_fs) --- The 'Show' instance is required the 'parsed' test case of GHC's test-suite. -instance Show (StringLiteral (GhcPass p)) where - show (StringLiteral srcTxt litFS) = unwords [ show srcTxt, show litFS ] - -- | Get the 'SourceText' of a 'StringLiteral' {-# INLINE stringLitSourceText #-} stringLitSourceText :: StringLiteral (GhcPass p) -> SourceText ===================================== compiler/GHC/Hs/Specificity.hs deleted ===================================== @@ -1,51 +0,0 @@ -{-# OPTIONS_GHC -Wno-orphans #-} -module GHC.Hs.Specificity where - -import Prelude -import Control.DeepSeq (NFData(..)) - -import GHC.Utils.Outputable -import GHC.Utils.Binary - -import Language.Haskell.Syntax.Specificity - -{- ********************************************************************* -* * -* ForAllTyFlag -* * -********************************************************************* -} - -instance Outputable ForAllTyFlag where - ppr Required = text "[req]" - ppr Specified = text "[spec]" - ppr Inferred = text "[infrd]" - -instance Binary Specificity where - put_ bh SpecifiedSpec = putByte bh 0 - put_ bh InferredSpec = putByte bh 1 - - get bh = do - h <- getByte bh - case h of - 0 -> return SpecifiedSpec - _ -> return InferredSpec - -instance Binary ForAllTyFlag where - put_ bh Required = putByte bh 0 - put_ bh Specified = putByte bh 1 - put_ bh Inferred = putByte bh 2 - - get bh = do - h <- getByte bh - case h of - 0 -> return Required - 1 -> return Specified - _ -> return Inferred - -instance NFData Specificity where - rnf SpecifiedSpec = () - rnf InferredSpec = () -instance NFData ForAllTyFlag where - rnf (Invisible spec) = rnf spec - rnf Required = () - ===================================== compiler/GHC/Parser/PostProcess.hs ===================================== @@ -136,7 +136,6 @@ import GHC.Hs -- Lots of it import GHC.Core.TyCon ( TyCon, isTupleTyCon, tyConSingleDataCon_maybe ) import GHC.Core.DataCon ( DataCon, dataConTyCon, dataConName ) import GHC.Core.ConLike ( ConLike(..) ) -import GHC.Core.Coercion.Axiom ( fsFromRole ) import GHC.Types.Name.Reader import GHC.Types.Name import GHC.Types.Basic @@ -424,7 +423,7 @@ mkRoleAnnotDecl loc tycon roles anns where role_data_type = dataTypeOf (undefined :: Role) all_roles = map fromConstr $ dataTypeConstrs role_data_type - possible_roles = [(fsFromRole role, role) | role <- all_roles] + possible_roles = [(strFromRole role, role) | role <- all_roles] parse_role (L loc_role Nothing) = return $ L (noAnnSrcSpan loc_role) Nothing parse_role (L loc_role (Just role)) ===================================== compiler/GHC/Types/Basic.hs ===================================== @@ -14,14 +14,6 @@ types that \end{itemize} -} -{-# OPTIONS_GHC -Wno-orphans #-} -{- -Above flag is necessary for these instances: - * Binary Boxity - * Binary PromotionFlag - * Outputable Boxity - * Outputable PromotionFlag --} {-# LANGUAGE DerivingVia #-} module GHC.Types.Basic ( @@ -377,27 +369,6 @@ unSwap NotSwapped f a b = f a b unSwap IsSwapped f a b = f b a -{- ********************************************************************* -* * - Promotion flag -* * -********************************************************************* -} - -instance Outputable PromotionFlag where - ppr NotPromoted = text "NotPromoted" - ppr IsPromoted = text "IsPromoted" - -instance Binary PromotionFlag where - put_ bh NotPromoted = putByte bh 0 - put_ bh IsPromoted = putByte bh 1 - - get bh = do - n <- getByte bh - case n of - 0 -> return NotPromoted - 1 -> return IsPromoted - _ -> fail "Binary(IsPromoted): fail)" - {- ************************************************************************ * * ===================================== compiler/GHC/Types/FieldLabel.hs ===================================== @@ -1,5 +1,4 @@ {-# LANGUAGE UndecidableInstances #-} -{-# OPTIONS_GHC -Wno-orphans #-} -- Outputable FieldLabelString {- % @@ -48,7 +47,6 @@ import GHC.Prelude import {-# SOURCE #-} GHC.Types.Name -import GHC.Types.Unique (Uniquable(..)) import GHC.Utils.Outputable import GHC.Utils.Binary import GHC.Data.FastString @@ -89,12 +87,6 @@ instance Outputable FieldLabel where <> ppr (flHasDuplicateRecordFields fl) <> ppr (flHasFieldSelector fl)) -instance Outputable FieldLabelString where - ppr (FieldLabelString l) = ppr l - -instance Uniquable FieldLabelString where - getUnique (FieldLabelString fs) = getUnique (mkFastStringShortText fs) - -- | Flag to indicate whether the DuplicateRecordFields extension is enabled. data DuplicateRecordFields = DuplicateRecordFields -- ^ Fields may be duplicated in a single module ===================================== compiler/GHC/Types/Fixity.hs ===================================== @@ -1,5 +1,3 @@ -{-# OPTIONS_GHC -Wno-dodgy-exports #-} -- For re-export of GHC.Hs.Basic instances - -- | Fixity module GHC.Types.Fixity ( Fixity (..) @@ -11,14 +9,12 @@ module GHC.Types.Fixity , negateFixity , funTyFixity , compareFixity - , module GHC.Hs.Basic ) where import GHC.Prelude import Language.Haskell.Syntax.Basic (LexicalFixity(..), FixityDirection(..), Fixity(..) ) -import GHC.Hs.Basic () -- For instances only ------------------------ ===================================== compiler/GHC/Types/ForeignCall.hs ===================================== @@ -319,13 +319,6 @@ type instance XXHeader (GhcPass p) = DataConCantHappen deriving instance Eq (Header (GhcPass p)) -instance NFData (CType (GhcPass p)) where - rnf (CType ext mh fs) = - rnf ext `seq` rnf mh `seq` rnf fs - -instance NFData (Header (GhcPass p)) where - rnf (Header s h) = - rnf s `seq` rnf h instance NFData CCallStaticTargetUnit where rnf = \case @@ -388,14 +381,6 @@ instance forall p. IsPass p => Eq (CCallTarget (GhcPass p)) where GhcTc -> x1 == x2 _ -> False -instance forall p. IsPass p => NFData (CCallTarget (GhcPass p)) where - rnf = \case - DynamicTarget NoExtField -> () - StaticTarget x a b -> rnf a `seq` rnf b `seq` case ghcPass @p of - GhcPs -> rnf x - GhcRn -> rnf x - GhcTc -> rnf x - instance forall p. IsPass p => Binary (CCallTarget (GhcPass p)) where put_ bh = \case StaticTarget x a b -> do ===================================== compiler/GHC/Types/InlinePragma.hs ===================================== @@ -9,16 +9,8 @@ -} {-# OPTIONS_GHC -Wno-orphans #-} -{- -Suppression of warnings are required for instances: - - Binary Activation - - Binary CompilerPhase - - Binary InlinePragma - - Binary InlineSaturation - - Binary XActivation - - Binary XInlinePragmaGhc - - Outputable CompilerPhase --} +-- Required for TTG type-family definitions, +-- There are no orphan type-class instances module GHC.Types.InlinePragma ( -- * Inline Pragma Encoding @@ -494,10 +486,6 @@ no harm. always returns 'False' when its second argument is 'NeverActive'. -} -{- TODO: These orphan instance should be moved to the GHC.Utils.{Binary,Outputable} -modules once TTG has progressed and the Language.Haskell.Syntax.Types module -no longer depends on importing GHC.Hs.Doc. --} instance Binary XInlinePragmaGhc where put_ bh (XInlinePragmaGhc s a) = do put_ bh s @@ -508,26 +496,6 @@ instance Binary XInlinePragmaGhc where a <- get bh return (XInlinePragmaGhc s a) -instance forall p. IsPass p => Binary (InlinePragma (GhcPass p)) where - put_ bh (InlinePragma s a b c) = do - put_ bh a - put_ bh b - put_ bh c - case ghcPass @p of - GhcPs -> put_ bh s - GhcRn -> put_ bh s - GhcTc -> put_ bh s - - get bh = do - a <- get bh - b <- get bh - c <- get bh - s <- case ghcPass @p of - GhcPs -> get bh - GhcRn -> get bh - GhcTc -> get bh - return (InlinePragma s a b c) - instance Binary InlineSaturation where put_ bh AnySaturation = putByte bh 0 put_ bh (AppliedToAtLeast w) = putByte bh 1 *> put_ bh w @@ -620,5 +588,24 @@ pprInline' emptyInline (InlinePragma AnySaturation -> empty AppliedToAtLeast ar -> parens (text "sat-args=" <> int ar) +{- TODO: This orphan instance should be moved to GHC.Utils.Outputable once that +module can import 'GhcPass' without causing an import cycle. +@ +┌──────▶ GHC.Utils.Outputable +│ │ +│ │ Needs to access GhcPass for instance: +│ │ Outputable (InlinePragma (GhcPass p)) +│ ▼ +│ GHC.Hs.Extension.GhcPass +│ │ +│ │ For GenLocated, SrcSpan, unLoc +│ ▼ +│ GHC.Types.SrcLoc +│ │ +│ │ for Outputable, SDoc, +│ │ pprFastFilePath, ppr combinators +└───────────────┘ +@ +-} instance forall p. IsPass p => Outputable (InlinePragma (GhcPass p)) where ppr = pprInline ===================================== compiler/GHC/Types/Unique.hs ===================================== @@ -68,7 +68,8 @@ import GHC.Exts (indexCharOffAddr#, Char(..), Int(..)) import GHC.Word ( Word64 ) import Data.Char ( chr, ord, isPrint ) -import Language.Haskell.Syntax.Module.Name +import Language.Haskell.Syntax.Basic ( FieldLabelString(..) ) +import Language.Haskell.Syntax.Module.Name ( ModuleName(..) ) {- ************************************************************************ @@ -419,6 +420,8 @@ instance Uniquable Word64 where instance Uniquable ModuleName where getUnique (ModuleName nm) = getUnique nm +instance Uniquable FieldLabelString where + getUnique (FieldLabelString fs) = getUnique (mkFastStringShortText fs) {- ************************************************************************ ===================================== compiler/GHC/Types/Var.hs ===================================== @@ -129,7 +129,6 @@ import GHC.Utils.Binary import GHC.Utils.Outputable import GHC.Utils.Panic -import GHC.Hs.Specificity () import Language.Haskell.Syntax.Specificity import Control.DeepSeq ===================================== compiler/GHC/Utils/Binary.hs ===================================== @@ -1,5 +1,8 @@ {-# LANGUAGE CPP #-} +{-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE MagicHash #-} +{-# LANGUAGE TypeFamilies #-} +{-# LANGUAGE UndecidableInstances #-} {-# LANGUAGE UnboxedTuples #-} {-# LANGUAGE DerivingVia #-} @@ -119,8 +122,13 @@ import GHC.Prelude import Language.Haskell.Syntax.Basic import Language.Haskell.Syntax.Binds.InlinePragma +import Language.Haskell.Syntax.Decls.Overlap +import Language.Haskell.Syntax.Doc +import Language.Haskell.Syntax.Extension import Language.Haskell.Syntax.Module.Name (ModuleName(..)) import Language.Haskell.Syntax.ImpExp.IsBoot (IsBootInterface(..)) +import Language.Haskell.Syntax.Specificity +import Language.Haskell.Syntax.Type (PromotionFlag(..)) import {-# SOURCE #-} GHC.Types.Name (Name) import GHC.Data.ShortText (ShortText) @@ -164,7 +172,7 @@ import qualified Data.Map.Strict as Map import Data.Proxy import Data.Set ( Set ) import qualified Data.Set as Set -import Data.Time +import Data.Time hiding ( Nominal ) import Data.List (unfoldr) import System.IO as IO import System.IO.Error ( mkIOError, eofErrorType ) @@ -1926,6 +1934,85 @@ instance Binary ModuleName where put_ bh (ModuleName fs) = put_ bh fs get bh = do fs <- get bh; return (ModuleName fs) +instance Binary Specificity where + put_ bh SpecifiedSpec = putByte bh 0 + put_ bh InferredSpec = putByte bh 1 + + get bh = do + h <- getByte bh + case h of + 0 -> return SpecifiedSpec + _ -> return InferredSpec + +instance Binary ForAllTyFlag where + put_ bh Required = putByte bh 0 + put_ bh Specified = putByte bh 1 + put_ bh Inferred = putByte bh 2 + + get bh = do + h <- getByte bh + case h of + 0 -> return Required + 1 -> return Specified + _ -> return Inferred + +instance Binary HsDocStringDecorator where + put_ bh x = case x of + HsDocStringNext -> putByte bh 0 + HsDocStringPrevious -> putByte bh 1 + HsDocStringNamed n -> putByte bh 2 >> put_ bh n + HsDocStringGroup n -> putByte bh 3 >> put_ bh n + + get bh = do + tag <- getByte bh + case tag of + 0 -> pure HsDocStringNext + 1 -> pure HsDocStringPrevious + 2 -> HsDocStringNamed <$> get bh + 3 -> HsDocStringGroup <$> get bh + t -> fail $ "HsDocStringDecorator: invalid tag " ++ show t + +instance Binary HsDocStringChunk where + put_ bh (HsDocStringChunk bs) = put_ bh bs + get bh = HsDocStringChunk <$> get bh + +instance ( Binary (XInlinePragma p) + , Binary (Activation p) + , XXInlinePragma p ~ DataConCantHappen + ) => Binary (InlinePragma p) where + put_ bh (InlinePragma s a b c) = do + put_ bh a + put_ bh b + put_ bh c + put_ bh s + + get bh = do + a <- get bh + b <- get bh + c <- get bh + s <- get bh + return (InlinePragma s a b c) + +instance ( Binary (XOverlapMode p) + , XXOverlapMode p ~ DataConCantHappen + ) => Binary (OverlapMode p) where + put_ bh (NoOverlap s) = putByte bh 0 >> put_ bh s + put_ bh (Overlaps s) = putByte bh 1 >> put_ bh s + put_ bh (Incoherent s) = putByte bh 2 >> put_ bh s + put_ bh (Overlapping s) = putByte bh 3 >> put_ bh s + put_ bh (Overlappable s) = putByte bh 4 >> put_ bh s + put_ bh (NonCanonical s) = putByte bh 5 >> put_ bh s + + get bh = do + h <- getByte bh + case h of + 0 -> get bh >>= \s -> return $ NoOverlap s + 1 -> get bh >>= \s -> return $ Overlaps s + 2 -> get bh >>= \s -> return $ Incoherent s + 3 -> get bh >>= \s -> return $ Overlapping s + 4 -> get bh >>= \s -> return $ Overlappable s + _ -> get bh >>= \s -> return $ NonCanonical s + newtype BinLocated a = BinLocated { unBinLocated :: Located a } instance Binary a => Binary (BinLocated a) where @@ -2087,6 +2174,26 @@ instance Binary Boxity where -- implemented via isBoxed-isomorphism to Bool b <- get bh pure $ if b then Boxed else Unboxed +instance Binary Fixity where + put_ bh (Fixity aa ab) = do + put_ bh aa + put_ bh ab + get bh = do + aa <- get bh + ab <- get bh + return (Fixity aa ab) + +instance Binary FixityDirection where + put_ bh InfixL = putByte bh 0 + put_ bh InfixR = putByte bh 1 + put_ bh InfixN = putByte bh 2 + get bh = do + h <- getByte bh + case h of + 0 -> return InfixL + 1 -> return InfixR + _ -> return InfixN + instance Binary ConInfoTable where get bh = Binary.decode <$> get bh @@ -2149,3 +2256,49 @@ instance Binary RuleMatchInfo where h <- getByte bh if h == 1 then pure ConLike else pure FunLike + +instance Binary Role where + put_ bh Nominal = putByte bh 1 + put_ bh Representational = putByte bh 2 + put_ bh Phantom = putByte bh 3 + + get bh = do tag <- getByte bh + case tag of 1 -> return Nominal + 2 -> return Representational + 3 -> return Phantom + _ -> panic ("get Role " ++ show tag) + +instance Binary SrcStrictness where + put_ bh SrcLazy = putByte bh 0 + put_ bh SrcStrict = putByte bh 1 + put_ bh NoSrcStrict = putByte bh 2 + + get bh = + do h <- getByte bh + case h of + 0 -> return SrcLazy + 1 -> return SrcStrict + _ -> return NoSrcStrict + +instance Binary SrcUnpackedness where + put_ bh SrcNoUnpack = putByte bh 0 + put_ bh SrcUnpack = putByte bh 1 + put_ bh NoSrcUnpack = putByte bh 2 + + get bh = + do h <- getByte bh + case h of + 0 -> return SrcNoUnpack + 1 -> return SrcUnpack + _ -> return NoSrcUnpack + +instance Binary PromotionFlag where + put_ bh NotPromoted = putByte bh 0 + put_ bh IsPromoted = putByte bh 1 + + get bh = do + n <- getByte bh + case n of + 0 -> return NotPromoted + 1 -> return IsPromoted + _ -> fail "Binary(IsPromoted): fail)" ===================================== compiler/GHC/Utils/Outputable.hs ===================================== @@ -115,12 +115,17 @@ import {-# SOURCE #-} GHC.Types.Name.Occurrence( OccName ) import Language.Haskell.Syntax.Basic import Language.Haskell.Syntax.Binds.InlinePragma import Language.Haskell.Syntax.Decls.Overlap ( OverlapMode(..) ) +import Language.Haskell.Syntax.Doc +import Language.Haskell.Syntax.ImpExp ( NamespaceSpecifier(..) ) import Language.Haskell.Syntax.Module.Name ( ModuleName(..) ) +import Language.Haskell.Syntax.Specificity import Language.Haskell.Syntax.Text +import Language.Haskell.Syntax.Type ( PromotionFlag(..) ) import GHC.Prelude.Basic import GHC.Utils.BufHandle (BufHandle, bPutChar, bPutStr, bPutFS, bPutFZS) +import GHC.Utils.Encoding ( utf8DecodeByteString ) import GHC.Data.FastString import qualified GHC.Utils.Ppr as Pretty import qualified GHC.Utils.Ppr.Colour as Col @@ -1108,6 +1113,28 @@ instance Outputable Extension where instance Outputable ModuleName where ppr = pprModuleName +instance Outputable FieldLabelString where + ppr (FieldLabelString l) = ppr l + +instance Outputable ForAllTyFlag where + ppr Required = text "[req]" + ppr Specified = text "[spec]" + ppr Inferred = text "[infrd]" + +instance Outputable HsDocStringDecorator where + ppr HsDocStringNext = text "|" + ppr HsDocStringPrevious = text "^" + ppr (HsDocStringNamed n) = char '$' <> text n + ppr (HsDocStringGroup n) = text (replicate n '*') + +instance Outputable HsDocStringChunk where + ppr (HsDocStringChunk bs) = text (utf8DecodeByteString bs) + +-- | For compatibility with the existing @-ddump-parsed@ output, we only show +-- the docstring. +instance Outputable a => Outputable (WithHsDocIdentifiers a pass) where + ppr (WithHsDocIdentifiers s _ids) = ppr s + instance Outputable OsPath where ppr p = text $ either show id (decodeUtf p) @@ -2039,6 +2066,35 @@ instance Outputable TopLevelFlag where ppr TopLevel = text "<TopLevel>" ppr NotTopLevel = text "<NotTopLevel>" +instance Outputable LexicalFixity where + ppr Prefix = text "Prefix" + ppr Infix = text "Infix" + +instance Outputable FixityDirection where + ppr InfixL = text "infixl" + ppr InfixR = text "infixr" + ppr InfixN = text "infix" + +instance Outputable Fixity where + ppr (Fixity prec dir) = hcat [ppr dir, space, int prec] + +instance Outputable SrcStrictness where + ppr SrcLazy = char '~' + ppr SrcStrict = char '!' + ppr NoSrcStrict = empty + +instance Outputable SrcUnpackedness where + ppr SrcUnpack = text "{-# UNPACK #-}" + ppr SrcNoUnpack = text "{-# NOUNPACK #-}" + ppr NoSrcUnpack = empty + +instance Outputable PromotionFlag where + ppr NotPromoted = text "NotPromoted" + ppr IsPromoted = text "IsPromoted" + +instance Outputable Role where + ppr = ftext . strFromRole + instance Outputable (OverlapMode p) where ppr (NoOverlap _) = empty ppr (Overlappable _) = text "[overlappable]" @@ -2047,3 +2103,9 @@ instance Outputable (OverlapMode p) where ppr (Incoherent _) = text "[incoherent]" ppr (NonCanonical _) = text "[noncanonical]" ppr (XOverlapMode _) = text "[user TTG extension]" + +instance Outputable (NamespaceSpecifier p) where + ppr NoNamespaceSpecifier{} = empty + ppr TypeNamespaceSpecifier{} = text "type" + ppr DataNamespaceSpecifier{} = text "data" + ppr (XNamespaceSpecifier _) = text "[user TTG extension]" ===================================== compiler/Language/Haskell/Syntax/Basic.hs ===================================== @@ -8,6 +8,7 @@ import Data.Data (Data) import Data.Eq import Data.Ord import Data.Bool +import Data.String (IsString(..)) import Prelude {- @@ -93,6 +94,20 @@ Field Labels data Role = Nominal | Representational | Phantom deriving (Eq, Ord, Data) +instance NFData Role where + rnf Nominal = () + rnf Representational = () + rnf Phantom = () + +-- These names are slurped into the parser code. Changing these strings +-- will change the **surface syntax** that GHC accepts! If you want to +-- change only the pretty-printing, do some replumbing. See +-- mkRoleAnnotDecl in GHC.Parser.PostProcess +strFromRole :: IsString s => Role -> s +strFromRole Nominal = fromString "nominal" +strFromRole Representational = fromString "representational" +strFromRole Phantom = fromString "phantom" + {- ************************************************************************ * * @@ -109,6 +124,11 @@ data SrcStrictness = SrcLazy -- ^ Lazy, ie '~' | NoSrcStrict -- ^ no strictness annotation deriving (Eq, Data) +instance NFData SrcStrictness where + rnf SrcLazy = () + rnf SrcStrict = () + rnf NoSrcStrict = () + -- | Source Unpackedness -- -- What unpackedness the user requested @@ -117,6 +137,11 @@ data SrcUnpackedness = SrcUnpack -- ^ {-# UNPACK #-} specified | NoSrcUnpack -- ^ no unpack pragma deriving (Eq, Data) +instance NFData SrcUnpackedness where + rnf SrcNoUnpack = () + rnf SrcUnpack = () + rnf NoSrcUnpack = () + {- ************************************************************************ * * ===================================== compiler/Language/Haskell/Syntax/Decls/Foreign.hs ===================================== @@ -74,7 +74,7 @@ import Control.DeepSeq import Data.Data hiding (TyCon, Fixity, Infix) import Data.Maybe import Data.Eq -import Prelude (Enum, Show) +import Prelude (Enum, Show, seq) {- ************************************************************************ @@ -211,6 +211,12 @@ data CCallTarget pass | DynamicTarget (XDynamicTarget pass) | XCCallTarget !(XXCCallTarget pass) +instance (NFData (XStaticTarget pass), NFData (XDynamicTarget pass), NFData (XXCCallTarget pass)) + => NFData (CCallTarget pass) where + rnf (StaticTarget x a b) = rnf x `seq` rnf a `seq` rnf b + rnf (DynamicTarget x) = rnf x + rnf (XCCallTarget x) = rnf x + data CExportSpec -- | foreign export ccall foo :: ty = CExportStatic @@ -228,6 +234,11 @@ data CType pass HText | XCType !(XXCType pass) +instance (NFData (XCType pass), NFData (Header pass), NFData (XXCType pass)) + => NFData (CType pass) where + rnf (CType ext mh fs) = rnf ext `seq` rnf mh `seq` rnf fs + rnf (XCType x) = rnf x + -- | The filename for a C header file data Header pass = Header @@ -235,6 +246,10 @@ data Header pass HText | XHeader !(XXHeader pass) +instance (NFData (XHeader pass), NFData (XXHeader pass)) => NFData (Header pass) where + rnf (Header s h) = rnf s `seq` rnf h + rnf (XHeader x) = rnf x + data Safety = PlaySafe -- ^ Might invoke Haskell GC, or do a call back, or -- switch threads, etc. So make sure things are ===================================== compiler/Language/Haskell/Syntax/Doc.hs ===================================== @@ -65,6 +65,32 @@ data HsDocString pass | XHsDocString !(XXHsDocString pass) +instance + ( NFData (XMultiLineDocString pass) + , NFData (XNestedDocString pass) + , NFData (XGeneratedDocString pass) + , NFData (XXHsDocString pass) + , NFData (LHsDocStringChunk pass) + ) => NFData (HsDocString pass) where + rnf (MultiLineDocString x a b) = rnf x `seq` rnf a `seq` rnf b + rnf (NestedDocString x a b) = rnf x `seq` rnf a `seq` rnf b + rnf (GeneratedDocString x a) = rnf x `seq` rnf a + rnf (XHsDocString x) = rnf x + +instance (Show (LHsDocStringChunk pass), Show (XXHsDocString pass)) => Show (HsDocString pass) where + showsPrec d (MultiLineDocString _ dec xs) = + showParen (d > 10) $ + showString "MultiLineDocString " . showsPrec 11 dec . showChar ' ' . showsPrec 11 xs + showsPrec d (NestedDocString _ dec x) = + showParen (d > 10) $ + showString "NestedDocString " . showsPrec 11 dec . showChar ' ' . showsPrec 11 x + showsPrec d (GeneratedDocString _ x) = + showParen (d > 10) $ + showString "GeneratedDocString " . showsPrec 11 x + showsPrec d (XHsDocString x) = + showParen (d > 10) $ + showString "XHsDocString " . showsPrec 11 x + mkGeneratedHsDocString :: XGeneratedDocString p -> HsDocStringChunk -> HsDocString p mkGeneratedHsDocString x = GeneratedDocString x @@ -110,3 +136,6 @@ data WithHsDocIdentifiers a pass = WithHsDocIdentifiers { hsDocString :: !a , hsDocIdentifiers :: ![LIdP pass] } + +instance (UnXRec pass, NFData (IdP pass), NFData a) => NFData (WithHsDocIdentifiers a pass) where + rnf (WithHsDocIdentifiers d i) = rnf d `seq` rnf (map (unXRec @pass) i) ===================================== compiler/Language/Haskell/Syntax/Extension.hs ===================================== @@ -9,6 +9,7 @@ module Language.Haskell.Syntax.Extension where -- This module captures the type families to precisely identify the extension -- points for GHC.Hs syntax +import Control.DeepSeq import Data.Type.Equality (type (~)) import Data.Data hiding ( Fixity ) @@ -16,6 +17,7 @@ import Data.Kind (Type) import Data.Eq import Data.Ord +import Text.Show {- Note [Trees That Grow] @@ -62,6 +64,9 @@ See also Note [IsPass] and Note [NoGhcTc] in GHC.Hs.Extension. data NoExtField = NoExtField deriving (Data,Eq,Ord) +instance NFData NoExtField where + rnf NoExtField = () + -- | Used when constructing a term with an unused extension point. noExtField :: NoExtField noExtField = NoExtField @@ -95,7 +100,10 @@ can only do that if the extension field was strict (#18764). See also [DataConCantHappen and strict fields]. -} data DataConCantHappen - deriving (Data,Eq,Ord) + deriving (Data,Eq,Ord,Show) + +instance NFData DataConCantHappen where + rnf = dataConCantHappen -- | Eliminate a 'DataConCantHappen'. See Note [Constructor cannot occur]. dataConCantHappen :: DataConCantHappen -> a ===================================== compiler/Language/Haskell/Syntax/ImpExp.hs ===================================== @@ -1,4 +1,6 @@ {-# LANGUAGE TypeFamilies #-} +{-# LANGUAGE UndecidableInstances #-} -- Wrinkle in Note [Trees That Grow] + -- in module Language.Haskell.Syntax.Extension module Language.Haskell.Syntax.ImpExp ( module Language.Haskell.Syntax.ImpExp, IsBootInterface(..) ) where import Language.Haskell.Syntax.Doc (LHsDoc) @@ -6,9 +8,9 @@ import Language.Haskell.Syntax.Extension import Language.Haskell.Syntax.Module.Name import Language.Haskell.Syntax.ImpExp.IsBoot ( IsBootInterface(..) ) -import Data.Eq (Eq) +import Data.Eq (Eq(..)) import Data.Data (Data) -import Data.Bool (Bool) +import Data.Bool (Bool(..)) import Data.Maybe (Maybe) import Data.String (String) import Data.Int (Int) ===================================== compiler/Language/Haskell/Syntax/Lit.hs ===================================== @@ -1,3 +1,4 @@ +{-# LANGUAGE RecordWildCards #-} {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE UndecidableInstances #-} -- Wrinkle in Note [Trees That Grow] -- in module Language.Haskell.Syntax.Extension @@ -118,6 +119,7 @@ data OverLitVal x = HsIntegral !(IntegralLit x) -- ^ Integer-looking literals | HsFractional !(FractionalLit x) -- ^ Frac-looking literals | HsIsString !(StringLiteral x) -- ^ String-looking literals + -- | Haskell Qualified Literal data HsQualLit p = QualLit @@ -158,6 +160,18 @@ data FractionalLit pass = FL } | XFractionalLit !(XXFractionalLit pass) +-- The 'Show' instance is required for the derived +-- 'GHC.Parser.Lexer.Token' instance when DEBUG is enabled. +instance (Show (XFractionalLit pass), Show (XXFractionalLit pass)) => Show (FractionalLit pass) where + show (FL{..}) = unwords + [ show fl_text + , show fl_neg + , show fl_signi + , show fl_exp + , show fl_exp_base + ] + show (XFractionalLit x) = show x + {- Note [fractional exponent bases] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ For hexadecimal rationals of @@ -183,6 +197,10 @@ data IntegralLit pass = IL } | XIntegralLit !(XXIntegralLit pass) +instance (Show (XIntegralLit pass), Show (XXIntegralLit pass)) => Show (IntegralLit pass) where + show (IL{..}) = unwords [ show il_text, show il_neg, show il_value ] + show (XIntegralLit x) = show x + -- | Located Haskell String Literal type LStringLit p = XRec p (StringLiteral p) @@ -193,3 +211,8 @@ data StringLiteral pass = StringLiteral , sl_fs :: HText -- literal string value } | XStringLit !(XXStringLit pass) + +-- The 'Show' instance is required the 'parsed' test case of GHC's test-suite. +instance (Show (XStringLit pass), Show (XXStringLit pass)) => Show (StringLiteral pass) where + show (StringLiteral srcTxt litFS) = unwords [ show srcTxt, show litFS ] + show (XStringLit x) = show x ===================================== compiler/Language/Haskell/Syntax/Specificity.hs ===================================== @@ -14,6 +14,7 @@ module Language.Haskell.Syntax.Specificity ( import Prelude +import Control.DeepSeq (NFData(..)) import Data.Data -- | ForAllTyFlag @@ -27,6 +28,10 @@ data ForAllTyFlag = Invisible !Specificity deriving (Eq, Ord, Data) -- (<) on ForAllTyFlag means "is less visible than" +instance NFData ForAllTyFlag where + rnf (Invisible spec) = rnf spec + rnf Required = () + -- | Whether an 'Invisible' argument may appear in source Haskell. data Specificity = InferredSpec -- ^ the argument may not appear in source Haskell, it is @@ -36,6 +41,10 @@ data Specificity = InferredSpec -- required. deriving (Eq, Ord, Data) +instance NFData Specificity where + rnf SpecifiedSpec = () + rnf InferredSpec = () + pattern Inferred, Specified :: ForAllTyFlag pattern Inferred = Invisible InferredSpec pattern Specified = Invisible SpecifiedSpec ===================================== compiler/ghc.cabal.in ===================================== @@ -566,7 +566,6 @@ Library GHC.Hs.Instances GHC.Hs.Lit GHC.Hs.Pat - GHC.Hs.Specificity GHC.Hs.Stats GHC.HsToCore GHC.HsToCore.Arrows ===================================== testsuite/tests/count-deps/CountDepsParser.stdout ===================================== @@ -113,7 +113,6 @@ GHC.Hs.ImpExp GHC.Hs.Instances GHC.Hs.Lit GHC.Hs.Pat -GHC.Hs.Specificity GHC.Hs.Type GHC.Hs.Utils GHC.HsToCore.Errors.Types View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/13b83052dedcadf22265f3e801f3625e... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/13b83052dedcadf22265f3e801f3625e... You're receiving this email because of your account on gitlab.haskell.org.
participants (1)
-
recursion-ninja (@recursion-ninja)