ghc-9.6.3: The GHC API

Safe Haskell | Safe-Inferred
Language | Haskell2010

GHC.Tc.Plugin

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 Unit
  - | FoundMultiple [(Module, ModuleOrigin)]
  - | NotFound {
    - fr_paths :: [FilePath]
    - fr_pkg :: Maybe Unit
    - fr_mods_hidden :: [Unit]
    - fr_pkgs_hidden :: [Unit]
    - fr_unusables :: [(Unit, UnusableUnitReason)]
    - fr_suggestions :: [ModuleSuggestion]
    }
- findImportedModule :: ModuleName -> PkgQual -> 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
- getTargetPlatform :: TcPluginM Platform
- getEnvs :: TcPluginM (TcGblEnv, TcLclEnv)
- getInstEnvs :: TcPluginM InstEnvs
- getFamInstEnvs :: TcPluginM (FamInstEnv, FamInstEnv)
- matchFam :: TyCon -> [Type] -> TcPluginM (Maybe Reduction)
- newUnique :: TcPluginM Unique
- newFlexiTyVar :: Kind -> TcPluginM TcTyVar
- isTouchableTcPluginM :: TcTyVar -> TcPluginM Bool
- zonkTcType :: TcType -> TcPluginM TcType
- zonkCt :: Ct -> TcPluginM Ct
- newWanted :: CtLoc -> PredType -> TcPluginM CtEvidence
- newGiven :: EvBindsVar -> CtLoc -> PredType -> EvExpr -> TcPluginM CtEvidence
- newCoercionHole :: PredType -> TcPluginM CoercionHole
- newEvVar :: PredType -> TcPluginM EvVar
- setEvBind :: EvBindsVar -> EvBind -> TcPluginM ()

# Basic TcPluginM functionality

data TcPluginM a Source #

`TcPluginM` is the monad in which type-checking plugins operate.

#### Instances

Instances details

MonadFail TcPluginM Source # |
Instance details Defined in GHC.Tc.Types Methods fail :: String -> TcPluginM a Source #
Applicative TcPluginM Source # |
Instance details Defined in GHC.Tc.Types 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 #
Functor TcPluginM Source # |
Instance details Defined in GHC.Tc.Types Methods fmap :: (a -> b) -> TcPluginM a -> TcPluginM b Source # (<$) :: a -> TcPluginM b -> TcPluginM a Source #
Monad TcPluginM Source # |
Instance details Defined in GHC.Tc.Types Methods (>>=) :: TcPluginM a -> (a -> TcPluginM b) -> TcPluginM b Source # (>>) :: TcPluginM a -> TcPluginM b -> TcPluginM b Source # return :: a -> TcPluginM a Source #

tcPluginIO :: IO a -> TcPluginM a Source #

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

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

Output useful for debugging the compiler.

unsafeTcPluginTcM :: TcM a -> TcPluginM a Source #

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 Source #

The result of searching for an imported module.

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

Constructors

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

Fields

- fr_paths :: [FilePath]

  Places where I looked

- fr_pkg :: Maybe Unit

  Just p => module is in this unit's manifest, but couldn't find the .hi file

- fr_mods_hidden :: [Unit]

  Module is in these units, but the *module* is hidden

- fr_pkgs_hidden :: [Unit]

  Module is in these units, but the *unit* is hidden

- fr_unusables :: [(Unit, UnusableUnitReason)]

  Module is in these units, but it is unusable

- fr_suggestions :: [ModuleSuggestion]

  Possible mis-spelled modules

findImportedModule :: ModuleName -> PkgQual -> TcPluginM FindResult Source #

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

# Looking up Names in the typechecking environment

tcLookupGlobal :: Name -> TcPluginM TyThing Source #

tcLookupTyCon :: Name -> TcPluginM TyCon Source #

tcLookupDataCon :: Name -> TcPluginM DataCon Source #

tcLookupClass :: Name -> TcPluginM Class Source #

tcLookup :: Name -> TcPluginM TcTyThing Source #

tcLookupId :: Name -> TcPluginM Id Source #

# Getting the TcM state

getTopEnv :: TcPluginM HscEnv Source #

getTargetPlatform :: TcPluginM Platform Source #

getEnvs :: TcPluginM (TcGblEnv, TcLclEnv) Source #

getInstEnvs :: TcPluginM InstEnvs Source #

getFamInstEnvs :: TcPluginM (FamInstEnv, FamInstEnv) Source #

matchFam :: TyCon -> [Type] -> TcPluginM (Maybe Reduction) Source #

# Type variables

newUnique :: TcPluginM Unique Source #

newFlexiTyVar :: Kind -> TcPluginM TcTyVar Source #

isTouchableTcPluginM :: TcTyVar -> TcPluginM Bool Source #

# Zonking

zonkTcType :: TcType -> TcPluginM TcType Source #

zonkCt :: Ct -> TcPluginM Ct Source #

# Creating constraints

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

Create a new Wanted constraint with the given `CtLoc`.

newGiven :: EvBindsVar -> CtLoc -> PredType -> EvExpr -> TcPluginM CtEvidence Source #

Create a new given constraint, with the supplied evidence.

This should only be invoked within `tcPluginSolve`.

newCoercionHole :: PredType -> TcPluginM CoercionHole Source #

Create a fresh coercion hole. This should only be invoked within `tcPluginSolve`.

# Manipulating evidence bindings

newEvVar :: PredType -> TcPluginM EvVar Source #

Create a fresh evidence variable.

This should only be invoked within `tcPluginSolve`.

setEvBind :: EvBindsVar -> EvBind -> TcPluginM () Source #

Bind an evidence variable.

This should only be invoked within `tcPluginSolve`.