Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC
Commits:
-
28ce1f8a
by Andreas Klebinger at 2026-04-03T19:58:44-04:00
2 changed files:
Changes:
| ... | ... | @@ -17,6 +17,21 @@ module GHC.Hs.Instances where |
| 17 | 17 | |
| 18 | 18 | -- UndecidableInstances ?
|
| 19 | 19 | |
| 20 | +{- Note [Data.Data instances for GHC AST Types]
|
|
| 21 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
| 22 | +We give all of the frontend types and their instantiations (HsSyn) and
|
|
| 23 | +some other types Data.Data instances. There are two main motivations to
|
|
| 24 | +do so:
|
|
| 25 | + |
|
| 26 | +* For users of the GHC API it allows to write Generic code over the GHC AST.
|
|
| 27 | +* GHC itself has a few uses of these as well:
|
|
| 28 | + * In the showAstData, showAstDataFull helpers to print a representation of
|
|
| 29 | + the actual AST using it's constructors rather than just user facing pretty printing.
|
|
| 30 | + * It's used to some degree for HIE file generation in the ToHIE instances.
|
|
| 31 | + * TH serialization uses it for serialization of Annotations (GHC.Serialized)
|
|
| 32 | + * Some of the dump flags use showAstData to produce the actual dump output.
|
|
| 33 | +-}
|
|
| 34 | + |
|
| 20 | 35 | import Data.Data hiding ( Fixity )
|
| 21 | 36 | |
| 22 | 37 | import GHC.Prelude
|
| ... | ... | @@ -17,7 +17,8 @@ instance Data ModuleName where |
| 17 | 17 | -- don't traverse?
|
| 18 | 18 | toConstr x = constr
|
| 19 | 19 | where
|
| 20 | - constr = mkConstr (dataTypeOf x) "{abstract:ModuleName}" [] Prefix
|
|
| 20 | + -- Fake a Algebraic constr. See #27129
|
|
| 21 | + constr = mkConstrTag (dataTypeOf x) "{abstract:ModuleName}" 1 [] Prefix
|
|
| 21 | 22 | gunfold _ _ = error "gunfold"
|
| 22 | 23 | dataTypeOf _ = mkNoRepType "ModuleName"
|
| 23 | 24 |