import HsSyn ( InPat(..), HsExpr(..), MonoBinds(..),
Match(..), GRHSs(..), Stmt(..), HsLit(..),
- HsBinds(..), StmtCtxt(..),
+ HsBinds(..), StmtCtxt(..), HsType(..),
unguardedRHS, mkSimpleMatch
)
import RdrHsSyn ( mkOpApp, RdrNameMonoBinds, RdrNameHsExpr, RdrNamePat )
import PrelInfo -- Lots of RdrNames
import SrcLoc ( mkGeneratedSrcLoc, SrcLoc )
import TyCon ( TyCon, isNewTyCon, tyConDataCons, isEnumerationTyCon,
- maybeTyConSingleCon
+ maybeTyConSingleCon, tyConFamilySize
)
import Type ( isUnLiftedType, isUnboxedType, Type )
import TysPrim ( charPrimTy, intPrimTy, wordPrimTy, addrPrimTy,
zipWith3Equal, nOfThem )
import Panic ( panic, assertPanic )
import Maybes ( maybeToBool, assocMaybe )
+import Constants
import List ( partition, intersperse )
\end{code}
gen_Ord_binds :: TyCon -> RdrNameMonoBinds
gen_Ord_binds tycon
- = defaulted `AndMonoBinds` compare
+ = compare -- `AndMonoBinds` compare
+ -- The default declaration in PrelBase handles this
where
tycon_loc = getSrcLoc tycon
--------------------------------------------------------------------
-- Tags are equal, no args => return EQ
--------------------------------------------------------------------
+{- Not necessary: the default decls in PrelBase handle these
+
defaulted = foldr1 AndMonoBinds [lt, le, ge, gt, max_, min_]
lt = mk_easy_FunMonoBind mkGeneratedSrcLoc lt_RDR [a_Pat, b_Pat] [] (
compare_Case b_Expr a_Expr a_Expr a_Expr b_Expr)
min_ = mk_easy_FunMonoBind mkGeneratedSrcLoc min_RDR [a_Pat, b_Pat] [] (
compare_Case a_Expr b_Expr b_Expr a_Expr b_Expr)
+-}
\end{code}
%************************************************************************
])
| lab_fields == 0 = -- common case.
snd (mapAccumL mk_qual
- c_Expr
+ d_Expr
(zipWithEqual "as_needed"
(\ con_field draw_from -> (mk_read_qual 10 con_field,
draw_from))
as_needed bs_needed))
| otherwise =
snd $
- mapAccumL mk_qual c_Expr
+ mapAccumL mk_qual d_Expr
(zipEqual "bs_needed"
((str_qual "{":
concat (
| not is_infix = 9
| otherwise = getFixity fixities dc_nm
- read_paren_arg = -- parens depend on precedence...
- HsPar (genOpApp a_Expr gt_RDR (HsLit (HsInt paren_prec_limit)))
+ read_paren_arg -- parens depend on precedence...
+ | nullary_con = false_Expr -- it's optional.
+ | otherwise = HsPar (genOpApp a_Expr gt_RDR (HsLit (HsInt paren_prec_limit)))
\end{code}
-> RdrNameMonoBinds
gen_tag_n_con_monobind (rdr_name, tycon, GenCon2Tag)
+ | lots_of_constructors
+ = mk_FunMonoBind (getSrcLoc tycon) rdr_name
+ [([VarPatIn a_RDR], HsApp getTag_Expr a_Expr)]
+
+ | otherwise
= mk_FunMonoBind (getSrcLoc tycon) rdr_name (map mk_stuff (tyConDataCons tycon))
+
where
- mk_stuff :: DataCon -> ([RdrNamePat], RdrNameHsExpr)
+ lots_of_constructors = tyConFamilySize tycon > mAX_FAMILY_SIZE_FOR_VEC_RETURNS
+ mk_stuff :: DataCon -> ([RdrNamePat], RdrNameHsExpr)
mk_stuff var
= ([pat], HsLit (HsIntPrim (toInteger ((dataConTag var) - fIRST_TAG))))
where
var_RDR = qual_orig_name var
gen_tag_n_con_monobind (rdr_name, tycon, GenTag2Con)
- = mk_FunMonoBind (getSrcLoc tycon) rdr_name (map mk_stuff (tyConDataCons tycon) ++
- [([WildPatIn], impossible_Expr)])
- where
- mk_stuff :: DataCon -> ([RdrNamePat], RdrNameHsExpr)
- mk_stuff var = ([lit_pat], HsVar var_RDR)
- where
- lit_pat = ConPatIn mkInt_RDR [LitPatIn (HsIntPrim (toInteger ((dataConTag var) - fIRST_TAG)))]
- var_RDR = qual_orig_name var
+ = mk_FunMonoBind (getSrcLoc tycon) rdr_name
+ [([ConPatIn mkInt_RDR [VarPatIn a_RDR]],
+ ExprWithTySig (HsApp tagToEnum_Expr a_Expr)
+ (MonoTyVar (qual_orig_name tycon)))]
gen_tag_n_con_monobind (rdr_name, tycon, GenMaxTag)
= mk_easy_FunMonoBind (getSrcLoc tycon)
false_Expr = HsVar false_RDR
true_Expr = HsVar true_RDR
+getTag_Expr = HsVar getTag_RDR
+tagToEnum_Expr = HsVar tagToEnumH_RDR
con2tag_Expr tycon = HsVar (con2tag_RDR tycon)
a_Pat = VarPatIn a_RDR