HsBinds(..), HsType(..), HsStmtContext(..),
unguardedRHS, mkSimpleMatch, mkMonoBind, andMonoBindList, placeHolderType
)
-import PrelNames ( )
import RdrName ( RdrName, mkUnqual, nameRdrName, getRdrName )
import RdrHsSyn ( mkHsOpApp, RdrNameMonoBinds, RdrNameHsExpr, RdrNamePat, mkHsDo )
import BasicTypes ( RecFlag(..), Fixity(..), FixityDirection(..)
import PrimOp -- Lots of Names
import SrcLoc ( generatedSrcLoc, SrcLoc )
import TyCon ( TyCon, isNewTyCon, tyConDataCons, isEnumerationTyCon,
- maybeTyConSingleCon, tyConFamilySize
+ maybeTyConSingleCon, tyConFamilySize, tyConTyVars
)
import TcType ( isUnLiftedType, tcEqType, Type )
import TysPrim ( charPrimTy, intPrimTy, wordPrimTy, addrPrimTy,
gen_tag_n_con_monobind (rdr_name, tycon, GenCon2Tag)
| lots_of_constructors
- = mk_FunMonoBind (getSrcLoc tycon) rdr_name
- [([VarPat a_RDR], HsApp getTag_Expr a_Expr)]
+ = mk_FunMonoBind loc rdr_name [([], get_tag_rhs)]
| otherwise
- = mk_FunMonoBind (getSrcLoc tycon) rdr_name (map mk_stuff (tyConDataCons tycon))
+ = mk_FunMonoBind loc rdr_name (map mk_stuff (tyConDataCons tycon))
where
+ loc = getSrcLoc tycon
+
+ -- Give a signature to the bound variable, so
+ -- that the case expression generated by getTag is
+ -- monomorphic. In the push-enter model we get better code.
+ get_tag_rhs = ExprWithTySig
+ (HsLam (mk_match loc [VarPat a_RDR]
+ (HsApp getTag_Expr a_Expr)
+ EmptyBinds))
+ (HsForAllTy Nothing [] con2tag_ty)
+ -- Nothing => implicit quantification
+
+ con2tag_ty = foldl HsAppTy (HsTyVar (getRdrName tycon))
+ [HsTyVar (getRdrName tv) | tv <- tyConTyVars tycon]
+ `HsFunTy`
+ HsTyVar (getRdrName intPrimTyConName)
+
lots_of_constructors = tyConFamilySize tycon > mAX_FAMILY_SIZE_FOR_VEC_RETURNS
mk_stuff :: DataCon -> ([RdrNamePat], RdrNameHsExpr)