X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=ghc%2Fcompiler%2FcoreSyn%2FPprCore.lhs;h=a1515a0f3a83497d1a38c41134c2100ae5667b1d;hb=7f668158a743bdcbe1ad6d0c61bbd5a58812ba2a;hp=b98b18fc13e65699d9b8578691ec766b2f17b7ea;hpb=3058c4a9633090cc1c74d1bf99429ef845b2c1bb;p=ghc-hetmet.git diff --git a/ghc/compiler/coreSyn/PprCore.lhs b/ghc/compiler/coreSyn/PprCore.lhs index b98b18f..a1515a0 100644 --- a/ghc/compiler/coreSyn/PprCore.lhs +++ b/ghc/compiler/coreSyn/PprCore.lhs @@ -9,9 +9,9 @@ \begin{code} module PprCore ( - pprCoreExpr, pprParendExpr, pprIdBndr, + pprCoreExpr, pprParendExpr, pprCoreBinding, pprCoreBindings, pprCoreAlt, - pprIdRules, pprCoreRule + pprRules ) where #include "HsVersions.h" @@ -21,26 +21,25 @@ import CostCentre ( pprCostCentreCore ) import Var ( Var ) import Id ( Id, idType, isDataConWorkId_maybe, idLBVarInfo, idArity, idInfo, idInlinePragma, idOccInfo, -#ifdef OLD_STRICTNESS - idDemandInfo, -#endif globalIdDetails, isGlobalId, isExportedId, isSpecPragmaId, idNewDemandInfo ) -import Var ( isTyVar ) +import Var ( TyVar, isTyVar, tyVarKind ) import IdInfo ( IdInfo, megaSeqIdInfo, arityInfo, ppArityInfo, specInfo, pprNewStrictness, workerInfo, ppWorkerInfo, - newStrictnessInfo, cafInfo, ppCafInfo, + newStrictnessInfo, cafInfo, ppCafInfo, specInfoRules + ) + #ifdef OLD_STRICTNESS - cprInfo, ppCprInfo, - strictnessInfo, ppStrictnessInfo, +import Id ( idDemandInfo ) +import IdInfo ( cprInfo, ppCprInfo, strictnessInfo, ppStrictnessInfo ) #endif - ) + import DataCon ( dataConTyCon ) import TyCon ( tupleTyConBoxity, isTupleTyCon ) -import PprType ( pprParendType, pprType, pprTyVarBndr ) +import Type ( pprParendType, pprType, pprParendKind ) import BasicTypes ( tupleParens ) import Util ( lengthIs ) import Outputable @@ -153,11 +152,12 @@ ppr_expr add_par expr@(App fun arg) other -> add_par (hang (pprParendExpr fun) 2 pp_args) } -ppr_expr add_par (Case expr var [(con,args,rhs)]) +ppr_expr add_par (Case expr var ty [(con,args,rhs)]) = add_par $ - sep [sep [ptext SLIT("case") <+> pprCoreExpr expr, + sep [sep [ptext SLIT("case") {- <+> pprParendType ty -} <+> pprCoreExpr expr, + -- Printing the result type is excessive! hsep [ptext SLIT("of"), - ppr_bndr var, + ppr_bndr var, char '{', ppr_case_pat con args ]], @@ -167,9 +167,9 @@ ppr_expr add_par (Case expr var [(con,args,rhs)]) where ppr_bndr = pprBndr CaseBind -ppr_expr add_par (Case expr var alts) +ppr_expr add_par (Case expr var ty alts) = add_par $ - sep [sep [ptext SLIT("case") <+> pprCoreExpr expr, + sep [sep [ptext SLIT("case") {- <+> pprParendType ty -} <+> pprCoreExpr expr, ptext SLIT("of") <+> ppr_bndr var <+> char '{'], nest 2 (sep (punctuate semi (map pprCoreAlt alts))), char '}' @@ -275,7 +275,7 @@ pprCoreBinder LetBind binder pragmas = ppIdInfo binder (idInfo binder) -- Lambda bound type variables are preceded by "@" -pprCoreBinder LambdaBind bndr = pprTypedBinder bndr +pprCoreBinder LambdaBind bndr = parens (pprTypedBinder bndr) -- Case bound things don't get a signature or a herald pprCoreBinder CaseBind bndr = pprUntypedBinder bndr @@ -287,12 +287,17 @@ pprUntypedBinder binder pprTypedBinder binder | isTyVar binder = ptext SLIT("@") <+> pprTyVarBndr binder | otherwise = pprIdBndr binder <+> dcolon <+> pprType (idType binder) - -- The space before the :: is important; it helps the lexer - -- when reading inferfaces. Otherwise it would lex "a::b" as one thing. - -- - -- It's important that the type is parenthesised too, at least when - -- printing interfaces, because we get \ x::(a->b) y::(c->d) -> ... - -- [Jun 2002: interfaces are now binary, so this doesn't matter] + +pprTyVarBndr :: TyVar -> SDoc +pprTyVarBndr tyvar + = getPprStyle $ \ sty -> + if debugStyle sty then + hsep [ppr tyvar, dcolon, pprParendKind kind] + -- See comments with ppDcolon in PprCore.lhs + else + ppr tyvar + where + kind = tyVarKind tyvar -- pprIdBndr does *not* print the type -- When printing any Id binder in debug mode, we print its inline pragma and one-shot-ness @@ -317,7 +322,8 @@ pprIdDetails id | isGlobalId id = ppr (globalIdDetails id) ppIdInfo :: Id -> IdInfo -> SDoc ppIdInfo b info - = hsep [ ppArityInfo a, + = brackets $ + vcat [ ppArityInfo a, ppWorkerInfo (workerInfo info), ppCafInfo (cafInfo info), #ifdef OLD_STRICTNESS @@ -325,7 +331,8 @@ ppIdInfo b info ppCprInfo m, #endif pprNewStrictness (newStrictnessInfo info), - vcat (map (pprCoreRule (ppr b)) (rulesRules p)) + if null rules then empty + else ptext SLIT("RULES:") <+> vcat (map pprRule rules) -- Inline pragma, occ, demand, lbvar info -- printed out with all binders (when debug is on); -- see PprCore.pprIdBndr @@ -336,26 +343,28 @@ ppIdInfo b info s = strictnessInfo info m = cprInfo info #endif - p = specInfo info + rules = specInfoRules (specInfo info) \end{code} \begin{code} -pprIdRules :: [IdCoreRule] -> SDoc -pprIdRules rules = vcat (map pprIdRule rules) +instance Outputable CoreRule where + ppr = pprRule -pprIdRule :: IdCoreRule -> SDoc -pprIdRule (id,rule) = pprCoreRule (ppr id) rule +pprRules :: [CoreRule] -> SDoc +pprRules rules = vcat (map pprRule rules) -pprCoreRule :: SDoc -> CoreRule -> SDoc -pprCoreRule pp_fn (BuiltinRule name _) - = ptext SLIT("Built in rule for") <+> pp_fn <> colon <+> doubleQuotes (ftext name) +pprRule :: CoreRule -> SDoc +pprRule (BuiltinRule { ru_fn = fn, ru_name = name}) + = ptext SLIT("Built in rule for") <+> ppr fn <> colon <+> doubleQuotes (ftext name) -pprCoreRule pp_fn (Rule name act tpl_vars tpl_args rhs) +pprRule (Rule { ru_name = name, ru_act = act, ru_fn = fn, + ru_bndrs = tpl_vars, ru_args = tpl_args, + ru_rhs = rhs }) = doubleQuotes (ftext name) <+> ppr act <+> sep [ ptext SLIT("__forall") <+> braces (sep (map pprTypedBinder tpl_vars)), - nest 2 (pp_fn <+> sep (map pprArg tpl_args)), + nest 2 (ppr fn <+> sep (map pprArg tpl_args)), nest 2 (ptext SLIT("=") <+> pprCoreExpr rhs) ] <+> semi \end{code}