[project @ 2001-03-19 16:20:44 by simonpj]
[ghc-hetmet.git] / ghc / compiler / coreSyn / CoreLint.lhs
index 6f7ad36..c5315ec 100644 (file)
@@ -7,7 +7,7 @@
 module CoreLint (
        lintCoreBindings,
        lintUnfolding, 
-       beginPass, endPass, endPassWithRules
+       showPass, endPass, endPassWithRules
     ) where
 
 #include "HsVersions.h"
@@ -16,29 +16,29 @@ import IO           ( hPutStr, hPutStrLn, stdout )
 
 import CoreSyn
 import Rules            ( RuleBase, pprRuleBase )
-import CoreFVs         ( idFreeVars, mustHaveLocalBinding )
+import CoreFVs         ( idFreeVars )
 import CoreUtils       ( exprOkForSpeculation, coreBindsSize, mkPiType )
 
 import Bag
 import Literal         ( literalType )
 import DataCon         ( dataConRepType )
-import Var             ( Var, Id, TyVar, idType, tyVarKind, isTyVar, isId )
+import Var             ( Var, Id, TyVar, idType, tyVarKind, isTyVar, isId, mustHaveLocalBinding )
 import VarSet
 import Subst           ( mkTyVarSubst, substTy )
 import Name            ( getSrcLoc )
 import PprCore
-import ErrUtils                ( doIfSet_dyn, dumpIfSet, ghcExit, Message, 
+import ErrUtils                ( doIfSet, dumpIfSet_core, ghcExit, Message, showPass,
                          ErrMsg, addErrLocHdrLine, pprBagOfErrors,
                           WarnMsg, pprBagOfWarnings)
 import SrcLoc          ( SrcLoc, noSrcLoc )
 import Type            ( Type, tyVarsOfType,
                          splitFunTy_maybe, mkTyVarTy,
-                         splitForAllTy_maybe, splitTyConApp_maybe,
+                         splitForAllTy_maybe, splitTyConApp_maybe, splitTyConApp,
                          isUnLiftedType, typeKind, 
                          isUnboxedTupleType,
                          hasMoreBoxityInfo
                        )
-import TyCon           ( TyCon, isPrimTyCon, tyConDataCons )
+import TyCon           ( isPrimTyCon )
 import BasicTypes      ( RecFlag(..), isNonRec )
 import CmdLineOpts
 import Maybe
@@ -58,21 +58,14 @@ place for them.  They print out stuff before and after core passes,
 and do Core Lint when necessary.
 
 \begin{code}
-beginPass :: DynFlags -> String -> IO ()
-beginPass dflags pass_name
-  | dopt Opt_D_show_passes dflags
-  = hPutStrLn stdout ("*** " ++ pass_name)
-  | otherwise
-  = return ()
-
-
-endPass :: DynFlags -> String -> Bool -> [CoreBind] -> IO [CoreBind]
+endPass :: DynFlags -> String -> DynFlag -> [CoreBind] -> IO [CoreBind]
 endPass dflags pass_name dump_flag binds
   = do  
         (binds, _) <- endPassWithRules dflags pass_name dump_flag binds Nothing
         return binds
 
-endPassWithRules :: DynFlags -> String -> Bool -> [CoreBind] -> Maybe RuleBase
+endPassWithRules :: DynFlags -> String -> DynFlag -> [CoreBind] 
+                -> Maybe RuleBase
                  -> IO ([CoreBind], Maybe RuleBase)
 endPassWithRules dflags pass_name dump_flag binds rules
   = do 
@@ -80,13 +73,13 @@ endPassWithRules dflags pass_name dump_flag binds rules
 
        -- Report result size if required
        -- This has the side effect of forcing the intermediate to be evaluated
-       if dopt Opt_D_show_passes dflags then
+       if verbosity dflags >= 2 then
           hPutStrLn stdout ("    Result size = " ++ show (coreBindsSize binds))
         else
           return ()
 
        -- Report verbosely, if required
-       dumpIfSet dump_flag pass_name
+       dumpIfSet_core dflags dump_flag pass_name
                  (pprCoreBindings binds $$ case rules of
                                               Nothing -> empty
                                               Just rb -> pprRuleBase rb)
@@ -156,7 +149,7 @@ lintCoreBindings dflags whoDunnit binds
                                  returnL ()
     lint_bind (NonRec bndr rhs) = lintSingleBinding NonRecursive (bndr,rhs)
 
-    done_lint = doIfSet_dyn dflags (dopt Opt_D_show_passes)
+    done_lint = doIfSet (verbosity dflags >= 2)
                        (hPutStr stdout ("*** Core Linted result of " ++ whoDunnit ++ "\n"))
     warn warnings
       = vcat [
@@ -474,7 +467,7 @@ lintCoreAlt scrut_ty alt@(DataAlt con, args, rhs)
        -- Scrutinee type must be a tycon applicn; checked by caller
        -- This code is remarkably compact considering what it does!
        -- NB: args must be in scope here so that the lintCoreArgs line works.
-    case splitTyConApp_maybe scrut_ty of { Just (tycon, tycon_arg_tys) ->
+    case splitTyConApp scrut_ty of { (tycon, tycon_arg_tys) ->
        lintTyApps (dataConRepType con) tycon_arg_tys   `thenL` \ con_type ->
        lintCoreArgs con_type (map mk_arg args)         `thenL` \ con_result_ty ->
        checkTys con_result_ty scrut_ty (mkBadPatMsg con_result_ty scrut_ty)