ghc-tcplugins-extra-0.4.6: Utilities for writing GHC type-checker plugins

Copyright | (C) 2015-2016 University of Twente
License | BSD2 (see the file LICENSE)
Maintainer | Christiaan Baaij <christiaan.baaij@gmail.com>
Safe Haskell | None
Language | Haskell2010
Extensions | Cpp

GHC.TcPluginM.Extra

Contents

- Create new constraints
- Creating evidence
- Lookup
- Trace state of the plugin
- Substitutions

Description

Synopsis

- newWanted :: CtLoc -> PredType -> TcPluginM CtEvidence
- newGiven :: EvBindsVar -> CtLoc -> PredType -> EvTerm -> TcPluginM CtEvidence
- evByFiat :: String -> Type -> Type -> EvTerm
- lookupModule :: ModuleName -> FastString -> TcPluginM Module
- lookupName :: Module -> OccName -> TcPluginM Name
- tracePlugin :: String -> TcPlugin -> TcPlugin
- flattenGivens :: [Ct] -> [Ct]
- mkSubst :: Ct -> Maybe ((TcTyVar, TcType), Ct)
- mkSubst' :: [Ct] -> [((TcTyVar, TcType), Ct)]
- substType :: [(TcTyVar, TcType)] -> TcType -> TcType
- substCt :: [(TcTyVar, TcType)] -> Ct -> Ct

# Create new constraints

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

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

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

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

# Creating evidence

evByFiat Source #

Arguments

:: String | Name the coercion should have
-> Type | The LHS of the equivalence relation (~)
-> Type | The RHS of the equivalence relation (~)
-> EvTerm |

The `EvTerm` equivalent for `unsafeCoerce`

# Lookup

lookupModule Source #

Arguments

:: ModuleName | Name of the module
-> FastString | Name of the package containing the module. NOTE: This value is ignored on ghc>=8.0.
-> TcPluginM Module |

Find a module

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

Find a `Name` in a `Module` given an `OccName`

# Trace state of the plugin

tracePlugin :: String -> TcPlugin -> TcPlugin Source #

Print out extra information about the initialisation, stop, and every run of the plugin when `-ddump-tc-trace` is enabled.

# Substitutions

flattenGivens :: [Ct] -> [Ct] Source #

Flattens evidence of constraints by substituting each others equalities.

NB: Should only be used on [G]iven constraints!

NB: Doesn't flatten under binders

mkSubst :: Ct -> Maybe ((TcTyVar, TcType), Ct) Source #

Create simple substitution from type equalities

mkSubst' :: [Ct] -> [((TcTyVar, TcType), Ct)] Source #

Create flattened substitutions from type equalities, i.e. the substitutions have been applied to each others right hand sides.

substType :: [(TcTyVar, TcType)] -> TcType -> TcType Source #

Apply substitutions in Types

NB: Doesn't substitute under binders

substCt :: [(TcTyVar, TcType)] -> Ct -> Ct Source #

Apply substitution in the evidence of Cts