X-Git-Url: http://git.megacz.com/?p=ghc-hetmet.git;a=blobdiff_plain;f=compiler%2FdeSugar%2FMatch.lhs;h=ca18706f229fc388cf5ca19e83cf3e96688ee801;hp=d793343e4177b8ec2180e7420265ab8d05fcc8c6;hb=a8427a4125e9b78e88a487eeabf018f1c6e8bc08;hpb=3cec5683766a13019c2835a4e79cc7e7dc066b96 diff --git a/compiler/deSugar/Match.lhs b/compiler/deSugar/Match.lhs index d793343..ca18706 100644 --- a/compiler/deSugar/Match.lhs +++ b/compiler/deSugar/Match.lhs @@ -1,40 +1,39 @@ % +% (c) The University of Glasgow 2006 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1998 % -\section[Main_match]{The @match@ function} + +The @match@ function \begin{code} module Match ( match, matchEquations, matchWrapper, matchSimply, matchSinglePat ) where #include "HsVersions.h" -import DynFlags ( DynFlag(..), dopt ) +import DynFlags import HsSyn -import TcHsSyn ( mkVanillaTuplePat, hsPatType ) -import Check ( check, ExhaustivePat ) +import TcHsSyn +import Check import CoreSyn -import Literal ( Literal ) -import CoreUtils ( bindNonRec, exprType ) +import Literal +import CoreUtils import DsMonad -import DsBinds ( dsLHsBinds, dsCoercion ) -import DsGRHSs ( dsGRHSs ) +import DsBinds +import DsGRHSs import DsUtils -import Id ( idName, idType, Id ) -import DataCon ( DataCon ) -import MatchCon ( matchConFamily ) -import MatchLit ( matchLiterals, matchNPlusKPats, matchNPats, - tidyLitPat, tidyNPat, hsLitKey, hsOverLitKey ) -import PrelInfo ( pAT_ERROR_ID ) -import TcType ( Type ) -import Type ( splitFunTysN, coreEqType ) -import TysWiredIn ( consDataCon, mkListTy, unitTy, - tupleCon, parrFakeCon, mkPArrTy ) -import BasicTypes ( Boxity(..) ) -import ListSetOps ( equivClasses, runs ) -import SrcLoc ( unLoc, Located(..) ) -import Maybes ( isJust ) -import Util ( lengthExceeds, notNull ) -import Name ( Name ) +import Id +import DataCon +import MatchCon +import MatchLit +import PrelInfo +import Type +import TysWiredIn +import BasicTypes +import ListSetOps +import SrcLoc +import Maybes +import Util +import Name import Outputable \end{code} @@ -124,8 +123,8 @@ pp_context (DsMatchContext kind _loc) msg rest_of_msg_fun where (ppr_match, pref) = case kind of - FunRhs fun -> (pprMatchContext kind, \ pp -> ppr fun <+> pp) - other -> (pprMatchContext kind, \ pp -> pp) + FunRhs fun _ -> (pprMatchContext kind, \ pp -> ppr fun <+> pp) + other -> (pprMatchContext kind, \ pp -> pp) ppr_pats pats = sep (map ppr pats) @@ -254,7 +253,7 @@ match :: [Id] -- Variables rep'ing the exprs we're matching with -> DsM MatchResult -- Desugared result! match [] ty eqns - = ASSERT( not (null eqns) ) + = ASSERT2( not (null eqns), ppr ty ) returnDs (foldr1 combineMatchResults match_results) where match_results = [ ASSERT( null (eqn_pats eqn) ) @@ -392,7 +391,7 @@ tidy1 :: Id -- The Id being scrutinised tidy1 v (ParPat pat) = tidy1 v (unLoc pat) tidy1 v (SigPatOut pat _) = tidy1 v (unLoc pat) -tidy1 v (WildPat ty) = returnDs (idWrapper, WildPat ty) +tidy1 v (WildPat ty) = returnDs (idDsWrapper, WildPat ty) -- case v of { x -> mr[] } -- = case v of { _ -> let x=v in mr[] } @@ -427,7 +426,7 @@ tidy1 v (LazyPat pat) ; returnDs (mkDsLets sel_binds, WildPat (idType v)) } tidy1 v (ListPat pats ty) - = returnDs (idWrapper, unLoc list_ConPat) + = returnDs (idDsWrapper, unLoc list_ConPat) where list_ty = mkListTy ty list_ConPat = foldr (\ x y -> mkPrefixConPat consDataCon [x, y] list_ty) @@ -437,38 +436,29 @@ tidy1 v (ListPat pats ty) -- Introduce fake parallel array constructors to be able to handle parallel -- arrays with the existing machinery for constructor pattern tidy1 v (PArrPat pats ty) - = returnDs (idWrapper, unLoc parrConPat) + = returnDs (idDsWrapper, unLoc parrConPat) where arity = length pats parrConPat = mkPrefixConPat (parrFakeCon arity) pats (mkPArrTy ty) tidy1 v (TuplePat pats boxity ty) - = returnDs (idWrapper, unLoc tuple_ConPat) + = returnDs (idDsWrapper, unLoc tuple_ConPat) where arity = length pats tuple_ConPat = mkPrefixConPat (tupleCon boxity arity) pats ty -tidy1 v (DictPat dicts methods) - = case num_of_d_and_ms of - 0 -> tidy1 v (TuplePat [] Boxed unitTy) - 1 -> tidy1 v (unLoc (head dict_and_method_pats)) - _ -> tidy1 v (mkVanillaTuplePat dict_and_method_pats Boxed) - where - num_of_d_and_ms = length dicts + length methods - dict_and_method_pats = map nlVarPat (dicts ++ methods) - -- LitPats: we *might* be able to replace these w/ a simpler form tidy1 v (LitPat lit) - = returnDs (idWrapper, tidyLitPat lit) + = returnDs (idDsWrapper, tidyLitPat lit) -- NPats: we *might* be able to replace these w/ a simpler form tidy1 v (NPat lit mb_neg eq lit_ty) - = returnDs (idWrapper, tidyNPat lit mb_neg eq lit_ty) + = returnDs (idDsWrapper, tidyNPat lit mb_neg eq lit_ty) -- Everything else goes through unchanged... tidy1 v non_interesting_pat - = returnDs (idWrapper, non_interesting_pat) + = returnDs (idDsWrapper, non_interesting_pat) \end{code} \noindent @@ -610,7 +600,8 @@ JJQC 30-Nov-1997 \begin{code} matchWrapper ctxt (MatchGroup matches match_ty) - = do { eqns_info <- mapM mk_eqn_info matches + = ASSERT( notNull matches ) + do { eqns_info <- mapM mk_eqn_info matches ; new_vars <- selectMatchVars arg_pats ; result_expr <- matchEquations ctxt new_vars eqns_info rhs_ty ; return (new_vars, result_expr) } @@ -715,6 +706,9 @@ data PatGroup groupEquations :: [EquationInfo] -> [[(PatGroup, EquationInfo)]] +-- If the result is of form [g1, g2, g3], +-- (a) all the (pg,eq) pairs in g1 have the same pg +-- (b) none of the gi are empty groupEquations eqns = runs same_gp [(patGroup (firstPat eqn), eqn) | eqn <- eqns] where