GHC.Core.Rules

ghc-9.2.0.20210821: The GHC API

Safe Haskell | Safe-Inferred
Language | Haskell2010

GHC.Core.Rules

Contents

- Constructing
- Checking rule applications
- Manipulating `RuleInfo` rules
- Misc. CoreRule helpers

Description

Functions for collecting together and applying rewrite rules to a module. The `CoreRule` datatype itself is declared elsewhere.

Synopsis

- emptyRuleBase :: RuleBase
- mkRuleBase :: [CoreRule] -> RuleBase
- extendRuleBaseList :: RuleBase -> [CoreRule] -> RuleBase
- unionRuleBase :: RuleBase -> RuleBase -> RuleBase
- pprRuleBase :: RuleBase -> SDoc
- ruleCheckProgram :: RuleOpts -> CompilerPhase -> String -> (Id -> [CoreRule]) -> CoreProgram -> SDoc
- extendRuleInfo :: RuleInfo -> [CoreRule] -> RuleInfo
- addRuleInfo :: RuleInfo -> RuleInfo -> RuleInfo
- addIdSpecialisations :: Id -> [CoreRule] -> Id
- rulesOfBinds :: [CoreBind] -> [CoreRule]
- getRules :: RuleEnv -> Id -> [CoreRule]
- pprRulesForUser :: [CoreRule] -> SDoc
- lookupRule :: RuleOpts -> InScopeEnv -> (Activation -> Bool) -> Id -> [CoreExpr] -> [CoreRule] -> Maybe (CoreRule, CoreExpr)
- mkRule :: Module -> Bool -> Bool -> RuleName -> Activation -> Name -> [CoreBndr] -> [CoreExpr] -> CoreExpr -> CoreRule
- roughTopNames :: [CoreExpr] -> [Maybe Name]
- initRuleOpts :: DynFlags -> RuleOpts

## Constructing

emptyRuleBase :: RuleBase Source #

mkRuleBase :: [CoreRule] -> RuleBase Source #

extendRuleBaseList :: RuleBase -> [CoreRule] -> RuleBase Source #

unionRuleBase :: RuleBase -> RuleBase -> RuleBase Source #

pprRuleBase :: RuleBase -> SDoc Source #

## Checking rule applications

ruleCheckProgram Source #

Arguments

:: RuleOpts | Rule options
-> CompilerPhase | Rule activation test
-> String | Rule pattern
-> (Id -> [CoreRule]) | Rules for an Id
-> CoreProgram | Bindings to check in
-> SDoc | Resulting check message

Report partial matches for rules beginning with the specified string for the purposes of error reporting

## Manipulating `RuleInfo` rules

extendRuleInfo :: RuleInfo -> [CoreRule] -> RuleInfo Source #

addRuleInfo :: RuleInfo -> RuleInfo -> RuleInfo Source #

addIdSpecialisations :: Id -> [CoreRule] -> Id Source #

# Misc. CoreRule helpers

rulesOfBinds :: [CoreBind] -> [CoreRule] Source #

Gather all the rules for locally bound identifiers from the supplied bindings

getRules :: RuleEnv -> Id -> [CoreRule] Source #

pprRulesForUser :: [CoreRule] -> SDoc Source #

lookupRule :: RuleOpts -> InScopeEnv -> (Activation -> Bool) -> Id -> [CoreExpr] -> [CoreRule] -> Maybe (CoreRule, CoreExpr) Source #

The main rule matching function. Attempts to apply all (active) supplied rules to this instance of an application in a given context, returning the rule applied and the resulting expression if successful.

mkRule :: Module -> Bool -> Bool -> RuleName -> Activation -> Name -> [CoreBndr] -> [CoreExpr] -> CoreExpr -> CoreRule Source #

Used to make `CoreRule` for an `Id` defined in the module being compiled. See also `CoreRule`

roughTopNames :: [CoreExpr] -> [Maybe Name] Source #

Find the "top" free names of several expressions. Such names are either:

1. The function finally being applied to in an application chain (if that name is a GlobalId: see GHC.Types.Var), or
2. The `TyCon` if the expression is a `Expr`

This is used for the fast-match-check for rules; if the top names don't match, the rest can't

initRuleOpts :: DynFlags -> RuleOpts Source #

Initialize RuleOpts from DynFlags