{-# LANGUAGE CPP #-}
{-# OPTIONS_GHC -Wno-incomplete-uni-patterns #-}
module GHC.Types.Id.Make (
mkDictFunId, mkDictFunTy, mkDictSelId, mkDictSelRhs,
mkPrimOpId, mkFCallId,
unwrapNewTypeBody, wrapFamInstBody,
DataConBoxer(..), vanillaDataConBoxer,
mkDataConRep, mkDataConWorkId,
wiredInIds, ghcPrimIds,
realWorldPrimId,
voidPrimId, voidArgId,
nullAddrId, seqId, lazyId, lazyIdKey,
coercionTokenId, magicDictId, coerceId,
proxyHashId, noinlineId, noinlineIdName,
coerceName,
module GHC.Core.Opt.ConstantFold
) where
#include "HsVersions.h"
import GHC.Prelude
import GHC.Builtin.Types.Prim
import GHC.Builtin.Types
import GHC.Core.Opt.ConstantFold
import GHC.Core.Type
import GHC.Core.Multiplicity
import GHC.Core.TyCo.Rep
import GHC.Core.FamInstEnv
import GHC.Core.Coercion
import GHC.Tc.Utils.TcType as TcType
import GHC.Core.Make
import GHC.Core.FVs ( mkRuleInfo )
import GHC.Core.Utils ( mkCast, mkDefaultCase )
import GHC.Core.Unfold
import GHC.Types.Literal
import GHC.Core.TyCon
import GHC.Core.Class
import GHC.Types.Name.Set
import GHC.Types.Name
import GHC.Builtin.PrimOps
import GHC.Types.ForeignCall
import GHC.Core.DataCon
import GHC.Types.Id
import GHC.Types.Id.Info
import GHC.Types.Demand
import GHC.Types.Cpr
import GHC.Core
import GHC.Types.Unique
import GHC.Types.Unique.Supply
import GHC.Builtin.Names
import GHC.Types.Basic hiding ( SuccessFlag(..) )
import GHC.Utils.Misc
import GHC.Driver.Session
import GHC.Utils.Outputable
import GHC.Data.FastString
import GHC.Data.List.SetOps
import GHC.Types.Var (VarBndr(Bndr))
import qualified GHC.LanguageExtensions as LangExt
import Data.Maybe ( maybeToList )
wiredInIds :: [Id]
wiredInIds :: [Var]
wiredInIds
= [Var]
magicIds
[Var] -> [Var] -> [Var]
forall a. [a] -> [a] -> [a]
++ [Var]
ghcPrimIds
[Var] -> [Var] -> [Var]
forall a. [a] -> [a] -> [a]
++ [Var]
errorIds
magicIds :: [Id]
magicIds :: [Var]
magicIds = [Var
lazyId, Var
oneShotId, Var
noinlineId]
ghcPrimIds :: [Id]
ghcPrimIds :: [Var]
ghcPrimIds
= [ Var
realWorldPrimId
, Var
voidPrimId
, Var
nullAddrId
, Var
seqId
, Var
magicDictId
, Var
coerceId
, Var
proxyHashId
]
mkDictSelId :: Name
-> Class -> Id
mkDictSelId :: Name -> Class -> Var
mkDictSelId Name
name Class
clas
= IdDetails -> Name -> Type -> IdInfo -> Var
mkGlobalId (Class -> IdDetails
ClassOpId Class
clas) Name
name Type
sel_ty IdInfo
info
where
tycon :: TyCon
tycon = Class -> TyCon
classTyCon Class
clas
sel_names :: [Name]
sel_names = (Var -> Name) -> [Var] -> [Name]
forall a b. (a -> b) -> [a] -> [b]
map Var -> Name
idName (Class -> [Var]
classAllSelIds Class
clas)
new_tycon :: Bool
new_tycon = TyCon -> Bool
isNewTyCon TyCon
tycon
[DataCon
data_con] = TyCon -> [DataCon]
tyConDataCons TyCon
tycon
tyvars :: [InvisTVBinder]
tyvars = DataCon -> [InvisTVBinder]
dataConUserTyVarBinders DataCon
data_con
n_ty_args :: Arity
n_ty_args = [InvisTVBinder] -> Arity
forall (t :: * -> *) a. Foldable t => t a -> Arity
length [InvisTVBinder]
tyvars
arg_tys :: [Scaled Type]
arg_tys = DataCon -> [Scaled Type]
dataConRepArgTys DataCon
data_con
val_index :: Arity
val_index = String -> Assoc Name Arity -> Name -> Arity
forall a b. Eq a => String -> Assoc a b -> a -> b
assoc String
"MkId.mkDictSelId" ([Name]
sel_names [Name] -> [Arity] -> Assoc Name Arity
forall a b. [a] -> [b] -> [(a, b)]
`zip` [Arity
0..]) Name
name
sel_ty :: Type
sel_ty = [InvisTVBinder] -> Type -> Type
mkInvisForAllTys [InvisTVBinder]
tyvars (Type -> Type) -> Type -> Type
forall a b. (a -> b) -> a -> b
$
Type -> Type -> Type
mkInvisFunTyMany (Class -> [Type] -> Type
mkClassPred Class
clas ([Var] -> [Type]
mkTyVarTys ([InvisTVBinder] -> [Var]
forall tv argf. [VarBndr tv argf] -> [tv]
binderVars [InvisTVBinder]
tyvars))) (Type -> Type) -> Type -> Type
forall a b. (a -> b) -> a -> b
$
Scaled Type -> Type
forall a. Scaled a -> a
scaledThing ([Scaled Type] -> Arity -> Scaled Type
forall a. Outputable a => [a] -> Arity -> a
getNth [Scaled Type]
arg_tys Arity
val_index)
base_info :: IdInfo
base_info = IdInfo
noCafIdInfo
IdInfo -> Arity -> IdInfo
`setArityInfo` Arity
1
IdInfo -> StrictSig -> IdInfo
`setStrictnessInfo` StrictSig
strict_sig
IdInfo -> CprSig -> IdInfo
`setCprInfo` CprSig
topCprSig
IdInfo -> Type -> IdInfo
`setLevityInfoWithType` Type
sel_ty
info :: IdInfo
info | Bool
new_tycon
= IdInfo
base_info IdInfo -> InlinePragma -> IdInfo
`setInlinePragInfo` InlinePragma
alwaysInlinePragma
IdInfo -> Unfolding -> IdInfo
`setUnfoldingInfo` Arity -> CoreExpr -> Unfolding
mkInlineUnfoldingWithArity Arity
1
(Class -> Arity -> CoreExpr
mkDictSelRhs Class
clas Arity
val_index)
| Bool
otherwise
= IdInfo
base_info IdInfo -> RuleInfo -> IdInfo
`setRuleInfo` [CoreRule] -> RuleInfo
mkRuleInfo [CoreRule
rule]
rule :: CoreRule
rule = BuiltinRule :: RuleName -> Name -> Arity -> RuleFun -> CoreRule
BuiltinRule { ru_name :: RuleName
ru_name = String -> RuleName
fsLit String
"Class op " RuleName -> RuleName -> RuleName
`appendFS`
OccName -> RuleName
occNameFS (Name -> OccName
forall a. NamedThing a => a -> OccName
getOccName Name
name)
, ru_fn :: Name
ru_fn = Name
name
, ru_nargs :: Arity
ru_nargs = Arity
n_ty_args Arity -> Arity -> Arity
forall a. Num a => a -> a -> a
+ Arity
1
, ru_try :: RuleFun
ru_try = Arity -> Arity -> RuleFun
dictSelRule Arity
val_index Arity
n_ty_args }
strict_sig :: StrictSig
strict_sig = [Demand] -> Divergence -> StrictSig
mkClosedStrictSig [Demand
arg_dmd] Divergence
topDiv
arg_dmd :: Demand
arg_dmd | Bool
new_tycon = Demand
evalDmd
| Bool
otherwise = CleanDemand -> Demand
mkManyUsedDmd (CleanDemand -> Demand) -> CleanDemand -> Demand
forall a b. (a -> b) -> a -> b
$
[Demand] -> CleanDemand
mkProdDmd [ if Name
name Name -> Name -> Bool
forall a. Eq a => a -> a -> Bool
== Name
sel_name then Demand
evalDmd else Demand
absDmd
| Name
sel_name <- [Name]
sel_names ]
mkDictSelRhs :: Class
-> Int
-> CoreExpr
mkDictSelRhs :: Class -> Arity -> CoreExpr
mkDictSelRhs Class
clas Arity
val_index
= [Var] -> CoreExpr -> CoreExpr
forall b. [b] -> Expr b -> Expr b
mkLams [Var]
tyvars (Var -> CoreExpr -> CoreExpr
forall b. b -> Expr b -> Expr b
Lam Var
dict_id CoreExpr
rhs_body)
where
tycon :: TyCon
tycon = Class -> TyCon
classTyCon Class
clas
new_tycon :: Bool
new_tycon = TyCon -> Bool
isNewTyCon TyCon
tycon
[DataCon
data_con] = TyCon -> [DataCon]
tyConDataCons TyCon
tycon
tyvars :: [Var]
tyvars = DataCon -> [Var]
dataConUnivTyVars DataCon
data_con
arg_tys :: [Scaled Type]
arg_tys = DataCon -> [Scaled Type]
dataConRepArgTys DataCon
data_con
the_arg_id :: Var
the_arg_id = [Var] -> Arity -> Var
forall a. Outputable a => [a] -> Arity -> a
getNth [Var]
arg_ids Arity
val_index
pred :: Type
pred = Class -> [Type] -> Type
mkClassPred Class
clas ([Var] -> [Type]
mkTyVarTys [Var]
tyvars)
dict_id :: Var
dict_id = Arity -> Type -> Var
mkTemplateLocal Arity
1 Type
pred
arg_ids :: [Var]
arg_ids = Arity -> [Type] -> [Var]
mkTemplateLocalsNum Arity
2 ((Scaled Type -> Type) -> [Scaled Type] -> [Type]
forall a b. (a -> b) -> [a] -> [b]
map Scaled Type -> Type
forall a. Scaled a -> a
scaledThing [Scaled Type]
arg_tys)
rhs_body :: CoreExpr
rhs_body | Bool
new_tycon = TyCon -> [Type] -> CoreExpr -> CoreExpr
unwrapNewTypeBody TyCon
tycon ([Var] -> [Type]
mkTyVarTys [Var]
tyvars)
(Var -> CoreExpr
forall b. Var -> Expr b
Var Var
dict_id)
| Bool
otherwise = CoreExpr -> Var -> AltCon -> [Var] -> CoreExpr -> CoreExpr
mkSingleAltCase (Var -> CoreExpr
forall b. Var -> Expr b
Var Var
dict_id) Var
dict_id (DataCon -> AltCon
DataAlt DataCon
data_con)
[Var]
arg_ids (Var -> CoreExpr
forall b. Var -> Expr b
varToCoreExpr Var
the_arg_id)
dictSelRule :: Int -> Arity -> RuleFun
dictSelRule :: Arity -> Arity -> RuleFun
dictSelRule Arity
val_index Arity
n_ty_args RuleOpts
_ InScopeEnv
id_unf Var
_ [CoreExpr]
args
| (CoreExpr
dict_arg : [CoreExpr]
_) <- Arity -> [CoreExpr] -> [CoreExpr]
forall a. Arity -> [a] -> [a]
drop Arity
n_ty_args [CoreExpr]
args
, Just (InScopeSet
_, [FloatBind]
floats, DataCon
_, [Type]
_, [CoreExpr]
con_args) <- InScopeEnv
-> CoreExpr
-> Maybe (InScopeSet, [FloatBind], DataCon, [Type], [CoreExpr])
HasDebugCallStack =>
InScopeEnv
-> CoreExpr
-> Maybe (InScopeSet, [FloatBind], DataCon, [Type], [CoreExpr])
exprIsConApp_maybe InScopeEnv
id_unf CoreExpr
dict_arg
= CoreExpr -> Maybe CoreExpr
forall a. a -> Maybe a
Just ([FloatBind] -> CoreExpr -> CoreExpr
wrapFloats [FloatBind]
floats (CoreExpr -> CoreExpr) -> CoreExpr -> CoreExpr
forall a b. (a -> b) -> a -> b
$ [CoreExpr] -> Arity -> CoreExpr
forall a. Outputable a => [a] -> Arity -> a
getNth [CoreExpr]
con_args Arity
val_index)
| Bool
otherwise
= Maybe CoreExpr
forall a. Maybe a
Nothing
mkDataConWorkId :: Name -> DataCon -> Id
mkDataConWorkId :: Name -> DataCon -> Var
mkDataConWorkId Name
wkr_name DataCon
data_con
| TyCon -> Bool
isNewTyCon TyCon
tycon
= IdDetails -> Name -> Type -> IdInfo -> Var
mkGlobalId (DataCon -> IdDetails
DataConWrapId DataCon
data_con) Name
wkr_name Type
wkr_ty IdInfo
nt_work_info
| Bool
otherwise
= IdDetails -> Name -> Type -> IdInfo -> Var
mkGlobalId (DataCon -> IdDetails
DataConWorkId DataCon
data_con) Name
wkr_name Type
wkr_ty IdInfo
alg_wkr_info
where
tycon :: TyCon
tycon = DataCon -> TyCon
dataConTyCon DataCon
data_con
wkr_ty :: Type
wkr_ty = DataCon -> Type
dataConRepType DataCon
data_con
alg_wkr_info :: IdInfo
alg_wkr_info = IdInfo
noCafIdInfo
IdInfo -> Arity -> IdInfo
`setArityInfo` Arity
wkr_arity
IdInfo -> CprSig -> IdInfo
`setCprInfo` Arity -> CprResult -> CprSig
mkCprSig Arity
wkr_arity (DataCon -> CprResult
dataConCPR DataCon
data_con)
IdInfo -> InlinePragma -> IdInfo
`setInlinePragInfo` InlinePragma
wkr_inline_prag
IdInfo -> Unfolding -> IdInfo
`setUnfoldingInfo` Unfolding
evaldUnfolding
IdInfo -> Type -> IdInfo
`setLevityInfoWithType` Type
wkr_ty
wkr_inline_prag :: InlinePragma
wkr_inline_prag = InlinePragma
defaultInlinePragma { inl_rule :: RuleMatchInfo
inl_rule = RuleMatchInfo
ConLike }
wkr_arity :: Arity
wkr_arity = DataCon -> Arity
dataConRepArity DataCon
data_con
univ_tvs :: [Var]
univ_tvs = DataCon -> [Var]
dataConUnivTyVars DataCon
data_con
arg_tys :: [Scaled Type]
arg_tys = DataCon -> [Scaled Type]
dataConRepArgTys DataCon
data_con
nt_work_info :: IdInfo
nt_work_info = IdInfo
noCafIdInfo
IdInfo -> Arity -> IdInfo
`setArityInfo` Arity
1
IdInfo -> InlinePragma -> IdInfo
`setInlinePragInfo` InlinePragma
dataConWrapperInlinePragma
IdInfo -> Unfolding -> IdInfo
`setUnfoldingInfo` Unfolding
newtype_unf
IdInfo -> Type -> IdInfo
`setLevityInfoWithType` Type
wkr_ty
id_arg1 :: Var
id_arg1 = Arity -> Scaled Type -> Var
mkScaledTemplateLocal Arity
1 ([Scaled Type] -> Scaled Type
forall a. [a] -> a
head [Scaled Type]
arg_tys)
res_ty_args :: [Type]
res_ty_args = [Var] -> [Type]
mkTyCoVarTys [Var]
univ_tvs
newtype_unf :: Unfolding
newtype_unf = ASSERT2( isVanillaDataCon data_con &&
isSingleton arg_tys
, ppr data_con )
CoreExpr -> Unfolding
mkCompulsoryUnfolding (CoreExpr -> Unfolding) -> CoreExpr -> Unfolding
forall a b. (a -> b) -> a -> b
$
[Var] -> CoreExpr -> CoreExpr
forall b. [b] -> Expr b -> Expr b
mkLams [Var]
univ_tvs (CoreExpr -> CoreExpr) -> CoreExpr -> CoreExpr
forall a b. (a -> b) -> a -> b
$ Var -> CoreExpr -> CoreExpr
forall b. b -> Expr b -> Expr b
Lam Var
id_arg1 (CoreExpr -> CoreExpr) -> CoreExpr -> CoreExpr
forall a b. (a -> b) -> a -> b
$
TyCon -> [Type] -> CoreExpr -> CoreExpr
wrapNewTypeBody TyCon
tycon [Type]
res_ty_args (Var -> CoreExpr
forall b. Var -> Expr b
Var Var
id_arg1)
dataConCPR :: DataCon -> CprResult
dataConCPR :: DataCon -> CprResult
dataConCPR DataCon
con
| TyCon -> Bool
isDataTyCon TyCon
tycon
, [Var] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null (DataCon -> [Var]
dataConExTyCoVars DataCon
con)
, Arity
wkr_arity Arity -> Arity -> Bool
forall a. Ord a => a -> a -> Bool
> Arity
0
, Arity
wkr_arity Arity -> Arity -> Bool
forall a. Ord a => a -> a -> Bool
<= Arity
mAX_CPR_SIZE
= Arity -> CprResult
conCpr (DataCon -> Arity
dataConTag DataCon
con)
| Bool
otherwise
= CprResult
topCpr
where
tycon :: TyCon
tycon = DataCon -> TyCon
dataConTyCon DataCon
con
wkr_arity :: Arity
wkr_arity = DataCon -> Arity
dataConRepArity DataCon
con
mAX_CPR_SIZE :: Arity
mAX_CPR_SIZE :: Arity
mAX_CPR_SIZE = Arity
10
type Unboxer = Var -> UniqSM ([Var], CoreExpr -> CoreExpr)
data Boxer = UnitBox | Boxer (TCvSubst -> UniqSM ([Var], CoreExpr))
newtype DataConBoxer = DCB ([Type] -> [Var] -> UniqSM ([Var], [CoreBind]))
vanillaDataConBoxer :: DataConBoxer
vanillaDataConBoxer :: DataConBoxer
vanillaDataConBoxer = ([Type] -> [Var] -> UniqSM ([Var], [CoreBind])) -> DataConBoxer
DCB (\[Type]
_tys [Var]
args -> ([Var], [CoreBind]) -> UniqSM ([Var], [CoreBind])
forall (m :: * -> *) a. Monad m => a -> m a
return ([Var]
args, []))
mkDataConRep :: DynFlags
-> FamInstEnvs
-> Name
-> Maybe [HsImplBang]
-> DataCon
-> UniqSM DataConRep
mkDataConRep :: DynFlags
-> FamInstEnvs
-> Name
-> Maybe [HsImplBang]
-> DataCon
-> UniqSM DataConRep
mkDataConRep DynFlags
dflags FamInstEnvs
fam_envs Name
wrap_name Maybe [HsImplBang]
mb_bangs DataCon
data_con
| Bool -> Bool
not Bool
wrapper_reqd
= DataConRep -> UniqSM DataConRep
forall (m :: * -> *) a. Monad m => a -> m a
return DataConRep
NoDataConRep
| Bool
otherwise
= do { [Var]
wrap_args <- (Scaled Type -> UniqSM Var) -> [Scaled Type] -> UniqSM [Var]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM Scaled Type -> UniqSM Var
newLocal [Scaled Type]
wrap_arg_tys
; CoreExpr
wrap_body <- [(Var, Unboxer)] -> CoreExpr -> UniqSM CoreExpr
mk_rep_app ([Var]
wrap_args [Var] -> [Unboxer] -> [(Var, Unboxer)]
forall a b. [a] -> [b] -> [(a, b)]
`zip` [EqSpec] -> [Unboxer] -> [Unboxer]
forall b a. [b] -> [a] -> [a]
dropList [EqSpec]
eq_spec [Unboxer]
unboxers)
CoreExpr
forall {b}. Expr b
initial_wrap_app
; let wrap_id :: Var
wrap_id = IdDetails -> Name -> Type -> IdInfo -> Var
mkGlobalId (DataCon -> IdDetails
DataConWrapId DataCon
data_con) Name
wrap_name Type
wrap_ty IdInfo
wrap_info
wrap_info :: IdInfo
wrap_info = IdInfo
noCafIdInfo
IdInfo -> Arity -> IdInfo
`setArityInfo` Arity
wrap_arity
IdInfo -> InlinePragma -> IdInfo
`setInlinePragInfo` InlinePragma
wrap_prag
IdInfo -> Unfolding -> IdInfo
`setUnfoldingInfo` Unfolding
wrap_unf
IdInfo -> StrictSig -> IdInfo
`setStrictnessInfo` StrictSig
wrap_sig
IdInfo -> CprSig -> IdInfo
`setCprInfo` Arity -> CprResult -> CprSig
mkCprSig Arity
wrap_arity (DataCon -> CprResult
dataConCPR DataCon
data_con)
IdInfo -> Type -> IdInfo
`setLevityInfoWithType` Type
wrap_ty
wrap_sig :: StrictSig
wrap_sig = [Demand] -> Divergence -> StrictSig
mkClosedStrictSig [Demand]
wrap_arg_dmds Divergence
topDiv
wrap_arg_dmds :: [Demand]
wrap_arg_dmds =
Arity -> Demand -> [Demand]
forall a. Arity -> a -> [a]
replicate ([Type] -> Arity
forall (t :: * -> *) a. Foldable t => t a -> Arity
length [Type]
theta) Demand
topDmd [Demand] -> [Demand] -> [Demand]
forall a. [a] -> [a] -> [a]
++ (HsImplBang -> Demand) -> [HsImplBang] -> [Demand]
forall a b. (a -> b) -> [a] -> [b]
map HsImplBang -> Demand
mk_dmd [HsImplBang]
arg_ibangs
mk_dmd :: HsImplBang -> Demand
mk_dmd HsImplBang
str | HsImplBang -> Bool
isBanged HsImplBang
str = Demand
evalDmd
| Bool
otherwise = Demand
topDmd
wrap_prag :: InlinePragma
wrap_prag = InlinePragma
dataConWrapperInlinePragma
InlinePragma -> Activation -> InlinePragma
`setInlinePragmaActivation` Activation
activateDuringFinal
wrap_unf :: Unfolding
wrap_unf | TyCon -> Bool
isNewTyCon TyCon
tycon = CoreExpr -> Unfolding
mkCompulsoryUnfolding CoreExpr
wrap_rhs
| Bool
otherwise = CoreExpr -> Unfolding
mkInlineUnfolding CoreExpr
wrap_rhs
wrap_rhs :: CoreExpr
wrap_rhs = [Var] -> CoreExpr -> CoreExpr
forall b. [b] -> Expr b -> Expr b
mkLams [Var]
wrap_tvs (CoreExpr -> CoreExpr) -> CoreExpr -> CoreExpr
forall a b. (a -> b) -> a -> b
$
[Var] -> CoreExpr -> CoreExpr
forall b. [b] -> Expr b -> Expr b
mkLams [Var]
wrap_args (CoreExpr -> CoreExpr) -> CoreExpr -> CoreExpr
forall a b. (a -> b) -> a -> b
$
TyCon -> [Type] -> CoreExpr -> CoreExpr
wrapFamInstBody TyCon
tycon [Type]
res_ty_args (CoreExpr -> CoreExpr) -> CoreExpr -> CoreExpr
forall a b. (a -> b) -> a -> b
$
CoreExpr
wrap_body
; DataConRep -> UniqSM DataConRep
forall (m :: * -> *) a. Monad m => a -> m a
return (DCR :: Var
-> DataConBoxer
-> [Scaled Type]
-> [StrictnessMark]
-> [HsImplBang]
-> DataConRep
DCR { dcr_wrap_id :: Var
dcr_wrap_id = Var
wrap_id
, dcr_boxer :: DataConBoxer
dcr_boxer = [Boxer] -> DataConBoxer
mk_boxer [Boxer]
boxers
, dcr_arg_tys :: [Scaled Type]
dcr_arg_tys = [Scaled Type]
rep_tys
, dcr_stricts :: [StrictnessMark]
dcr_stricts = [StrictnessMark]
rep_strs
, dcr_bangs :: [HsImplBang]
dcr_bangs = [HsImplBang]
arg_ibangs }) }
where
([Var]
univ_tvs, [Var]
ex_tvs, [EqSpec]
eq_spec, [Type]
theta, [Scaled Type]
orig_arg_tys, Type
_orig_res_ty)
= DataCon -> ([Var], [Var], [EqSpec], [Type], [Scaled Type], Type)
dataConFullSig DataCon
data_con
wrap_tvs :: [Var]
wrap_tvs = DataCon -> [Var]
dataConUserTyVars DataCon
data_con
res_ty_args :: [Type]
res_ty_args = TCvSubst -> [Var] -> [Type]
substTyVars ([(Var, Type)] -> TCvSubst
mkTvSubstPrs ((EqSpec -> (Var, Type)) -> [EqSpec] -> [(Var, Type)]
forall a b. (a -> b) -> [a] -> [b]
map EqSpec -> (Var, Type)
eqSpecPair [EqSpec]
eq_spec)) [Var]
univ_tvs
tycon :: TyCon
tycon = DataCon -> TyCon
dataConTyCon DataCon
data_con
wrap_ty :: Type
wrap_ty = DataCon -> Type
dataConWrapperType DataCon
data_con
ev_tys :: [Type]
ev_tys = [EqSpec] -> [Type]
eqSpecPreds [EqSpec]
eq_spec [Type] -> [Type] -> [Type]
forall a. [a] -> [a] -> [a]
++ [Type]
theta
all_arg_tys :: [Scaled Type]
all_arg_tys = (Type -> Scaled Type) -> [Type] -> [Scaled Type]
forall a b. (a -> b) -> [a] -> [b]
map Type -> Scaled Type
forall a. a -> Scaled a
unrestricted [Type]
ev_tys [Scaled Type] -> [Scaled Type] -> [Scaled Type]
forall a. [a] -> [a] -> [a]
++ [Scaled Type]
orig_arg_tys
ev_ibangs :: [HsImplBang]
ev_ibangs = (Type -> HsImplBang) -> [Type] -> [HsImplBang]
forall a b. (a -> b) -> [a] -> [b]
map (HsImplBang -> Type -> HsImplBang
forall a b. a -> b -> a
const HsImplBang
HsLazy) [Type]
ev_tys
orig_bangs :: [HsSrcBang]
orig_bangs = DataCon -> [HsSrcBang]
dataConSrcBangs DataCon
data_con
wrap_arg_tys :: [Scaled Type]
wrap_arg_tys = ((Type -> Scaled Type) -> [Type] -> [Scaled Type]
forall a b. (a -> b) -> [a] -> [b]
map Type -> Scaled Type
forall a. a -> Scaled a
unrestricted [Type]
theta) [Scaled Type] -> [Scaled Type] -> [Scaled Type]
forall a. [a] -> [a] -> [a]
++ [Scaled Type]
orig_arg_tys
wrap_arity :: Arity
wrap_arity = (Var -> Bool) -> [Var] -> Arity
forall a. (a -> Bool) -> [a] -> Arity
count Var -> Bool
isCoVar [Var]
ex_tvs Arity -> Arity -> Arity
forall a. Num a => a -> a -> a
+ [Scaled Type] -> Arity
forall (t :: * -> *) a. Foldable t => t a -> Arity
length [Scaled Type]
wrap_arg_tys
new_tycon :: Bool
new_tycon = TyCon -> Bool
isNewTyCon TyCon
tycon
arg_ibangs :: [HsImplBang]
arg_ibangs
| Bool
new_tycon
= (Scaled Type -> HsImplBang) -> [Scaled Type] -> [HsImplBang]
forall a b. (a -> b) -> [a] -> [b]
map (HsImplBang -> Scaled Type -> HsImplBang
forall a b. a -> b -> a
const HsImplBang
HsLazy) [Scaled Type]
orig_arg_tys
| Bool
otherwise
= case Maybe [HsImplBang]
mb_bangs of
Maybe [HsImplBang]
Nothing -> (Scaled Type -> HsSrcBang -> HsImplBang)
-> [Scaled Type] -> [HsSrcBang] -> [HsImplBang]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith (DynFlags -> FamInstEnvs -> Scaled Type -> HsSrcBang -> HsImplBang
dataConSrcToImplBang DynFlags
dflags FamInstEnvs
fam_envs)
[Scaled Type]
orig_arg_tys [HsSrcBang]
orig_bangs
Just [HsImplBang]
bangs -> [HsImplBang]
bangs
([[(Scaled Type, StrictnessMark)]]
rep_tys_w_strs, [(Unboxer, Boxer)]
wrappers)
= [([(Scaled Type, StrictnessMark)], (Unboxer, Boxer))]
-> ([[(Scaled Type, StrictnessMark)]], [(Unboxer, Boxer)])
forall a b. [(a, b)] -> ([a], [b])
unzip ((Scaled Type
-> HsImplBang
-> ([(Scaled Type, StrictnessMark)], (Unboxer, Boxer)))
-> [Scaled Type]
-> [HsImplBang]
-> [([(Scaled Type, StrictnessMark)], (Unboxer, Boxer))]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith Scaled Type
-> HsImplBang
-> ([(Scaled Type, StrictnessMark)], (Unboxer, Boxer))
dataConArgRep [Scaled Type]
all_arg_tys ([HsImplBang]
ev_ibangs [HsImplBang] -> [HsImplBang] -> [HsImplBang]
forall a. [a] -> [a] -> [a]
++ [HsImplBang]
arg_ibangs))
([Unboxer]
unboxers, [Boxer]
boxers) = [(Unboxer, Boxer)] -> ([Unboxer], [Boxer])
forall a b. [(a, b)] -> ([a], [b])
unzip [(Unboxer, Boxer)]
wrappers
([Scaled Type]
rep_tys, [StrictnessMark]
rep_strs) = [(Scaled Type, StrictnessMark)]
-> ([Scaled Type], [StrictnessMark])
forall a b. [(a, b)] -> ([a], [b])
unzip ([[(Scaled Type, StrictnessMark)]]
-> [(Scaled Type, StrictnessMark)]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [[(Scaled Type, StrictnessMark)]]
rep_tys_w_strs)
wrapper_reqd :: Bool
wrapper_reqd =
(Bool -> Bool
not Bool
new_tycon
Bool -> Bool -> Bool
&& ((HsImplBang -> Bool) -> [HsImplBang] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any HsImplBang -> Bool
isBanged ([HsImplBang]
ev_ibangs [HsImplBang] -> [HsImplBang] -> [HsImplBang]
forall a. [a] -> [a] -> [a]
++ [HsImplBang]
arg_ibangs)
Bool -> Bool -> Bool
|| (Bool -> Bool
not (Bool -> Bool) -> Bool -> Bool
forall a b. (a -> b) -> a -> b
$ [EqSpec] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [EqSpec]
eq_spec)))
Bool -> Bool -> Bool
|| TyCon -> Bool
isFamInstTyCon TyCon
tycon
Bool -> Bool -> Bool
|| DataCon -> Bool
dataConUserTyVarsArePermuted DataCon
data_con
initial_wrap_app :: Expr b
initial_wrap_app = Var -> Expr b
forall b. Var -> Expr b
Var (DataCon -> Var
dataConWorkId DataCon
data_con)
Expr b -> [Type] -> Expr b
forall b. Expr b -> [Type] -> Expr b
`mkTyApps` [Type]
res_ty_args
Expr b -> [Var] -> Expr b
forall b. Expr b -> [Var] -> Expr b
`mkVarApps` [Var]
ex_tvs
Expr b -> [Coercion] -> Expr b
forall b. Expr b -> [Coercion] -> Expr b
`mkCoApps` (EqSpec -> Coercion) -> [EqSpec] -> [Coercion]
forall a b. (a -> b) -> [a] -> [b]
map (Role -> Type -> Coercion
mkReflCo Role
Nominal (Type -> Coercion) -> (EqSpec -> Type) -> EqSpec -> Coercion
forall b c a. (b -> c) -> (a -> b) -> a -> c
. EqSpec -> Type
eqSpecType) [EqSpec]
eq_spec
mk_boxer :: [Boxer] -> DataConBoxer
mk_boxer :: [Boxer] -> DataConBoxer
mk_boxer [Boxer]
boxers = ([Type] -> [Var] -> UniqSM ([Var], [CoreBind])) -> DataConBoxer
DCB (\ [Type]
ty_args [Var]
src_vars ->
do { let ([Var]
ex_vars, [Var]
term_vars) = [Var] -> [Var] -> ([Var], [Var])
forall b a. [b] -> [a] -> ([a], [a])
splitAtList [Var]
ex_tvs [Var]
src_vars
subst1 :: TCvSubst
subst1 = [Var] -> [Type] -> TCvSubst
HasDebugCallStack => [Var] -> [Type] -> TCvSubst
zipTvSubst [Var]
univ_tvs [Type]
ty_args
subst2 :: TCvSubst
subst2 = TCvSubst -> [Var] -> [Type] -> TCvSubst
extendTCvSubstList TCvSubst
subst1 [Var]
ex_tvs
([Var] -> [Type]
mkTyCoVarTys [Var]
ex_vars)
; ([Var]
rep_ids, [CoreBind]
binds) <- TCvSubst -> [Boxer] -> [Var] -> UniqSM ([Var], [CoreBind])
go TCvSubst
subst2 [Boxer]
boxers [Var]
term_vars
; ([Var], [CoreBind]) -> UniqSM ([Var], [CoreBind])
forall (m :: * -> *) a. Monad m => a -> m a
return ([Var]
ex_vars [Var] -> [Var] -> [Var]
forall a. [a] -> [a] -> [a]
++ [Var]
rep_ids, [CoreBind]
binds) } )
go :: TCvSubst -> [Boxer] -> [Var] -> UniqSM ([Var], [CoreBind])
go TCvSubst
_ [] [Var]
src_vars = ASSERT2( null src_vars, ppr data_con ) return ([], [])
go TCvSubst
subst (Boxer
UnitBox : [Boxer]
boxers) (Var
src_var : [Var]
src_vars)
= do { ([Var]
rep_ids2, [CoreBind]
binds) <- TCvSubst -> [Boxer] -> [Var] -> UniqSM ([Var], [CoreBind])
go TCvSubst
subst [Boxer]
boxers [Var]
src_vars
; ([Var], [CoreBind]) -> UniqSM ([Var], [CoreBind])
forall (m :: * -> *) a. Monad m => a -> m a
return (Var
src_var Var -> [Var] -> [Var]
forall a. a -> [a] -> [a]
: [Var]
rep_ids2, [CoreBind]
binds) }
go TCvSubst
subst (Boxer TCvSubst -> UniqSM ([Var], CoreExpr)
boxer : [Boxer]
boxers) (Var
src_var : [Var]
src_vars)
= do { ([Var]
rep_ids1, CoreExpr
arg) <- TCvSubst -> UniqSM ([Var], CoreExpr)
boxer TCvSubst
subst
; ([Var]
rep_ids2, [CoreBind]
binds) <- TCvSubst -> [Boxer] -> [Var] -> UniqSM ([Var], [CoreBind])
go TCvSubst
subst [Boxer]
boxers [Var]
src_vars
; ([Var], [CoreBind]) -> UniqSM ([Var], [CoreBind])
forall (m :: * -> *) a. Monad m => a -> m a
return ([Var]
rep_ids1 [Var] -> [Var] -> [Var]
forall a. [a] -> [a] -> [a]
++ [Var]
rep_ids2, Var -> CoreExpr -> CoreBind
forall b. b -> Expr b -> Bind b
NonRec Var
src_var CoreExpr
arg CoreBind -> [CoreBind] -> [CoreBind]
forall a. a -> [a] -> [a]
: [CoreBind]
binds) }
go TCvSubst
_ (Boxer
_:[Boxer]
_) [] = String -> SDoc -> UniqSM ([Var], [CoreBind])
forall a. HasCallStack => String -> SDoc -> a
pprPanic String
"mk_boxer" (DataCon -> SDoc
forall a. Outputable a => a -> SDoc
ppr DataCon
data_con)
mk_rep_app :: [(Id,Unboxer)] -> CoreExpr -> UniqSM CoreExpr
mk_rep_app :: [(Var, Unboxer)] -> CoreExpr -> UniqSM CoreExpr
mk_rep_app [] CoreExpr
con_app
= CoreExpr -> UniqSM CoreExpr
forall (m :: * -> *) a. Monad m => a -> m a
return CoreExpr
con_app
mk_rep_app ((Var
wrap_arg, Unboxer
unboxer) : [(Var, Unboxer)]
prs) CoreExpr
con_app
= do { ([Var]
rep_ids, CoreExpr -> CoreExpr
unbox_fn) <- Unboxer
unboxer Var
wrap_arg
; CoreExpr
expr <- [(Var, Unboxer)] -> CoreExpr -> UniqSM CoreExpr
mk_rep_app [(Var, Unboxer)]
prs (CoreExpr -> [Var] -> CoreExpr
forall b. Expr b -> [Var] -> Expr b
mkVarApps CoreExpr
con_app [Var]
rep_ids)
; CoreExpr -> UniqSM CoreExpr
forall (m :: * -> *) a. Monad m => a -> m a
return (CoreExpr -> CoreExpr
unbox_fn CoreExpr
expr) }
dataConWrapperInlinePragma :: InlinePragma
dataConWrapperInlinePragma :: InlinePragma
dataConWrapperInlinePragma = InlinePragma
alwaysInlinePragma { inl_rule :: RuleMatchInfo
inl_rule = RuleMatchInfo
ConLike
, inl_inline :: InlineSpec
inl_inline = InlineSpec
Inline }
newLocal :: Scaled Type -> UniqSM Var
newLocal :: Scaled Type -> UniqSM Var
newLocal (Scaled Type
w Type
ty) = do { Unique
uniq <- UniqSM Unique
forall (m :: * -> *). MonadUnique m => m Unique
getUniqueM
; Var -> UniqSM Var
forall (m :: * -> *) a. Monad m => a -> m a
return (RuleName -> Unique -> Type -> Type -> Var
mkSysLocalOrCoVar (String -> RuleName
fsLit String
"dt") Unique
uniq Type
w Type
ty) }
dataConSrcToImplBang
:: DynFlags
-> FamInstEnvs
-> Scaled Type
-> HsSrcBang
-> HsImplBang
dataConSrcToImplBang :: DynFlags -> FamInstEnvs -> Scaled Type -> HsSrcBang -> HsImplBang
dataConSrcToImplBang DynFlags
dflags FamInstEnvs
fam_envs Scaled Type
arg_ty
(HsSrcBang SourceText
ann SrcUnpackedness
unpk SrcStrictness
NoSrcStrict)
| Extension -> DynFlags -> Bool
xopt Extension
LangExt.StrictData DynFlags
dflags
= DynFlags -> FamInstEnvs -> Scaled Type -> HsSrcBang -> HsImplBang
dataConSrcToImplBang DynFlags
dflags FamInstEnvs
fam_envs Scaled Type
arg_ty
(SourceText -> SrcUnpackedness -> SrcStrictness -> HsSrcBang
HsSrcBang SourceText
ann SrcUnpackedness
unpk SrcStrictness
SrcStrict)
| Bool
otherwise
= HsImplBang
HsLazy
dataConSrcToImplBang DynFlags
_ FamInstEnvs
_ Scaled Type
_ (HsSrcBang SourceText
_ SrcUnpackedness
_ SrcStrictness
SrcLazy)
= HsImplBang
HsLazy
dataConSrcToImplBang DynFlags
dflags FamInstEnvs
fam_envs Scaled Type
arg_ty
(HsSrcBang SourceText
_ SrcUnpackedness
unpk_prag SrcStrictness
SrcStrict)
| HasDebugCallStack => Type -> Bool
Type -> Bool
isUnliftedType (Scaled Type -> Type
forall a. Scaled a -> a
scaledThing Scaled Type
arg_ty)
= HsImplBang
HsLazy
| Bool -> Bool
not (GeneralFlag -> DynFlags -> Bool
gopt GeneralFlag
Opt_OmitInterfacePragmas DynFlags
dflags)
, let mb_co :: Maybe (Coercion, Type)
mb_co = FamInstEnvs -> Type -> Maybe (Coercion, Type)
topNormaliseType_maybe FamInstEnvs
fam_envs (Scaled Type -> Type
forall a. Scaled a -> a
scaledThing Scaled Type
arg_ty)
arg_ty' :: Scaled Type
arg_ty' = case Maybe (Coercion, Type)
mb_co of { Just (Coercion
_,Type
ty) -> Scaled Type -> Type -> Scaled Type
forall a b. Scaled a -> b -> Scaled b
scaledSet Scaled Type
arg_ty Type
ty; Maybe (Coercion, Type)
Nothing -> Scaled Type
arg_ty }
, DynFlags -> FamInstEnvs -> Type -> Bool
isUnpackableType DynFlags
dflags FamInstEnvs
fam_envs (Scaled Type -> Type
forall a. Scaled a -> a
scaledThing Scaled Type
arg_ty')
, ([(Scaled Type, StrictnessMark)]
rep_tys, (Unboxer, Boxer)
_) <- Scaled Type -> ([(Scaled Type, StrictnessMark)], (Unboxer, Boxer))
dataConArgUnpack Scaled Type
arg_ty'
, case SrcUnpackedness
unpk_prag of
SrcUnpackedness
NoSrcUnpack ->
GeneralFlag -> DynFlags -> Bool
gopt GeneralFlag
Opt_UnboxStrictFields DynFlags
dflags
Bool -> Bool -> Bool
|| (GeneralFlag -> DynFlags -> Bool
gopt GeneralFlag
Opt_UnboxSmallStrictFields DynFlags
dflags
Bool -> Bool -> Bool
&& [(Scaled Type, StrictnessMark)]
rep_tys [(Scaled Type, StrictnessMark)] -> Arity -> Bool
forall a. [a] -> Arity -> Bool
`lengthAtMost` Arity
1)
SrcUnpackedness
srcUnpack -> SrcUnpackedness -> Bool
isSrcUnpacked SrcUnpackedness
srcUnpack
= case Maybe (Coercion, Type)
mb_co of
Maybe (Coercion, Type)
Nothing -> Maybe Coercion -> HsImplBang
HsUnpack Maybe Coercion
forall a. Maybe a
Nothing
Just (Coercion
co,Type
_) -> Maybe Coercion -> HsImplBang
HsUnpack (Coercion -> Maybe Coercion
forall a. a -> Maybe a
Just Coercion
co)
| Bool
otherwise
= HsImplBang
HsStrict
dataConArgRep
:: Scaled Type
-> HsImplBang
-> ([(Scaled Type,StrictnessMark)]
,(Unboxer,Boxer))
dataConArgRep :: Scaled Type
-> HsImplBang
-> ([(Scaled Type, StrictnessMark)], (Unboxer, Boxer))
dataConArgRep Scaled Type
arg_ty HsImplBang
HsLazy
= ([(Scaled Type
arg_ty, StrictnessMark
NotMarkedStrict)], (Unboxer
unitUnboxer, Boxer
unitBoxer))
dataConArgRep Scaled Type
arg_ty HsImplBang
HsStrict
= ([(Scaled Type
arg_ty, StrictnessMark
MarkedStrict)], (Unboxer
seqUnboxer, Boxer
unitBoxer))
dataConArgRep Scaled Type
arg_ty (HsUnpack Maybe Coercion
Nothing)
| ([(Scaled Type, StrictnessMark)]
rep_tys, (Unboxer, Boxer)
wrappers) <- Scaled Type -> ([(Scaled Type, StrictnessMark)], (Unboxer, Boxer))
dataConArgUnpack Scaled Type
arg_ty
= ([(Scaled Type, StrictnessMark)]
rep_tys, (Unboxer, Boxer)
wrappers)
dataConArgRep (Scaled Type
w Type
_) (HsUnpack (Just Coercion
co))
| let co_rep_ty :: Type
co_rep_ty = Coercion -> Type
coercionRKind Coercion
co
, ([(Scaled Type, StrictnessMark)]
rep_tys, (Unboxer, Boxer)
wrappers) <- Scaled Type -> ([(Scaled Type, StrictnessMark)], (Unboxer, Boxer))
dataConArgUnpack (Type -> Type -> Scaled Type
forall a. Type -> a -> Scaled a
Scaled Type
w Type
co_rep_ty)
= ([(Scaled Type, StrictnessMark)]
rep_tys, Coercion -> Type -> (Unboxer, Boxer) -> (Unboxer, Boxer)
wrapCo Coercion
co Type
co_rep_ty (Unboxer, Boxer)
wrappers)
wrapCo :: Coercion -> Type -> (Unboxer, Boxer) -> (Unboxer, Boxer)
wrapCo :: Coercion -> Type -> (Unboxer, Boxer) -> (Unboxer, Boxer)
wrapCo Coercion
co Type
rep_ty (Unboxer
unbox_rep, Boxer
box_rep)
= (Unboxer
unboxer, Boxer
boxer)
where
unboxer :: Unboxer
unboxer Var
arg_id = do { Var
rep_id <- Scaled Type -> UniqSM Var
newLocal (Type -> Type -> Scaled Type
forall a. Type -> a -> Scaled a
Scaled (Var -> Type
idMult Var
arg_id) Type
rep_ty)
; ([Var]
rep_ids, CoreExpr -> CoreExpr
rep_fn) <- Unboxer
unbox_rep Var
rep_id
; let co_bind :: CoreBind
co_bind = Var -> CoreExpr -> CoreBind
forall b. b -> Expr b -> Bind b
NonRec Var
rep_id (Var -> CoreExpr
forall b. Var -> Expr b
Var Var
arg_id CoreExpr -> Coercion -> CoreExpr
forall b. Expr b -> Coercion -> Expr b
`Cast` Coercion
co)
; ([Var], CoreExpr -> CoreExpr)
-> UniqSM ([Var], CoreExpr -> CoreExpr)
forall (m :: * -> *) a. Monad m => a -> m a
return ([Var]
rep_ids, CoreBind -> CoreExpr -> CoreExpr
forall b. Bind b -> Expr b -> Expr b
Let CoreBind
co_bind (CoreExpr -> CoreExpr)
-> (CoreExpr -> CoreExpr) -> CoreExpr -> CoreExpr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CoreExpr -> CoreExpr
rep_fn) }
boxer :: Boxer
boxer = (TCvSubst -> UniqSM ([Var], CoreExpr)) -> Boxer
Boxer ((TCvSubst -> UniqSM ([Var], CoreExpr)) -> Boxer)
-> (TCvSubst -> UniqSM ([Var], CoreExpr)) -> Boxer
forall a b. (a -> b) -> a -> b
$ \ TCvSubst
subst ->
do { ([Var]
rep_ids, CoreExpr
rep_expr)
<- case Boxer
box_rep of
Boxer
UnitBox -> do { Var
rep_id <- Scaled Type -> UniqSM Var
newLocal (Type -> Scaled Type
forall a. a -> Scaled a
linear (Type -> Scaled Type) -> Type -> Scaled Type
forall a b. (a -> b) -> a -> b
$ HasCallStack => TCvSubst -> Type -> Type
TCvSubst -> Type -> Type
TcType.substTy TCvSubst
subst Type
rep_ty)
; ([Var], CoreExpr) -> UniqSM ([Var], CoreExpr)
forall (m :: * -> *) a. Monad m => a -> m a
return ([Var
rep_id], Var -> CoreExpr
forall b. Var -> Expr b
Var Var
rep_id) }
Boxer TCvSubst -> UniqSM ([Var], CoreExpr)
boxer -> TCvSubst -> UniqSM ([Var], CoreExpr)
boxer TCvSubst
subst
; let sco :: Coercion
sco = TCvSubst -> Coercion -> Coercion
substCoUnchecked TCvSubst
subst Coercion
co
; ([Var], CoreExpr) -> UniqSM ([Var], CoreExpr)
forall (m :: * -> *) a. Monad m => a -> m a
return ([Var]
rep_ids, CoreExpr
rep_expr CoreExpr -> Coercion -> CoreExpr
forall b. Expr b -> Coercion -> Expr b
`Cast` Coercion -> Coercion
mkSymCo Coercion
sco) }
seqUnboxer :: Unboxer
seqUnboxer :: Unboxer
seqUnboxer Var
v = ([Var], CoreExpr -> CoreExpr)
-> UniqSM ([Var], CoreExpr -> CoreExpr)
forall (m :: * -> *) a. Monad m => a -> m a
return ([Var
v], CoreExpr -> Var -> CoreExpr -> CoreExpr
mkDefaultCase (Var -> CoreExpr
forall b. Var -> Expr b
Var Var
v) Var
v)
unitUnboxer :: Unboxer
unitUnboxer :: Unboxer
unitUnboxer Var
v = ([Var], CoreExpr -> CoreExpr)
-> UniqSM ([Var], CoreExpr -> CoreExpr)
forall (m :: * -> *) a. Monad m => a -> m a
return ([Var
v], \CoreExpr
e -> CoreExpr
e)
unitBoxer :: Boxer
unitBoxer :: Boxer
unitBoxer = Boxer
UnitBox
dataConArgUnpack
:: Scaled Type
-> ( [(Scaled Type, StrictnessMark)]
, (Unboxer, Boxer) )
dataConArgUnpack :: Scaled Type -> ([(Scaled Type, StrictnessMark)], (Unboxer, Boxer))
dataConArgUnpack (Scaled Type
arg_mult Type
arg_ty)
| Just (TyCon
tc, [Type]
tc_args) <- HasDebugCallStack => Type -> Maybe (TyCon, [Type])
Type -> Maybe (TyCon, [Type])
splitTyConApp_maybe Type
arg_ty
, Just DataCon
con <- TyCon -> Maybe DataCon
tyConSingleAlgDataCon_maybe TyCon
tc
, let rep_tys :: [Scaled Type]
rep_tys = (Scaled Type -> Scaled Type) -> [Scaled Type] -> [Scaled Type]
forall a b. (a -> b) -> [a] -> [b]
map (Type -> Scaled Type -> Scaled Type
forall a. Type -> Scaled a -> Scaled a
scaleScaled Type
arg_mult) ([Scaled Type] -> [Scaled Type]) -> [Scaled Type] -> [Scaled Type]
forall a b. (a -> b) -> a -> b
$ DataCon -> [Type] -> [Scaled Type]
dataConInstArgTys DataCon
con [Type]
tc_args
= ASSERT( null (dataConExTyCoVars con) )
( [Scaled Type]
rep_tys [Scaled Type]
-> [StrictnessMark] -> [(Scaled Type, StrictnessMark)]
forall a b. [a] -> [b] -> [(a, b)]
`zip` DataCon -> [StrictnessMark]
dataConRepStrictness DataCon
con
,( \ Var
arg_id ->
do { [Var]
rep_ids <- (Scaled Type -> UniqSM Var) -> [Scaled Type] -> UniqSM [Var]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM Scaled Type -> UniqSM Var
newLocal [Scaled Type]
rep_tys
; let r_mult :: Type
r_mult = Var -> Type
idMult Var
arg_id
; let rep_ids' :: [Var]
rep_ids' = (Var -> Var) -> [Var] -> [Var]
forall a b. (a -> b) -> [a] -> [b]
map (Type -> Var -> Var
scaleIdBy Type
r_mult) [Var]
rep_ids
; let unbox_fn :: CoreExpr -> CoreExpr
unbox_fn CoreExpr
body
= CoreExpr -> Var -> AltCon -> [Var] -> CoreExpr -> CoreExpr
mkSingleAltCase (Var -> CoreExpr
forall b. Var -> Expr b
Var Var
arg_id) Var
arg_id
(DataCon -> AltCon
DataAlt DataCon
con) [Var]
rep_ids' CoreExpr
body
; ([Var], CoreExpr -> CoreExpr)
-> UniqSM ([Var], CoreExpr -> CoreExpr)
forall (m :: * -> *) a. Monad m => a -> m a
return ([Var]
rep_ids, CoreExpr -> CoreExpr
unbox_fn) }
, (TCvSubst -> UniqSM ([Var], CoreExpr)) -> Boxer
Boxer ((TCvSubst -> UniqSM ([Var], CoreExpr)) -> Boxer)
-> (TCvSubst -> UniqSM ([Var], CoreExpr)) -> Boxer
forall a b. (a -> b) -> a -> b
$ \ TCvSubst
subst ->
do { [Var]
rep_ids <- (Scaled Type -> UniqSM Var) -> [Scaled Type] -> UniqSM [Var]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (Scaled Type -> UniqSM Var
newLocal (Scaled Type -> UniqSM Var)
-> (Scaled Type -> Scaled Type) -> Scaled Type -> UniqSM Var
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HasCallStack => TCvSubst -> Scaled Type -> Scaled Type
TCvSubst -> Scaled Type -> Scaled Type
TcType.substScaledTyUnchecked TCvSubst
subst) [Scaled Type]
rep_tys
; ([Var], CoreExpr) -> UniqSM ([Var], CoreExpr)
forall (m :: * -> *) a. Monad m => a -> m a
return ([Var]
rep_ids, Var -> CoreExpr
forall b. Var -> Expr b
Var (DataCon -> Var
dataConWorkId DataCon
con)
CoreExpr -> [Type] -> CoreExpr
forall b. Expr b -> [Type] -> Expr b
`mkTyApps` (TCvSubst -> [Type] -> [Type]
substTysUnchecked TCvSubst
subst [Type]
tc_args)
CoreExpr -> [Var] -> CoreExpr
forall b. Expr b -> [Var] -> Expr b
`mkVarApps` [Var]
rep_ids ) } ) )
| Bool
otherwise
= String
-> SDoc -> ([(Scaled Type, StrictnessMark)], (Unboxer, Boxer))
forall a. HasCallStack => String -> SDoc -> a
pprPanic String
"dataConArgUnpack" (Type -> SDoc
forall a. Outputable a => a -> SDoc
ppr Type
arg_ty)
isUnpackableType :: DynFlags -> FamInstEnvs -> Type -> Bool
isUnpackableType :: DynFlags -> FamInstEnvs -> Type -> Bool
isUnpackableType DynFlags
dflags FamInstEnvs
fam_envs Type
ty
| Just DataCon
data_con <- Type -> Maybe DataCon
unpackable_type Type
ty
= NameSet -> DataCon -> Bool
ok_con_args NameSet
emptyNameSet DataCon
data_con
| Bool
otherwise
= Bool
False
where
ok_con_args :: NameSet -> DataCon -> Bool
ok_con_args NameSet
dcs DataCon
con
| Name
dc_name Name -> NameSet -> Bool
`elemNameSet` NameSet
dcs
= Bool
False
| Bool
otherwise
= ((Scaled Type, HsSrcBang) -> Bool)
-> [(Scaled Type, HsSrcBang)] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all (NameSet -> (Scaled Type, HsSrcBang) -> Bool
ok_arg NameSet
dcs')
(DataCon -> [Scaled Type]
dataConOrigArgTys DataCon
con [Scaled Type] -> [HsSrcBang] -> [(Scaled Type, HsSrcBang)]
forall a b. [a] -> [b] -> [(a, b)]
`zip` DataCon -> [HsSrcBang]
dataConSrcBangs DataCon
con)
where
dc_name :: Name
dc_name = DataCon -> Name
forall a. NamedThing a => a -> Name
getName DataCon
con
dcs' :: NameSet
dcs' = NameSet
dcs NameSet -> Name -> NameSet
`extendNameSet` Name
dc_name
ok_arg :: NameSet -> (Scaled Type, HsSrcBang) -> Bool
ok_arg NameSet
dcs (Scaled Type
_ Type
ty, HsSrcBang
bang)
= Bool -> Bool
not (HsSrcBang -> Bool
attempt_unpack HsSrcBang
bang) Bool -> Bool -> Bool
|| NameSet -> Type -> Bool
ok_ty NameSet
dcs Type
norm_ty
where
norm_ty :: Type
norm_ty = FamInstEnvs -> Type -> Type
topNormaliseType FamInstEnvs
fam_envs Type
ty
ok_ty :: NameSet -> Type -> Bool
ok_ty NameSet
dcs Type
ty
| Just DataCon
data_con <- Type -> Maybe DataCon
unpackable_type Type
ty
= NameSet -> DataCon -> Bool
ok_con_args NameSet
dcs DataCon
data_con
| Bool
otherwise
= Bool
True
attempt_unpack :: HsSrcBang -> Bool
attempt_unpack (HsSrcBang SourceText
_ SrcUnpackedness
SrcUnpack SrcStrictness
NoSrcStrict)
= Extension -> DynFlags -> Bool
xopt Extension
LangExt.StrictData DynFlags
dflags
attempt_unpack (HsSrcBang SourceText
_ SrcUnpackedness
SrcUnpack SrcStrictness
SrcStrict)
= Bool
True
attempt_unpack (HsSrcBang SourceText
_ SrcUnpackedness
NoSrcUnpack SrcStrictness
SrcStrict)
= Bool
True
attempt_unpack (HsSrcBang SourceText
_ SrcUnpackedness
NoSrcUnpack SrcStrictness
NoSrcStrict)
= Extension -> DynFlags -> Bool
xopt Extension
LangExt.StrictData DynFlags
dflags
attempt_unpack HsSrcBang
_ = Bool
False
unpackable_type :: Type -> Maybe DataCon
unpackable_type :: Type -> Maybe DataCon
unpackable_type Type
ty
| Just (TyCon
tc, [Type]
_) <- HasDebugCallStack => Type -> Maybe (TyCon, [Type])
Type -> Maybe (TyCon, [Type])
splitTyConApp_maybe Type
ty
, Just DataCon
data_con <- TyCon -> Maybe DataCon
tyConSingleAlgDataCon_maybe TyCon
tc
, [Var] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null (DataCon -> [Var]
dataConExTyCoVars DataCon
data_con)
= DataCon -> Maybe DataCon
forall a. a -> Maybe a
Just DataCon
data_con
| Bool
otherwise
= Maybe DataCon
forall a. Maybe a
Nothing
wrapNewTypeBody :: TyCon -> [Type] -> CoreExpr -> CoreExpr
wrapNewTypeBody :: TyCon -> [Type] -> CoreExpr -> CoreExpr
wrapNewTypeBody TyCon
tycon [Type]
args CoreExpr
result_expr
= ASSERT( isNewTyCon tycon )
CoreExpr -> Coercion -> CoreExpr
mkCast CoreExpr
result_expr (Coercion -> Coercion
mkSymCo Coercion
co)
where
co :: Coercion
co = Role -> CoAxiom Unbranched -> [Type] -> [Coercion] -> Coercion
mkUnbranchedAxInstCo Role
Representational (TyCon -> CoAxiom Unbranched
newTyConCo TyCon
tycon) [Type]
args []
unwrapNewTypeBody :: TyCon -> [Type] -> CoreExpr -> CoreExpr
unwrapNewTypeBody :: TyCon -> [Type] -> CoreExpr -> CoreExpr
unwrapNewTypeBody TyCon
tycon [Type]
args CoreExpr
result_expr
= ASSERT( isNewTyCon tycon )
CoreExpr -> Coercion -> CoreExpr
mkCast CoreExpr
result_expr (Role -> CoAxiom Unbranched -> [Type] -> [Coercion] -> Coercion
mkUnbranchedAxInstCo Role
Representational (TyCon -> CoAxiom Unbranched
newTyConCo TyCon
tycon) [Type]
args [])
wrapFamInstBody :: TyCon -> [Type] -> CoreExpr -> CoreExpr
wrapFamInstBody :: TyCon -> [Type] -> CoreExpr -> CoreExpr
wrapFamInstBody TyCon
tycon [Type]
args CoreExpr
body
| Just CoAxiom Unbranched
co_con <- TyCon -> Maybe (CoAxiom Unbranched)
tyConFamilyCoercion_maybe TyCon
tycon
= CoreExpr -> Coercion -> CoreExpr
mkCast CoreExpr
body (Coercion -> Coercion
mkSymCo (Role -> CoAxiom Unbranched -> [Type] -> [Coercion] -> Coercion
mkUnbranchedAxInstCo Role
Representational CoAxiom Unbranched
co_con [Type]
args []))
| Bool
otherwise
= CoreExpr
body
mkPrimOpId :: PrimOp -> Id
mkPrimOpId :: PrimOp -> Var
mkPrimOpId PrimOp
prim_op
= Var
id
where
([Var]
tyvars,[Type]
arg_tys,Type
res_ty, Arity
arity, StrictSig
strict_sig) = PrimOp -> ([Var], [Type], Type, Arity, StrictSig)
primOpSig PrimOp
prim_op
ty :: Type
ty = [Var] -> Type -> Type
mkSpecForAllTys [Var]
tyvars ([Type] -> Type -> Type
mkVisFunTysMany [Type]
arg_tys Type
res_ty)
name :: Name
name = Module -> OccName -> Unique -> TyThing -> BuiltInSyntax -> Name
mkWiredInName Module
gHC_PRIM (PrimOp -> OccName
primOpOcc PrimOp
prim_op)
(Arity -> Unique
mkPrimOpIdUnique (PrimOp -> Arity
primOpTag PrimOp
prim_op))
(Var -> TyThing
AnId Var
id) BuiltInSyntax
UserSyntax
id :: Var
id = IdDetails -> Name -> Type -> IdInfo -> Var
mkGlobalId (PrimOp -> IdDetails
PrimOpId PrimOp
prim_op) Name
name Type
ty IdInfo
info
cpr :: CprResult
cpr
| Divergence -> Bool
isDeadEndDiv (([Demand], Divergence) -> Divergence
forall a b. (a, b) -> b
snd (StrictSig -> ([Demand], Divergence)
splitStrictSig StrictSig
strict_sig)) = CprResult
botCpr
| Bool
otherwise = CprResult
topCpr
info :: IdInfo
info = IdInfo
noCafIdInfo
IdInfo -> RuleInfo -> IdInfo
`setRuleInfo` [CoreRule] -> RuleInfo
mkRuleInfo (Maybe CoreRule -> [CoreRule]
forall a. Maybe a -> [a]
maybeToList (Maybe CoreRule -> [CoreRule]) -> Maybe CoreRule -> [CoreRule]
forall a b. (a -> b) -> a -> b
$ Name -> PrimOp -> Maybe CoreRule
primOpRules Name
name PrimOp
prim_op)
IdInfo -> Arity -> IdInfo
`setArityInfo` Arity
arity
IdInfo -> StrictSig -> IdInfo
`setStrictnessInfo` StrictSig
strict_sig
IdInfo -> CprSig -> IdInfo
`setCprInfo` Arity -> CprResult -> CprSig
mkCprSig Arity
arity CprResult
cpr
IdInfo -> InlinePragma -> IdInfo
`setInlinePragInfo` InlinePragma
neverInlinePragma
IdInfo -> Type -> IdInfo
`setLevityInfoWithType` Type
res_ty
mkFCallId :: DynFlags -> Unique -> ForeignCall -> Type -> Id
mkFCallId :: DynFlags -> Unique -> ForeignCall -> Type -> Var
mkFCallId DynFlags
dflags Unique
uniq ForeignCall
fcall Type
ty
= ASSERT( noFreeVarsOfType ty )
IdDetails -> Name -> Type -> IdInfo -> Var
mkGlobalId (ForeignCall -> IdDetails
FCallId ForeignCall
fcall) Name
name Type
ty IdInfo
info
where
occ_str :: String
occ_str = DynFlags -> SDoc -> String
showSDoc DynFlags
dflags (SDoc -> SDoc
braces (ForeignCall -> SDoc
forall a. Outputable a => a -> SDoc
ppr ForeignCall
fcall SDoc -> SDoc -> SDoc
<+> Type -> SDoc
forall a. Outputable a => a -> SDoc
ppr Type
ty))
name :: Name
name = Unique -> String -> Name
mkFCallName Unique
uniq String
occ_str
info :: IdInfo
info = IdInfo
noCafIdInfo
IdInfo -> Arity -> IdInfo
`setArityInfo` Arity
arity
IdInfo -> StrictSig -> IdInfo
`setStrictnessInfo` StrictSig
strict_sig
IdInfo -> CprSig -> IdInfo
`setCprInfo` CprSig
topCprSig
IdInfo -> Type -> IdInfo
`setLevityInfoWithType` Type
ty
([TyBinder]
bndrs, Type
_) = Type -> ([TyBinder], Type)
tcSplitPiTys Type
ty
arity :: Arity
arity = (TyBinder -> Bool) -> [TyBinder] -> Arity
forall a. (a -> Bool) -> [a] -> Arity
count TyBinder -> Bool
isAnonTyCoBinder [TyBinder]
bndrs
strict_sig :: StrictSig
strict_sig = [Demand] -> Divergence -> StrictSig
mkClosedStrictSig (Arity -> Demand -> [Demand]
forall a. Arity -> a -> [a]
replicate Arity
arity Demand
topDmd) Divergence
topDiv
mkDictFunId :: Name
-> [TyVar]
-> ThetaType
-> Class
-> [Type]
-> Id
mkDictFunId :: Name -> [Var] -> [Type] -> Class -> [Type] -> Var
mkDictFunId Name
dfun_name [Var]
tvs [Type]
theta Class
clas [Type]
tys
= IdDetails -> Name -> Type -> Var
mkExportedLocalId (Bool -> IdDetails
DFunId Bool
is_nt)
Name
dfun_name
Type
dfun_ty
where
is_nt :: Bool
is_nt = TyCon -> Bool
isNewTyCon (Class -> TyCon
classTyCon Class
clas)
dfun_ty :: Type
dfun_ty = [Var] -> [Type] -> Class -> [Type] -> Type
mkDictFunTy [Var]
tvs [Type]
theta Class
clas [Type]
tys
mkDictFunTy :: [TyVar] -> ThetaType -> Class -> [Type] -> Type
mkDictFunTy :: [Var] -> [Type] -> Class -> [Type] -> Type
mkDictFunTy [Var]
tvs [Type]
theta Class
clas [Type]
tys
= [Var] -> [Type] -> Type -> Type
mkSpecSigmaTy [Var]
tvs [Type]
theta (Class -> [Type] -> Type
mkClassPred Class
clas [Type]
tys)
nullAddrName, seqName,
realWorldName, voidPrimIdName, coercionTokenName,
magicDictName, coerceName, proxyName :: Name
nullAddrName :: Name
nullAddrName = Module -> RuleName -> Unique -> Var -> Name
mkWiredInIdName Module
gHC_PRIM (String -> RuleName
fsLit String
"nullAddr#") Unique
nullAddrIdKey Var
nullAddrId
seqName :: Name
seqName = Module -> RuleName -> Unique -> Var -> Name
mkWiredInIdName Module
gHC_PRIM (String -> RuleName
fsLit String
"seq") Unique
seqIdKey Var
seqId
realWorldName :: Name
realWorldName = Module -> RuleName -> Unique -> Var -> Name
mkWiredInIdName Module
gHC_PRIM (String -> RuleName
fsLit String
"realWorld#") Unique
realWorldPrimIdKey Var
realWorldPrimId
voidPrimIdName :: Name
voidPrimIdName = Module -> RuleName -> Unique -> Var -> Name
mkWiredInIdName Module
gHC_PRIM (String -> RuleName
fsLit String
"void#") Unique
voidPrimIdKey Var
voidPrimId
coercionTokenName :: Name
coercionTokenName = Module -> RuleName -> Unique -> Var -> Name
mkWiredInIdName Module
gHC_PRIM (String -> RuleName
fsLit String
"coercionToken#") Unique
coercionTokenIdKey Var
coercionTokenId
magicDictName :: Name
magicDictName = Module -> RuleName -> Unique -> Var -> Name
mkWiredInIdName Module
gHC_PRIM (String -> RuleName
fsLit String
"magicDict") Unique
magicDictKey Var
magicDictId
coerceName :: Name
coerceName = Module -> RuleName -> Unique -> Var -> Name
mkWiredInIdName Module
gHC_PRIM (String -> RuleName
fsLit String
"coerce") Unique
coerceKey Var
coerceId
proxyName :: Name
proxyName = Module -> RuleName -> Unique -> Var -> Name
mkWiredInIdName Module
gHC_PRIM (String -> RuleName
fsLit String
"proxy#") Unique
proxyHashKey Var
proxyHashId
lazyIdName, oneShotName, noinlineIdName :: Name
lazyIdName :: Name
lazyIdName = Module -> RuleName -> Unique -> Var -> Name
mkWiredInIdName Module
gHC_MAGIC (String -> RuleName
fsLit String
"lazy") Unique
lazyIdKey Var
lazyId
oneShotName :: Name
oneShotName = Module -> RuleName -> Unique -> Var -> Name
mkWiredInIdName Module
gHC_MAGIC (String -> RuleName
fsLit String
"oneShot") Unique
oneShotKey Var
oneShotId
noinlineIdName :: Name
noinlineIdName = Module -> RuleName -> Unique -> Var -> Name
mkWiredInIdName Module
gHC_MAGIC (String -> RuleName
fsLit String
"noinline") Unique
noinlineIdKey Var
noinlineId
proxyHashId :: Id
proxyHashId :: Var
proxyHashId
= Name -> Type -> IdInfo -> Var
pcMiscPrelId Name
proxyName Type
ty
(IdInfo
noCafIdInfo IdInfo -> Unfolding -> IdInfo
`setUnfoldingInfo` Unfolding
evaldUnfolding
HasDebugCallStack => IdInfo -> Type -> IdInfo
IdInfo -> Type -> IdInfo
`setNeverLevPoly` Type
ty)
where
[Var
kv,Var
tv] = [Type] -> ([Type] -> [Type]) -> [Var]
mkTemplateKiTyVars [Type
liftedTypeKind] [Type] -> [Type]
forall a. a -> a
id
kv_ty :: Type
kv_ty = Var -> Type
mkTyVarTy Var
kv
tv_ty :: Type
tv_ty = Var -> Type
mkTyVarTy Var
tv
ty :: Type
ty = Var -> Type -> Type
mkInfForAllTy Var
kv (Type -> Type) -> Type -> Type
forall a b. (a -> b) -> a -> b
$ Var -> Type -> Type
mkSpecForAllTy Var
tv (Type -> Type) -> Type -> Type
forall a b. (a -> b) -> a -> b
$ Type -> Type -> Type
mkProxyPrimTy Type
kv_ty Type
tv_ty
nullAddrId :: Id
nullAddrId :: Var
nullAddrId = Name -> Type -> IdInfo -> Var
pcMiscPrelId Name
nullAddrName Type
addrPrimTy IdInfo
info
where
info :: IdInfo
info = IdInfo
noCafIdInfo IdInfo -> InlinePragma -> IdInfo
`setInlinePragInfo` InlinePragma
alwaysInlinePragma
IdInfo -> Unfolding -> IdInfo
`setUnfoldingInfo` CoreExpr -> Unfolding
mkCompulsoryUnfolding (Literal -> CoreExpr
forall b. Literal -> Expr b
Lit Literal
nullAddrLit)
HasDebugCallStack => IdInfo -> Type -> IdInfo
IdInfo -> Type -> IdInfo
`setNeverLevPoly` Type
addrPrimTy
seqId :: Id
seqId :: Var
seqId = Name -> Type -> IdInfo -> Var
pcMiscPrelId Name
seqName Type
ty IdInfo
info
where
info :: IdInfo
info = IdInfo
noCafIdInfo IdInfo -> InlinePragma -> IdInfo
`setInlinePragInfo` InlinePragma
inline_prag
IdInfo -> Unfolding -> IdInfo
`setUnfoldingInfo` CoreExpr -> Unfolding
mkCompulsoryUnfolding CoreExpr
rhs
inline_prag :: InlinePragma
inline_prag
= InlinePragma
alwaysInlinePragma InlinePragma -> Activation -> InlinePragma
`setInlinePragmaActivation` SourceText -> Arity -> Activation
ActiveAfter
SourceText
NoSourceText Arity
0
ty :: Type
ty =
Var -> Type -> Type
mkInfForAllTy Var
runtimeRep2TyVar
(Type -> Type) -> Type -> Type
forall a b. (a -> b) -> a -> b
$ [Var] -> Type -> Type
mkSpecForAllTys [Var
alphaTyVar, Var
openBetaTyVar]
(Type -> Type) -> Type -> Type
forall a b. (a -> b) -> a -> b
$ Type -> Type -> Type
mkVisFunTyMany Type
alphaTy (Type -> Type -> Type
mkVisFunTyMany Type
openBetaTy Type
openBetaTy)
[Var
x,Var
y] = [Type] -> [Var]
mkTemplateLocals [Type
alphaTy, Type
openBetaTy]
rhs :: CoreExpr
rhs = [Var] -> CoreExpr -> CoreExpr
forall b. [b] -> Expr b -> Expr b
mkLams ([Var
runtimeRep2TyVar, Var
alphaTyVar, Var
openBetaTyVar, Var
x, Var
y]) (CoreExpr -> CoreExpr) -> CoreExpr -> CoreExpr
forall a b. (a -> b) -> a -> b
$
CoreExpr -> Var -> Type -> [Alt Var] -> CoreExpr
forall b. Expr b -> b -> Type -> [Alt b] -> Expr b
Case (Var -> CoreExpr
forall b. Var -> Expr b
Var Var
x) Var
x Type
openBetaTy [(AltCon
DEFAULT, [], Var -> CoreExpr
forall b. Var -> Expr b
Var Var
y)]
lazyId :: Id
lazyId :: Var
lazyId = Name -> Type -> IdInfo -> Var
pcMiscPrelId Name
lazyIdName Type
ty IdInfo
info
where
info :: IdInfo
info = IdInfo
noCafIdInfo HasDebugCallStack => IdInfo -> Type -> IdInfo
IdInfo -> Type -> IdInfo
`setNeverLevPoly` Type
ty
ty :: Type
ty = [Var] -> Type -> Type
mkSpecForAllTys [Var
alphaTyVar] (Type -> Type -> Type
mkVisFunTyMany Type
alphaTy Type
alphaTy)
noinlineId :: Id
noinlineId :: Var
noinlineId = Name -> Type -> IdInfo -> Var
pcMiscPrelId Name
noinlineIdName Type
ty IdInfo
info
where
info :: IdInfo
info = IdInfo
noCafIdInfo HasDebugCallStack => IdInfo -> Type -> IdInfo
IdInfo -> Type -> IdInfo
`setNeverLevPoly` Type
ty
ty :: Type
ty = [Var] -> Type -> Type
mkSpecForAllTys [Var
alphaTyVar] (Type -> Type -> Type
mkVisFunTyMany Type
alphaTy Type
alphaTy)
oneShotId :: Id
oneShotId :: Var
oneShotId = Name -> Type -> IdInfo -> Var
pcMiscPrelId Name
oneShotName Type
ty IdInfo
info
where
info :: IdInfo
info = IdInfo
noCafIdInfo IdInfo -> InlinePragma -> IdInfo
`setInlinePragInfo` InlinePragma
alwaysInlinePragma
IdInfo -> Unfolding -> IdInfo
`setUnfoldingInfo` CoreExpr -> Unfolding
mkCompulsoryUnfolding CoreExpr
rhs
ty :: Type
ty = [Var] -> Type -> Type
mkSpecForAllTys [ Var
runtimeRep1TyVar, Var
runtimeRep2TyVar
, Var
openAlphaTyVar, Var
openBetaTyVar ]
(Type -> Type -> Type
mkVisFunTyMany Type
fun_ty Type
fun_ty)
fun_ty :: Type
fun_ty = Type -> Type -> Type
mkVisFunTyMany Type
openAlphaTy Type
openBetaTy
[Var
body, Var
x] = [Type] -> [Var]
mkTemplateLocals [Type
fun_ty, Type
openAlphaTy]
x' :: Var
x' = Var -> Var
setOneShotLambda Var
x
rhs :: CoreExpr
rhs = [Var] -> CoreExpr -> CoreExpr
forall b. [b] -> Expr b -> Expr b
mkLams [ Var
runtimeRep1TyVar, Var
runtimeRep2TyVar
, Var
openAlphaTyVar, Var
openBetaTyVar
, Var
body, Var
x'] (CoreExpr -> CoreExpr) -> CoreExpr -> CoreExpr
forall a b. (a -> b) -> a -> b
$
Var -> CoreExpr
forall b. Var -> Expr b
Var Var
body CoreExpr -> CoreExpr -> CoreExpr
forall b. Expr b -> Expr b -> Expr b
`App` Var -> CoreExpr
forall b. Var -> Expr b
Var Var
x
magicDictId :: Id
magicDictId :: Var
magicDictId = Name -> Type -> IdInfo -> Var
pcMiscPrelId Name
magicDictName Type
ty IdInfo
info
where
info :: IdInfo
info = IdInfo
noCafIdInfo IdInfo -> InlinePragma -> IdInfo
`setInlinePragInfo` InlinePragma
neverInlinePragma
HasDebugCallStack => IdInfo -> Type -> IdInfo
IdInfo -> Type -> IdInfo
`setNeverLevPoly` Type
ty
ty :: Type
ty = [Var] -> Type -> Type
mkSpecForAllTys [Var
alphaTyVar] Type
alphaTy
coerceId :: Id
coerceId :: Var
coerceId = Name -> Type -> IdInfo -> Var
pcMiscPrelId Name
coerceName Type
ty IdInfo
info
where
info :: IdInfo
info = IdInfo
noCafIdInfo IdInfo -> InlinePragma -> IdInfo
`setInlinePragInfo` InlinePragma
alwaysInlinePragma
IdInfo -> Unfolding -> IdInfo
`setUnfoldingInfo` CoreExpr -> Unfolding
mkCompulsoryUnfolding CoreExpr
rhs
eqRTy :: Type
eqRTy = TyCon -> [Type] -> Type
mkTyConApp TyCon
coercibleTyCon [ Type -> Type
tYPE Type
r , Type
a, Type
b ]
eqRPrimTy :: Type
eqRPrimTy = TyCon -> [Type] -> Type
mkTyConApp TyCon
eqReprPrimTyCon [ Type -> Type
tYPE Type
r, Type -> Type
tYPE Type
r, Type
a, Type
b ]
ty :: Type
ty = [InvisTVBinder] -> Type -> Type
mkInvisForAllTys [ Var -> Specificity -> InvisTVBinder
forall var argf. var -> argf -> VarBndr var argf
Bndr Var
rv Specificity
InferredSpec
, Var -> Specificity -> InvisTVBinder
forall var argf. var -> argf -> VarBndr var argf
Bndr Var
av Specificity
SpecifiedSpec
, Var -> Specificity -> InvisTVBinder
forall var argf. var -> argf -> VarBndr var argf
Bndr Var
bv Specificity
SpecifiedSpec
] (Type -> Type) -> Type -> Type
forall a b. (a -> b) -> a -> b
$
Type -> Type -> Type
mkInvisFunTyMany Type
eqRTy (Type -> Type) -> Type -> Type
forall a b. (a -> b) -> a -> b
$
Type -> Type -> Type
mkVisFunTyMany Type
a Type
b
bndrs :: [Var]
bndrs@[Var
rv,Var
av,Var
bv] = Type -> (Type -> [Type]) -> [Var]
mkTemplateKiTyVar Type
runtimeRepTy
(\Type
r -> [Type -> Type
tYPE Type
r, Type -> Type
tYPE Type
r])
[Type
r, Type
a, Type
b] = [Var] -> [Type]
mkTyVarTys [Var]
bndrs
[Var
eqR,Var
x,Var
eq] = [Type] -> [Var]
mkTemplateLocals [Type
eqRTy, Type
a, Type
eqRPrimTy]
rhs :: CoreExpr
rhs = [Var] -> CoreExpr -> CoreExpr
forall b. [b] -> Expr b -> Expr b
mkLams ([Var]
bndrs [Var] -> [Var] -> [Var]
forall a. [a] -> [a] -> [a]
++ [Var
eqR, Var
x]) (CoreExpr -> CoreExpr) -> CoreExpr -> CoreExpr
forall a b. (a -> b) -> a -> b
$
CoreExpr -> Scaled Type -> Type -> [Alt Var] -> CoreExpr
mkWildCase (Var -> CoreExpr
forall b. Var -> Expr b
Var Var
eqR) (Type -> Scaled Type
forall a. a -> Scaled a
unrestricted Type
eqRTy) Type
b ([Alt Var] -> CoreExpr) -> [Alt Var] -> CoreExpr
forall a b. (a -> b) -> a -> b
$
[(DataCon -> AltCon
DataAlt DataCon
coercibleDataCon, [Var
eq], CoreExpr -> Coercion -> CoreExpr
forall b. Expr b -> Coercion -> Expr b
Cast (Var -> CoreExpr
forall b. Var -> Expr b
Var Var
x) (Var -> Coercion
mkCoVarCo Var
eq))]
realWorldPrimId :: Id
realWorldPrimId :: Var
realWorldPrimId = Name -> Type -> IdInfo -> Var
pcMiscPrelId Name
realWorldName Type
realWorldStatePrimTy
(IdInfo
noCafIdInfo IdInfo -> Unfolding -> IdInfo
`setUnfoldingInfo` Unfolding
evaldUnfolding
IdInfo -> OneShotInfo -> IdInfo
`setOneShotInfo` OneShotInfo
stateHackOneShot
HasDebugCallStack => IdInfo -> Type -> IdInfo
IdInfo -> Type -> IdInfo
`setNeverLevPoly` Type
realWorldStatePrimTy)
voidPrimId :: Id
voidPrimId :: Var
voidPrimId = Name -> Type -> IdInfo -> Var
pcMiscPrelId Name
voidPrimIdName Type
voidPrimTy
(IdInfo
noCafIdInfo IdInfo -> Unfolding -> IdInfo
`setUnfoldingInfo` Unfolding
evaldUnfolding
HasDebugCallStack => IdInfo -> Type -> IdInfo
IdInfo -> Type -> IdInfo
`setNeverLevPoly` Type
voidPrimTy)
voidArgId :: Id
voidArgId :: Var
voidArgId = RuleName -> Unique -> Type -> Type -> Var
mkSysLocal (String -> RuleName
fsLit String
"void") Unique
voidArgIdKey Type
Many Type
voidPrimTy
coercionTokenId :: Id
coercionTokenId :: Var
coercionTokenId
= Name -> Type -> IdInfo -> Var
pcMiscPrelId Name
coercionTokenName
(TyCon -> [Type] -> Type
mkTyConApp TyCon
eqPrimTyCon [Type
liftedTypeKind, Type
liftedTypeKind, Type
unitTy, Type
unitTy])
IdInfo
noCafIdInfo
pcMiscPrelId :: Name -> Type -> IdInfo -> Id
pcMiscPrelId :: Name -> Type -> IdInfo -> Var
pcMiscPrelId Name
name Type
ty IdInfo
info
= Name -> Type -> IdInfo -> Var
mkVanillaGlobalWithInfo Name
name Type
ty IdInfo
info