goldfirere / th-desugar

Desugars Template Haskell abstract syntax to a simpler format without changing semantics
BSD 3-Clause "New" or "Revised" License
20 stars 13 forks source link

GHC 9.6 checklist #170

Closed RyanGlScott closed 1 year ago

RyanGlScott commented 1 year ago

This issue serves as a reminder to do certain things before we ship a new major release that supports GHC 9.6:

RyanGlScott commented 1 year ago

The type data-in-TH patch added support for type data declarations with the following Dec constructor:

data Dec
  = ...
  | TypeDataD Name [TyVarBndr ()]
          (Maybe Kind)            -- Kind signature (allowed only for GADTs)
          [Con]                   -- ^ @{ type data T x = A x | B (T x) }@
  | ...

We now have three different Dec data constructors for data type declarations: DataD, NewtypeD, and TypeDataD. The existing precedent in th-desugar is to combine these different data constructors into a single form:

data DDec
  = ...
  | DDataD NewOrData DCxt Name [DTyVarBndrUnit] (Maybe DKind) [DCon] [DDerivClause]
  | ...

Where NewOrData distinguishes between newtypes and other data types:

data NewOrData = Newtype
               | Data

I think we should continue this precedent and meld TypeDataD into DDataD, extending NewOrData in the process. I'm thinking something like this:

data NewOrData = Newtype
               | Data Bool -- 'True' for @type data@, 'False' otherwise
                           -- Alternatively, we could use some type isomorphic to Bool

Or even this:

data NewOrData = Newtype
               | Data
               | TypeData

Regardless of how we represent this, we could make sure to carefully document the invariants that DDataD upholds vis-à-vis NewOrData. Specifically:

goldfirere commented 1 year ago

I think I prefer

data DataFlavor
  = NewType
  | Data
  | TypeData

but it's a pretty weak preference. If you go with the data NewOrData = Newtype | Data Bool idea, I have a somewhat stronger preference for a type isomorphic to Bool instead of just using Bool.

RyanGlScott commented 1 year ago

Re-opening to track uploading th-desugar-1.15 to Hackage.

RyanGlScott commented 1 year ago

Released to Hackage as th-desugar-1.15.