ghc-lib-parser-9.14.1.20251220: The GHC API, decoupled from GHC versions

Safe Haskell | Ignore
Language | GHC2021

GHC.Types.Annotations

Contents

- Main Annotation data types
- AnnEnv for collecting and querying Annotations

Description

Support for source code annotation feature of GHC. That is the ANN pragma.

(c) The University of Glasgow 2006 (c) The GRASP/AQUA Project, Glasgow University, 1992-1998

Synopsis

- data Annotation = Annotation {
  - ann_target :: CoreAnnTarget
  - ann_value :: AnnPayload
  }
- type AnnPayload = Serialized
- data AnnTarget name
  - = NamedTarget name
  - | ModuleTarget Module
- type CoreAnnTarget = AnnTarget Name
- data AnnEnv
- mkAnnEnv :: [Annotation] -> AnnEnv
- extendAnnEnvList :: AnnEnv -> [Annotation] -> AnnEnv
- plusAnnEnv :: AnnEnv -> AnnEnv -> AnnEnv
- emptyAnnEnv :: AnnEnv
- findAnns :: Typeable a => ([Word8] -> a) -> AnnEnv -> CoreAnnTarget -> [a]
- findAnnsByTypeRep :: AnnEnv -> CoreAnnTarget -> TypeRep -> [[Word8]]
- deserializeAnns :: Typeable a => ([Word8] -> a) -> AnnEnv -> (ModuleEnv [a], NameEnv [a])

# Main Annotation data types

data Annotation #

Represents an annotation after it has been sufficiently desugared from it's initial form of `AnnDecl`

Constructors

Annotation |
Fields ann_target :: CoreAnnTarget The target of the annotation ann_value :: AnnPayload

#### Instances

Instances details

Outputable Annotation # |
Instance details Defined in GHC.Types.Annotations Methods ppr :: Annotation -> SDoc #

type AnnPayload #

Arguments

= Serialized | The "payload" of an annotation allows recovery of its value at a given type, and can be persisted to an interface file

data AnnTarget name #

An annotation target

Constructors

NamedTarget name | We are annotating something with a name: a type or identifier
ModuleTarget Module | We are annotating a particular module

#### Instances

Instances details

Functor AnnTarget # |
Instance details Defined in GHC.Types.Annotations Methods fmap :: (a -> b) -> AnnTarget a -> AnnTarget b # (<$) :: a -> AnnTarget b -> AnnTarget a #
NFData name => NFData (AnnTarget name) # |
Instance details Defined in GHC.Types.Annotations Methods rnf :: AnnTarget name -> () #
Binary name => Binary (AnnTarget name) # |
Instance details Defined in GHC.Types.Annotations Methods put_ :: WriteBinHandle -> AnnTarget name -> IO () # put :: WriteBinHandle -> AnnTarget name -> IO (Bin (AnnTarget name)) # get :: ReadBinHandle -> IO (AnnTarget name) #
Outputable name => Outputable (AnnTarget name) # |
Instance details Defined in GHC.Types.Annotations Methods ppr :: AnnTarget name -> SDoc #

type CoreAnnTarget = AnnTarget Name #

The kind of annotation target found in the middle end of the compiler

# AnnEnv for collecting and querying Annotations

data AnnEnv #

A collection of annotations

mkAnnEnv :: [Annotation] -> AnnEnv #

Construct a new annotation environment that contains the list of annotations provided.

extendAnnEnvList :: AnnEnv -> [Annotation] -> AnnEnv #

Add the given annotation to the environment.

plusAnnEnv :: AnnEnv -> AnnEnv -> AnnEnv #

Union two annotation environments.

emptyAnnEnv :: AnnEnv #

An empty annotation environment.

findAnns :: Typeable a => ([Word8] -> a) -> AnnEnv -> CoreAnnTarget -> [a] #

Find the annotations attached to the given target as `Typeable` values of your choice. If no deserializer is specified, only transient annotations will be returned.

findAnnsByTypeRep :: AnnEnv -> CoreAnnTarget -> TypeRep -> [[Word8]] #

Find the annotations attached to the given target as `Typeable` values of your choice. If no deserializer is specified, only transient annotations will be returned.

deserializeAnns :: Typeable a => ([Word8] -> a) -> AnnEnv -> (ModuleEnv [a], NameEnv [a]) #

Deserialize all annotations of a given type. This happens lazily, that is no deserialization will take place until the [a] is actually demanded and the [a] can also be empty (the UniqFM is not filtered).