Safe Haskell | None |
---|
- data CoreProg
- data CoreDef = Def Id CoreExpr
- type CoreTickish = Tickish Id
- progSyntaxEq :: CoreProg -> CoreProg -> Bool
- bindSyntaxEq :: CoreBind -> CoreBind -> Bool
- defSyntaxEq :: CoreDef -> CoreDef -> Bool
- exprSyntaxEq :: CoreExpr -> CoreExpr -> Bool
- altSyntaxEq :: CoreAlt -> CoreAlt -> Bool
- typeSyntaxEq :: Type -> Type -> Bool
- coercionSyntaxEq :: Coercion -> Coercion -> Bool
- progAlphaEq :: CoreProg -> CoreProg -> Bool
- bindAlphaEq :: CoreBind -> CoreBind -> Bool
- defAlphaEq :: CoreDef -> CoreDef -> Bool
- exprAlphaEq :: CoreExpr -> CoreExpr -> Bool
- altAlphaEq :: CoreAlt -> CoreAlt -> Bool
- typeAlphaEq :: Type -> Type -> Bool
- coercionAlphaEq :: Coercion -> Coercion -> Bool
- defsToRecBind :: [CoreDef] -> CoreBind
- defToIdExpr :: CoreDef -> (Id, CoreExpr)
- progToBinds :: CoreProg -> [CoreBind]
- bindsToProg :: [CoreBind] -> CoreProg
- bindToVarExprs :: CoreBind -> [(Var, CoreExpr)]
- progIds :: CoreProg -> [Id]
- bindVars :: CoreBind -> [Var]
- defId :: CoreDef -> Id
- altVars :: CoreAlt -> [Var]
- freeVarsProg :: CoreProg -> VarSet
- freeVarsBind :: CoreBind -> VarSet
- freeVarsDef :: CoreDef -> VarSet
- freeVarsExpr :: CoreExpr -> VarSet
- freeVarsAlt :: CoreAlt -> VarSet
- freeVarsType :: Type -> TyVarSet
- freeVarsCoercion :: Coercion -> VarSet
- localFreeVarsExpr :: CoreExpr -> VarSet
- freeIdsExpr :: CoreExpr -> IdSet
- localFreeIdsExpr :: CoreExpr -> VarSet
- isCoArg :: CoreExpr -> Bool
- exprKindOrType :: CoreExpr -> KindOrType
- exprTypeM :: Monad m => CoreExpr -> m Type
- endoFunType :: Monad m => CoreExpr -> m Type
- splitFunTypeM :: Monad m => Type -> m (Type, Type)
- funArgResTypes :: Monad m => CoreExpr -> m (Type, Type)
- funsWithInverseTypes :: MonadCatch m => CoreExpr -> CoreExpr -> m (Type, Type)
- appCount :: CoreExpr -> Int
- mapAlts :: (CoreExpr -> CoreExpr) -> [CoreAlt] -> [CoreAlt]
- data Crumb
- = ModGuts_Prog
- | ProgCons_Head
- | ProgCons_Tail
- | NonRec_RHS
- | NonRec_Var
- | Rec_Def Int
- | Def_Id
- | Def_RHS
- | Var_Id
- | Lit_Lit
- | App_Fun
- | App_Arg
- | Lam_Var
- | Lam_Body
- | Let_Bind
- | Let_Body
- | Case_Scrutinee
- | Case_Binder
- | Case_Type
- | Case_Alt Int
- | Cast_Expr
- | Cast_Co
- | Tick_Tick
- | Tick_Expr
- | Type_Type
- | Co_Co
- | Alt_Con
- | Alt_Var Int
- | Alt_RHS
- | TyVarTy_TyVar
- | LitTy_TyLit
- | AppTy_Fun
- | AppTy_Arg
- | TyConApp_TyCon
- | TyConApp_Arg Int
- | FunTy_Dom
- | FunTy_CoDom
- | ForAllTy_Var
- | ForAllTy_Body
- | Refl_Type
- | TyConAppCo_TyCon
- | TyConAppCo_Arg Int
- | AppCo_Fun
- | AppCo_Arg
- | ForAllCo_TyVar
- | ForAllCo_Body
- | CoVarCo_CoVar
- | AxiomInstCo_Axiom
- | AxiomInstCo_Index
- | AxiomInstCo_Arg Int
- | UnsafeCo_Left
- | UnsafeCo_Right
- | SymCo_Co
- | TransCo_Left
- | TransCo_Right
- | NthCo_Int
- | NthCo_Co
- | InstCo_Co
- | InstCo_Type
- | LRCo_LR
- | LRCo_Co
- showCrumbs :: [Crumb] -> String
- deprecatedLeftSibling :: Crumb -> Maybe Crumb
- deprecatedRightSibling :: Crumb -> Maybe Crumb
Generic Data Type
A program is a telescope of nested binding groups.
That is, each binding scopes over the remainder of the program.
In GHC Core, programs are encoded as [CoreBind
].
This data type is isomorphic.
type CoreTickish = Tickish IdSource
Equality
We define both syntactic equality and alpha equality.
Syntactic Equality
progSyntaxEq :: CoreProg -> CoreProg -> BoolSource
Syntactic Equality of programs.
bindSyntaxEq :: CoreBind -> CoreBind -> BoolSource
Syntactic Equality of binding groups.
defSyntaxEq :: CoreDef -> CoreDef -> BoolSource
Syntactic Equality of recursive definitions.
exprSyntaxEq :: CoreExpr -> CoreExpr -> BoolSource
Syntactic Equality of expressions.
altSyntaxEq :: CoreAlt -> CoreAlt -> BoolSource
Syntactic Equality of case alternatives.
Alpha Equality
progAlphaEq :: CoreProg -> CoreProg -> BoolSource
Alpha equality of programs.
bindAlphaEq :: CoreBind -> CoreBind -> BoolSource
Alpha equality of binding groups.
defAlphaEq :: CoreDef -> CoreDef -> BoolSource
Alpha equality of recursive definitions.
exprAlphaEq :: CoreExpr -> CoreExpr -> BoolSource
Alpha equality of expressions.
altAlphaEq :: CoreAlt -> CoreAlt -> BoolSource
Alpha equality of case alternatives.
typeAlphaEq :: Type -> Type -> BoolSource
Alpha equality of types.
coercionAlphaEq :: Coercion -> Coercion -> BoolSource
Alpha equality of coercions.
Conversions to/from Core
defsToRecBind :: [CoreDef] -> CoreBindSource
Convert a list of recursive definitions into an (isomorphic) recursive binding group.
defToIdExpr :: CoreDef -> (Id, CoreExpr)Source
Convert a definition to an identifier/expression pair.
progToBinds :: CoreProg -> [CoreBind]Source
Get the list of bindings in a program.
bindsToProg :: [CoreBind] -> CoreProgSource
Build a program from a list of bindings. Note that bindings earlier in the list are considered scope over bindings later in the list.
bindToVarExprs :: CoreBind -> [(Var, CoreExpr)]Source
Extract the list of identifier/expression pairs from a binding group.
Collecting variable bindings
Collecting free variables
The GHC Function exprFreeVars defined in CoreFVs only returns *locally-defined* free variables. In HERMIT, this is typically not what we want, so we define our own functions. We reuse some of the functionality in CoreFVs, but alas much of it is not exposed, so we have to reimplement some of it.
freeVarsProg :: CoreProg -> VarSetSource
Find all free variables in a program.
freeVarsBind :: CoreBind -> VarSetSource
Find all free identifiers in a binding group, which excludes any variables bound in the group.
freeVarsDef :: CoreDef -> VarSetSource
Find all free variables is a recursive definition, which excludes the bound variable.
freeVarsExpr :: CoreExpr -> VarSetSource
Find all free variables in an expression.
freeVarsAlt :: CoreAlt -> VarSetSource
Find all free variables in a case alternative, which excludes any variables bound in the alternative.
freeVarsType :: Type -> TyVarSetSource
Find all free variables in a type.
freeVarsCoercion :: Coercion -> VarSetSource
Find all free variables in a coercion.
localFreeVarsExpr :: CoreExpr -> VarSetSource
Find all locally defined free variables in an expression.
freeIdsExpr :: CoreExpr -> IdSetSource
Find all free identifiers in an expression.
localFreeIdsExpr :: CoreExpr -> VarSetSource
Find all locally defined free identifiers in an expression.
Utilities
isCoArg :: CoreExpr -> BoolSource
Returns True
iff the expression is a Coercion
expression at its top level.
endoFunType :: Monad m => CoreExpr -> m TypeSource
Return the domain/codomain type of an endofunction expression.
splitFunTypeM :: Monad m => Type -> m (Type, Type)Source
Return the domain and codomain types of a function type, if it is a function type.
funArgResTypes :: Monad m => CoreExpr -> m (Type, Type)Source
Return the domain and codomain types of a function expression.
funsWithInverseTypes :: MonadCatch m => CoreExpr -> CoreExpr -> m (Type, Type)Source
Check two expressions have types a -> b
and b -> a
, returning (a,b)
.
mapAlts :: (CoreExpr -> CoreExpr) -> [CoreAlt] -> [CoreAlt]Source
Map a function over the RHS of each case alternative.
Crumbs
Crumbs record a path through the tree, using descriptive constructor names.
Eq Crumb | |
Read Crumb | |
Show Crumb | |
Extern Crumb | |
Extern LocalPathH | |
ExtendPath HermitC Crumb | Extend the |
ExtendPath PrettyC Crumb | |
ReadPath HermitC Crumb | Retrieve the |
ReadPath PrettyC Crumb | |
Extern (TranslateH CoreTC LocalPathH) | |
Extern (TranslateH Core LocalPathH) |
showCrumbs :: [Crumb] -> StringSource