import HsSyn ( InPat(..), HsExpr(..), MonoBinds(..),
Match(..), GRHSs(..), Stmt(..), HsLit(..),
- HsBinds(..), HsType(..), HsMatchContext(..),
- unguardedRHS, mkSimpleMatch, mkMonoBind, andMonoBindList
+ HsBinds(..), HsType(..), HsDoContext(..),
+ unguardedRHS, mkSimpleMatch, mkMonoBind, andMonoBindList, placeHolderType
)
import RdrHsSyn ( mkHsOpApp, RdrNameMonoBinds, RdrNameHsExpr, RdrNamePat )
import RdrName ( RdrName, mkUnqual )
import BasicTypes ( RecFlag(..), Fixity(..), FixityDirection(..)
- , maxPrecedence, defaultFixity
+ , maxPrecedence
, Boxity(..)
)
import FieldLabel ( fieldLabelName )
isDataSymOcc, isSymOcc
)
+import HscTypes ( FixityEnv, lookupFixity )
import PrelInfo -- Lots of RdrNames
import SrcLoc ( generatedSrcLoc, SrcLoc )
import TyCon ( TyCon, isNewTyCon, tyConDataCons, isEnumerationTyCon,
maybeTyConSingleCon, tyConFamilySize
)
-import Type ( isUnLiftedType, Type )
+import TcType ( isUnLiftedType, tcEqType, Type )
import TysPrim ( charPrimTy, intPrimTy, wordPrimTy, addrPrimTy,
floatPrimTy, doublePrimTy
)
-import Util ( mapAccumL, zipEqual, zipWithEqual,
+import Util ( mapAccumL, zipEqual, zipWithEqual, isSingleton,
zipWith3Equal, nOfThem )
import Panic ( panic, assertPanic )
-import Maybes ( maybeToBool, orElse )
+import Maybes ( maybeToBool )
import Constants
import List ( partition, intersperse )
-
-#if __GLASGOW_HASKELL__ >= 404
-import GlaExts ( fromInt )
-#endif
\end{code}
%************************************************************************
else -- calc. and compare the tags
[([a_Pat, b_Pat],
untag_Expr tycon [(a_RDR,ah_RDR), (b_RDR,bh_RDR)]
- (cmp_tags_Expr eqH_Int_RDR ah_RDR bh_RDR true_Expr false_Expr))]
+ (genOpApp (HsVar ah_RDR) eqH_Int_RDR (HsVar bh_RDR)))]
in
mk_FunMonoBind tycon_loc eq_RDR ((map pats_etc nonnullary_cons) ++ rest)
`AndMonoBinds`
cmp_eq =
mk_FunMonoBind tycon_loc
cmp_eq_RDR
- (if null nonnullary_cons && (length nullary_cons == 1) then
+ (if null nonnullary_cons && isSingleton nullary_cons then
-- catch this specially to avoid warnings
-- about overlapping patterns from the desugarer.
let
else
map pats_etc nonnullary_cons ++
-- leave out wildcards to silence desugarer.
- (if length tycon_data_cons == 1 then
+ (if isSingleton tycon_data_cons then
[]
else
[([WildPatIn, WildPatIn], default_rhs)]))
-- inexhaustive patterns
| otherwise = eqTag_Expr -- Some nullary constructors;
-- 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 generatedSrcLoc lt_RDR [a_Pat, b_Pat] [] (
- compare_Case true_Expr false_Expr false_Expr a_Expr b_Expr)
-le = mk_easy_FunMonoBind generatedSrcLoc le_RDR [a_Pat, b_Pat] [] (
- compare_Case true_Expr true_Expr false_Expr a_Expr b_Expr)
-ge = mk_easy_FunMonoBind generatedSrcLoc ge_RDR [a_Pat, b_Pat] [] (
- compare_Case false_Expr true_Expr true_Expr a_Expr b_Expr)
-gt = mk_easy_FunMonoBind generatedSrcLoc gt_RDR [a_Pat, b_Pat] [] (
- compare_Case false_Expr false_Expr true_Expr a_Expr b_Expr)
-
-max_ = mk_easy_FunMonoBind generatedSrcLoc max_RDR [a_Pat, b_Pat] [] (
- compare_Case b_Expr a_Expr a_Expr a_Expr b_Expr)
-min_ = mk_easy_FunMonoBind generatedSrcLoc min_RDR [a_Pat, b_Pat] [] (
- compare_Case a_Expr b_Expr b_Expr a_Expr b_Expr)
--}
\end{code}
%************************************************************************
= if isEnumerationTyCon tycon then
min_bound_enum `AndMonoBinds` max_bound_enum
else
- ASSERT(length data_cons == 1)
+ ASSERT(isSingleton data_cons)
min_bound_1con `AndMonoBinds` max_bound_1con
where
data_cons = tyConDataCons tycon
in
HsCase
(genOpApp (HsVar dh_RDR) minusH_RDR (HsVar ah_RDR))
- [mkSimpleMatch [VarPatIn c_RDR] rhs Nothing tycon_loc]
+ [mkSimpleMatch [VarPatIn c_RDR] rhs placeHolderType tycon_loc]
tycon_loc
))
) {-else-} (
%************************************************************************
\begin{code}
-gen_Read_binds :: (Name -> Maybe Fixity) -> TyCon -> RdrNameMonoBinds
+gen_Read_binds :: FixityEnv -> TyCon -> RdrNameMonoBinds
gen_Read_binds get_fixity tycon
= reads_prec `AndMonoBinds` read_list
%************************************************************************
\begin{code}
-gen_Show_binds :: (Name -> Maybe Fixity) -> TyCon -> RdrNameMonoBinds
+gen_Show_binds :: FixityEnv -> TyCon -> RdrNameMonoBinds
gen_Show_binds get_fixity tycon
= shows_prec `AndMonoBinds` show_list
\end{code}
\begin{code}
-getLRPrecs :: Bool -> (Name -> Maybe Fixity) -> Name -> [Integer]
+getLRPrecs :: Bool -> FixityEnv -> Name -> [Integer]
getLRPrecs is_infix get_fixity nm = [lp, rp]
where
{-
| otherwise = paren_con_prec + 1
defaultPrecedence :: Integer
-defaultPrecedence = fromInt maxPrecedence
+defaultPrecedence = fromIntegral maxPrecedence
-getPrecedence :: (Name -> Maybe Fixity) -> Name -> Integer
+getPrecedence :: FixityEnv -> Name -> Integer
getPrecedence get_fixity nm
- = case get_fixity nm of
- Just (Fixity x _) -> fromInt x
- other -> defaultPrecedence
+ = case lookupFixity get_fixity nm of
+ Fixity x _ -> fromIntegral x
-isLRAssoc :: (Name -> Maybe Fixity) -> Name -> (Bool, Bool)
+isLRAssoc :: FixityEnv -> Name -> (Bool, Bool)
isLRAssoc get_fixity nm =
- case get_fixity nm `orElse` defaultFixity of
+ case lookupFixity get_fixity nm of
Fixity _ InfixN -> (False, False)
Fixity _ InfixR -> (False, True)
Fixity _ InfixL -> (True, False)
-
-isInfixOccName :: String -> Bool
-isInfixOccName str =
- case str of
- (':':_) -> True
- _ -> False
\end{code}
loc
mk_match loc pats expr binds
- = Match [] (map paren pats) Nothing
- (GRHSs (unguardedRHS expr loc) binds Nothing)
+ = Match (map paren pats) Nothing
+ (GRHSs (unguardedRHS expr loc) binds placeHolderType)
where
paren p@(VarPatIn _) = p
paren other_p = ParPatIn other_p
ToDo: Better SrcLocs.
\begin{code}
-compare_Case ::
- RdrNameHsExpr -> RdrNameHsExpr -> RdrNameHsExpr
- -> RdrNameHsExpr -> RdrNameHsExpr
- -> RdrNameHsExpr
compare_gen_Case ::
RdrName
-> RdrNameHsExpr -> RdrNameHsExpr -> RdrNameHsExpr
-> RdrNameHsExpr -> RdrNameHsExpr
-> RdrNameHsExpr
-compare_Case = compare_gen_Case compare_RDR
cmp_eq_Expr a b = HsApp (HsApp (HsVar cmp_eq_RDR) a) b
-- Was: compare_gen_Case cmp_eq_RDR
compare_gen_Case fun lt eq gt a b
= HsCase (HsPar (HsApp (HsApp (HsVar fun) a) b)) {-of-}
- [mkSimpleMatch [ConPatIn ltTag_RDR []] lt Nothing generatedSrcLoc,
- mkSimpleMatch [ConPatIn eqTag_RDR []] eq Nothing generatedSrcLoc,
- mkSimpleMatch [ConPatIn gtTag_RDR []] gt Nothing generatedSrcLoc]
+ [mkSimpleMatch [ConPatIn ltTag_RDR []] lt placeHolderType generatedSrcLoc,
+ mkSimpleMatch [ConPatIn eqTag_RDR []] eq placeHolderType generatedSrcLoc,
+ mkSimpleMatch [ConPatIn gtTag_RDR []] gt placeHolderType generatedSrcLoc]
generatedSrcLoc
careful_compare_Case ty lt eq gt a b
- = if not (isUnLiftedType ty) then
+ | not (isUnLiftedType ty) =
compare_gen_Case compare_RDR lt eq gt a b
-
- else -- we have to do something special for primitive things...
+ | otherwise =
+ -- we have to do something special for primitive things...
HsIf (genOpApp a relevant_eq_op b)
eq
(HsIf (genOpApp a relevant_lt_op b) lt gt generatedSrcLoc)
= if null res then panic "assoc_ty"
else head res
where
- res = [id | (ty',id) <- tyids, ty == ty']
+ res = [id | (ty',id) <- tyids, ty `tcEqType` ty']
eq_op_tbl =
[(charPrimTy, eqH_Char_RDR)
-----------------------------------------------------------------------
eq_Expr :: Type -> RdrNameHsExpr -> RdrNameHsExpr -> RdrNameHsExpr
-eq_Expr ty a b
- = if not (isUnLiftedType ty) then
- genOpApp a eq_RDR b
- else -- we have to do something special for primitive things...
- genOpApp a relevant_eq_op b
- where
- relevant_eq_op = assoc_ty_id eq_op_tbl ty
+eq_Expr ty a b = genOpApp a eq_op b
+ where
+ eq_op
+ | not (isUnLiftedType ty) = eq_RDR
+ | otherwise =
+ -- we have to do something special for primitive things...
+ assoc_ty_id eq_op_tbl ty
+
\end{code}
\begin{code}
untag_Expr tycon [] expr = expr
untag_Expr tycon ((untag_this, put_tag_here) : more) expr
= HsCase (HsPar (HsApp (con2tag_Expr tycon) (HsVar untag_this))) {-of-}
- [mkSimpleMatch [VarPatIn put_tag_here] (untag_Expr tycon more expr) Nothing generatedSrcLoc]
+ [mkSimpleMatch [VarPatIn put_tag_here] (untag_Expr tycon more expr) placeHolderType generatedSrcLoc]
generatedSrcLoc
cmp_tags_Expr :: RdrName -- Comparison op
qual_orig_name n = nameRdrName (getName n)
varUnqual n = mkUnqual varName n
-zz_a_RDR = varUnqual SLIT("_a")
-a_RDR = varUnqual SLIT("a")
-b_RDR = varUnqual SLIT("b")
-c_RDR = varUnqual SLIT("c")
-d_RDR = varUnqual SLIT("d")
-ah_RDR = varUnqual SLIT("a#")
-bh_RDR = varUnqual SLIT("b#")
-ch_RDR = varUnqual SLIT("c#")
-dh_RDR = varUnqual SLIT("d#")
-cmp_eq_RDR = varUnqual SLIT("cmp_eq")
-rangeSize_RDR = varUnqual SLIT("rangeSize")
+zz_a_RDR = varUnqual FSLIT("_a")
+a_RDR = varUnqual FSLIT("a")
+b_RDR = varUnqual FSLIT("b")
+c_RDR = varUnqual FSLIT("c")
+d_RDR = varUnqual FSLIT("d")
+ah_RDR = varUnqual FSLIT("a#")
+bh_RDR = varUnqual FSLIT("b#")
+ch_RDR = varUnqual FSLIT("c#")
+dh_RDR = varUnqual FSLIT("d#")
+cmp_eq_RDR = varUnqual FSLIT("cmp_eq")
+rangeSize_RDR = varUnqual FSLIT("rangeSize")
as_RDRs = [ varUnqual (_PK_ ("a"++show i)) | i <- [(1::Int) .. ] ]
bs_RDRs = [ varUnqual (_PK_ ("b"++show i)) | i <- [(1::Int) .. ] ]