{-# LANGUAGE CPP #-}
module MkCore (
mkCoreLet, mkCoreLets,
mkCoreApp, mkCoreApps, mkCoreConApps,
mkCoreLams, mkWildCase, mkIfThenElse,
mkWildValBinder, mkWildEvBinder,
sortQuantVars, castBottomExpr,
mkWordExpr, mkWordExprWord,
mkIntExpr, mkIntExprInt,
mkIntegerExpr, mkNaturalExpr,
mkFloatExpr, mkDoubleExpr,
mkCharExpr, mkStringExpr, mkStringExprFS, mkStringExprFSWith,
FloatBind(..), wrapFloat,
mkCoreVarTup, mkCoreVarTupTy, mkCoreTup, mkCoreUbxTup,
mkCoreTupBoxity, unitExpr,
mkBigCoreVarTup, mkBigCoreVarTup1,
mkBigCoreVarTupTy, mkBigCoreTupTy,
mkBigCoreTup,
mkSmallTupleSelector, mkSmallTupleCase,
mkTupleSelector, mkTupleSelector1, mkTupleCase,
mkNilExpr, mkConsExpr, mkListExpr,
mkFoldrExpr, mkBuildExpr,
mkNothingExpr, mkJustExpr,
mkRuntimeErrorApp, mkImpossibleExpr, mkAbsentErrorApp, errorIds,
rEC_CON_ERROR_ID, rUNTIME_ERROR_ID,
nON_EXHAUSTIVE_GUARDS_ERROR_ID, nO_METHOD_BINDING_ERROR_ID,
pAT_ERROR_ID, rEC_SEL_ERROR_ID, aBSENT_ERROR_ID,
tYPE_ERROR_ID, aBSENT_SUM_FIELD_ERROR_ID
) where
#include "HsVersions.h"
import GhcPrelude
import Id
import Var ( EvVar, setTyVarUnique )
import CoreSyn
import CoreUtils ( exprType, needsCaseBinding, bindNonRec )
import Literal
import HscTypes
import TysWiredIn
import PrelNames
import HsUtils ( mkChunkified, chunkify )
import Type
import Coercion ( isCoVar )
import TysPrim
import DataCon ( DataCon, dataConWorkId )
import IdInfo
import Demand
import Name hiding ( varName )
import Outputable
import FastString
import UniqSupply
import BasicTypes
import Util
import DynFlags
import Data.List
import Data.Char ( ord )
import Control.Monad.Fail as MonadFail ( MonadFail )
infixl 4 `mkCoreApp`, `mkCoreApps`
sortQuantVars :: [Var] -> [Var]
sortQuantVars :: [Var] -> [Var]
sortQuantVars vs :: [Var]
vs = [Var]
sorted_tcvs [Var] -> [Var] -> [Var]
forall a. [a] -> [a] -> [a]
++ [Var]
ids
where
(tcvs :: [Var]
tcvs, ids :: [Var]
ids) = (Var -> Bool) -> [Var] -> ([Var], [Var])
forall a. (a -> Bool) -> [a] -> ([a], [a])
partition (Var -> Bool
isTyVar (Var -> Bool) -> (Var -> Bool) -> Var -> Bool
forall (f :: * -> *). Applicative f => f Bool -> f Bool -> f Bool
<||> Var -> Bool
isCoVar) [Var]
vs
sorted_tcvs :: [Var]
sorted_tcvs = [Var] -> [Var]
scopedSort [Var]
tcvs
mkCoreLet :: CoreBind -> CoreExpr -> CoreExpr
mkCoreLet :: CoreBind -> CoreExpr -> CoreExpr
mkCoreLet (NonRec bndr :: Var
bndr rhs :: CoreExpr
rhs) body :: CoreExpr
body
= Var -> CoreExpr -> CoreExpr -> CoreExpr
bindNonRec Var
bndr CoreExpr
rhs CoreExpr
body
mkCoreLet bind :: CoreBind
bind body :: CoreExpr
body
= CoreBind -> CoreExpr -> CoreExpr
forall b. Bind b -> Expr b -> Expr b
Let CoreBind
bind CoreExpr
body
mkCoreLets :: [CoreBind] -> CoreExpr -> CoreExpr
mkCoreLets :: [CoreBind] -> CoreExpr -> CoreExpr
mkCoreLets binds :: [CoreBind]
binds body :: CoreExpr
body = (CoreBind -> CoreExpr -> CoreExpr)
-> CoreExpr -> [CoreBind] -> CoreExpr
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr CoreBind -> CoreExpr -> CoreExpr
mkCoreLet CoreExpr
body [CoreBind]
binds
mkCoreAppTyped :: SDoc -> (CoreExpr, Type) -> CoreExpr -> (CoreExpr, Type)
mkCoreAppTyped :: SDoc -> (CoreExpr, Type) -> CoreExpr -> (CoreExpr, Type)
mkCoreAppTyped _ (fun :: CoreExpr
fun, fun_ty :: Type
fun_ty) (Type ty :: Type
ty)
= (CoreExpr -> CoreExpr -> CoreExpr
forall b. Expr b -> Expr b -> Expr b
App CoreExpr
fun (Type -> CoreExpr
forall b. Type -> Expr b
Type Type
ty), HasDebugCallStack => Type -> Type -> Type
Type -> Type -> Type
piResultTy Type
fun_ty Type
ty)
mkCoreAppTyped _ (fun :: CoreExpr
fun, fun_ty :: Type
fun_ty) (Coercion co :: Coercion
co)
= (CoreExpr -> CoreExpr -> CoreExpr
forall b. Expr b -> Expr b -> Expr b
App CoreExpr
fun (Coercion -> CoreExpr
forall b. Coercion -> Expr b
Coercion Coercion
co), Type
res_ty)
where
(_, res_ty :: Type
res_ty) = Type -> (Type, Type)
splitFunTy Type
fun_ty
mkCoreAppTyped d :: SDoc
d (fun :: CoreExpr
fun, fun_ty :: Type
fun_ty) arg :: CoreExpr
arg
= ASSERT2( isFunTy fun_ty, ppr fun $$ ppr arg $$ d )
(CoreExpr -> CoreExpr -> Type -> Type -> CoreExpr
mk_val_app CoreExpr
fun CoreExpr
arg Type
arg_ty Type
res_ty, Type
res_ty)
where
(arg_ty :: Type
arg_ty, res_ty :: Type
res_ty) = Type -> (Type, Type)
splitFunTy Type
fun_ty
mkCoreApp :: SDoc -> CoreExpr -> CoreExpr -> CoreExpr
mkCoreApp :: SDoc -> CoreExpr -> CoreExpr -> CoreExpr
mkCoreApp s :: SDoc
s fun :: CoreExpr
fun arg :: CoreExpr
arg
= (CoreExpr, Type) -> CoreExpr
forall a b. (a, b) -> a
fst ((CoreExpr, Type) -> CoreExpr) -> (CoreExpr, Type) -> CoreExpr
forall a b. (a -> b) -> a -> b
$ SDoc -> (CoreExpr, Type) -> CoreExpr -> (CoreExpr, Type)
mkCoreAppTyped SDoc
s (CoreExpr
fun, CoreExpr -> Type
exprType CoreExpr
fun) CoreExpr
arg
mkCoreApps :: CoreExpr -> [CoreExpr] -> CoreExpr
mkCoreApps :: CoreExpr -> [CoreExpr] -> CoreExpr
mkCoreApps fun :: CoreExpr
fun args :: [CoreExpr]
args
= (CoreExpr, Type) -> CoreExpr
forall a b. (a, b) -> a
fst ((CoreExpr, Type) -> CoreExpr) -> (CoreExpr, Type) -> CoreExpr
forall a b. (a -> b) -> a -> b
$
((CoreExpr, Type) -> CoreExpr -> (CoreExpr, Type))
-> (CoreExpr, Type) -> [CoreExpr] -> (CoreExpr, Type)
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' (SDoc -> (CoreExpr, Type) -> CoreExpr -> (CoreExpr, Type)
mkCoreAppTyped SDoc
doc_string) (CoreExpr
fun, Type
fun_ty) [CoreExpr]
args
where
doc_string :: SDoc
doc_string = Type -> SDoc
forall a. Outputable a => a -> SDoc
ppr Type
fun_ty SDoc -> SDoc -> SDoc
$$ CoreExpr -> SDoc
forall a. Outputable a => a -> SDoc
ppr CoreExpr
fun SDoc -> SDoc -> SDoc
$$ [CoreExpr] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [CoreExpr]
args
fun_ty :: Type
fun_ty = CoreExpr -> Type
exprType CoreExpr
fun
mkCoreConApps :: DataCon -> [CoreExpr] -> CoreExpr
mkCoreConApps :: DataCon -> [CoreExpr] -> CoreExpr
mkCoreConApps con :: DataCon
con args :: [CoreExpr]
args = CoreExpr -> [CoreExpr] -> CoreExpr
mkCoreApps (Var -> CoreExpr
forall b. Var -> Expr b
Var (DataCon -> Var
dataConWorkId DataCon
con)) [CoreExpr]
args
mk_val_app :: CoreExpr -> CoreExpr -> Type -> Type -> CoreExpr
mk_val_app :: CoreExpr -> CoreExpr -> Type -> Type -> CoreExpr
mk_val_app fun :: CoreExpr
fun arg :: CoreExpr
arg arg_ty :: Type
arg_ty res_ty :: Type
res_ty
| Bool -> Bool
not (Type -> CoreExpr -> Bool
needsCaseBinding Type
arg_ty CoreExpr
arg)
= CoreExpr -> CoreExpr -> CoreExpr
forall b. Expr b -> Expr b -> Expr b
App CoreExpr
fun CoreExpr
arg
| Bool
otherwise
= CoreExpr -> Var -> Type -> [Alt Var] -> CoreExpr
forall b. Expr b -> b -> Type -> [Alt b] -> Expr b
Case CoreExpr
arg Var
arg_id Type
res_ty [(AltCon
DEFAULT,[],CoreExpr -> CoreExpr -> CoreExpr
forall b. Expr b -> Expr b -> Expr b
App CoreExpr
fun (Var -> CoreExpr
forall b. Var -> Expr b
Var Var
arg_id))]
where
arg_id :: Var
arg_id = Type -> Var
mkWildValBinder Type
arg_ty
mkWildEvBinder :: PredType -> EvVar
mkWildEvBinder :: Type -> Var
mkWildEvBinder pred :: Type
pred = Type -> Var
mkWildValBinder Type
pred
mkWildValBinder :: Type -> Id
mkWildValBinder :: Type -> Var
mkWildValBinder ty :: Type
ty = Name -> Type -> Var
mkLocalIdOrCoVar Name
wildCardName Type
ty
mkWildCase :: CoreExpr -> Type -> Type -> [CoreAlt] -> CoreExpr
mkWildCase :: CoreExpr -> Type -> Type -> [Alt Var] -> CoreExpr
mkWildCase scrut :: CoreExpr
scrut scrut_ty :: Type
scrut_ty res_ty :: Type
res_ty alts :: [Alt Var]
alts
= CoreExpr -> Var -> Type -> [Alt Var] -> CoreExpr
forall b. Expr b -> b -> Type -> [Alt b] -> Expr b
Case CoreExpr
scrut (Type -> Var
mkWildValBinder Type
scrut_ty) Type
res_ty [Alt Var]
alts
mkIfThenElse :: CoreExpr -> CoreExpr -> CoreExpr -> CoreExpr
mkIfThenElse :: CoreExpr -> CoreExpr -> CoreExpr -> CoreExpr
mkIfThenElse guard :: CoreExpr
guard then_expr :: CoreExpr
then_expr else_expr :: CoreExpr
else_expr
= CoreExpr -> Type -> Type -> [Alt Var] -> CoreExpr
mkWildCase CoreExpr
guard Type
boolTy (CoreExpr -> Type
exprType CoreExpr
then_expr)
[ (DataCon -> AltCon
DataAlt DataCon
falseDataCon, [], CoreExpr
else_expr),
(DataCon -> AltCon
DataAlt DataCon
trueDataCon, [], CoreExpr
then_expr) ]
castBottomExpr :: CoreExpr -> Type -> CoreExpr
castBottomExpr :: CoreExpr -> Type -> CoreExpr
castBottomExpr e :: CoreExpr
e res_ty :: Type
res_ty
| Type
e_ty Type -> Type -> Bool
`eqType` Type
res_ty = CoreExpr
e
| Bool
otherwise = CoreExpr -> Var -> Type -> [Alt Var] -> CoreExpr
forall b. Expr b -> b -> Type -> [Alt b] -> Expr b
Case CoreExpr
e (Type -> Var
mkWildValBinder Type
e_ty) Type
res_ty []
where
e_ty :: Type
e_ty = CoreExpr -> Type
exprType CoreExpr
e
mkCoreLams :: [CoreBndr] -> CoreExpr -> CoreExpr
mkCoreLams :: [Var] -> CoreExpr -> CoreExpr
mkCoreLams = [Var] -> CoreExpr -> CoreExpr
forall b. [b] -> Expr b -> Expr b
mkLams
mkIntExpr :: DynFlags -> Integer -> CoreExpr
mkIntExpr :: DynFlags -> Integer -> CoreExpr
mkIntExpr dflags :: DynFlags
dflags i :: Integer
i = DataCon -> [CoreExpr] -> CoreExpr
mkCoreConApps DataCon
intDataCon [DynFlags -> Integer -> CoreExpr
forall b. DynFlags -> Integer -> Expr b
mkIntLit DynFlags
dflags Integer
i]
mkIntExprInt :: DynFlags -> Int -> CoreExpr
mkIntExprInt :: DynFlags -> Int -> CoreExpr
mkIntExprInt dflags :: DynFlags
dflags i :: Int
i = DataCon -> [CoreExpr] -> CoreExpr
mkCoreConApps DataCon
intDataCon [DynFlags -> Int -> CoreExpr
forall b. DynFlags -> Int -> Expr b
mkIntLitInt DynFlags
dflags Int
i]
mkWordExpr :: DynFlags -> Integer -> CoreExpr
mkWordExpr :: DynFlags -> Integer -> CoreExpr
mkWordExpr dflags :: DynFlags
dflags w :: Integer
w = DataCon -> [CoreExpr] -> CoreExpr
mkCoreConApps DataCon
wordDataCon [DynFlags -> Integer -> CoreExpr
forall b. DynFlags -> Integer -> Expr b
mkWordLit DynFlags
dflags Integer
w]
mkWordExprWord :: DynFlags -> Word -> CoreExpr
mkWordExprWord :: DynFlags -> Word -> CoreExpr
mkWordExprWord dflags :: DynFlags
dflags w :: Word
w = DataCon -> [CoreExpr] -> CoreExpr
mkCoreConApps DataCon
wordDataCon [DynFlags -> Word -> CoreExpr
forall b. DynFlags -> Word -> Expr b
mkWordLitWord DynFlags
dflags Word
w]
mkIntegerExpr :: MonadThings m => Integer -> m CoreExpr
mkIntegerExpr :: Integer -> m CoreExpr
mkIntegerExpr i :: Integer
i = do TyCon
t <- Name -> m TyCon
forall (m :: * -> *). MonadThings m => Name -> m TyCon
lookupTyCon Name
integerTyConName
CoreExpr -> m CoreExpr
forall (m :: * -> *) a. Monad m => a -> m a
return (Literal -> CoreExpr
forall b. Literal -> Expr b
Lit (Integer -> Type -> Literal
mkLitInteger Integer
i (TyCon -> Type
mkTyConTy TyCon
t)))
mkNaturalExpr :: MonadThings m => Integer -> m CoreExpr
mkNaturalExpr :: Integer -> m CoreExpr
mkNaturalExpr i :: Integer
i = do TyCon
t <- Name -> m TyCon
forall (m :: * -> *). MonadThings m => Name -> m TyCon
lookupTyCon Name
naturalTyConName
CoreExpr -> m CoreExpr
forall (m :: * -> *) a. Monad m => a -> m a
return (Literal -> CoreExpr
forall b. Literal -> Expr b
Lit (Integer -> Type -> Literal
mkLitNatural Integer
i (TyCon -> Type
mkTyConTy TyCon
t)))
mkFloatExpr :: Float -> CoreExpr
mkFloatExpr :: Float -> CoreExpr
mkFloatExpr f :: Float
f = DataCon -> [CoreExpr] -> CoreExpr
mkCoreConApps DataCon
floatDataCon [Float -> CoreExpr
forall b. Float -> Expr b
mkFloatLitFloat Float
f]
mkDoubleExpr :: Double -> CoreExpr
mkDoubleExpr :: Double -> CoreExpr
mkDoubleExpr d :: Double
d = DataCon -> [CoreExpr] -> CoreExpr
mkCoreConApps DataCon
doubleDataCon [Double -> CoreExpr
forall b. Double -> Expr b
mkDoubleLitDouble Double
d]
mkCharExpr :: Char -> CoreExpr
mkCharExpr :: Char -> CoreExpr
mkCharExpr c :: Char
c = DataCon -> [CoreExpr] -> CoreExpr
mkCoreConApps DataCon
charDataCon [Char -> CoreExpr
forall b. Char -> Expr b
mkCharLit Char
c]
mkStringExpr :: MonadThings m => String -> m CoreExpr
mkStringExprFS :: MonadThings m => FastString -> m CoreExpr
mkStringExpr :: String -> m CoreExpr
mkStringExpr str :: String
str = FastString -> m CoreExpr
forall (m :: * -> *). MonadThings m => FastString -> m CoreExpr
mkStringExprFS (String -> FastString
mkFastString String
str)
mkStringExprFS :: FastString -> m CoreExpr
mkStringExprFS = (Name -> m Var) -> FastString -> m CoreExpr
forall (m :: * -> *).
Monad m =>
(Name -> m Var) -> FastString -> m CoreExpr
mkStringExprFSWith Name -> m Var
forall (m :: * -> *). MonadThings m => Name -> m Var
lookupId
mkStringExprFSWith :: Monad m => (Name -> m Id) -> FastString -> m CoreExpr
mkStringExprFSWith :: (Name -> m Var) -> FastString -> m CoreExpr
mkStringExprFSWith lookupM :: Name -> m Var
lookupM str :: FastString
str
| FastString -> Bool
nullFS FastString
str
= CoreExpr -> m CoreExpr
forall (m :: * -> *) a. Monad m => a -> m a
return (Type -> CoreExpr
mkNilExpr Type
charTy)
| (Char -> Bool) -> String -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all Char -> Bool
safeChar String
chars
= do Var
unpack_id <- Name -> m Var
lookupM Name
unpackCStringName
CoreExpr -> m CoreExpr
forall (m :: * -> *) a. Monad m => a -> m a
return (CoreExpr -> CoreExpr -> CoreExpr
forall b. Expr b -> Expr b -> Expr b
App (Var -> CoreExpr
forall b. Var -> Expr b
Var Var
unpack_id) CoreExpr
forall b. Expr b
lit)
| Bool
otherwise
= do Var
unpack_utf8_id <- Name -> m Var
lookupM Name
unpackCStringUtf8Name
CoreExpr -> m CoreExpr
forall (m :: * -> *) a. Monad m => a -> m a
return (CoreExpr -> CoreExpr -> CoreExpr
forall b. Expr b -> Expr b -> Expr b
App (Var -> CoreExpr
forall b. Var -> Expr b
Var Var
unpack_utf8_id) CoreExpr
forall b. Expr b
lit)
where
chars :: String
chars = FastString -> String
unpackFS FastString
str
safeChar :: Char -> Bool
safeChar c :: Char
c = Char -> Int
ord Char
c Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= 1 Bool -> Bool -> Bool
&& Char -> Int
ord Char
c Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= 0x7F
lit :: Expr b
lit = Literal -> Expr b
forall b. Literal -> Expr b
Lit (ByteString -> Literal
LitString (FastString -> ByteString
fastStringToByteString FastString
str))
mkCoreVarTup :: [Id] -> CoreExpr
mkCoreVarTup :: [Var] -> CoreExpr
mkCoreVarTup ids :: [Var]
ids = [CoreExpr] -> CoreExpr
mkCoreTup ((Var -> CoreExpr) -> [Var] -> [CoreExpr]
forall a b. (a -> b) -> [a] -> [b]
map Var -> CoreExpr
forall b. Var -> Expr b
Var [Var]
ids)
mkCoreVarTupTy :: [Id] -> Type
mkCoreVarTupTy :: [Var] -> Type
mkCoreVarTupTy ids :: [Var]
ids = [Type] -> Type
mkBoxedTupleTy ((Var -> Type) -> [Var] -> [Type]
forall a b. (a -> b) -> [a] -> [b]
map Var -> Type
idType [Var]
ids)
mkCoreTup :: [CoreExpr] -> CoreExpr
mkCoreTup :: [CoreExpr] -> CoreExpr
mkCoreTup [] = Var -> CoreExpr
forall b. Var -> Expr b
Var Var
unitDataConId
mkCoreTup [c :: CoreExpr
c] = CoreExpr
c
mkCoreTup cs :: [CoreExpr]
cs = DataCon -> [CoreExpr] -> CoreExpr
mkCoreConApps (Boxity -> Int -> DataCon
tupleDataCon Boxity
Boxed ([CoreExpr] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [CoreExpr]
cs))
((CoreExpr -> CoreExpr) -> [CoreExpr] -> [CoreExpr]
forall a b. (a -> b) -> [a] -> [b]
map (Type -> CoreExpr
forall b. Type -> Expr b
Type (Type -> CoreExpr) -> (CoreExpr -> Type) -> CoreExpr -> CoreExpr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CoreExpr -> Type
exprType) [CoreExpr]
cs [CoreExpr] -> [CoreExpr] -> [CoreExpr]
forall a. [a] -> [a] -> [a]
++ [CoreExpr]
cs)
mkCoreUbxTup :: [Type] -> [CoreExpr] -> CoreExpr
mkCoreUbxTup :: [Type] -> [CoreExpr] -> CoreExpr
mkCoreUbxTup tys :: [Type]
tys exps :: [CoreExpr]
exps
= ASSERT( tys `equalLength` exps)
DataCon -> [CoreExpr] -> CoreExpr
mkCoreConApps (Boxity -> Int -> DataCon
tupleDataCon Boxity
Unboxed ([Type] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Type]
tys))
((Type -> CoreExpr) -> [Type] -> [CoreExpr]
forall a b. (a -> b) -> [a] -> [b]
map (Type -> CoreExpr
forall b. Type -> Expr b
Type (Type -> CoreExpr) -> (Type -> Type) -> Type -> CoreExpr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HasDebugCallStack => Type -> Type
Type -> Type
getRuntimeRep) [Type]
tys [CoreExpr] -> [CoreExpr] -> [CoreExpr]
forall a. [a] -> [a] -> [a]
++ (Type -> CoreExpr) -> [Type] -> [CoreExpr]
forall a b. (a -> b) -> [a] -> [b]
map Type -> CoreExpr
forall b. Type -> Expr b
Type [Type]
tys [CoreExpr] -> [CoreExpr] -> [CoreExpr]
forall a. [a] -> [a] -> [a]
++ [CoreExpr]
exps)
mkCoreTupBoxity :: Boxity -> [CoreExpr] -> CoreExpr
mkCoreTupBoxity :: Boxity -> [CoreExpr] -> CoreExpr
mkCoreTupBoxity Boxed exps :: [CoreExpr]
exps = [CoreExpr] -> CoreExpr
mkCoreTup [CoreExpr]
exps
mkCoreTupBoxity Unboxed exps :: [CoreExpr]
exps = [Type] -> [CoreExpr] -> CoreExpr
mkCoreUbxTup ((CoreExpr -> Type) -> [CoreExpr] -> [Type]
forall a b. (a -> b) -> [a] -> [b]
map CoreExpr -> Type
exprType [CoreExpr]
exps) [CoreExpr]
exps
mkBigCoreVarTup :: [Id] -> CoreExpr
mkBigCoreVarTup :: [Var] -> CoreExpr
mkBigCoreVarTup ids :: [Var]
ids = [CoreExpr] -> CoreExpr
mkBigCoreTup ((Var -> CoreExpr) -> [Var] -> [CoreExpr]
forall a b. (a -> b) -> [a] -> [b]
map Var -> CoreExpr
forall b. Var -> Expr b
Var [Var]
ids)
mkBigCoreVarTup1 :: [Id] -> CoreExpr
mkBigCoreVarTup1 :: [Var] -> CoreExpr
mkBigCoreVarTup1 [id :: Var
id] = DataCon -> [CoreExpr] -> CoreExpr
mkCoreConApps (Boxity -> Int -> DataCon
tupleDataCon Boxity
Boxed 1)
[Type -> CoreExpr
forall b. Type -> Expr b
Type (Var -> Type
idType Var
id), Var -> CoreExpr
forall b. Var -> Expr b
Var Var
id]
mkBigCoreVarTup1 ids :: [Var]
ids = [CoreExpr] -> CoreExpr
mkBigCoreTup ((Var -> CoreExpr) -> [Var] -> [CoreExpr]
forall a b. (a -> b) -> [a] -> [b]
map Var -> CoreExpr
forall b. Var -> Expr b
Var [Var]
ids)
mkBigCoreVarTupTy :: [Id] -> Type
mkBigCoreVarTupTy :: [Var] -> Type
mkBigCoreVarTupTy ids :: [Var]
ids = [Type] -> Type
mkBigCoreTupTy ((Var -> Type) -> [Var] -> [Type]
forall a b. (a -> b) -> [a] -> [b]
map Var -> Type
idType [Var]
ids)
mkBigCoreTup :: [CoreExpr] -> CoreExpr
mkBigCoreTup :: [CoreExpr] -> CoreExpr
mkBigCoreTup = ([CoreExpr] -> CoreExpr) -> [CoreExpr] -> CoreExpr
forall a. ([a] -> a) -> [a] -> a
mkChunkified [CoreExpr] -> CoreExpr
mkCoreTup
mkBigCoreTupTy :: [Type] -> Type
mkBigCoreTupTy :: [Type] -> Type
mkBigCoreTupTy = ([Type] -> Type) -> [Type] -> Type
forall a. ([a] -> a) -> [a] -> a
mkChunkified [Type] -> Type
mkBoxedTupleTy
unitExpr :: CoreExpr
unitExpr :: CoreExpr
unitExpr = Var -> CoreExpr
forall b. Var -> Expr b
Var Var
unitDataConId
mkTupleSelector, mkTupleSelector1
:: [Id]
-> Id
-> Id
-> CoreExpr
-> CoreExpr
mkTupleSelector :: [Var] -> Var -> Var -> CoreExpr -> CoreExpr
mkTupleSelector vars :: [Var]
vars the_var :: Var
the_var scrut_var :: Var
scrut_var scrut :: CoreExpr
scrut
= [[Var]] -> Var -> CoreExpr
mk_tup_sel ([Var] -> [[Var]]
forall a. [a] -> [[a]]
chunkify [Var]
vars) Var
the_var
where
mk_tup_sel :: [[Var]] -> Var -> CoreExpr
mk_tup_sel [vars :: [Var]
vars] the_var :: Var
the_var = [Var] -> Var -> Var -> CoreExpr -> CoreExpr
mkSmallTupleSelector [Var]
vars Var
the_var Var
scrut_var CoreExpr
scrut
mk_tup_sel vars_s :: [[Var]]
vars_s the_var :: Var
the_var = [Var] -> Var -> Var -> CoreExpr -> CoreExpr
mkSmallTupleSelector [Var]
group Var
the_var Var
tpl_v (CoreExpr -> CoreExpr) -> CoreExpr -> CoreExpr
forall a b. (a -> b) -> a -> b
$
[[Var]] -> Var -> CoreExpr
mk_tup_sel ([Var] -> [[Var]]
forall a. [a] -> [[a]]
chunkify [Var]
tpl_vs) Var
tpl_v
where
tpl_tys :: [Type]
tpl_tys = [[Type] -> Type
mkBoxedTupleTy ((Var -> Type) -> [Var] -> [Type]
forall a b. (a -> b) -> [a] -> [b]
map Var -> Type
idType [Var]
gp) | [Var]
gp <- [[Var]]
vars_s]
tpl_vs :: [Var]
tpl_vs = [Type] -> [Var]
mkTemplateLocals [Type]
tpl_tys
[(tpl_v :: Var
tpl_v, group :: [Var]
group)] = [(Var
tpl,[Var]
gp) | (tpl :: Var
tpl,gp :: [Var]
gp) <- String -> [Var] -> [[Var]] -> [(Var, [Var])]
forall a b. String -> [a] -> [b] -> [(a, b)]
zipEqual "mkTupleSelector" [Var]
tpl_vs [[Var]]
vars_s,
Var
the_var Var -> [Var] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Var]
gp ]
mkTupleSelector1 :: [Var] -> Var -> Var -> CoreExpr -> CoreExpr
mkTupleSelector1 vars :: [Var]
vars the_var :: Var
the_var scrut_var :: Var
scrut_var scrut :: CoreExpr
scrut
| [_] <- [Var]
vars
= [Var] -> Var -> Var -> CoreExpr -> CoreExpr
mkSmallTupleSelector1 [Var]
vars Var
the_var Var
scrut_var CoreExpr
scrut
| Bool
otherwise
= [Var] -> Var -> Var -> CoreExpr -> CoreExpr
mkTupleSelector [Var]
vars Var
the_var Var
scrut_var CoreExpr
scrut
mkSmallTupleSelector, mkSmallTupleSelector1
:: [Id]
-> Id
-> Id
-> CoreExpr
-> CoreExpr
mkSmallTupleSelector :: [Var] -> Var -> Var -> CoreExpr -> CoreExpr
mkSmallTupleSelector [var :: Var
var] should_be_the_same_var :: Var
should_be_the_same_var _ scrut :: CoreExpr
scrut
= ASSERT(var == should_be_the_same_var)
CoreExpr
scrut
mkSmallTupleSelector vars :: [Var]
vars the_var :: Var
the_var scrut_var :: Var
scrut_var scrut :: CoreExpr
scrut
= [Var] -> Var -> Var -> CoreExpr -> CoreExpr
mkSmallTupleSelector1 [Var]
vars Var
the_var Var
scrut_var CoreExpr
scrut
mkSmallTupleSelector1 :: [Var] -> Var -> Var -> CoreExpr -> CoreExpr
mkSmallTupleSelector1 vars :: [Var]
vars the_var :: Var
the_var scrut_var :: Var
scrut_var scrut :: CoreExpr
scrut
= ASSERT( notNull vars )
CoreExpr -> Var -> Type -> [Alt Var] -> CoreExpr
forall b. Expr b -> b -> Type -> [Alt b] -> Expr b
Case CoreExpr
scrut Var
scrut_var (Var -> Type
idType Var
the_var)
[(DataCon -> AltCon
DataAlt (Boxity -> Int -> DataCon
tupleDataCon Boxity
Boxed ([Var] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Var]
vars)), [Var]
vars, Var -> CoreExpr
forall b. Var -> Expr b
Var Var
the_var)]
mkTupleCase :: UniqSupply
-> [Id]
-> CoreExpr
-> Id
-> CoreExpr
-> CoreExpr
mkTupleCase :: UniqSupply -> [Var] -> CoreExpr -> Var -> CoreExpr -> CoreExpr
mkTupleCase uniqs :: UniqSupply
uniqs vars :: [Var]
vars body :: CoreExpr
body scrut_var :: Var
scrut_var scrut :: CoreExpr
scrut
= UniqSupply -> [[Var]] -> CoreExpr -> CoreExpr
mk_tuple_case UniqSupply
uniqs ([Var] -> [[Var]]
forall a. [a] -> [[a]]
chunkify [Var]
vars) CoreExpr
body
where
mk_tuple_case :: UniqSupply -> [[Var]] -> CoreExpr -> CoreExpr
mk_tuple_case _ [vars :: [Var]
vars] body :: CoreExpr
body
= [Var] -> CoreExpr -> Var -> CoreExpr -> CoreExpr
mkSmallTupleCase [Var]
vars CoreExpr
body Var
scrut_var CoreExpr
scrut
mk_tuple_case us :: UniqSupply
us vars_s :: [[Var]]
vars_s body :: CoreExpr
body
= let (us' :: UniqSupply
us', vars' :: [Var]
vars', body' :: CoreExpr
body') = ([Var]
-> (UniqSupply, [Var], CoreExpr) -> (UniqSupply, [Var], CoreExpr))
-> (UniqSupply, [Var], CoreExpr)
-> [[Var]]
-> (UniqSupply, [Var], CoreExpr)
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr [Var]
-> (UniqSupply, [Var], CoreExpr) -> (UniqSupply, [Var], CoreExpr)
one_tuple_case (UniqSupply
us, [], CoreExpr
body) [[Var]]
vars_s
in UniqSupply -> [[Var]] -> CoreExpr -> CoreExpr
mk_tuple_case UniqSupply
us' ([Var] -> [[Var]]
forall a. [a] -> [[a]]
chunkify [Var]
vars') CoreExpr
body'
one_tuple_case :: [Var]
-> (UniqSupply, [Var], CoreExpr) -> (UniqSupply, [Var], CoreExpr)
one_tuple_case chunk_vars :: [Var]
chunk_vars (us :: UniqSupply
us, vs :: [Var]
vs, body :: CoreExpr
body)
= let (uniq :: Unique
uniq, us' :: UniqSupply
us') = UniqSupply -> (Unique, UniqSupply)
takeUniqFromSupply UniqSupply
us
scrut_var :: Var
scrut_var = FastString -> Unique -> Type -> Var
mkSysLocal (String -> FastString
fsLit "ds") Unique
uniq
([Type] -> Type
mkBoxedTupleTy ((Var -> Type) -> [Var] -> [Type]
forall a b. (a -> b) -> [a] -> [b]
map Var -> Type
idType [Var]
chunk_vars))
body' :: CoreExpr
body' = [Var] -> CoreExpr -> Var -> CoreExpr -> CoreExpr
mkSmallTupleCase [Var]
chunk_vars CoreExpr
body Var
scrut_var (Var -> CoreExpr
forall b. Var -> Expr b
Var Var
scrut_var)
in (UniqSupply
us', Var
scrut_varVar -> [Var] -> [Var]
forall a. a -> [a] -> [a]
:[Var]
vs, CoreExpr
body')
mkSmallTupleCase
:: [Id]
-> CoreExpr
-> Id
-> CoreExpr
-> CoreExpr
mkSmallTupleCase :: [Var] -> CoreExpr -> Var -> CoreExpr -> CoreExpr
mkSmallTupleCase [var :: Var
var] body :: CoreExpr
body _scrut_var :: Var
_scrut_var scrut :: CoreExpr
scrut
= Var -> CoreExpr -> CoreExpr -> CoreExpr
bindNonRec Var
var CoreExpr
scrut CoreExpr
body
mkSmallTupleCase vars :: [Var]
vars body :: CoreExpr
body scrut_var :: Var
scrut_var scrut :: CoreExpr
scrut
= CoreExpr -> Var -> Type -> [Alt Var] -> CoreExpr
forall b. Expr b -> b -> Type -> [Alt b] -> Expr b
Case CoreExpr
scrut Var
scrut_var (CoreExpr -> Type
exprType CoreExpr
body)
[(DataCon -> AltCon
DataAlt (Boxity -> Int -> DataCon
tupleDataCon Boxity
Boxed ([Var] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Var]
vars)), [Var]
vars, CoreExpr
body)]
data FloatBind
= FloatLet CoreBind
| FloatCase CoreExpr Id AltCon [Var]
instance Outputable FloatBind where
ppr :: FloatBind -> SDoc
ppr (FloatLet b :: CoreBind
b) = String -> SDoc
text "LET" SDoc -> SDoc -> SDoc
<+> CoreBind -> SDoc
forall a. Outputable a => a -> SDoc
ppr CoreBind
b
ppr (FloatCase e :: CoreExpr
e b :: Var
b c :: AltCon
c bs :: [Var]
bs) = SDoc -> Int -> SDoc -> SDoc
hang (String -> SDoc
text "CASE" SDoc -> SDoc -> SDoc
<+> CoreExpr -> SDoc
forall a. Outputable a => a -> SDoc
ppr CoreExpr
e SDoc -> SDoc -> SDoc
<+> PtrString -> SDoc
ptext (String -> PtrString
sLit "of") SDoc -> SDoc -> SDoc
<+> Var -> SDoc
forall a. Outputable a => a -> SDoc
ppr Var
b)
2 (AltCon -> SDoc
forall a. Outputable a => a -> SDoc
ppr AltCon
c SDoc -> SDoc -> SDoc
<+> [Var] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [Var]
bs)
wrapFloat :: FloatBind -> CoreExpr -> CoreExpr
wrapFloat :: FloatBind -> CoreExpr -> CoreExpr
wrapFloat (FloatLet defns :: CoreBind
defns) body :: CoreExpr
body = CoreBind -> CoreExpr -> CoreExpr
forall b. Bind b -> Expr b -> Expr b
Let CoreBind
defns CoreExpr
body
wrapFloat (FloatCase e :: CoreExpr
e b :: Var
b con :: AltCon
con bs :: [Var]
bs) body :: CoreExpr
body = CoreExpr -> Var -> Type -> [Alt Var] -> CoreExpr
forall b. Expr b -> b -> Type -> [Alt b] -> Expr b
Case CoreExpr
e Var
b (CoreExpr -> Type
exprType CoreExpr
body) [(AltCon
con, [Var]
bs, CoreExpr
body)]
mkNilExpr :: Type -> CoreExpr
mkNilExpr :: Type -> CoreExpr
mkNilExpr ty :: Type
ty = DataCon -> [CoreExpr] -> CoreExpr
mkCoreConApps DataCon
nilDataCon [Type -> CoreExpr
forall b. Type -> Expr b
Type Type
ty]
mkConsExpr :: Type -> CoreExpr -> CoreExpr -> CoreExpr
mkConsExpr :: Type -> CoreExpr -> CoreExpr -> CoreExpr
mkConsExpr ty :: Type
ty hd :: CoreExpr
hd tl :: CoreExpr
tl = DataCon -> [CoreExpr] -> CoreExpr
mkCoreConApps DataCon
consDataCon [Type -> CoreExpr
forall b. Type -> Expr b
Type Type
ty, CoreExpr
hd, CoreExpr
tl]
mkListExpr :: Type -> [CoreExpr] -> CoreExpr
mkListExpr :: Type -> [CoreExpr] -> CoreExpr
mkListExpr ty :: Type
ty xs :: [CoreExpr]
xs = (CoreExpr -> CoreExpr -> CoreExpr)
-> CoreExpr -> [CoreExpr] -> CoreExpr
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (Type -> CoreExpr -> CoreExpr -> CoreExpr
mkConsExpr Type
ty) (Type -> CoreExpr
mkNilExpr Type
ty) [CoreExpr]
xs
mkFoldrExpr :: MonadThings m
=> Type
-> Type
-> CoreExpr
-> CoreExpr
-> CoreExpr
-> m CoreExpr
mkFoldrExpr :: Type -> Type -> CoreExpr -> CoreExpr -> CoreExpr -> m CoreExpr
mkFoldrExpr elt_ty :: Type
elt_ty result_ty :: Type
result_ty c :: CoreExpr
c n :: CoreExpr
n list :: CoreExpr
list = do
Var
foldr_id <- Name -> m Var
forall (m :: * -> *). MonadThings m => Name -> m Var
lookupId Name
foldrName
CoreExpr -> m CoreExpr
forall (m :: * -> *) a. Monad m => a -> m a
return (Var -> CoreExpr
forall b. Var -> Expr b
Var Var
foldr_id CoreExpr -> CoreExpr -> CoreExpr
forall b. Expr b -> Expr b -> Expr b
`App` Type -> CoreExpr
forall b. Type -> Expr b
Type Type
elt_ty
CoreExpr -> CoreExpr -> CoreExpr
forall b. Expr b -> Expr b -> Expr b
`App` Type -> CoreExpr
forall b. Type -> Expr b
Type Type
result_ty
CoreExpr -> CoreExpr -> CoreExpr
forall b. Expr b -> Expr b -> Expr b
`App` CoreExpr
c
CoreExpr -> CoreExpr -> CoreExpr
forall b. Expr b -> Expr b -> Expr b
`App` CoreExpr
n
CoreExpr -> CoreExpr -> CoreExpr
forall b. Expr b -> Expr b -> Expr b
`App` CoreExpr
list)
mkBuildExpr :: (MonadFail.MonadFail m, MonadThings m, MonadUnique m)
=> Type
-> ((Id, Type) -> (Id, Type) -> m CoreExpr)
-> m CoreExpr
mkBuildExpr :: Type -> ((Var, Type) -> (Var, Type) -> m CoreExpr) -> m CoreExpr
mkBuildExpr elt_ty :: Type
elt_ty mk_build_inside :: (Var, Type) -> (Var, Type) -> m CoreExpr
mk_build_inside = do
[n_tyvar :: Var
n_tyvar] <- [Var] -> m [Var]
forall (m :: * -> *). MonadUnique m => [Var] -> m [Var]
newTyVars [Var
alphaTyVar]
let n_ty :: Type
n_ty = Var -> Type
mkTyVarTy Var
n_tyvar
c_ty :: Type
c_ty = [Type] -> Type -> Type
mkFunTys [Type
elt_ty, Type
n_ty] Type
n_ty
[c :: Var
c, n :: Var
n] <- [m Var] -> m [Var]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence [FastString -> Type -> m Var
forall (m :: * -> *). MonadUnique m => FastString -> Type -> m Var
mkSysLocalM (String -> FastString
fsLit "c") Type
c_ty, FastString -> Type -> m Var
forall (m :: * -> *). MonadUnique m => FastString -> Type -> m Var
mkSysLocalM (String -> FastString
fsLit "n") Type
n_ty]
CoreExpr
build_inside <- (Var, Type) -> (Var, Type) -> m CoreExpr
mk_build_inside (Var
c, Type
c_ty) (Var
n, Type
n_ty)
Var
build_id <- Name -> m Var
forall (m :: * -> *). MonadThings m => Name -> m Var
lookupId Name
buildName
CoreExpr -> m CoreExpr
forall (m :: * -> *) a. Monad m => a -> m a
return (CoreExpr -> m CoreExpr) -> CoreExpr -> m CoreExpr
forall a b. (a -> b) -> a -> b
$ Var -> CoreExpr
forall b. Var -> Expr b
Var Var
build_id CoreExpr -> CoreExpr -> CoreExpr
forall b. Expr b -> Expr b -> Expr b
`App` Type -> CoreExpr
forall b. Type -> Expr b
Type Type
elt_ty CoreExpr -> CoreExpr -> CoreExpr
forall b. Expr b -> Expr b -> Expr b
`App` [Var] -> CoreExpr -> CoreExpr
forall b. [b] -> Expr b -> Expr b
mkLams [Var
n_tyvar, Var
c, Var
n] CoreExpr
build_inside
where
newTyVars :: [Var] -> m [Var]
newTyVars tyvar_tmpls :: [Var]
tyvar_tmpls = do
[Unique]
uniqs <- m [Unique]
forall (m :: * -> *). MonadUnique m => m [Unique]
getUniquesM
[Var] -> m [Var]
forall (m :: * -> *) a. Monad m => a -> m a
return ((Var -> Unique -> Var) -> [Var] -> [Unique] -> [Var]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith Var -> Unique -> Var
setTyVarUnique [Var]
tyvar_tmpls [Unique]
uniqs)
mkNothingExpr :: Type -> CoreExpr
mkNothingExpr :: Type -> CoreExpr
mkNothingExpr ty :: Type
ty = DataCon -> [CoreExpr] -> CoreExpr
forall b. DataCon -> [Arg b] -> Arg b
mkConApp DataCon
nothingDataCon [Type -> CoreExpr
forall b. Type -> Expr b
Type Type
ty]
mkJustExpr :: Type -> CoreExpr -> CoreExpr
mkJustExpr :: Type -> CoreExpr -> CoreExpr
mkJustExpr ty :: Type
ty val :: CoreExpr
val = DataCon -> [CoreExpr] -> CoreExpr
forall b. DataCon -> [Arg b] -> Arg b
mkConApp DataCon
justDataCon [Type -> CoreExpr
forall b. Type -> Expr b
Type Type
ty, CoreExpr
val]
mkRuntimeErrorApp
:: Id
-> Type
-> String
-> CoreExpr
mkRuntimeErrorApp :: Var -> Type -> String -> CoreExpr
mkRuntimeErrorApp err_id :: Var
err_id res_ty :: Type
res_ty err_msg :: String
err_msg
= CoreExpr -> [CoreExpr] -> CoreExpr
forall b. Expr b -> [Expr b] -> Expr b
mkApps (Var -> CoreExpr
forall b. Var -> Expr b
Var Var
err_id) [ Type -> CoreExpr
forall b. Type -> Expr b
Type (HasDebugCallStack => Type -> Type
Type -> Type
getRuntimeRep Type
res_ty)
, Type -> CoreExpr
forall b. Type -> Expr b
Type Type
res_ty, CoreExpr
forall b. Expr b
err_string ]
where
err_string :: Expr b
err_string = Literal -> Expr b
forall b. Literal -> Expr b
Lit (String -> Literal
mkLitString String
err_msg)
mkImpossibleExpr :: Type -> CoreExpr
mkImpossibleExpr :: Type -> CoreExpr
mkImpossibleExpr res_ty :: Type
res_ty
= Var -> Type -> String -> CoreExpr
mkRuntimeErrorApp Var
rUNTIME_ERROR_ID Type
res_ty "Impossible case alternative"
errorIds :: [Id]
errorIds :: [Var]
errorIds
= [ Var
rUNTIME_ERROR_ID,
Var
nON_EXHAUSTIVE_GUARDS_ERROR_ID,
Var
nO_METHOD_BINDING_ERROR_ID,
Var
pAT_ERROR_ID,
Var
rEC_CON_ERROR_ID,
Var
rEC_SEL_ERROR_ID,
Var
aBSENT_ERROR_ID,
Var
tYPE_ERROR_ID
]
recSelErrorName, runtimeErrorName, absentErrorName :: Name
recConErrorName, patErrorName :: Name
nonExhaustiveGuardsErrorName, noMethodBindingErrorName :: Name
typeErrorName :: Name
absentSumFieldErrorName :: Name
recSelErrorName :: Name
recSelErrorName = String -> Unique -> Var -> Name
err_nm "recSelError" Unique
recSelErrorIdKey Var
rEC_SEL_ERROR_ID
absentErrorName :: Name
absentErrorName = String -> Unique -> Var -> Name
err_nm "absentError" Unique
absentErrorIdKey Var
aBSENT_ERROR_ID
absentSumFieldErrorName :: Name
absentSumFieldErrorName = String -> Unique -> Var -> Name
err_nm "absentSumFieldError" Unique
absentSumFieldErrorIdKey
Var
aBSENT_SUM_FIELD_ERROR_ID
runtimeErrorName :: Name
runtimeErrorName = String -> Unique -> Var -> Name
err_nm "runtimeError" Unique
runtimeErrorIdKey Var
rUNTIME_ERROR_ID
recConErrorName :: Name
recConErrorName = String -> Unique -> Var -> Name
err_nm "recConError" Unique
recConErrorIdKey Var
rEC_CON_ERROR_ID
patErrorName :: Name
patErrorName = String -> Unique -> Var -> Name
err_nm "patError" Unique
patErrorIdKey Var
pAT_ERROR_ID
typeErrorName :: Name
typeErrorName = String -> Unique -> Var -> Name
err_nm "typeError" Unique
typeErrorIdKey Var
tYPE_ERROR_ID
noMethodBindingErrorName :: Name
noMethodBindingErrorName = String -> Unique -> Var -> Name
err_nm "noMethodBindingError"
Unique
noMethodBindingErrorIdKey Var
nO_METHOD_BINDING_ERROR_ID
nonExhaustiveGuardsErrorName :: Name
nonExhaustiveGuardsErrorName = String -> Unique -> Var -> Name
err_nm "nonExhaustiveGuardsError"
Unique
nonExhaustiveGuardsErrorIdKey Var
nON_EXHAUSTIVE_GUARDS_ERROR_ID
err_nm :: String -> Unique -> Id -> Name
err_nm :: String -> Unique -> Var -> Name
err_nm str :: String
str uniq :: Unique
uniq id :: Var
id = Module -> FastString -> Unique -> Var -> Name
mkWiredInIdName Module
cONTROL_EXCEPTION_BASE (String -> FastString
fsLit String
str) Unique
uniq Var
id
rEC_SEL_ERROR_ID, rUNTIME_ERROR_ID, rEC_CON_ERROR_ID :: Id
pAT_ERROR_ID, nO_METHOD_BINDING_ERROR_ID, nON_EXHAUSTIVE_GUARDS_ERROR_ID :: Id
tYPE_ERROR_ID, aBSENT_ERROR_ID, aBSENT_SUM_FIELD_ERROR_ID :: Id
rEC_SEL_ERROR_ID :: Var
rEC_SEL_ERROR_ID = Name -> Var
mkRuntimeErrorId Name
recSelErrorName
rUNTIME_ERROR_ID :: Var
rUNTIME_ERROR_ID = Name -> Var
mkRuntimeErrorId Name
runtimeErrorName
rEC_CON_ERROR_ID :: Var
rEC_CON_ERROR_ID = Name -> Var
mkRuntimeErrorId Name
recConErrorName
pAT_ERROR_ID :: Var
pAT_ERROR_ID = Name -> Var
mkRuntimeErrorId Name
patErrorName
nO_METHOD_BINDING_ERROR_ID :: Var
nO_METHOD_BINDING_ERROR_ID = Name -> Var
mkRuntimeErrorId Name
noMethodBindingErrorName
nON_EXHAUSTIVE_GUARDS_ERROR_ID :: Var
nON_EXHAUSTIVE_GUARDS_ERROR_ID = Name -> Var
mkRuntimeErrorId Name
nonExhaustiveGuardsErrorName
tYPE_ERROR_ID :: Var
tYPE_ERROR_ID = Name -> Var
mkRuntimeErrorId Name
typeErrorName
aBSENT_SUM_FIELD_ERROR_ID :: Var
aBSENT_SUM_FIELD_ERROR_ID
= Name -> Type -> IdInfo -> Var
mkVanillaGlobalWithInfo Name
absentSumFieldErrorName
([Var] -> Type -> Type
mkSpecForAllTys [Var
alphaTyVar] (Var -> Type
mkTyVarTy Var
alphaTyVar))
(IdInfo
vanillaIdInfo IdInfo -> StrictSig -> IdInfo
`setStrictnessInfo` [Demand] -> DmdResult -> StrictSig
mkClosedStrictSig [] DmdResult
exnRes
IdInfo -> Int -> IdInfo
`setArityInfo` 0
IdInfo -> CafInfo -> IdInfo
`setCafInfo` CafInfo
NoCafRefs)
mkRuntimeErrorId :: Name -> Id
mkRuntimeErrorId :: Name -> Var
mkRuntimeErrorId name :: Name
name
= Name -> Type -> IdInfo -> Var
mkVanillaGlobalWithInfo Name
name Type
runtimeErrorTy IdInfo
bottoming_info
where
bottoming_info :: IdInfo
bottoming_info = IdInfo
vanillaIdInfo IdInfo -> StrictSig -> IdInfo
`setStrictnessInfo` StrictSig
strict_sig
IdInfo -> Int -> IdInfo
`setArityInfo` 1
strict_sig :: StrictSig
strict_sig = [Demand] -> DmdResult -> StrictSig
mkClosedStrictSig [Demand
evalDmd] DmdResult
exnRes
runtimeErrorTy :: Type
runtimeErrorTy :: Type
runtimeErrorTy = [Var] -> Type -> Type
mkSpecForAllTys [Var
runtimeRep1TyVar, Var
openAlphaTyVar]
(Type -> Type -> Type
mkFunTy Type
addrPrimTy Type
openAlphaTy)
aBSENT_ERROR_ID :: Var
aBSENT_ERROR_ID
= Name -> Type -> IdInfo -> Var
mkVanillaGlobalWithInfo Name
absentErrorName Type
absent_ty IdInfo
arity_info
where
absent_ty :: Type
absent_ty = [Var] -> Type -> Type
mkSpecForAllTys [Var
alphaTyVar] (Type -> Type -> Type
mkFunTy Type
addrPrimTy Type
alphaTy)
arity_info :: IdInfo
arity_info = IdInfo
vanillaIdInfo IdInfo -> Int -> IdInfo
`setArityInfo` 1
mkAbsentErrorApp :: Type
-> String
-> CoreExpr
mkAbsentErrorApp :: Type -> String -> CoreExpr
mkAbsentErrorApp res_ty :: Type
res_ty err_msg :: String
err_msg
= CoreExpr -> [CoreExpr] -> CoreExpr
forall b. Expr b -> [Expr b] -> Expr b
mkApps (Var -> CoreExpr
forall b. Var -> Expr b
Var Var
aBSENT_ERROR_ID) [ Type -> CoreExpr
forall b. Type -> Expr b
Type Type
res_ty, CoreExpr
forall b. Expr b
err_string ]
where
err_string :: Expr b
err_string = Literal -> Expr b
forall b. Literal -> Expr b
Lit (String -> Literal
mkLitString String
err_msg)