hermit- Haskell Equational Reasoning Model-to-Implementation Tunnel

Safe HaskellNone




HERMIT Contexts

Path Synonyms

The Standard Context

data HermitC Source

The HERMIT context, containing all bindings in scope and the current location in the AST. The bindings here are lazy by choice, so that we can avoid the cost of building the context if we never use it.

initHermitC :: ModGuts -> HermitCSource

Create the initial HERMIT HermitC by providing a ModGuts.


data HermitBindingSite Source

HERMIT's representation of variable bindings. Bound expressions cannot be inlined without checking for shadowing issues (using the depth information).



A lambda-bound variable.


A non-recursive binding of an expression.

REC CoreExpr

A (potentially) recursive binding of an expression.


A (potentially) recursive binding of a superexpression of the current node.


A variable bound in a case alternative.

CASEWILD CoreExpr (AltCon, [Var])

A case wildcard binder. We store both the scrutinised expression, and the case alternative AltCon and variables.


A universally quantified type variable.

type BindingDepth = IntSource

The depth of a binding. Used, for example, to detect shadowing when inlining.

hermitBindingSiteExpr :: HermitBindingSite -> KureM CoreExprSource

Retrieve the expression in a HermitBindingSite, if there is one.

hermitBindingExpr :: HermitBinding -> KureM CoreExprSource

Retrieve the expression in a HermitBinding, if there is one.

Adding bindings to contexts

class AddBindings c whereSource

A class of contexts that can have HERMIT bindings added to them.


addHermitBindings :: [(Var, HermitBindingSite)] -> c -> cSource

Add a complete set of parrallel bindings to the context. (Parallel bindings occur in recursive let bindings and case alternatives.) This can also be used for solitary bindings (e.g. lambdas). Bindings are added in parallel sets to help with shadowing issues.


AddBindings HermitC 
AddBindings PrettyC 
AddBindings (SnocPath crumb)

The bindings are just discarded.

(AddBindings c, AddBindings e) => AddBindings (ExtendContext c e)

The bindings are added to the base context and the extra context.

addBindingGroup :: AddBindings c => CoreBind -> c -> cSource

Add all bindings in a binding group to a context.

addDefBinding :: AddBindings c => Id -> c -> cSource

Add the binding for a recursive definition currently under examination. Note that because the expression may later be modified, the context only records the identifier, not the expression.

addDefBindingsExcept :: AddBindings c => Int -> [(Id, CoreExpr)] -> c -> cSource

Add a list of recursive bindings to the context, except the nth binding in the list. The idea is to exclude the definition being descended into.

addLambdaBinding :: AddBindings c => Var -> c -> cSource

Add a lambda bound variable to a context. All that is known is the variable, which may shadow something. If so, we don't worry about that here, it is instead checked during inlining.

addAltBindings :: AddBindings c => [Var] -> c -> cSource

Add the variables bound by a DataCon in a case. They are all bound at the same depth.

addCaseWildBinding :: AddBindings c => (Id, CoreExpr, CoreAlt) -> c -> cSource

Add a wildcard binding for a specific case alternative.

addForallBinding :: AddBindings c => TyVar -> c -> cSource

Add a universally quantified type variable to a context.

Reading bindings from the context

class BoundVars c whereSource

A class of contexts that stores the set of variables in scope that have been bound during the traversal.


boundVars :: c -> VarSetSource

boundIn :: ReadBindings c => Var -> c -> BoolSource

Determine if a variable is bound in a context.

findBoundVars :: BoundVars c => Name -> c -> VarSetSource

List all variables bound in the context that match the given name.

class BoundVars c => ReadBindings c whereSource

A class of contexts from which HERMIT bindings can be retrieved.

lookupHermitBinding :: (ReadBindings c, Monad m) => Var -> c -> m HermitBindingSource

Lookup the binding for a variable in a context.

lookupHermitBindingDepth :: (ReadBindings c, Monad m) => Var -> c -> m BindingDepthSource

Lookup the depth of a variable's binding in a context.

lookupHermitBindingSite :: (ReadBindings c, Monad m) => Var -> BindingDepth -> c -> m HermitBindingSiteSource

Lookup the binding for a variable in a context, ensuring it was bound at the specified depth.

Accessing the Global Reader Environment from the context

class HasGlobalRdrEnv c whereSource

A class of contexts that store the Global Reader Environment.

Accessing GHC rewrite rules from the context

class HasCoreRules c whereSource

A class of contexts that store GHC rewrite rules.