Skip to content

API Annotations

Alan Zimmerman edited this page Jun 1, 2016 · 2 revisions

The API Annotations are documented here: https://ghc.haskell.org/trac/ghc/wiki/ApiAnnotations

Some of the early discussion around it is here: https://ghc.haskell.org/trac/ghc/wiki/GhcAstAnnotations

One of the things that is turning out awkwardly is that the SrcSpan itself is not enough to uniquely identify the location of a particular annotation, as sometimes a nested construct in the AST has parts having the same SrcSpan.

In ghc-exactprint we make use of the following

-- | For every @Located a@, use the @SrcSpan@ and constructor name of
-- a as the key, to store the standard annotation.
-- These are used to maintain context in the AP and EP monads
data AnnKey   = AnnKey GHC.SrcSpan AnnConName
                  deriving (Eq, Ord)

-- Holds the name of a constructor
data AnnConName = CN { unConName :: String }
                 deriving (Eq,Ord)

annGetConstr :: (Data a) => a -> AnnConName
annGetConstr a = CN (show $ toConstr a)

So we are using Typeable to index by the specific constructor used, as a String so that annotations can be constructed easily if needed.

It would be useful to do the same in the update, if the indexed scheme is retained.

Clone this wiki locally