hermit-0.2.0.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.

anyCallR :: forall c m. (ExtendPath c Crumb, ReadPath c Crumb, AddBindings c, MonadCatch m) => Rewrite c m Core -> Rewrite c m CoreSource

Top-down traversal tuned to matching function calls.

Free Variables

coreExprFreeIds :: CoreExpr -> Set IdSource

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

coreExprFreeVars :: CoreExpr -> Set VarSource

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

typeFreeVars :: Type -> Set VarSource

List all free variables in a type.

freeIdsT :: Monad m => Translate c m CoreExpr (Set Id)Source

Lifted version of coreExprFreeIds.

freeTyVarsT :: Monad m => Translate c m Type (Set Var)Source

Lifted version of typeFreeVars.

altFreeVarsT :: (ExtendPath c Crumb, AddBindings c, Monad m) => Translate c m CoreAlt (Set Var)Source

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

altFreeVarsExclWildT :: (ExtendPath c Crumb, AddBindings c, Monad m) => Translate c m CoreAlt (Id -> Set 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 :: (ExtendPath c Crumb, AddBindings c, MonadCatch m) => Var -> CoreExpr -> Rewrite c m CoreSource

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

substExprR :: Monad m => Var -> CoreExpr -> Rewrite c m CoreExprSource

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

letSubstR :: MonadCatch m => Rewrite c m CoreExprSource

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

safeLetSubstR :: (ReadBindings c, MonadCatch m) => Rewrite c m CoreExprSource

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

safeLetSubstPlusR :: (ExtendPath c Crumb, AddBindings c, ReadBindings c, MonadCatch m) => Rewrite c m CoreExprSource

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

Equality

Utilities

inScope :: ReadBindings c => c -> Id -> BoolSource

Determine whether an identifier is in scope.

showVars :: [Var] -> StringSource

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

rule :: (ReadBindings c, HasCoreRules c) => String -> Rewrite c HermitM CoreExprSource

Lookup a rule and attempt to construct a corresponding rewrite.

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

Lifted GHC capabilities

lintExprT :: (BoundVars c, Monad m, HasDynFlags m) => Translate c m 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.