[Git][ghc/ghc][master] Give the Data instance for ModuleName a non-bottom toConstr implementation.
Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC Commits: 28ce1f8a by Andreas Klebinger at 2026-04-03T19:58:44-04:00 Give the Data instance for ModuleName a non-bottom toConstr implementation. I've also taken the liberty to add Note [Data.Data instances for GHC AST Types] describing some of the uses of Data.Data I could find. Fixes #27129 - - - - - 2 changed files: - compiler/GHC/Hs/Instances.hs - compiler/Language/Haskell/Syntax/Module/Name.hs Changes: ===================================== compiler/GHC/Hs/Instances.hs ===================================== @@ -17,6 +17,21 @@ module GHC.Hs.Instances where -- UndecidableInstances ? +{- Note [Data.Data instances for GHC AST Types] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +We give all of the frontend types and their instantiations (HsSyn) and +some other types Data.Data instances. There are two main motivations to +do so: + +* For users of the GHC API it allows to write Generic code over the GHC AST. +* GHC itself has a few uses of these as well: + * In the showAstData, showAstDataFull helpers to print a representation of + the actual AST using it's constructors rather than just user facing pretty printing. + * It's used to some degree for HIE file generation in the ToHIE instances. + * TH serialization uses it for serialization of Annotations (GHC.Serialized) + * Some of the dump flags use showAstData to produce the actual dump output. +-} + import Data.Data hiding ( Fixity ) import GHC.Prelude ===================================== compiler/Language/Haskell/Syntax/Module/Name.hs ===================================== @@ -17,7 +17,8 @@ instance Data ModuleName where -- don't traverse? toConstr x = constr where - constr = mkConstr (dataTypeOf x) "{abstract:ModuleName}" [] Prefix + -- Fake a Algebraic constr. See #27129 + constr = mkConstrTag (dataTypeOf x) "{abstract:ModuleName}" 1 [] Prefix gunfold _ _ = error "gunfold" dataTypeOf _ = mkNoRepType "ModuleName" View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/28ce1f8afb9dd74bc39148a36f5bf61f... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/28ce1f8afb9dd74bc39148a36f5bf61f... You're receiving this email because of your account on gitlab.haskell.org.
participants (1)
-
Marge Bot (@marge-bot)