ghc-8.2.2: The GHC API

Safe Haskell | None
Language | Haskell2010

TcPluginM

Contents

- Basic TcPluginM functionality
- Finding Modules and Names
- Looking up Names in the typechecking environment
- Getting the TcM state
- Type variables
- Zonking
- Creating constraints
- Manipulating evidence bindings

Description

This module provides an interface for typechecker plugins to access select functions of the `TcM`, principally those to do with reading parts of the state.

Synopsis

- data TcPluginM a
- tcPluginIO :: IO a -> TcPluginM a
- tcPluginTrace :: String -> SDoc -> TcPluginM ()
- unsafeTcPluginTcM :: TcM a -> TcPluginM a
- data FindResult
  - = Found ModLocation Module
  - | NoPackage UnitId
  - | FoundMultiple [(Module, ModuleOrigin)]
  - | NotFound {
    - fr_paths :: [FilePath]
    - fr_pkg :: Maybe UnitId
    - fr_mods_hidden :: [UnitId]
    - fr_pkgs_hidden :: [UnitId]
    - fr_suggestions :: [ModuleSuggestion]
    }
- findImportedModule :: ModuleName -> Maybe FastString -> TcPluginM FindResult
- lookupOrig :: Module -> OccName -> TcPluginM Name
- tcLookupGlobal :: Name -> TcPluginM TyThing
- tcLookupTyCon :: Name -> TcPluginM TyCon
- tcLookupDataCon :: Name -> TcPluginM DataCon
- tcLookupClass :: Name -> TcPluginM Class
- tcLookup :: Name -> TcPluginM TcTyThing
- tcLookupId :: Name -> TcPluginM Id
- getTopEnv :: TcPluginM HscEnv
- getEnvs :: TcPluginM (TcGblEnv, TcLclEnv)
- getInstEnvs :: TcPluginM InstEnvs
- getFamInstEnvs :: TcPluginM (FamInstEnv, FamInstEnv)
- matchFam :: TyCon -> [Type] -> TcPluginM (Maybe (TcCoercion, TcType))
- newUnique :: TcPluginM Unique
- newFlexiTyVar :: Kind -> TcPluginM TcTyVar
- isTouchableTcPluginM :: TcTyVar -> TcPluginM Bool
- zonkTcType :: TcType -> TcPluginM TcType
- zonkCt :: Ct -> TcPluginM Ct
- newWanted :: CtLoc -> PredType -> TcPluginM CtEvidence
- newDerived :: CtLoc -> PredType -> TcPluginM CtEvidence
- newGiven :: CtLoc -> PredType -> EvTerm -> TcPluginM CtEvidence
- newCoercionHole :: TcPluginM CoercionHole
- newEvVar :: PredType -> TcPluginM EvVar
- setEvBind :: EvBind -> TcPluginM ()
- getEvBindsTcPluginM :: TcPluginM EvBindsVar

# Basic TcPluginM functionality

data TcPluginM a #

Instances

Monad TcPluginM # |
Methods (>>=) :: TcPluginM a -> (a -> TcPluginM b) -> TcPluginM b Source # (>>) :: TcPluginM a -> TcPluginM b -> TcPluginM b Source # return :: a -> TcPluginM a Source # fail :: String -> TcPluginM a Source #
Functor TcPluginM # |
Methods fmap :: (a -> b) -> TcPluginM a -> TcPluginM b Source # (<$) :: a -> TcPluginM b -> TcPluginM a Source #
MonadFail TcPluginM # |
Methods fail :: String -> TcPluginM a Source #
Applicative TcPluginM # |
Methods pure :: a -> TcPluginM a Source # (<*>) :: TcPluginM (a -> b) -> TcPluginM a -> TcPluginM b Source # liftA2 :: (a -> b -> c) -> TcPluginM a -> TcPluginM b -> TcPluginM c Source # (*>) :: TcPluginM a -> TcPluginM b -> TcPluginM b Source # (<*) :: TcPluginM a -> TcPluginM b -> TcPluginM a Source #

tcPluginIO :: IO a -> TcPluginM a #

Perform some IO, typically to interact with an external tool.

tcPluginTrace :: String -> SDoc -> TcPluginM () #

Output useful for debugging the compiler.

unsafeTcPluginTcM :: TcM a -> TcPluginM a #

This function provides an escape for direct access to the `TcM` monad. It should not be used lightly, and the provided `TcPluginM` API should be favoured instead.

# Finding Modules and Names

data FindResult #

The result of searching for an imported module.

NB: FindResult manages both user source-import lookups (which can result in `Module`) as well as direct imports for interfaces (which always result in `InstalledModule`).

Constructors

Found ModLocation Module | The module was found
NoPackage UnitId | The requested package was not found
FoundMultiple [(Module, ModuleOrigin)] | _Error_: both in multiple packages
NotFound | Not found

Fields

- fr_paths :: [FilePath]
- fr_pkg :: Maybe UnitId
- fr_mods_hidden :: [UnitId]
- fr_pkgs_hidden :: [UnitId]
- fr_suggestions :: [ModuleSuggestion]

findImportedModule :: ModuleName -> Maybe FastString -> TcPluginM FindResult #

lookupOrig :: Module -> OccName -> TcPluginM Name #

# Looking up Names in the typechecking environment

tcLookupGlobal :: Name -> TcPluginM TyThing #

tcLookupTyCon :: Name -> TcPluginM TyCon #

tcLookupDataCon :: Name -> TcPluginM DataCon #

tcLookupClass :: Name -> TcPluginM Class #

tcLookup :: Name -> TcPluginM TcTyThing #

tcLookupId :: Name -> TcPluginM Id #

# Getting the TcM state

getTopEnv :: TcPluginM HscEnv #

getEnvs :: TcPluginM (TcGblEnv, TcLclEnv) #

getInstEnvs :: TcPluginM InstEnvs #

getFamInstEnvs :: TcPluginM (FamInstEnv, FamInstEnv) #

matchFam :: TyCon -> [Type] -> TcPluginM (Maybe (TcCoercion, TcType)) #

# Type variables

newUnique :: TcPluginM Unique #

newFlexiTyVar :: Kind -> TcPluginM TcTyVar #

isTouchableTcPluginM :: TcTyVar -> TcPluginM Bool #

# Zonking

zonkTcType :: TcType -> TcPluginM TcType #

zonkCt :: Ct -> TcPluginM Ct #

# Creating constraints

newWanted :: CtLoc -> PredType -> TcPluginM CtEvidence #

Create a new wanted constraint.

newDerived :: CtLoc -> PredType -> TcPluginM CtEvidence #

Create a new derived constraint.

newGiven :: CtLoc -> PredType -> EvTerm -> TcPluginM CtEvidence #

Create a new given constraint, with the supplied evidence. This must not be invoked from `tcPluginInit` or `tcPluginStop`, or it will panic.

newCoercionHole :: TcPluginM CoercionHole #

Create a fresh coercion hole.

# Manipulating evidence bindings

newEvVar :: PredType -> TcPluginM EvVar #

Create a fresh evidence variable.

setEvBind :: EvBind -> TcPluginM () #

Bind an evidence variable. This must not be invoked from `tcPluginInit` or `tcPluginStop`, or it will panic.

getEvBindsTcPluginM :: TcPluginM EvBindsVar #

Access the `EvBindsVar` carried by the `TcPluginM` during constraint solving. Returns `Nothing` if invoked during `tcPluginInit` or `tcPluginStop`.