Simon's big boxy-type commit
[ghc-hetmet.git] / ghc / compiler / coreSyn / PprCore.lhs
index 2d62772..e20d5ee 100644 (file)
@@ -9,9 +9,9 @@
 
 \begin{code}
 module PprCore (
-       pprCoreExpr, pprParendExpr, pprIdBndr,
+       pprCoreExpr, pprParendExpr,
        pprCoreBinding, pprCoreBindings, pprCoreAlt,
-       pprIdRules, pprCoreRule
+       pprRules
     ) where
 
 #include "HsVersions.h"
@@ -19,29 +19,28 @@ module PprCore (
 import CoreSyn
 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 Id              ( Id, idType, isDataConWorkId_maybe, idArity,
+                         idInfo, globalIdDetails, isGlobalId, isExportedId 
                        )
-import Var             ( isTyVar )
+import Var             ( TyVar, isTyVar, tyVarKind )
 import IdInfo          ( IdInfo, megaSeqIdInfo, 
+                         inlinePragInfo, occInfo, newDemandInfo, 
+                         lbvarInfo, hasNoLBVarInfo,
                          arityInfo, ppArityInfo, 
                          specInfo, pprNewStrictness,
                          workerInfo, ppWorkerInfo,
-                         newStrictnessInfo, cafInfo, ppCafInfo,
+                         newStrictnessInfo, cafInfo, ppCafInfo, specInfoRules
+                       )
+import NewDemand       ( isTop )
 #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 BasicTypes      ( tupleParens )
+import Type            ( pprParendType, pprType, pprParendKind )
+import BasicTypes      ( tupleParens, isNoOcc, isAlwaysActive )
 import Util             ( lengthIs )
 import Outputable
 import FastString       ( mkFastString )
@@ -102,7 +101,7 @@ ppr_bind (Rec binds)               = vcat (map pp binds)
 ppr_binding :: OutputableBndr b => (b, Expr b) -> SDoc
 ppr_binding (val_bdr, expr)
   = pprBndr LetBind val_bdr $$ 
-    (ppr val_bdr <+> equals <+> pprCoreExpr expr)
+    hang (ppr val_bdr <+> equals) 2 (pprCoreExpr expr)
 \end{code}
 
 \begin{code}
@@ -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 '}'
@@ -258,8 +258,6 @@ ppr_case_pat con args
 
 pprArg (Type ty) = ptext SLIT("@") <+> pprParendType ty
 pprArg expr      = pprParendExpr expr
-
-arrow = ptext SLIT("->")
 \end{code}
 
 Other printing bits-and-bobs used with the general @pprCoreBinding@
@@ -277,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
@@ -289,24 +287,42 @@ 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
-pprIdBndr id = ppr id <+> 
-              (megaSeqIdInfo (idInfo id) `seq`
-                       -- Useful for poking on black holes
-               ifPprDebug (ppr (idInlinePragma id) <+> ppr (idOccInfo id) <+> 
+pprIdBndr id = ppr id <+> pprIdBndrInfo (idInfo id)
+
+pprIdBndrInfo info 
+  = megaSeqIdInfo `seq` doc -- The seq is useful for poking on black holes
+  where
+    prag_info = inlinePragInfo info
+    occ_info  = occInfo info
+    dmd_info  = newDemandInfo info
+    lbv_info  = lbvarInfo info
+
+    no_info = isAlwaysActive prag_info && isNoOcc occ_info && 
+             (case dmd_info of { Nothing -> True; Just d -> isTop d }) &&
+             hasNoLBVarInfo lbv_info
+
+    doc | no_info = empty
+       | otherwise
+        = brackets $ hcat [ppr prag_info, ppr occ_info, 
+                          ppr dmd_info, ppr lbv_info
 #ifdef OLD_STRICTNESS
-                           ppr (idDemandInfo id) <+>
+                          , ppr (demandInfo id)
 #endif
-                           ppr (idNewDemandInfo id) <+>
-                           ppr (idLBVarInfo id)))
+                         ]
 \end{code}
 
 
@@ -314,12 +330,12 @@ pprIdBndr id = ppr id <+>
 pprIdDetails :: Id -> SDoc
 pprIdDetails id | isGlobalId id     = ppr (globalIdDetails id)
                | isExportedId id   = ptext SLIT("[Exported]")
-               | isSpecPragmaId id = ptext SLIT("[SpecPrag]")
                | otherwise         = empty
 
 ppIdInfo :: Id -> IdInfo -> SDoc
 ppIdInfo b info
-  = hsep [  ppArityInfo a,
+  = brackets $
+    vcat [  ppArityInfo a,
            ppWorkerInfo (workerInfo info),
            ppCafInfo (cafInfo info),
 #ifdef OLD_STRICTNESS
@@ -327,7 +343,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
@@ -338,27 +355,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 _)
-  = ifPprDebug (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}