TTG: Removing orphan instances after AST separation
Issue Being Solved
Resolves issue #27469 and issue #21262
The TTG migration has moved much of the Haskell AST surface into the
Language.Haskell.Syntax namespace, while GHC-specific behavior remains in
the GHC namespace. During that transition, many instances for
Language.Haskell.Syntax data types were temporarily left in GHC-side modules
that define neither the type nor the class. Those instances are orphans.
The purpose of this MR is to retire as much of that temporary technical debt as possible
without changing AST semantics, without moving GHC internals into
Language.Haskell.Syntax, and without introducing new boot files.
How I Find Homes for Orphans
This MR resolves the orphan debt using a single, simple methodology:
Migrate all immediately movable orphan type-class instances for
Language.Haskell.Syntaxdata-types into the module that owns the class or the module that defines the data-type. For example,Binaryinstances move toGHC.Utils.Binary.
Throughout the MR, moved instance bodies preserve the previous encodings, pretty-printed strings, and uniqueness behavior. There should be no semantic rewrites.
Resolved Orphan Instances
The table below aggregates the all 39 of the resolved orphan type-class instances across the MR.
Click to expand table of resolved orphan type-class instances (all instances)
| 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 |
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 |
Remaining Orphan Instances
Some cases orphan instances remain because moving them would require a larger architectural refactor than is reasonable for this MR to attempt.
The common pattern across these cases is that the instance is not a leaf instance: it depends on pass-specific type-family equations, local payload types, local pretty-printer helpers, or Name/Id machinery that already sits above the class module in the import graph.
For the analysis of removing technical debt, I have only considered the type-class orphan instance heads introduced by the TTG decoupling commits between fe2b79f4f21acf077738eb9ae9868c6b28afd1c4 and 809c867c9a64e34616b1be09b5aff62c6bba1ff2.
This excludes type-family instances and pre-existing orphan class instances, or orphan instance introduced in non-TTG-authored commits.
Additionally, it excludes orphan type-class instances from the GHC.Hs.Instances module, since these instances are expected and intentionally defined in this module to reduce GHC compile times.
The table below lists the orphan type-class instances, which were introduced by TTG, and remain unresolved by this MR.
Click to expand table of remaining orphan type-class instances (introduced by TTG)
| Data-type | Remaining instance(s) | Current orphan module(s) | Notes |
|---|---|---|---|
CCallTarget |
Binary |
GHC.Types.ForeignCall |
Pass-indexed foreign-call target support remains split between generic Data derivings and foreign-call behavior. |
CType |
Binary; Outputable
|
GHC.Types.ForeignCall |
Depends on GHC-specific CTypeGhc payloads and source-text handling. |
FractionalLit |
Ord; Outputable
|
GHC.Hs.Lit |
Literal behavior remains tied to source text and literal pretty-printing helpers. |
Header |
Binary; Outputable
|
GHC.Types.ForeignCall |
Depends on GHC-specific header payloads and source-text handling. |
HsOverLit |
Ord |
GHC.Hs.Lit |
Outputable support is outside this TTG-authored partition. |
HsQualLit |
Ord |
GHC.Hs.Lit |
Outputable support is outside this TTG-authored partition. |
InlinePragma |
Outputable |
GHC.Types.InlinePragma |
The Binary instance is resolved by this MR; pretty-printing still depends on inline-pragmas helpers. |
IntegralLit |
Ord; Outputable
|
GHC.Hs.Lit |
Literal behavior remains tied to source text and literal pretty-printing helpers. |
OverLitVal |
Ord; Outputable
|
GHC.Hs.Lit |
Overloaded literal value behavior remains tied to GHC literal payloads. |
QualLitVal |
Ord; Outputable
|
GHC.Hs.Lit |
Qualified literal value behavior remains tied to GHC literal payloads. |
StringLiteral |
Outputable |
GHC.Hs.Lit |
String literal behavior remains tied to source text and encoding helpers. |
WarningTxt |
Outputable |
GHC.Unit.Module.Warnings |
Warning text behavior depends on warning-category payloads and doc/literal rendering. |
WithHsDocIdentifiers |
Binary |
GHC.Hs.Doc |
The Outputable instance is resolved by this MR; binary serialization still needs stable Name ordering. |
Summary Statistics
Resolves orphan instances, introduced by or predating, the TTG project.