hermit-0.1.8.0: Haskell Equational Reasoning Model-to-Implementation Tunnel

Safe HaskellNone

Language.HERMIT.Primitive.GHC

Contents

Synopsis

GHC-based Transformations

This module contains transformations that are reflections of GHC functions, or derived from GHC functions.

externals :: [External]Source

Externals that reflect GHC functions, or are derived from GHC functions.

Free Variables

coreExprFreeIds :: CoreExpr -> [Id]Source

List all free identifiers (value-level free variables) in the expression.

coreExprFreeVars :: CoreExpr -> [Var]Source

List all free variables (including types) in the expression.

altFreeVarsT :: TranslateH CoreAlt [Var]Source

The free variables in a case alternative, which excludes any identifiers bound in the alternative.

altFreeVarsExclWildT :: TranslateH CoreAlt (Id -> [Var])Source

A variant of altFreeVarsT that returns a function that accepts the case wild-card binder before giving a result. This is so we can use this with congruence combinators, for example:

caseT id (const altFreeVarsT) $ _ wild _ fvs -> [ f wild | f <- fvs ]

Substitution

substR :: Var -> CoreExpr -> RewriteH CoreSource

Substitute all occurrences of a variable with an expression, in either a program or an expression.

substExprR :: Var -> CoreExpr -> RewriteH CoreExprSource

Substitute all occurrences of a variable with an expression, in an expression.

letSubstR :: RewriteH CoreExprSource

(let x = e1 in e2) ==> (e2[e1/x]), x must not be free in e1.

safeLetSubstR :: RewriteH CoreExprSource

This is quite expensive (O(n) for the size of the sub-tree).

safeLetSubstPlusR :: RewriteH CoreExprSource

safeLetSubstPlusR tries to inline a stack of bindings, stopping when reaches the end of the stack of lets.

Equality

Utilities

inScope :: HermitC -> Id -> BoolSource

Determine whether an identifier is in scope.

showVars :: [Var] -> StringSource

Show a human-readable version of a list of Vars.

rule :: String -> RewriteH CoreExprSource

Lookup a rule and attempt to construct a corresponding rewrite.

lintExprT :: TranslateH CoreExpr StringSource

Note: this can miss several things that a whole-module core lint will find. For instance, running this on the RHS of a binding, the type of the RHS will not be checked against the type of the binding. Running on the whole let expression will catch that however.

lintModuleT :: TranslateH ModGuts StringSource

Run the Core Lint typechecker. Fails on errors, with error messages. Succeeds returning warnings.

equivalent :: (a -> a -> Bool) -> [a] -> BoolSource