Exploring in-tree API Annotations via TTG
Motivation
At the moment the API Annotations are produced as a separate artifact of the parsing process, and are processed via external libraries to re-attach them to their relevant locations.
Also, in order to support the convention used to associate an API Annotation with an hsSyn AST element, the hsSyn AST has a lot more locations stored in it.
One of the purposes of the Trees That Grow mechanism is that it can be used to bring in additional information, as required.
This issue explores a way of bringing the API Annotations into the hsSyn AST, as a precursor to migrating the bulk of the ghc-exactprint
functionality directly into GHC.
As a by-product, it will enable reproducing the original source text for GHC-issued diagnostics.
Proposal
In addition to emitting the API Annotations as currently, also store them inside the TTG extension points.
We use a structure as per below to capture these
-- | The API Annotations are now kept in the HsSyn AST for the GhcPs
-- phase. We do not always have API Annotations though, only for
-- parsed code. This type captures that, and allows the
-- representation decision to be easily revisited as it evolves.
data AA = AA [AddAnn] -- ^ Annotations added by the Parser
| AANotUsed -- ^ No Annotation for generated code, e.g. from
-- TH, deriving, etc.
deriving (Data, Show)
noAnn :: AA
noAnn = AANotUsed