{-# LANGUAGE TypeFamilies, DataKinds, GADTs, FlexibleInstances #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE ConstraintKinds #-}
module GHC.Stg.Lift.Types(
Skeleton(..),
bothSk, altSk, rhsSk,
BinderInfo(..),
binderInfoBndr, binderInfoOccursAsArg
) where
import GHC.Prelude
import GHC.Types.Id
import GHC.Types.Demand
import GHC.Types.Var.Set
import GHC.Utils.Outputable
data Skeleton
= ClosureSk !Id !DIdSet !Skeleton
| RhsSk !Card !Skeleton
| AltSk !Skeleton !Skeleton
| BothSk !Skeleton !Skeleton
| NilSk
bothSk :: Skeleton -> Skeleton -> Skeleton
bothSk :: Skeleton -> Skeleton -> Skeleton
bothSk Skeleton
NilSk Skeleton
b = Skeleton
b
bothSk Skeleton
a Skeleton
NilSk = Skeleton
a
bothSk Skeleton
a Skeleton
b = Skeleton -> Skeleton -> Skeleton
BothSk Skeleton
a Skeleton
b
altSk :: Skeleton -> Skeleton -> Skeleton
altSk :: Skeleton -> Skeleton -> Skeleton
altSk Skeleton
NilSk Skeleton
b = Skeleton
b
altSk Skeleton
a Skeleton
NilSk = Skeleton
a
altSk Skeleton
a Skeleton
b = Skeleton -> Skeleton -> Skeleton
AltSk Skeleton
a Skeleton
b
rhsSk :: Card -> Skeleton -> Skeleton
rhsSk :: Card -> Skeleton -> Skeleton
rhsSk Card
_ Skeleton
NilSk = Skeleton
NilSk
rhsSk Card
body_dmd Skeleton
skel = Card -> Skeleton -> Skeleton
RhsSk Card
body_dmd Skeleton
skel
data BinderInfo
= BindsClosure !Id !Bool
| BoringBinder !Id
binderInfoBndr :: BinderInfo -> Id
binderInfoBndr :: BinderInfo -> Id
binderInfoBndr (BoringBinder Id
bndr) = Id
bndr
binderInfoBndr (BindsClosure Id
bndr Bool
_) = Id
bndr
binderInfoOccursAsArg :: BinderInfo -> Maybe Bool
binderInfoOccursAsArg :: BinderInfo -> Maybe Bool
binderInfoOccursAsArg BoringBinder{} = Maybe Bool
forall a. Maybe a
Nothing
binderInfoOccursAsArg (BindsClosure Id
_ Bool
b) = Bool -> Maybe Bool
forall a. a -> Maybe a
Just Bool
b
instance Outputable Skeleton where
ppr :: Skeleton -> SDoc
ppr Skeleton
NilSk = String -> SDoc
forall doc. IsLine doc => String -> doc
text String
""
ppr (AltSk Skeleton
l Skeleton
r) = [SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat
[ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"{ " SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> Skeleton -> SDoc
forall a. Outputable a => a -> SDoc
ppr Skeleton
l
, String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"ALT"
, String -> SDoc
forall doc. IsLine doc => String -> doc
text String
" " SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> Skeleton -> SDoc
forall a. Outputable a => a -> SDoc
ppr Skeleton
r
, String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"}"
]
ppr (BothSk Skeleton
l Skeleton
r) = Skeleton -> SDoc
forall a. Outputable a => a -> SDoc
ppr Skeleton
l SDoc -> SDoc -> SDoc
forall doc. IsDoc doc => doc -> doc -> doc
$$ Skeleton -> SDoc
forall a. Outputable a => a -> SDoc
ppr Skeleton
r
ppr (ClosureSk Id
f DIdSet
fvs Skeleton
body) = Id -> SDoc
forall a. Outputable a => a -> SDoc
ppr Id
f SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> DIdSet -> SDoc
forall a. Outputable a => a -> SDoc
ppr DIdSet
fvs SDoc -> SDoc -> SDoc
forall doc. IsDoc doc => doc -> doc -> doc
$$ Int -> SDoc -> SDoc
nest Int
2 (Skeleton -> SDoc
forall a. Outputable a => a -> SDoc
ppr Skeleton
body)
ppr (RhsSk Card
card Skeleton
body) = [SDoc] -> SDoc
forall doc. IsLine doc => [doc] -> doc
hcat
[ SDoc
lambda
, Card -> SDoc
forall a. Outputable a => a -> SDoc
ppr Card
card
, SDoc
forall doc. IsLine doc => doc
dot
, Skeleton -> SDoc
forall a. Outputable a => a -> SDoc
ppr Skeleton
body
]
instance Outputable BinderInfo where
ppr :: BinderInfo -> SDoc
ppr = Id -> SDoc
forall a. Outputable a => a -> SDoc
ppr (Id -> SDoc) -> (BinderInfo -> Id) -> BinderInfo -> SDoc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. BinderInfo -> Id
binderInfoBndr
instance OutputableBndr BinderInfo where
pprBndr :: BindingSite -> BinderInfo -> SDoc
pprBndr BindingSite
b = BindingSite -> Id -> SDoc
forall a. OutputableBndr a => BindingSite -> a -> SDoc
pprBndr BindingSite
b (Id -> SDoc) -> (BinderInfo -> Id) -> BinderInfo -> SDoc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. BinderInfo -> Id
binderInfoBndr
pprPrefixOcc :: BinderInfo -> SDoc
pprPrefixOcc = Id -> SDoc
forall a. OutputableBndr a => a -> SDoc
pprPrefixOcc (Id -> SDoc) -> (BinderInfo -> Id) -> BinderInfo -> SDoc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. BinderInfo -> Id
binderInfoBndr
pprInfixOcc :: BinderInfo -> SDoc
pprInfixOcc = Id -> SDoc
forall a. OutputableBndr a => a -> SDoc
pprInfixOcc (Id -> SDoc) -> (BinderInfo -> Id) -> BinderInfo -> SDoc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. BinderInfo -> Id
binderInfoBndr
bndrIsJoin_maybe :: BinderInfo -> Maybe Int
bndrIsJoin_maybe = Id -> Maybe Int
forall a. OutputableBndr a => a -> Maybe Int
bndrIsJoin_maybe (Id -> Maybe Int) -> (BinderInfo -> Id) -> BinderInfo -> Maybe Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. BinderInfo -> Id
binderInfoBndr