{-# LANGUAGE DeriveDataTypeable, FlexibleContexts #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE BangPatterns #-}
{-# OPTIONS_GHC -Wno-incomplete-uni-patterns #-}
{-# OPTIONS_GHC -Wno-incomplete-record-updates #-}
module GHC.Core (
Expr(..), Alt(..), Bind(..), AltCon(..), Arg,
CoreProgram, CoreExpr, CoreAlt, CoreBind, CoreArg, CoreBndr,
TaggedExpr, TaggedAlt, TaggedBind, TaggedArg, TaggedBndr(..), deTagExpr,
InId, InBind, InExpr, InAlt, InArg, InType, InKind,
InBndr, InVar, InCoercion, InTyVar, InCoVar,
OutId, OutBind, OutExpr, OutAlt, OutArg, OutType, OutKind,
OutBndr, OutVar, OutCoercion, OutTyVar, OutCoVar, MOutCoercion,
mkLet, mkLets, mkLetNonRec, mkLetRec, mkLams,
mkApps, mkTyApps, mkCoApps, mkVarApps, mkTyArg,
mkIntLit, mkIntLitWrap,
mkWordLit, mkWordLitWrap,
mkWord8Lit,
mkWord64LitWord64, mkInt64LitInt64,
mkCharLit, mkStringLit,
mkFloatLit, mkFloatLitFloat,
mkDoubleLit, mkDoubleLitDouble,
mkConApp, mkConApp2, mkTyBind, mkCoBind,
varToCoreExpr, varsToCoreExprs,
isId, cmpAltCon, cmpAlt, ltAlt,
bindersOf, bindersOfBinds, rhssOfBind, rhssOfAlts,
collectBinders, collectTyBinders, collectTyAndValBinders,
collectNBinders,
collectArgs, stripNArgs, collectArgsTicks, flattenBinds,
exprToType,
wrapLamBody,
isValArg, isTypeArg, isCoArg, isTyCoArg, valArgCount, valBndrCount,
isRuntimeArg, isRuntimeVar,
Unfolding(..), UnfoldingGuidance(..), UnfoldingSource(..),
noUnfolding, bootUnfolding, evaldUnfolding, mkOtherCon,
unSaturatedOk, needSaturated, boringCxtOk, boringCxtNotOk,
unfoldingTemplate, expandUnfolding_maybe,
maybeUnfoldingTemplate, otherCons,
isValueUnfolding, isEvaldUnfolding, isCheapUnfolding,
isExpandableUnfolding, isConLikeUnfolding, isCompulsoryUnfolding,
isStableUnfolding, isInlineUnfolding, isBootUnfolding,
hasCoreUnfolding, hasSomeUnfolding,
canUnfold, neverUnfoldGuidance, isStableSource,
AnnExpr, AnnExpr'(..), AnnBind(..), AnnAlt(..),
collectAnnArgs, collectAnnArgsTicks,
deAnnotate, deAnnotate', deAnnAlt, deAnnBind,
collectAnnBndrs, collectNAnnBndrs,
IsOrphan(..), isOrphan, notOrphan, chooseOrphanAnchor,
CoreRule(..), RuleBase,
RuleName, RuleFun, IdUnfoldingFun, InScopeEnv,
RuleEnv(..), RuleOpts(..), mkRuleEnv, emptyRuleEnv,
ruleArity, ruleName, ruleIdName, ruleActivation,
setRuleIdName, ruleModule,
isBuiltinRule, isLocalRule, isAutoRule,
) where
import GHC.Prelude
import GHC.Platform
import GHC.Types.Var.Env( InScopeSet )
import GHC.Types.Var
import GHC.Core.Type
import GHC.Core.Coercion
import GHC.Types.Name
import GHC.Types.Name.Set
import GHC.Types.Name.Env( NameEnv )
import GHC.Types.Literal
import GHC.Types.Tickish
import GHC.Core.DataCon
import GHC.Unit.Module
import GHC.Types.Basic
import GHC.Types.Unique.Set
import GHC.Utils.Binary
import GHC.Utils.Misc
import GHC.Utils.Outputable
import GHC.Utils.Panic
import GHC.Utils.Panic.Plain
import Data.Data hiding (TyCon)
import Data.Int
import Data.Word
infixl 4 `mkApps`, `mkTyApps`, `mkVarApps`, `App`, `mkCoApps`
data Expr b
= Var Id
| Lit Literal
| App (Expr b) (Arg b)
| Lam b (Expr b)
| Let (Bind b) (Expr b)
| Case (Expr b) b Type [Alt b]
| Cast (Expr b) CoercionR
| Tick CoreTickish (Expr b)
| Type Type
| Coercion Coercion
deriving Typeable (Expr b)
Typeable (Expr b)
-> (forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Expr b -> c (Expr b))
-> (forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Expr b))
-> (Expr b -> Constr)
-> (Expr b -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (Expr b)))
-> (forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Expr b)))
-> ((forall b. Data b => b -> b) -> Expr b -> Expr b)
-> (forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Expr b -> r)
-> (forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Expr b -> r)
-> (forall u. (forall d. Data d => d -> u) -> Expr b -> [u])
-> (forall u.
ConTag -> (forall d. Data d => d -> u) -> Expr b -> u)
-> (forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Expr b -> m (Expr b))
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Expr b -> m (Expr b))
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Expr b -> m (Expr b))
-> Data (Expr b)
Expr b -> Constr
Expr b -> DataType
(forall b. Data b => b -> b) -> Expr b -> Expr b
forall {b}. Data b => Typeable (Expr b)
forall b. Data b => Expr b -> Constr
forall b. Data b => Expr b -> DataType
forall b.
Data b =>
(forall b. Data b => b -> b) -> Expr b -> Expr b
forall b u.
Data b =>
ConTag -> (forall d. Data d => d -> u) -> Expr b -> u
forall b u. Data b => (forall d. Data d => d -> u) -> Expr b -> [u]
forall b r r'.
Data b =>
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Expr b -> r
forall b r r'.
Data b =>
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Expr b -> r
forall b (m :: * -> *).
(Data b, Monad m) =>
(forall d. Data d => d -> m d) -> Expr b -> m (Expr b)
forall b (m :: * -> *).
(Data b, MonadPlus m) =>
(forall d. Data d => d -> m d) -> Expr b -> m (Expr b)
forall b (c :: * -> *).
Data b =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Expr b)
forall b (c :: * -> *).
Data b =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Expr b -> c (Expr b)
forall b (t :: * -> *) (c :: * -> *).
(Data b, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (Expr b))
forall b (t :: * -> * -> *) (c :: * -> *).
(Data b, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Expr b))
forall a.
Typeable a
-> (forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. ConTag -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. ConTag -> (forall d. Data d => d -> u) -> Expr b -> u
forall u. (forall d. Data d => d -> u) -> Expr b -> [u]
forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Expr b -> r
forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Expr b -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Expr b -> m (Expr b)
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Expr b -> m (Expr b)
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Expr b)
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Expr b -> c (Expr b)
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (Expr b))
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Expr b))
$cgfoldl :: forall b (c :: * -> *).
Data b =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Expr b -> c (Expr b)
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Expr b -> c (Expr b)
$cgunfold :: forall b (c :: * -> *).
Data b =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Expr b)
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Expr b)
$ctoConstr :: forall b. Data b => Expr b -> Constr
toConstr :: Expr b -> Constr
$cdataTypeOf :: forall b. Data b => Expr b -> DataType
dataTypeOf :: Expr b -> DataType
$cdataCast1 :: forall b (t :: * -> *) (c :: * -> *).
(Data b, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (Expr b))
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (Expr b))
$cdataCast2 :: forall b (t :: * -> * -> *) (c :: * -> *).
(Data b, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Expr b))
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Expr b))
$cgmapT :: forall b.
Data b =>
(forall b. Data b => b -> b) -> Expr b -> Expr b
gmapT :: (forall b. Data b => b -> b) -> Expr b -> Expr b
$cgmapQl :: forall b r r'.
Data b =>
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Expr b -> r
gmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Expr b -> r
$cgmapQr :: forall b r r'.
Data b =>
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Expr b -> r
gmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Expr b -> r
$cgmapQ :: forall b u. Data b => (forall d. Data d => d -> u) -> Expr b -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> Expr b -> [u]
$cgmapQi :: forall b u.
Data b =>
ConTag -> (forall d. Data d => d -> u) -> Expr b -> u
gmapQi :: forall u. ConTag -> (forall d. Data d => d -> u) -> Expr b -> u
$cgmapM :: forall b (m :: * -> *).
(Data b, Monad m) =>
(forall d. Data d => d -> m d) -> Expr b -> m (Expr b)
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Expr b -> m (Expr b)
$cgmapMp :: forall b (m :: * -> *).
(Data b, MonadPlus m) =>
(forall d. Data d => d -> m d) -> Expr b -> m (Expr b)
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Expr b -> m (Expr b)
$cgmapMo :: forall b (m :: * -> *).
(Data b, MonadPlus m) =>
(forall d. Data d => d -> m d) -> Expr b -> m (Expr b)
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Expr b -> m (Expr b)
Data
type Arg b = Expr b
data Alt b
= Alt AltCon [b] (Expr b)
deriving (Typeable (Alt b)
Typeable (Alt b)
-> (forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Alt b -> c (Alt b))
-> (forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Alt b))
-> (Alt b -> Constr)
-> (Alt b -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (Alt b)))
-> (forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Alt b)))
-> ((forall b. Data b => b -> b) -> Alt b -> Alt b)
-> (forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Alt b -> r)
-> (forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Alt b -> r)
-> (forall u. (forall d. Data d => d -> u) -> Alt b -> [u])
-> (forall u. ConTag -> (forall d. Data d => d -> u) -> Alt b -> u)
-> (forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Alt b -> m (Alt b))
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Alt b -> m (Alt b))
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Alt b -> m (Alt b))
-> Data (Alt b)
Alt b -> Constr
Alt b -> DataType
(forall b. Data b => b -> b) -> Alt b -> Alt b
forall {b}. Data b => Typeable (Alt b)
forall b. Data b => Alt b -> Constr
forall b. Data b => Alt b -> DataType
forall b. Data b => (forall b. Data b => b -> b) -> Alt b -> Alt b
forall b u.
Data b =>
ConTag -> (forall d. Data d => d -> u) -> Alt b -> u
forall b u. Data b => (forall d. Data d => d -> u) -> Alt b -> [u]
forall b r r'.
Data b =>
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Alt b -> r
forall b r r'.
Data b =>
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Alt b -> r
forall b (m :: * -> *).
(Data b, Monad m) =>
(forall d. Data d => d -> m d) -> Alt b -> m (Alt b)
forall b (m :: * -> *).
(Data b, MonadPlus m) =>
(forall d. Data d => d -> m d) -> Alt b -> m (Alt b)
forall b (c :: * -> *).
Data b =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Alt b)
forall b (c :: * -> *).
Data b =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Alt b -> c (Alt b)
forall b (t :: * -> *) (c :: * -> *).
(Data b, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (Alt b))
forall b (t :: * -> * -> *) (c :: * -> *).
(Data b, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Alt b))
forall a.
Typeable a
-> (forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. ConTag -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. ConTag -> (forall d. Data d => d -> u) -> Alt b -> u
forall u. (forall d. Data d => d -> u) -> Alt b -> [u]
forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Alt b -> r
forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Alt b -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Alt b -> m (Alt b)
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Alt b -> m (Alt b)
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Alt b)
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Alt b -> c (Alt b)
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (Alt b))
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Alt b))
$cgfoldl :: forall b (c :: * -> *).
Data b =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Alt b -> c (Alt b)
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Alt b -> c (Alt b)
$cgunfold :: forall b (c :: * -> *).
Data b =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Alt b)
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Alt b)
$ctoConstr :: forall b. Data b => Alt b -> Constr
toConstr :: Alt b -> Constr
$cdataTypeOf :: forall b. Data b => Alt b -> DataType
dataTypeOf :: Alt b -> DataType
$cdataCast1 :: forall b (t :: * -> *) (c :: * -> *).
(Data b, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (Alt b))
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (Alt b))
$cdataCast2 :: forall b (t :: * -> * -> *) (c :: * -> *).
(Data b, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Alt b))
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Alt b))
$cgmapT :: forall b. Data b => (forall b. Data b => b -> b) -> Alt b -> Alt b
gmapT :: (forall b. Data b => b -> b) -> Alt b -> Alt b
$cgmapQl :: forall b r r'.
Data b =>
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Alt b -> r
gmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Alt b -> r
$cgmapQr :: forall b r r'.
Data b =>
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Alt b -> r
gmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Alt b -> r
$cgmapQ :: forall b u. Data b => (forall d. Data d => d -> u) -> Alt b -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> Alt b -> [u]
$cgmapQi :: forall b u.
Data b =>
ConTag -> (forall d. Data d => d -> u) -> Alt b -> u
gmapQi :: forall u. ConTag -> (forall d. Data d => d -> u) -> Alt b -> u
$cgmapM :: forall b (m :: * -> *).
(Data b, Monad m) =>
(forall d. Data d => d -> m d) -> Alt b -> m (Alt b)
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Alt b -> m (Alt b)
$cgmapMp :: forall b (m :: * -> *).
(Data b, MonadPlus m) =>
(forall d. Data d => d -> m d) -> Alt b -> m (Alt b)
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Alt b -> m (Alt b)
$cgmapMo :: forall b (m :: * -> *).
(Data b, MonadPlus m) =>
(forall d. Data d => d -> m d) -> Alt b -> m (Alt b)
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Alt b -> m (Alt b)
Data)
data AltCon
= DataAlt DataCon
| LitAlt Literal
| DEFAULT
deriving (AltCon -> AltCon -> Bool
(AltCon -> AltCon -> Bool)
-> (AltCon -> AltCon -> Bool) -> Eq AltCon
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: AltCon -> AltCon -> Bool
== :: AltCon -> AltCon -> Bool
$c/= :: AltCon -> AltCon -> Bool
/= :: AltCon -> AltCon -> Bool
Eq, Typeable AltCon
Typeable AltCon
-> (forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> AltCon -> c AltCon)
-> (forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c AltCon)
-> (AltCon -> Constr)
-> (AltCon -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c AltCon))
-> (forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c AltCon))
-> ((forall b. Data b => b -> b) -> AltCon -> AltCon)
-> (forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> AltCon -> r)
-> (forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> AltCon -> r)
-> (forall u. (forall d. Data d => d -> u) -> AltCon -> [u])
-> (forall u.
ConTag -> (forall d. Data d => d -> u) -> AltCon -> u)
-> (forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> AltCon -> m AltCon)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> AltCon -> m AltCon)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> AltCon -> m AltCon)
-> Data AltCon
AltCon -> Constr
AltCon -> DataType
(forall b. Data b => b -> b) -> AltCon -> AltCon
forall a.
Typeable a
-> (forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. ConTag -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. ConTag -> (forall d. Data d => d -> u) -> AltCon -> u
forall u. (forall d. Data d => d -> u) -> AltCon -> [u]
forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> AltCon -> r
forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> AltCon -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> AltCon -> m AltCon
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> AltCon -> m AltCon
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c AltCon
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> AltCon -> c AltCon
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c AltCon)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c AltCon)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> AltCon -> c AltCon
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> AltCon -> c AltCon
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c AltCon
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c AltCon
$ctoConstr :: AltCon -> Constr
toConstr :: AltCon -> Constr
$cdataTypeOf :: AltCon -> DataType
dataTypeOf :: AltCon -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c AltCon)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c AltCon)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c AltCon)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c AltCon)
$cgmapT :: (forall b. Data b => b -> b) -> AltCon -> AltCon
gmapT :: (forall b. Data b => b -> b) -> AltCon -> AltCon
$cgmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> AltCon -> r
gmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> AltCon -> r
$cgmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> AltCon -> r
gmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> AltCon -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> AltCon -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> AltCon -> [u]
$cgmapQi :: forall u. ConTag -> (forall d. Data d => d -> u) -> AltCon -> u
gmapQi :: forall u. ConTag -> (forall d. Data d => d -> u) -> AltCon -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> AltCon -> m AltCon
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> AltCon -> m AltCon
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> AltCon -> m AltCon
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> AltCon -> m AltCon
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> AltCon -> m AltCon
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> AltCon -> m AltCon
Data)
instance Ord AltCon where
compare :: AltCon -> AltCon -> Ordering
compare (DataAlt DataCon
con1) (DataAlt DataCon
con2) =
Bool -> Ordering -> Ordering
forall a. HasCallStack => Bool -> a -> a
assert (DataCon -> TyCon
dataConTyCon DataCon
con1 TyCon -> TyCon -> Bool
forall a. Eq a => a -> a -> Bool
== DataCon -> TyCon
dataConTyCon DataCon
con2) (Ordering -> Ordering) -> Ordering -> Ordering
forall a b. (a -> b) -> a -> b
$
ConTag -> ConTag -> Ordering
forall a. Ord a => a -> a -> Ordering
compare (DataCon -> ConTag
dataConTag DataCon
con1) (DataCon -> ConTag
dataConTag DataCon
con2)
compare (DataAlt DataCon
_) AltCon
_ = Ordering
GT
compare AltCon
_ (DataAlt DataCon
_) = Ordering
LT
compare (LitAlt Literal
l1) (LitAlt Literal
l2) = Literal -> Literal -> Ordering
forall a. Ord a => a -> a -> Ordering
compare Literal
l1 Literal
l2
compare (LitAlt Literal
_) AltCon
DEFAULT = Ordering
GT
compare AltCon
DEFAULT AltCon
DEFAULT = Ordering
EQ
compare AltCon
DEFAULT AltCon
_ = Ordering
LT
data Bind b = NonRec b (Expr b)
| Rec [(b, (Expr b))]
deriving Typeable (Bind b)
Typeable (Bind b)
-> (forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Bind b -> c (Bind b))
-> (forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Bind b))
-> (Bind b -> Constr)
-> (Bind b -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (Bind b)))
-> (forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Bind b)))
-> ((forall b. Data b => b -> b) -> Bind b -> Bind b)
-> (forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Bind b -> r)
-> (forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Bind b -> r)
-> (forall u. (forall d. Data d => d -> u) -> Bind b -> [u])
-> (forall u.
ConTag -> (forall d. Data d => d -> u) -> Bind b -> u)
-> (forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Bind b -> m (Bind b))
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Bind b -> m (Bind b))
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Bind b -> m (Bind b))
-> Data (Bind b)
Bind b -> Constr
Bind b -> DataType
(forall b. Data b => b -> b) -> Bind b -> Bind b
forall {b}. Data b => Typeable (Bind b)
forall b. Data b => Bind b -> Constr
forall b. Data b => Bind b -> DataType
forall b.
Data b =>
(forall b. Data b => b -> b) -> Bind b -> Bind b
forall b u.
Data b =>
ConTag -> (forall d. Data d => d -> u) -> Bind b -> u
forall b u. Data b => (forall d. Data d => d -> u) -> Bind b -> [u]
forall b r r'.
Data b =>
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Bind b -> r
forall b r r'.
Data b =>
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Bind b -> r
forall b (m :: * -> *).
(Data b, Monad m) =>
(forall d. Data d => d -> m d) -> Bind b -> m (Bind b)
forall b (m :: * -> *).
(Data b, MonadPlus m) =>
(forall d. Data d => d -> m d) -> Bind b -> m (Bind b)
forall b (c :: * -> *).
Data b =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Bind b)
forall b (c :: * -> *).
Data b =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Bind b -> c (Bind b)
forall b (t :: * -> *) (c :: * -> *).
(Data b, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (Bind b))
forall b (t :: * -> * -> *) (c :: * -> *).
(Data b, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Bind b))
forall a.
Typeable a
-> (forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. ConTag -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. ConTag -> (forall d. Data d => d -> u) -> Bind b -> u
forall u. (forall d. Data d => d -> u) -> Bind b -> [u]
forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Bind b -> r
forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Bind b -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Bind b -> m (Bind b)
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Bind b -> m (Bind b)
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Bind b)
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Bind b -> c (Bind b)
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (Bind b))
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Bind b))
$cgfoldl :: forall b (c :: * -> *).
Data b =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Bind b -> c (Bind b)
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Bind b -> c (Bind b)
$cgunfold :: forall b (c :: * -> *).
Data b =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Bind b)
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Bind b)
$ctoConstr :: forall b. Data b => Bind b -> Constr
toConstr :: Bind b -> Constr
$cdataTypeOf :: forall b. Data b => Bind b -> DataType
dataTypeOf :: Bind b -> DataType
$cdataCast1 :: forall b (t :: * -> *) (c :: * -> *).
(Data b, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (Bind b))
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (Bind b))
$cdataCast2 :: forall b (t :: * -> * -> *) (c :: * -> *).
(Data b, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Bind b))
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Bind b))
$cgmapT :: forall b.
Data b =>
(forall b. Data b => b -> b) -> Bind b -> Bind b
gmapT :: (forall b. Data b => b -> b) -> Bind b -> Bind b
$cgmapQl :: forall b r r'.
Data b =>
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Bind b -> r
gmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Bind b -> r
$cgmapQr :: forall b r r'.
Data b =>
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Bind b -> r
gmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Bind b -> r
$cgmapQ :: forall b u. Data b => (forall d. Data d => d -> u) -> Bind b -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> Bind b -> [u]
$cgmapQi :: forall b u.
Data b =>
ConTag -> (forall d. Data d => d -> u) -> Bind b -> u
gmapQi :: forall u. ConTag -> (forall d. Data d => d -> u) -> Bind b -> u
$cgmapM :: forall b (m :: * -> *).
(Data b, Monad m) =>
(forall d. Data d => d -> m d) -> Bind b -> m (Bind b)
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Bind b -> m (Bind b)
$cgmapMp :: forall b (m :: * -> *).
(Data b, MonadPlus m) =>
(forall d. Data d => d -> m d) -> Bind b -> m (Bind b)
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Bind b -> m (Bind b)
$cgmapMo :: forall b (m :: * -> *).
(Data b, MonadPlus m) =>
(forall d. Data d => d -> m d) -> Bind b -> m (Bind b)
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Bind b -> m (Bind b)
Data
type InBndr = CoreBndr
type InType = Type
type InKind = Kind
type InBind = CoreBind
type InExpr = CoreExpr
type InAlt = CoreAlt
type InArg = CoreArg
type InCoercion = Coercion
type OutBndr = CoreBndr
type OutType = Type
type OutKind = Kind
type OutCoercion = Coercion
type OutBind = CoreBind
type OutExpr = CoreExpr
type OutAlt = CoreAlt
type OutArg = CoreArg
type MOutCoercion = MCoercion
data IsOrphan
= IsOrphan
| NotOrphan !OccName
deriving Typeable IsOrphan
Typeable IsOrphan
-> (forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> IsOrphan -> c IsOrphan)
-> (forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c IsOrphan)
-> (IsOrphan -> Constr)
-> (IsOrphan -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c IsOrphan))
-> (forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c IsOrphan))
-> ((forall b. Data b => b -> b) -> IsOrphan -> IsOrphan)
-> (forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> IsOrphan -> r)
-> (forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> IsOrphan -> r)
-> (forall u. (forall d. Data d => d -> u) -> IsOrphan -> [u])
-> (forall u.
ConTag -> (forall d. Data d => d -> u) -> IsOrphan -> u)
-> (forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> IsOrphan -> m IsOrphan)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> IsOrphan -> m IsOrphan)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> IsOrphan -> m IsOrphan)
-> Data IsOrphan
IsOrphan -> Constr
IsOrphan -> DataType
(forall b. Data b => b -> b) -> IsOrphan -> IsOrphan
forall a.
Typeable a
-> (forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. ConTag -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. ConTag -> (forall d. Data d => d -> u) -> IsOrphan -> u
forall u. (forall d. Data d => d -> u) -> IsOrphan -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> IsOrphan -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> IsOrphan -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> IsOrphan -> m IsOrphan
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> IsOrphan -> m IsOrphan
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c IsOrphan
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> IsOrphan -> c IsOrphan
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c IsOrphan)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c IsOrphan)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> IsOrphan -> c IsOrphan
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> IsOrphan -> c IsOrphan
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c IsOrphan
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c IsOrphan
$ctoConstr :: IsOrphan -> Constr
toConstr :: IsOrphan -> Constr
$cdataTypeOf :: IsOrphan -> DataType
dataTypeOf :: IsOrphan -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c IsOrphan)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c IsOrphan)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c IsOrphan)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c IsOrphan)
$cgmapT :: (forall b. Data b => b -> b) -> IsOrphan -> IsOrphan
gmapT :: (forall b. Data b => b -> b) -> IsOrphan -> IsOrphan
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> IsOrphan -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> IsOrphan -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> IsOrphan -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> IsOrphan -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> IsOrphan -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> IsOrphan -> [u]
$cgmapQi :: forall u. ConTag -> (forall d. Data d => d -> u) -> IsOrphan -> u
gmapQi :: forall u. ConTag -> (forall d. Data d => d -> u) -> IsOrphan -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> IsOrphan -> m IsOrphan
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> IsOrphan -> m IsOrphan
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> IsOrphan -> m IsOrphan
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> IsOrphan -> m IsOrphan
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> IsOrphan -> m IsOrphan
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> IsOrphan -> m IsOrphan
Data
isOrphan :: IsOrphan -> Bool
isOrphan :: IsOrphan -> Bool
isOrphan IsOrphan
IsOrphan = Bool
True
isOrphan IsOrphan
_ = Bool
False
notOrphan :: IsOrphan -> Bool
notOrphan :: IsOrphan -> Bool
notOrphan NotOrphan{} = Bool
True
notOrphan IsOrphan
_ = Bool
False
chooseOrphanAnchor :: NameSet -> IsOrphan
chooseOrphanAnchor :: NameSet -> IsOrphan
chooseOrphanAnchor NameSet
local_names
| NameSet -> Bool
isEmptyNameSet NameSet
local_names = IsOrphan
IsOrphan
| Bool
otherwise = OccName -> IsOrphan
NotOrphan ([OccName] -> OccName
forall a. Ord a => [a] -> a
forall (t :: * -> *) a. (Foldable t, Ord a) => t a -> a
minimum [OccName]
occs)
where
occs :: [OccName]
occs = (Name -> OccName) -> [Name] -> [OccName]
forall a b. (a -> b) -> [a] -> [b]
map Name -> OccName
nameOccName ([Name] -> [OccName]) -> [Name] -> [OccName]
forall a b. (a -> b) -> a -> b
$ NameSet -> [Name]
forall elt. UniqSet elt -> [elt]
nonDetEltsUniqSet NameSet
local_names
instance Binary IsOrphan where
put_ :: BinHandle -> IsOrphan -> IO ()
put_ BinHandle
bh IsOrphan
IsOrphan = BinHandle -> Word8 -> IO ()
putByte BinHandle
bh Word8
0
put_ BinHandle
bh (NotOrphan OccName
n) = do
BinHandle -> Word8 -> IO ()
putByte BinHandle
bh Word8
1
BinHandle -> OccName -> IO ()
forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh OccName
n
get :: BinHandle -> IO IsOrphan
get BinHandle
bh = do
Word8
h <- BinHandle -> IO Word8
getByte BinHandle
bh
case Word8
h of
Word8
0 -> IsOrphan -> IO IsOrphan
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return IsOrphan
IsOrphan
Word8
_ -> do
OccName
n <- BinHandle -> IO OccName
forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
IsOrphan -> IO IsOrphan
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (IsOrphan -> IO IsOrphan) -> IsOrphan -> IO IsOrphan
forall a b. (a -> b) -> a -> b
$ OccName -> IsOrphan
NotOrphan OccName
n
type RuleBase = NameEnv [CoreRule]
data RuleEnv
= RuleEnv { RuleEnv -> [RuleBase]
re_base :: [RuleBase]
, RuleEnv -> ModuleSet
re_visible_orphs :: ModuleSet
}
mkRuleEnv :: RuleBase -> [Module] -> RuleEnv
mkRuleEnv :: RuleBase -> [Module] -> RuleEnv
mkRuleEnv RuleBase
rules [Module]
vis_orphs = [RuleBase] -> ModuleSet -> RuleEnv
RuleEnv [RuleBase
rules] ([Module] -> ModuleSet
mkModuleSet [Module]
vis_orphs)
emptyRuleEnv :: RuleEnv
emptyRuleEnv :: RuleEnv
emptyRuleEnv = [RuleBase] -> ModuleSet -> RuleEnv
RuleEnv [] ModuleSet
emptyModuleSet
data CoreRule
= Rule {
CoreRule -> RuleName
ru_name :: RuleName,
CoreRule -> Activation
ru_act :: Activation,
CoreRule -> Name
ru_fn :: Name,
CoreRule -> [Maybe Name]
ru_rough :: [Maybe Name],
CoreRule -> [Id]
ru_bndrs :: [CoreBndr],
CoreRule -> [CoreExpr]
ru_args :: [CoreExpr],
CoreRule -> CoreExpr
ru_rhs :: CoreExpr,
CoreRule -> Bool
ru_auto :: Bool,
CoreRule -> Module
ru_origin :: !Module,
CoreRule -> IsOrphan
ru_orphan :: !IsOrphan,
CoreRule -> Bool
ru_local :: Bool
}
| BuiltinRule {
ru_name :: RuleName,
ru_fn :: Name,
CoreRule -> ConTag
ru_nargs :: Int,
CoreRule -> RuleFun
ru_try :: RuleFun
}
data RuleOpts = RuleOpts
{ RuleOpts -> Platform
roPlatform :: !Platform
, RuleOpts -> Bool
roNumConstantFolding :: !Bool
, RuleOpts -> Bool
roExcessRationalPrecision :: !Bool
, RuleOpts -> Bool
roBignumRules :: !Bool
}
type RuleFun = RuleOpts -> InScopeEnv -> Id -> [CoreExpr] -> Maybe CoreExpr
type InScopeEnv = (InScopeSet, IdUnfoldingFun)
type IdUnfoldingFun = Id -> Unfolding
isBuiltinRule :: CoreRule -> Bool
isBuiltinRule :: CoreRule -> Bool
isBuiltinRule (BuiltinRule {}) = Bool
True
isBuiltinRule CoreRule
_ = Bool
False
isAutoRule :: CoreRule -> Bool
isAutoRule :: CoreRule -> Bool
isAutoRule (BuiltinRule {}) = Bool
False
isAutoRule (Rule { ru_auto :: CoreRule -> Bool
ru_auto = Bool
is_auto }) = Bool
is_auto
ruleArity :: CoreRule -> Int
ruleArity :: CoreRule -> ConTag
ruleArity (BuiltinRule {ru_nargs :: CoreRule -> ConTag
ru_nargs = ConTag
n}) = ConTag
n
ruleArity (Rule {ru_args :: CoreRule -> [CoreExpr]
ru_args = [CoreExpr]
args}) = [CoreExpr] -> ConTag
forall a. [a] -> ConTag
forall (t :: * -> *) a. Foldable t => t a -> ConTag
length [CoreExpr]
args
ruleName :: CoreRule -> RuleName
ruleName :: CoreRule -> RuleName
ruleName = CoreRule -> RuleName
ru_name
ruleModule :: CoreRule -> Maybe Module
ruleModule :: CoreRule -> Maybe Module
ruleModule Rule { Module
ru_origin :: CoreRule -> Module
ru_origin :: Module
ru_origin } = Module -> Maybe Module
forall a. a -> Maybe a
Just Module
ru_origin
ruleModule BuiltinRule {} = Maybe Module
forall a. Maybe a
Nothing
ruleActivation :: CoreRule -> Activation
ruleActivation :: CoreRule -> Activation
ruleActivation (BuiltinRule { }) = Activation
AlwaysActive
ruleActivation (Rule { ru_act :: CoreRule -> Activation
ru_act = Activation
act }) = Activation
act
ruleIdName :: CoreRule -> Name
ruleIdName :: CoreRule -> Name
ruleIdName = CoreRule -> Name
ru_fn
isLocalRule :: CoreRule -> Bool
isLocalRule :: CoreRule -> Bool
isLocalRule = CoreRule -> Bool
ru_local
setRuleIdName :: Name -> CoreRule -> CoreRule
setRuleIdName :: Name -> CoreRule -> CoreRule
setRuleIdName Name
nm CoreRule
ru = CoreRule
ru { ru_fn :: Name
ru_fn = Name
nm }
data Unfolding
= NoUnfolding
| BootUnfolding
| OtherCon [AltCon]
| DFunUnfolding {
Unfolding -> [Id]
df_bndrs :: [Var],
Unfolding -> DataCon
df_con :: DataCon,
Unfolding -> [CoreExpr]
df_args :: [CoreExpr]
}
| CoreUnfolding {
Unfolding -> CoreExpr
uf_tmpl :: CoreExpr,
Unfolding -> UnfoldingSource
uf_src :: UnfoldingSource,
Unfolding -> Bool
uf_is_top :: Bool,
Unfolding -> Bool
uf_is_value :: Bool,
Unfolding -> Bool
uf_is_conlike :: Bool,
Unfolding -> Bool
uf_is_work_free :: Bool,
Unfolding -> Bool
uf_expandable :: Bool,
Unfolding -> UnfoldingGuidance
uf_guidance :: UnfoldingGuidance
}
data UnfoldingSource
=
InlineRhs
| InlineStable
| InlineCompulsory
data UnfoldingGuidance
= UnfWhen {
UnfoldingGuidance -> ConTag
ug_arity :: Arity,
UnfoldingGuidance -> Bool
ug_unsat_ok :: Bool,
UnfoldingGuidance -> Bool
ug_boring_ok :: Bool
}
| UnfIfGoodArgs {
UnfoldingGuidance -> [ConTag]
ug_args :: [Int],
UnfoldingGuidance -> ConTag
ug_size :: Int,
UnfoldingGuidance -> ConTag
ug_res :: Int
}
| UnfNever
deriving (UnfoldingGuidance -> UnfoldingGuidance -> Bool
(UnfoldingGuidance -> UnfoldingGuidance -> Bool)
-> (UnfoldingGuidance -> UnfoldingGuidance -> Bool)
-> Eq UnfoldingGuidance
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: UnfoldingGuidance -> UnfoldingGuidance -> Bool
== :: UnfoldingGuidance -> UnfoldingGuidance -> Bool
$c/= :: UnfoldingGuidance -> UnfoldingGuidance -> Bool
/= :: UnfoldingGuidance -> UnfoldingGuidance -> Bool
Eq)
needSaturated, unSaturatedOk :: Bool
needSaturated :: Bool
needSaturated = Bool
False
unSaturatedOk :: Bool
unSaturatedOk = Bool
True
boringCxtNotOk, boringCxtOk :: Bool
boringCxtOk :: Bool
boringCxtOk = Bool
True
boringCxtNotOk :: Bool
boringCxtNotOk = Bool
False
noUnfolding :: Unfolding
evaldUnfolding :: Unfolding
noUnfolding :: Unfolding
noUnfolding = Unfolding
NoUnfolding
evaldUnfolding :: Unfolding
evaldUnfolding = [AltCon] -> Unfolding
OtherCon []
bootUnfolding :: Unfolding
bootUnfolding :: Unfolding
bootUnfolding = Unfolding
BootUnfolding
mkOtherCon :: [AltCon] -> Unfolding
mkOtherCon :: [AltCon] -> Unfolding
mkOtherCon = [AltCon] -> Unfolding
OtherCon
isStableSource :: UnfoldingSource -> Bool
isStableSource :: UnfoldingSource -> Bool
isStableSource UnfoldingSource
InlineCompulsory = Bool
True
isStableSource UnfoldingSource
InlineStable = Bool
True
isStableSource UnfoldingSource
InlineRhs = Bool
False
unfoldingTemplate :: Unfolding -> CoreExpr
unfoldingTemplate :: Unfolding -> CoreExpr
unfoldingTemplate = Unfolding -> CoreExpr
uf_tmpl
maybeUnfoldingTemplate :: Unfolding -> Maybe CoreExpr
maybeUnfoldingTemplate :: Unfolding -> Maybe CoreExpr
maybeUnfoldingTemplate (CoreUnfolding { uf_tmpl :: Unfolding -> CoreExpr
uf_tmpl = CoreExpr
expr })
= CoreExpr -> Maybe CoreExpr
forall a. a -> Maybe a
Just CoreExpr
expr
maybeUnfoldingTemplate (DFunUnfolding { df_bndrs :: Unfolding -> [Id]
df_bndrs = [Id]
bndrs, df_con :: Unfolding -> DataCon
df_con = DataCon
con, df_args :: Unfolding -> [CoreExpr]
df_args = [CoreExpr]
args })
= CoreExpr -> Maybe CoreExpr
forall a. a -> Maybe a
Just ([Id] -> CoreExpr -> CoreExpr
forall b. [b] -> Expr b -> Expr b
mkLams [Id]
bndrs (CoreExpr -> [CoreExpr] -> CoreExpr
forall b. Expr b -> [Expr b] -> Expr b
mkApps (Id -> CoreExpr
forall b. Id -> Expr b
Var (DataCon -> Id
dataConWorkId DataCon
con)) [CoreExpr]
args))
maybeUnfoldingTemplate Unfolding
_
= Maybe CoreExpr
forall a. Maybe a
Nothing
otherCons :: Unfolding -> [AltCon]
otherCons :: Unfolding -> [AltCon]
otherCons (OtherCon [AltCon]
cons) = [AltCon]
cons
otherCons Unfolding
_ = []
isValueUnfolding :: Unfolding -> Bool
isValueUnfolding :: Unfolding -> Bool
isValueUnfolding (CoreUnfolding { uf_is_value :: Unfolding -> Bool
uf_is_value = Bool
is_evald }) = Bool
is_evald
isValueUnfolding Unfolding
_ = Bool
False
isEvaldUnfolding :: Unfolding -> Bool
isEvaldUnfolding :: Unfolding -> Bool
isEvaldUnfolding (OtherCon [AltCon]
_) = Bool
True
isEvaldUnfolding (CoreUnfolding { uf_is_value :: Unfolding -> Bool
uf_is_value = Bool
is_evald }) = Bool
is_evald
isEvaldUnfolding Unfolding
_ = Bool
False
isConLikeUnfolding :: Unfolding -> Bool
isConLikeUnfolding :: Unfolding -> Bool
isConLikeUnfolding (OtherCon [AltCon]
_) = Bool
True
isConLikeUnfolding (CoreUnfolding { uf_is_conlike :: Unfolding -> Bool
uf_is_conlike = Bool
con }) = Bool
con
isConLikeUnfolding Unfolding
_ = Bool
False
isCheapUnfolding :: Unfolding -> Bool
isCheapUnfolding :: Unfolding -> Bool
isCheapUnfolding (CoreUnfolding { uf_is_work_free :: Unfolding -> Bool
uf_is_work_free = Bool
is_wf }) = Bool
is_wf
isCheapUnfolding Unfolding
_ = Bool
False
isExpandableUnfolding :: Unfolding -> Bool
isExpandableUnfolding :: Unfolding -> Bool
isExpandableUnfolding (CoreUnfolding { uf_expandable :: Unfolding -> Bool
uf_expandable = Bool
is_expable }) = Bool
is_expable
isExpandableUnfolding Unfolding
_ = Bool
False
expandUnfolding_maybe :: Unfolding -> Maybe CoreExpr
expandUnfolding_maybe :: Unfolding -> Maybe CoreExpr
expandUnfolding_maybe (CoreUnfolding { uf_expandable :: Unfolding -> Bool
uf_expandable = Bool
True, uf_tmpl :: Unfolding -> CoreExpr
uf_tmpl = CoreExpr
rhs }) = CoreExpr -> Maybe CoreExpr
forall a. a -> Maybe a
Just CoreExpr
rhs
expandUnfolding_maybe Unfolding
_ = Maybe CoreExpr
forall a. Maybe a
Nothing
isCompulsoryUnfolding :: Unfolding -> Bool
isCompulsoryUnfolding :: Unfolding -> Bool
isCompulsoryUnfolding (CoreUnfolding { uf_src :: Unfolding -> UnfoldingSource
uf_src = UnfoldingSource
InlineCompulsory }) = Bool
True
isCompulsoryUnfolding Unfolding
_ = Bool
False
isStableUnfolding :: Unfolding -> Bool
isStableUnfolding :: Unfolding -> Bool
isStableUnfolding (CoreUnfolding { uf_src :: Unfolding -> UnfoldingSource
uf_src = UnfoldingSource
src }) = UnfoldingSource -> Bool
isStableSource UnfoldingSource
src
isStableUnfolding (DFunUnfolding {}) = Bool
True
isStableUnfolding Unfolding
_ = Bool
False
isInlineUnfolding :: Unfolding -> Bool
isInlineUnfolding :: Unfolding -> Bool
isInlineUnfolding (CoreUnfolding { uf_src :: Unfolding -> UnfoldingSource
uf_src = UnfoldingSource
src, uf_guidance :: Unfolding -> UnfoldingGuidance
uf_guidance = UnfoldingGuidance
guidance })
| UnfoldingSource -> Bool
isStableSource UnfoldingSource
src
, UnfWhen {} <- UnfoldingGuidance
guidance
= Bool
True
isInlineUnfolding (DFunUnfolding {})
= Bool
True
isInlineUnfolding Unfolding
_ = Bool
False
hasSomeUnfolding :: Unfolding -> Bool
hasSomeUnfolding :: Unfolding -> Bool
hasSomeUnfolding Unfolding
NoUnfolding = Bool
False
hasSomeUnfolding Unfolding
BootUnfolding = Bool
False
hasSomeUnfolding Unfolding
_ = Bool
True
isBootUnfolding :: Unfolding -> Bool
isBootUnfolding :: Unfolding -> Bool
isBootUnfolding Unfolding
BootUnfolding = Bool
True
isBootUnfolding Unfolding
_ = Bool
False
neverUnfoldGuidance :: UnfoldingGuidance -> Bool
neverUnfoldGuidance :: UnfoldingGuidance -> Bool
neverUnfoldGuidance UnfoldingGuidance
UnfNever = Bool
True
neverUnfoldGuidance UnfoldingGuidance
_ = Bool
False
hasCoreUnfolding :: Unfolding -> Bool
hasCoreUnfolding :: Unfolding -> Bool
hasCoreUnfolding (CoreUnfolding {}) = Bool
True
hasCoreUnfolding (DFunUnfolding {}) = Bool
True
hasCoreUnfolding Unfolding
_ = Bool
False
canUnfold :: Unfolding -> Bool
canUnfold :: Unfolding -> Bool
canUnfold (CoreUnfolding { uf_guidance :: Unfolding -> UnfoldingGuidance
uf_guidance = UnfoldingGuidance
g }) = Bool -> Bool
not (UnfoldingGuidance -> Bool
neverUnfoldGuidance UnfoldingGuidance
g)
canUnfold Unfolding
_ = Bool
False
instance Outputable AltCon where
ppr :: AltCon -> SDoc
ppr (DataAlt DataCon
dc) = DataCon -> SDoc
forall a. Outputable a => a -> SDoc
ppr DataCon
dc
ppr (LitAlt Literal
lit) = Literal -> SDoc
forall a. Outputable a => a -> SDoc
ppr Literal
lit
ppr AltCon
DEFAULT = String -> SDoc
text String
"__DEFAULT"
cmpAlt :: Alt a -> Alt a -> Ordering
cmpAlt :: forall a. Alt a -> Alt a -> Ordering
cmpAlt (Alt AltCon
con1 [a]
_ Expr a
_) (Alt AltCon
con2 [a]
_ Expr a
_) = AltCon
con1 AltCon -> AltCon -> Ordering
`cmpAltCon` AltCon
con2
ltAlt :: Alt a -> Alt a -> Bool
ltAlt :: forall a. Alt a -> Alt a -> Bool
ltAlt Alt a
a1 Alt a
a2 = (Alt a
a1 Alt a -> Alt a -> Ordering
forall a. Alt a -> Alt a -> Ordering
`cmpAlt` Alt a
a2) Ordering -> Ordering -> Bool
forall a. Eq a => a -> a -> Bool
== Ordering
LT
cmpAltCon :: AltCon -> AltCon -> Ordering
cmpAltCon :: AltCon -> AltCon -> Ordering
cmpAltCon AltCon
DEFAULT AltCon
DEFAULT = Ordering
EQ
cmpAltCon AltCon
DEFAULT AltCon
_ = Ordering
LT
cmpAltCon (DataAlt DataCon
d1) (DataAlt DataCon
d2) = DataCon -> ConTag
dataConTag DataCon
d1 ConTag -> ConTag -> Ordering
forall a. Ord a => a -> a -> Ordering
`compare` DataCon -> ConTag
dataConTag DataCon
d2
cmpAltCon (DataAlt DataCon
_) AltCon
DEFAULT = Ordering
GT
cmpAltCon (LitAlt Literal
l1) (LitAlt Literal
l2) = Literal
l1 Literal -> Literal -> Ordering
forall a. Ord a => a -> a -> Ordering
`compare` Literal
l2
cmpAltCon (LitAlt Literal
_) AltCon
DEFAULT = Ordering
GT
cmpAltCon AltCon
con1 AltCon
con2 = String -> SDoc -> Ordering
forall a. HasCallStack => String -> SDoc -> a
pprPanic String
"cmpAltCon" (AltCon -> SDoc
forall a. Outputable a => a -> SDoc
ppr AltCon
con1 SDoc -> SDoc -> SDoc
$$ AltCon -> SDoc
forall a. Outputable a => a -> SDoc
ppr AltCon
con2)
type CoreProgram = [CoreBind]
type CoreBndr = Var
type CoreExpr = Expr CoreBndr
type CoreArg = Arg CoreBndr
type CoreBind = Bind CoreBndr
type CoreAlt = Alt CoreBndr
data TaggedBndr t = TB CoreBndr t
type TaggedBind t = Bind (TaggedBndr t)
type TaggedExpr t = Expr (TaggedBndr t)
type TaggedArg t = Arg (TaggedBndr t)
type TaggedAlt t = Alt (TaggedBndr t)
instance Outputable b => Outputable (TaggedBndr b) where
ppr :: TaggedBndr b -> SDoc
ppr (TB Id
b b
l) = Char -> SDoc
char Char
'<' SDoc -> SDoc -> SDoc
<> Id -> SDoc
forall a. Outputable a => a -> SDoc
ppr Id
b SDoc -> SDoc -> SDoc
<> SDoc
comma SDoc -> SDoc -> SDoc
<> b -> SDoc
forall a. Outputable a => a -> SDoc
ppr b
l SDoc -> SDoc -> SDoc
<> Char -> SDoc
char Char
'>'
deTagExpr :: TaggedExpr t -> CoreExpr
deTagExpr :: forall t. TaggedExpr t -> CoreExpr
deTagExpr (Var Id
v) = Id -> CoreExpr
forall b. Id -> Expr b
Var Id
v
deTagExpr (Lit Literal
l) = Literal -> CoreExpr
forall b. Literal -> Expr b
Lit Literal
l
deTagExpr (Type Type
ty) = Type -> CoreExpr
forall b. Type -> Expr b
Type Type
ty
deTagExpr (Coercion CoercionR
co) = CoercionR -> CoreExpr
forall b. CoercionR -> Expr b
Coercion CoercionR
co
deTagExpr (App Expr (TaggedBndr t)
e1 Expr (TaggedBndr t)
e2) = CoreExpr -> CoreExpr -> CoreExpr
forall b. Expr b -> Expr b -> Expr b
App (Expr (TaggedBndr t) -> CoreExpr
forall t. TaggedExpr t -> CoreExpr
deTagExpr Expr (TaggedBndr t)
e1) (Expr (TaggedBndr t) -> CoreExpr
forall t. TaggedExpr t -> CoreExpr
deTagExpr Expr (TaggedBndr t)
e2)
deTagExpr (Lam (TB Id
b t
_) Expr (TaggedBndr t)
e) = Id -> CoreExpr -> CoreExpr
forall b. b -> Expr b -> Expr b
Lam Id
b (Expr (TaggedBndr t) -> CoreExpr
forall t. TaggedExpr t -> CoreExpr
deTagExpr Expr (TaggedBndr t)
e)
deTagExpr (Let Bind (TaggedBndr t)
bind Expr (TaggedBndr t)
body) = Bind Id -> CoreExpr -> CoreExpr
forall b. Bind b -> Expr b -> Expr b
Let (Bind (TaggedBndr t) -> Bind Id
forall t. TaggedBind t -> Bind Id
deTagBind Bind (TaggedBndr t)
bind) (Expr (TaggedBndr t) -> CoreExpr
forall t. TaggedExpr t -> CoreExpr
deTagExpr Expr (TaggedBndr t)
body)
deTagExpr (Case Expr (TaggedBndr t)
e (TB Id
b t
_) Type
ty [Alt (TaggedBndr t)]
alts) = CoreExpr -> Id -> Type -> [Alt Id] -> CoreExpr
forall b. Expr b -> b -> Type -> [Alt b] -> Expr b
Case (Expr (TaggedBndr t) -> CoreExpr
forall t. TaggedExpr t -> CoreExpr
deTagExpr Expr (TaggedBndr t)
e) Id
b Type
ty ((Alt (TaggedBndr t) -> Alt Id) -> [Alt (TaggedBndr t)] -> [Alt Id]
forall a b. (a -> b) -> [a] -> [b]
map Alt (TaggedBndr t) -> Alt Id
forall t. TaggedAlt t -> Alt Id
deTagAlt [Alt (TaggedBndr t)]
alts)
deTagExpr (Tick CoreTickish
t Expr (TaggedBndr t)
e) = CoreTickish -> CoreExpr -> CoreExpr
forall b. CoreTickish -> Expr b -> Expr b
Tick CoreTickish
t (Expr (TaggedBndr t) -> CoreExpr
forall t. TaggedExpr t -> CoreExpr
deTagExpr Expr (TaggedBndr t)
e)
deTagExpr (Cast Expr (TaggedBndr t)
e CoercionR
co) = CoreExpr -> CoercionR -> CoreExpr
forall b. Expr b -> CoercionR -> Expr b
Cast (Expr (TaggedBndr t) -> CoreExpr
forall t. TaggedExpr t -> CoreExpr
deTagExpr Expr (TaggedBndr t)
e) CoercionR
co
deTagBind :: TaggedBind t -> CoreBind
deTagBind :: forall t. TaggedBind t -> Bind Id
deTagBind (NonRec (TB Id
b t
_) Expr (TaggedBndr t)
rhs) = Id -> CoreExpr -> Bind Id
forall b. b -> Expr b -> Bind b
NonRec Id
b (Expr (TaggedBndr t) -> CoreExpr
forall t. TaggedExpr t -> CoreExpr
deTagExpr Expr (TaggedBndr t)
rhs)
deTagBind (Rec [(TaggedBndr t, Expr (TaggedBndr t))]
prs) = [(Id, CoreExpr)] -> Bind Id
forall b. [(b, Expr b)] -> Bind b
Rec [(Id
b, Expr (TaggedBndr t) -> CoreExpr
forall t. TaggedExpr t -> CoreExpr
deTagExpr Expr (TaggedBndr t)
rhs) | (TB Id
b t
_, Expr (TaggedBndr t)
rhs) <- [(TaggedBndr t, Expr (TaggedBndr t))]
prs]
deTagAlt :: TaggedAlt t -> CoreAlt
deTagAlt :: forall t. TaggedAlt t -> Alt Id
deTagAlt (Alt AltCon
con [TaggedBndr t]
bndrs Expr (TaggedBndr t)
rhs) = AltCon -> [Id] -> CoreExpr -> Alt Id
forall b. AltCon -> [b] -> Expr b -> Alt b
Alt AltCon
con [Id
b | TB Id
b t
_ <- [TaggedBndr t]
bndrs] (Expr (TaggedBndr t) -> CoreExpr
forall t. TaggedExpr t -> CoreExpr
deTagExpr Expr (TaggedBndr t)
rhs)
mkApps :: Expr b -> [Arg b] -> Expr b
mkTyApps :: Expr b -> [Type] -> Expr b
mkCoApps :: Expr b -> [Coercion] -> Expr b
mkVarApps :: Expr b -> [Var] -> Expr b
mkConApp :: DataCon -> [Arg b] -> Expr b
mkApps :: forall b. Expr b -> [Expr b] -> Expr b
mkApps Expr b
f [Expr b]
args = (Expr b -> Expr b -> Expr b) -> Expr b -> [Expr b] -> Expr b
forall b a. (b -> a -> b) -> b -> [a] -> b
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' Expr b -> Expr b -> Expr b
forall b. Expr b -> Expr b -> Expr b
App Expr b
f [Expr b]
args
mkCoApps :: forall b. Expr b -> [CoercionR] -> Expr b
mkCoApps Expr b
f [CoercionR]
args = (Expr b -> CoercionR -> Expr b) -> Expr b -> [CoercionR] -> Expr b
forall b a. (b -> a -> b) -> b -> [a] -> b
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' (\ Expr b
e CoercionR
a -> Expr b -> Expr b -> Expr b
forall b. Expr b -> Expr b -> Expr b
App Expr b
e (CoercionR -> Expr b
forall b. CoercionR -> Expr b
Coercion CoercionR
a)) Expr b
f [CoercionR]
args
mkVarApps :: forall b. Expr b -> [Id] -> Expr b
mkVarApps Expr b
f [Id]
vars = (Expr b -> Id -> Expr b) -> Expr b -> [Id] -> Expr b
forall b a. (b -> a -> b) -> b -> [a] -> b
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' (\ Expr b
e Id
a -> Expr b -> Expr b -> Expr b
forall b. Expr b -> Expr b -> Expr b
App Expr b
e (Id -> Expr b
forall b. Id -> Expr b
varToCoreExpr Id
a)) Expr b
f [Id]
vars
mkConApp :: forall b. DataCon -> [Arg b] -> Arg b
mkConApp DataCon
con [Arg b]
args = Arg b -> [Arg b] -> Arg b
forall b. Expr b -> [Expr b] -> Expr b
mkApps (Id -> Arg b
forall b. Id -> Expr b
Var (DataCon -> Id
dataConWorkId DataCon
con)) [Arg b]
args
mkTyApps :: forall b. Expr b -> [Type] -> Expr b
mkTyApps Expr b
f [Type]
args = (Expr b -> Type -> Expr b) -> Expr b -> [Type] -> Expr b
forall b a. (b -> a -> b) -> b -> [a] -> b
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' (\ Expr b
e Type
a -> Expr b -> Expr b -> Expr b
forall b. Expr b -> Expr b -> Expr b
App Expr b
e (Type -> Expr b
forall b. Type -> Expr b
mkTyArg Type
a)) Expr b
f [Type]
args
mkConApp2 :: DataCon -> [Type] -> [Var] -> Expr b
mkConApp2 :: forall b. DataCon -> [Type] -> [Id] -> Expr b
mkConApp2 DataCon
con [Type]
tys [Id]
arg_ids = Id -> Expr b
forall b. Id -> Expr b
Var (DataCon -> Id
dataConWorkId DataCon
con)
Expr b -> [Expr b] -> Expr b
forall b. Expr b -> [Expr b] -> Expr b
`mkApps` (Type -> Expr b) -> [Type] -> [Expr b]
forall a b. (a -> b) -> [a] -> [b]
map Type -> Expr b
forall b. Type -> Expr b
Type [Type]
tys
Expr b -> [Expr b] -> Expr b
forall b. Expr b -> [Expr b] -> Expr b
`mkApps` (Id -> Expr b) -> [Id] -> [Expr b]
forall a b. (a -> b) -> [a] -> [b]
map Id -> Expr b
forall b. Id -> Expr b
varToCoreExpr [Id]
arg_ids
mkTyArg :: Type -> Expr b
mkTyArg :: forall b. Type -> Expr b
mkTyArg Type
ty
| Just CoercionR
co <- Type -> Maybe CoercionR
isCoercionTy_maybe Type
ty = CoercionR -> Expr b
forall b. CoercionR -> Expr b
Coercion CoercionR
co
| Bool
otherwise = Type -> Expr b
forall b. Type -> Expr b
Type Type
ty
mkIntLit :: Platform -> Integer -> Expr b
mkIntLit :: forall b. Platform -> Integer -> Expr b
mkIntLit Platform
platform Integer
n = Literal -> Expr b
forall b. Literal -> Expr b
Lit (Platform -> Integer -> Literal
mkLitInt Platform
platform Integer
n)
mkIntLitWrap :: Platform -> Integer -> Expr b
mkIntLitWrap :: forall b. Platform -> Integer -> Expr b
mkIntLitWrap Platform
platform Integer
n = Literal -> Expr b
forall b. Literal -> Expr b
Lit (Platform -> Integer -> Literal
mkLitIntWrap Platform
platform Integer
n)
mkWordLit :: Platform -> Integer -> Expr b
mkWordLit :: forall b. Platform -> Integer -> Expr b
mkWordLit Platform
platform Integer
w = Literal -> Expr b
forall b. Literal -> Expr b
Lit (Platform -> Integer -> Literal
mkLitWord Platform
platform Integer
w)
mkWordLitWrap :: Platform -> Integer -> Expr b
mkWordLitWrap :: forall b. Platform -> Integer -> Expr b
mkWordLitWrap Platform
platform Integer
w = Literal -> Expr b
forall b. Literal -> Expr b
Lit (Platform -> Integer -> Literal
mkLitWordWrap Platform
platform Integer
w)
mkWord8Lit :: Integer -> Expr b
mkWord8Lit :: forall b. Integer -> Expr b
mkWord8Lit Integer
w = Literal -> Expr b
forall b. Literal -> Expr b
Lit (Integer -> Literal
mkLitWord8 Integer
w)
mkWord64LitWord64 :: Word64 -> Expr b
mkWord64LitWord64 :: forall b. Word64 -> Expr b
mkWord64LitWord64 Word64
w = Literal -> Expr b
forall b. Literal -> Expr b
Lit (Integer -> Literal
mkLitWord64 (Word64 -> Integer
forall a. Integral a => a -> Integer
toInteger Word64
w))
mkInt64LitInt64 :: Int64 -> Expr b
mkInt64LitInt64 :: forall b. Int64 -> Expr b
mkInt64LitInt64 Int64
w = Literal -> Expr b
forall b. Literal -> Expr b
Lit (Integer -> Literal
mkLitInt64 (Int64 -> Integer
forall a. Integral a => a -> Integer
toInteger Int64
w))
mkCharLit :: Char -> Expr b
mkStringLit :: String -> Expr b
mkCharLit :: forall b. Char -> Expr b
mkCharLit Char
c = Literal -> Expr b
forall b. Literal -> Expr b
Lit (Char -> Literal
mkLitChar Char
c)
mkStringLit :: forall b. String -> Expr b
mkStringLit String
s = Literal -> Expr b
forall b. Literal -> Expr b
Lit (String -> Literal
mkLitString String
s)
mkFloatLit :: Rational -> Expr b
mkFloatLitFloat :: Float -> Expr b
mkFloatLit :: forall b. Rational -> Expr b
mkFloatLit Rational
f = Literal -> Expr b
forall b. Literal -> Expr b
Lit (Rational -> Literal
mkLitFloat Rational
f)
mkFloatLitFloat :: forall b. Float -> Expr b
mkFloatLitFloat Float
f = Literal -> Expr b
forall b. Literal -> Expr b
Lit (Rational -> Literal
mkLitFloat (Float -> Rational
forall a. Real a => a -> Rational
toRational Float
f))
mkDoubleLit :: Rational -> Expr b
mkDoubleLitDouble :: Double -> Expr b
mkDoubleLit :: forall b. Rational -> Expr b
mkDoubleLit Rational
d = Literal -> Expr b
forall b. Literal -> Expr b
Lit (Rational -> Literal
mkLitDouble Rational
d)
mkDoubleLitDouble :: forall b. Double -> Expr b
mkDoubleLitDouble Double
d = Literal -> Expr b
forall b. Literal -> Expr b
Lit (Rational -> Literal
mkLitDouble (Double -> Rational
forall a. Real a => a -> Rational
toRational Double
d))
mkLets :: [Bind b] -> Expr b -> Expr b
mkLams :: [b] -> Expr b -> Expr b
mkLams :: forall b. [b] -> Expr b -> Expr b
mkLams [b]
binders Expr b
body = (b -> Expr b -> Expr b) -> Expr b -> [b] -> Expr b
forall a b. (a -> b -> b) -> b -> [a] -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr b -> Expr b -> Expr b
forall b. b -> Expr b -> Expr b
Lam Expr b
body [b]
binders
mkLets :: forall b. [Bind b] -> Expr b -> Expr b
mkLets [Bind b]
binds Expr b
body = (Bind b -> Expr b -> Expr b) -> Expr b -> [Bind b] -> Expr b
forall a b. (a -> b -> b) -> b -> [a] -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr Bind b -> Expr b -> Expr b
forall b. Bind b -> Expr b -> Expr b
mkLet Expr b
body [Bind b]
binds
mkLet :: Bind b -> Expr b -> Expr b
mkLet :: forall b. Bind b -> Expr b -> Expr b
mkLet (Rec []) Expr b
body = Expr b
body
mkLet Bind b
bind Expr b
body = Bind b -> Expr b -> Expr b
forall b. Bind b -> Expr b -> Expr b
Let Bind b
bind Expr b
body
mkLetNonRec :: b -> Expr b -> Expr b -> Expr b
mkLetNonRec :: forall b. b -> Expr b -> Expr b -> Expr b
mkLetNonRec b
b Expr b
rhs Expr b
body = Bind b -> Expr b -> Expr b
forall b. Bind b -> Expr b -> Expr b
Let (b -> Expr b -> Bind b
forall b. b -> Expr b -> Bind b
NonRec b
b Expr b
rhs) Expr b
body
mkLetRec :: [(b, Expr b)] -> Expr b -> Expr b
mkLetRec :: forall b. [(b, Expr b)] -> Expr b -> Expr b
mkLetRec [] Expr b
body = Expr b
body
mkLetRec [(b, Expr b)]
bs Expr b
body = Bind b -> Expr b -> Expr b
forall b. Bind b -> Expr b -> Expr b
Let ([(b, Expr b)] -> Bind b
forall b. [(b, Expr b)] -> Bind b
Rec [(b, Expr b)]
bs) Expr b
body
mkTyBind :: TyVar -> Type -> CoreBind
mkTyBind :: Id -> Type -> Bind Id
mkTyBind Id
tv Type
ty = Id -> CoreExpr -> Bind Id
forall b. b -> Expr b -> Bind b
NonRec Id
tv (Type -> CoreExpr
forall b. Type -> Expr b
Type Type
ty)
mkCoBind :: CoVar -> Coercion -> CoreBind
mkCoBind :: Id -> CoercionR -> Bind Id
mkCoBind Id
cv CoercionR
co = Id -> CoreExpr -> Bind Id
forall b. b -> Expr b -> Bind b
NonRec Id
cv (CoercionR -> CoreExpr
forall b. CoercionR -> Expr b
Coercion CoercionR
co)
varToCoreExpr :: CoreBndr -> Expr b
varToCoreExpr :: forall b. Id -> Expr b
varToCoreExpr Id
v | Id -> Bool
isTyVar Id
v = Type -> Expr b
forall b. Type -> Expr b
Type (Id -> Type
mkTyVarTy Id
v)
| Id -> Bool
isCoVar Id
v = CoercionR -> Expr b
forall b. CoercionR -> Expr b
Coercion (Id -> CoercionR
mkCoVarCo Id
v)
| Bool
otherwise = Bool -> Expr b -> Expr b
forall a. HasCallStack => Bool -> a -> a
assert (Id -> Bool
isId Id
v) (Expr b -> Expr b) -> Expr b -> Expr b
forall a b. (a -> b) -> a -> b
$ Id -> Expr b
forall b. Id -> Expr b
Var Id
v
varsToCoreExprs :: [CoreBndr] -> [Expr b]
varsToCoreExprs :: forall b. [Id] -> [Expr b]
varsToCoreExprs [Id]
vs = (Id -> Expr b) -> [Id] -> [Expr b]
forall a b. (a -> b) -> [a] -> [b]
map Id -> Expr b
forall b. Id -> Expr b
varToCoreExpr [Id]
vs
exprToType :: CoreExpr -> Type
exprToType :: CoreExpr -> Type
exprToType (Type Type
ty) = Type
ty
exprToType CoreExpr
_bad = String -> SDoc -> Type
forall a. HasCallStack => String -> SDoc -> a
pprPanic String
"exprToType" SDoc
empty
bindersOf :: Bind b -> [b]
bindersOf :: forall b. Bind b -> [b]
bindersOf (NonRec b
binder Expr b
_) = [b
binder]
bindersOf (Rec [(b, Expr b)]
pairs) = [b
binder | (b
binder, Expr b
_) <- [(b, Expr b)]
pairs]
bindersOfBinds :: [Bind b] -> [b]
bindersOfBinds :: forall b. [Bind b] -> [b]
bindersOfBinds [Bind b]
binds = (Bind b -> [b] -> [b]) -> [b] -> [Bind b] -> [b]
forall a b. (a -> b -> b) -> b -> [a] -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr ([b] -> [b] -> [b]
forall a. [a] -> [a] -> [a]
(++) ([b] -> [b] -> [b]) -> (Bind b -> [b]) -> Bind b -> [b] -> [b]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bind b -> [b]
forall b. Bind b -> [b]
bindersOf) [] [Bind b]
binds
rhssOfBind :: Bind b -> [Expr b]
rhssOfBind :: forall b. Bind b -> [Expr b]
rhssOfBind (NonRec b
_ Expr b
rhs) = [Expr b
rhs]
rhssOfBind (Rec [(b, Expr b)]
pairs) = [Expr b
rhs | (b
_,Expr b
rhs) <- [(b, Expr b)]
pairs]
rhssOfAlts :: [Alt b] -> [Expr b]
rhssOfAlts :: forall b. [Alt b] -> [Expr b]
rhssOfAlts [Alt b]
alts = [Expr b
e | Alt AltCon
_ [b]
_ Expr b
e <- [Alt b]
alts]
flattenBinds :: [Bind b] -> [(b, Expr b)]
flattenBinds :: forall b. [Bind b] -> [(b, Expr b)]
flattenBinds (NonRec b
b Expr b
r : [Bind b]
binds) = (b
b,Expr b
r) (b, Expr b) -> [(b, Expr b)] -> [(b, Expr b)]
forall a. a -> [a] -> [a]
: [Bind b] -> [(b, Expr b)]
forall b. [Bind b] -> [(b, Expr b)]
flattenBinds [Bind b]
binds
flattenBinds (Rec [(b, Expr b)]
prs1 : [Bind b]
binds) = [(b, Expr b)]
prs1 [(b, Expr b)] -> [(b, Expr b)] -> [(b, Expr b)]
forall a. [a] -> [a] -> [a]
++ [Bind b] -> [(b, Expr b)]
forall b. [Bind b] -> [(b, Expr b)]
flattenBinds [Bind b]
binds
flattenBinds [] = []
collectBinders :: Expr b -> ([b], Expr b)
collectTyBinders :: CoreExpr -> ([TyVar], CoreExpr)
collectValBinders :: CoreExpr -> ([Id], CoreExpr)
collectTyAndValBinders :: CoreExpr -> ([TyVar], [Id], CoreExpr)
collectNBinders :: Int -> Expr b -> ([b], Expr b)
collectBinders :: forall b. Expr b -> ([b], Expr b)
collectBinders Expr b
expr
= [b] -> Expr b -> ([b], Expr b)
forall {a}. [a] -> Expr a -> ([a], Expr a)
go [] Expr b
expr
where
go :: [a] -> Expr a -> ([a], Expr a)
go [a]
bs (Lam a
b Expr a
e) = [a] -> Expr a -> ([a], Expr a)
go (a
ba -> [a] -> [a]
forall a. a -> [a] -> [a]
:[a]
bs) Expr a
e
go [a]
bs Expr a
e = ([a] -> [a]
forall a. [a] -> [a]
reverse [a]
bs, Expr a
e)
collectTyBinders :: CoreExpr -> ([Id], CoreExpr)
collectTyBinders CoreExpr
expr
= [Id] -> CoreExpr -> ([Id], CoreExpr)
go [] CoreExpr
expr
where
go :: [Id] -> CoreExpr -> ([Id], CoreExpr)
go [Id]
tvs (Lam Id
b CoreExpr
e) | Id -> Bool
isTyVar Id
b = [Id] -> CoreExpr -> ([Id], CoreExpr)
go (Id
bId -> [Id] -> [Id]
forall a. a -> [a] -> [a]
:[Id]
tvs) CoreExpr
e
go [Id]
tvs CoreExpr
e = ([Id] -> [Id]
forall a. [a] -> [a]
reverse [Id]
tvs, CoreExpr
e)
collectValBinders :: CoreExpr -> ([Id], CoreExpr)
collectValBinders CoreExpr
expr
= [Id] -> CoreExpr -> ([Id], CoreExpr)
go [] CoreExpr
expr
where
go :: [Id] -> CoreExpr -> ([Id], CoreExpr)
go [Id]
ids (Lam Id
b CoreExpr
e) | Id -> Bool
isId Id
b = [Id] -> CoreExpr -> ([Id], CoreExpr)
go (Id
bId -> [Id] -> [Id]
forall a. a -> [a] -> [a]
:[Id]
ids) CoreExpr
e
go [Id]
ids CoreExpr
body = ([Id] -> [Id]
forall a. [a] -> [a]
reverse [Id]
ids, CoreExpr
body)
collectTyAndValBinders :: CoreExpr -> ([Id], [Id], CoreExpr)
collectTyAndValBinders CoreExpr
expr
= ([Id]
tvs, [Id]
ids, CoreExpr
body)
where
([Id]
tvs, CoreExpr
body1) = CoreExpr -> ([Id], CoreExpr)
collectTyBinders CoreExpr
expr
([Id]
ids, CoreExpr
body) = CoreExpr -> ([Id], CoreExpr)
collectValBinders CoreExpr
body1
collectNBinders :: forall b. ConTag -> Expr b -> ([b], Expr b)
collectNBinders ConTag
orig_n Expr b
orig_expr
= ConTag -> [b] -> Expr b -> ([b], Expr b)
go ConTag
orig_n [] Expr b
orig_expr
where
go :: ConTag -> [b] -> Expr b -> ([b], Expr b)
go ConTag
0 [b]
bs Expr b
expr = ([b] -> [b]
forall a. [a] -> [a]
reverse [b]
bs, Expr b
expr)
go ConTag
n [b]
bs (Lam b
b Expr b
e) = ConTag -> [b] -> Expr b -> ([b], Expr b)
go (ConTag
nConTag -> ConTag -> ConTag
forall a. Num a => a -> a -> a
-ConTag
1) (b
bb -> [b] -> [b]
forall a. a -> [a] -> [a]
:[b]
bs) Expr b
e
go ConTag
_ [b]
_ Expr b
_ = String -> SDoc -> ([b], Expr b)
forall a. HasCallStack => String -> SDoc -> a
pprPanic String
"collectNBinders" (SDoc -> ([b], Expr b)) -> SDoc -> ([b], Expr b)
forall a b. (a -> b) -> a -> b
$ ConTag -> SDoc
int ConTag
orig_n
collectArgs :: Expr b -> (Expr b, [Arg b])
collectArgs :: forall b. Expr b -> (Expr b, [Expr b])
collectArgs Expr b
expr
= Expr b -> [Expr b] -> (Expr b, [Expr b])
forall {b}. Expr b -> [Expr b] -> (Expr b, [Expr b])
go Expr b
expr []
where
go :: Expr b -> [Expr b] -> (Expr b, [Expr b])
go (App Expr b
f Expr b
a) [Expr b]
as = Expr b -> [Expr b] -> (Expr b, [Expr b])
go Expr b
f (Expr b
aExpr b -> [Expr b] -> [Expr b]
forall a. a -> [a] -> [a]
:[Expr b]
as)
go Expr b
e [Expr b]
as = (Expr b
e, [Expr b]
as)
wrapLamBody :: (CoreExpr -> CoreExpr) -> CoreExpr -> CoreExpr
wrapLamBody :: (CoreExpr -> CoreExpr) -> CoreExpr -> CoreExpr
wrapLamBody CoreExpr -> CoreExpr
f CoreExpr
expr = CoreExpr -> CoreExpr
go CoreExpr
expr
where
go :: CoreExpr -> CoreExpr
go (Lam Id
v CoreExpr
body) = Id -> CoreExpr -> CoreExpr
forall b. b -> Expr b -> Expr b
Lam Id
v (CoreExpr -> CoreExpr) -> CoreExpr -> CoreExpr
forall a b. (a -> b) -> a -> b
$ CoreExpr -> CoreExpr
go CoreExpr
body
go CoreExpr
expr = CoreExpr -> CoreExpr
f CoreExpr
expr
stripNArgs :: Word -> Expr a -> Maybe (Expr a)
stripNArgs :: forall a. Word -> Expr a -> Maybe (Expr a)
stripNArgs !Word
n (Tick CoreTickish
_ Expr a
e) = Word -> Expr a -> Maybe (Expr a)
forall a. Word -> Expr a -> Maybe (Expr a)
stripNArgs Word
n Expr a
e
stripNArgs Word
n (Cast Expr a
f CoercionR
_) = Word -> Expr a -> Maybe (Expr a)
forall a. Word -> Expr a -> Maybe (Expr a)
stripNArgs Word
n Expr a
f
stripNArgs Word
0 Expr a
e = Expr a -> Maybe (Expr a)
forall a. a -> Maybe a
Just Expr a
e
stripNArgs Word
n (App Expr a
f Expr a
_) = Word -> Expr a -> Maybe (Expr a)
forall a. Word -> Expr a -> Maybe (Expr a)
stripNArgs (Word
n Word -> Word -> Word
forall a. Num a => a -> a -> a
- Word
1) Expr a
f
stripNArgs Word
_ Expr a
_ = Maybe (Expr a)
forall a. Maybe a
Nothing
collectArgsTicks :: (CoreTickish -> Bool) -> Expr b
-> (Expr b, [Arg b], [CoreTickish])
collectArgsTicks :: forall b.
(CoreTickish -> Bool)
-> Expr b -> (Expr b, [Expr b], [CoreTickish])
collectArgsTicks CoreTickish -> Bool
skipTick Expr b
expr
= Expr b
-> [Expr b] -> [CoreTickish] -> (Expr b, [Expr b], [CoreTickish])
go Expr b
expr [] []
where
go :: Expr b
-> [Expr b] -> [CoreTickish] -> (Expr b, [Expr b], [CoreTickish])
go (App Expr b
f Expr b
a) [Expr b]
as [CoreTickish]
ts = Expr b
-> [Expr b] -> [CoreTickish] -> (Expr b, [Expr b], [CoreTickish])
go Expr b
f (Expr b
aExpr b -> [Expr b] -> [Expr b]
forall a. a -> [a] -> [a]
:[Expr b]
as) [CoreTickish]
ts
go (Tick CoreTickish
t Expr b
e) [Expr b]
as [CoreTickish]
ts
| CoreTickish -> Bool
skipTick CoreTickish
t = Expr b
-> [Expr b] -> [CoreTickish] -> (Expr b, [Expr b], [CoreTickish])
go Expr b
e [Expr b]
as (CoreTickish
tCoreTickish -> [CoreTickish] -> [CoreTickish]
forall a. a -> [a] -> [a]
:[CoreTickish]
ts)
go Expr b
e [Expr b]
as [CoreTickish]
ts = (Expr b
e, [Expr b]
as, [CoreTickish] -> [CoreTickish]
forall a. [a] -> [a]
reverse [CoreTickish]
ts)
isRuntimeVar :: Var -> Bool
isRuntimeVar :: Id -> Bool
isRuntimeVar = Id -> Bool
isId
isRuntimeArg :: CoreExpr -> Bool
isRuntimeArg :: CoreExpr -> Bool
isRuntimeArg = CoreExpr -> Bool
forall b. Expr b -> Bool
isValArg
isValArg :: Expr b -> Bool
isValArg :: forall b. Expr b -> Bool
isValArg Expr b
e = Bool -> Bool
not (Expr b -> Bool
forall b. Expr b -> Bool
isTypeArg Expr b
e)
isTyCoArg :: Expr b -> Bool
isTyCoArg :: forall b. Expr b -> Bool
isTyCoArg (Type {}) = Bool
True
isTyCoArg (Coercion {}) = Bool
True
isTyCoArg Expr b
_ = Bool
False
isCoArg :: Expr b -> Bool
isCoArg :: forall b. Expr b -> Bool
isCoArg (Coercion {}) = Bool
True
isCoArg Expr b
_ = Bool
False
isTypeArg :: Expr b -> Bool
isTypeArg :: forall b. Expr b -> Bool
isTypeArg (Type {}) = Bool
True
isTypeArg Expr b
_ = Bool
False
valBndrCount :: [CoreBndr] -> Int
valBndrCount :: [Id] -> ConTag
valBndrCount = (Id -> Bool) -> [Id] -> ConTag
forall a. (a -> Bool) -> [a] -> ConTag
count Id -> Bool
isId
valArgCount :: [Arg b] -> Int
valArgCount :: forall b. [Arg b] -> ConTag
valArgCount = (Arg b -> Bool) -> [Arg b] -> ConTag
forall a. (a -> Bool) -> [a] -> ConTag
count Arg b -> Bool
forall b. Expr b -> Bool
isValArg
type AnnExpr bndr annot = (annot, AnnExpr' bndr annot)
data AnnExpr' bndr annot
= AnnVar Id
| AnnLit Literal
| AnnLam bndr (AnnExpr bndr annot)
| AnnApp (AnnExpr bndr annot) (AnnExpr bndr annot)
| AnnCase (AnnExpr bndr annot) bndr Type [AnnAlt bndr annot]
| AnnLet (AnnBind bndr annot) (AnnExpr bndr annot)
| AnnCast (AnnExpr bndr annot) (annot, Coercion)
| AnnTick CoreTickish (AnnExpr bndr annot)
| AnnType Type
| AnnCoercion Coercion
data AnnAlt bndr annot = AnnAlt AltCon [bndr] (AnnExpr bndr annot)
data AnnBind bndr annot
= AnnNonRec bndr (AnnExpr bndr annot)
| AnnRec [(bndr, AnnExpr bndr annot)]
collectAnnArgs :: AnnExpr b a -> (AnnExpr b a, [AnnExpr b a])
collectAnnArgs :: forall b a. AnnExpr b a -> (AnnExpr b a, [AnnExpr b a])
collectAnnArgs AnnExpr b a
expr
= AnnExpr b a -> [AnnExpr b a] -> (AnnExpr b a, [AnnExpr b a])
forall {bndr} {annot}.
AnnExpr bndr annot
-> [AnnExpr bndr annot]
-> (AnnExpr bndr annot, [AnnExpr bndr annot])
go AnnExpr b a
expr []
where
go :: AnnExpr bndr annot
-> [AnnExpr bndr annot]
-> (AnnExpr bndr annot, [AnnExpr bndr annot])
go (annot
_, AnnApp AnnExpr bndr annot
f AnnExpr bndr annot
a) [AnnExpr bndr annot]
as = AnnExpr bndr annot
-> [AnnExpr bndr annot]
-> (AnnExpr bndr annot, [AnnExpr bndr annot])
go AnnExpr bndr annot
f (AnnExpr bndr annot
aAnnExpr bndr annot -> [AnnExpr bndr annot] -> [AnnExpr bndr annot]
forall a. a -> [a] -> [a]
:[AnnExpr bndr annot]
as)
go AnnExpr bndr annot
e [AnnExpr bndr annot]
as = (AnnExpr bndr annot
e, [AnnExpr bndr annot]
as)
collectAnnArgsTicks :: (CoreTickish -> Bool) -> AnnExpr b a
-> (AnnExpr b a, [AnnExpr b a], [CoreTickish])
collectAnnArgsTicks :: forall b a.
(CoreTickish -> Bool)
-> AnnExpr b a -> (AnnExpr b a, [AnnExpr b a], [CoreTickish])
collectAnnArgsTicks CoreTickish -> Bool
tickishOk AnnExpr b a
expr
= AnnExpr b a
-> [AnnExpr b a]
-> [CoreTickish]
-> (AnnExpr b a, [AnnExpr b a], [CoreTickish])
go AnnExpr b a
expr [] []
where
go :: AnnExpr b a
-> [AnnExpr b a]
-> [CoreTickish]
-> (AnnExpr b a, [AnnExpr b a], [CoreTickish])
go (a
_, AnnApp AnnExpr b a
f AnnExpr b a
a) [AnnExpr b a]
as [CoreTickish]
ts = AnnExpr b a
-> [AnnExpr b a]
-> [CoreTickish]
-> (AnnExpr b a, [AnnExpr b a], [CoreTickish])
go AnnExpr b a
f (AnnExpr b a
aAnnExpr b a -> [AnnExpr b a] -> [AnnExpr b a]
forall a. a -> [a] -> [a]
:[AnnExpr b a]
as) [CoreTickish]
ts
go (a
_, AnnTick CoreTickish
t AnnExpr b a
e) [AnnExpr b a]
as [CoreTickish]
ts | CoreTickish -> Bool
tickishOk CoreTickish
t
= AnnExpr b a
-> [AnnExpr b a]
-> [CoreTickish]
-> (AnnExpr b a, [AnnExpr b a], [CoreTickish])
go AnnExpr b a
e [AnnExpr b a]
as (CoreTickish
tCoreTickish -> [CoreTickish] -> [CoreTickish]
forall a. a -> [a] -> [a]
:[CoreTickish]
ts)
go AnnExpr b a
e [AnnExpr b a]
as [CoreTickish]
ts = (AnnExpr b a
e, [AnnExpr b a]
as, [CoreTickish] -> [CoreTickish]
forall a. [a] -> [a]
reverse [CoreTickish]
ts)
deAnnotate :: AnnExpr bndr annot -> Expr bndr
deAnnotate :: forall bndr annot. AnnExpr bndr annot -> Expr bndr
deAnnotate (annot
_, AnnExpr' bndr annot
e) = AnnExpr' bndr annot -> Expr bndr
forall bndr annot. AnnExpr' bndr annot -> Expr bndr
deAnnotate' AnnExpr' bndr annot
e
deAnnotate' :: AnnExpr' bndr annot -> Expr bndr
deAnnotate' :: forall bndr annot. AnnExpr' bndr annot -> Expr bndr
deAnnotate' (AnnType Type
t) = Type -> Expr bndr
forall b. Type -> Expr b
Type Type
t
deAnnotate' (AnnCoercion CoercionR
co) = CoercionR -> Expr bndr
forall b. CoercionR -> Expr b
Coercion CoercionR
co
deAnnotate' (AnnVar Id
v) = Id -> Expr bndr
forall b. Id -> Expr b
Var Id
v
deAnnotate' (AnnLit Literal
lit) = Literal -> Expr bndr
forall b. Literal -> Expr b
Lit Literal
lit
deAnnotate' (AnnLam bndr
binder AnnExpr bndr annot
body) = bndr -> Expr bndr -> Expr bndr
forall b. b -> Expr b -> Expr b
Lam bndr
binder (AnnExpr bndr annot -> Expr bndr
forall bndr annot. AnnExpr bndr annot -> Expr bndr
deAnnotate AnnExpr bndr annot
body)
deAnnotate' (AnnApp AnnExpr bndr annot
fun AnnExpr bndr annot
arg) = Expr bndr -> Expr bndr -> Expr bndr
forall b. Expr b -> Expr b -> Expr b
App (AnnExpr bndr annot -> Expr bndr
forall bndr annot. AnnExpr bndr annot -> Expr bndr
deAnnotate AnnExpr bndr annot
fun) (AnnExpr bndr annot -> Expr bndr
forall bndr annot. AnnExpr bndr annot -> Expr bndr
deAnnotate AnnExpr bndr annot
arg)
deAnnotate' (AnnCast AnnExpr bndr annot
e (annot
_,CoercionR
co)) = Expr bndr -> CoercionR -> Expr bndr
forall b. Expr b -> CoercionR -> Expr b
Cast (AnnExpr bndr annot -> Expr bndr
forall bndr annot. AnnExpr bndr annot -> Expr bndr
deAnnotate AnnExpr bndr annot
e) CoercionR
co
deAnnotate' (AnnTick CoreTickish
tick AnnExpr bndr annot
body) = CoreTickish -> Expr bndr -> Expr bndr
forall b. CoreTickish -> Expr b -> Expr b
Tick CoreTickish
tick (AnnExpr bndr annot -> Expr bndr
forall bndr annot. AnnExpr bndr annot -> Expr bndr
deAnnotate AnnExpr bndr annot
body)
deAnnotate' (AnnLet AnnBind bndr annot
bind AnnExpr bndr annot
body)
= Bind bndr -> Expr bndr -> Expr bndr
forall b. Bind b -> Expr b -> Expr b
Let (AnnBind bndr annot -> Bind bndr
forall b annot. AnnBind b annot -> Bind b
deAnnBind AnnBind bndr annot
bind) (AnnExpr bndr annot -> Expr bndr
forall bndr annot. AnnExpr bndr annot -> Expr bndr
deAnnotate AnnExpr bndr annot
body)
deAnnotate' (AnnCase AnnExpr bndr annot
scrut bndr
v Type
t [AnnAlt bndr annot]
alts)
= Expr bndr -> bndr -> Type -> [Alt bndr] -> Expr bndr
forall b. Expr b -> b -> Type -> [Alt b] -> Expr b
Case (AnnExpr bndr annot -> Expr bndr
forall bndr annot. AnnExpr bndr annot -> Expr bndr
deAnnotate AnnExpr bndr annot
scrut) bndr
v Type
t ((AnnAlt bndr annot -> Alt bndr)
-> [AnnAlt bndr annot] -> [Alt bndr]
forall a b. (a -> b) -> [a] -> [b]
map AnnAlt bndr annot -> Alt bndr
forall bndr annot. AnnAlt bndr annot -> Alt bndr
deAnnAlt [AnnAlt bndr annot]
alts)
deAnnAlt :: AnnAlt bndr annot -> Alt bndr
deAnnAlt :: forall bndr annot. AnnAlt bndr annot -> Alt bndr
deAnnAlt (AnnAlt AltCon
con [bndr]
args AnnExpr bndr annot
rhs) = AltCon -> [bndr] -> Expr bndr -> Alt bndr
forall b. AltCon -> [b] -> Expr b -> Alt b
Alt AltCon
con [bndr]
args (AnnExpr bndr annot -> Expr bndr
forall bndr annot. AnnExpr bndr annot -> Expr bndr
deAnnotate AnnExpr bndr annot
rhs)
deAnnBind :: AnnBind b annot -> Bind b
deAnnBind :: forall b annot. AnnBind b annot -> Bind b
deAnnBind (AnnNonRec b
var AnnExpr b annot
rhs) = b -> Expr b -> Bind b
forall b. b -> Expr b -> Bind b
NonRec b
var (AnnExpr b annot -> Expr b
forall bndr annot. AnnExpr bndr annot -> Expr bndr
deAnnotate AnnExpr b annot
rhs)
deAnnBind (AnnRec [(b, AnnExpr b annot)]
pairs) = [(b, Expr b)] -> Bind b
forall b. [(b, Expr b)] -> Bind b
Rec [(b
v,AnnExpr b annot -> Expr b
forall bndr annot. AnnExpr bndr annot -> Expr bndr
deAnnotate AnnExpr b annot
rhs) | (b
v,AnnExpr b annot
rhs) <- [(b, AnnExpr b annot)]
pairs]
collectAnnBndrs :: AnnExpr bndr annot -> ([bndr], AnnExpr bndr annot)
collectAnnBndrs :: forall bndr annot.
AnnExpr bndr annot -> ([bndr], AnnExpr bndr annot)
collectAnnBndrs AnnExpr bndr annot
e
= [bndr] -> AnnExpr bndr annot -> ([bndr], AnnExpr bndr annot)
forall {a} {annot}.
[a] -> AnnExpr a annot -> ([a], AnnExpr a annot)
collect [] AnnExpr bndr annot
e
where
collect :: [a] -> AnnExpr a annot -> ([a], AnnExpr a annot)
collect [a]
bs (annot
_, AnnLam a
b AnnExpr a annot
body) = [a] -> AnnExpr a annot -> ([a], AnnExpr a annot)
collect (a
ba -> [a] -> [a]
forall a. a -> [a] -> [a]
:[a]
bs) AnnExpr a annot
body
collect [a]
bs AnnExpr a annot
body = ([a] -> [a]
forall a. [a] -> [a]
reverse [a]
bs, AnnExpr a annot
body)
collectNAnnBndrs :: Int -> AnnExpr bndr annot -> ([bndr], AnnExpr bndr annot)
collectNAnnBndrs :: forall bndr annot.
ConTag -> AnnExpr bndr annot -> ([bndr], AnnExpr bndr annot)
collectNAnnBndrs ConTag
orig_n AnnExpr bndr annot
e
= ConTag
-> [bndr] -> AnnExpr bndr annot -> ([bndr], AnnExpr bndr annot)
collect ConTag
orig_n [] AnnExpr bndr annot
e
where
collect :: ConTag
-> [bndr] -> AnnExpr bndr annot -> ([bndr], AnnExpr bndr annot)
collect ConTag
0 [bndr]
bs AnnExpr bndr annot
body = ([bndr] -> [bndr]
forall a. [a] -> [a]
reverse [bndr]
bs, AnnExpr bndr annot
body)
collect ConTag
n [bndr]
bs (annot
_, AnnLam bndr
b AnnExpr bndr annot
body) = ConTag
-> [bndr] -> AnnExpr bndr annot -> ([bndr], AnnExpr bndr annot)
collect (ConTag
nConTag -> ConTag -> ConTag
forall a. Num a => a -> a -> a
-ConTag
1) (bndr
bbndr -> [bndr] -> [bndr]
forall a. a -> [a] -> [a]
:[bndr]
bs) AnnExpr bndr annot
body
collect ConTag
_ [bndr]
_ AnnExpr bndr annot
_ = String -> SDoc -> ([bndr], AnnExpr bndr annot)
forall a. HasCallStack => String -> SDoc -> a
pprPanic String
"collectNBinders" (SDoc -> ([bndr], AnnExpr bndr annot))
-> SDoc -> ([bndr], AnnExpr bndr annot)
forall a b. (a -> b) -> a -> b
$ ConTag -> SDoc
int ConTag
orig_n