In an AbsBinds, the 'dicts' can include EqInsts
[ghc-hetmet.git] / compiler / main / TidyPgm.lhs
index b95d4d3..a1a049a 100644 (file)
@@ -4,6 +4,13 @@
 \section{Tidying up Core}
 
 \begin{code}
+{-# OPTIONS -w #-}
+-- The above warning supression flag is a temporary kludge.
+-- While working on this module you are encouraged to remove it and fix
+-- any warnings in the module. See
+--     http://hackage.haskell.org/trac/ghc/wiki/Commentary/CodingStyle#Warnings
+-- for details
+
 module TidyPgm( mkBootModDetails, tidyProgram ) where
 
 #include "HsVersions.h"
@@ -21,16 +28,14 @@ import VarSet
 import Var             ( Id, Var )
 import Id              ( idType, idInfo, idName, idCoreRules, isGlobalId,
                          isExportedId, mkVanillaGlobal, isLocalId, isNaughtyRecordSelector,
-                         idArity, idCafInfo, idUnfolding, isImplicitId, setIdInfo
+                         idArity, idCafInfo, idUnfolding, isImplicitId, setIdInfo,
+                         isTickBoxOp
                        ) 
 import IdInfo          {- loads of stuff -}
 import InstEnv         ( Instance, DFunId, instanceDFunId, setInstanceDFunId )
 import NewDemand       ( isBottomingSig, topSig )
 import BasicTypes      ( Arity, isNeverActive, isNonRuleLoopBreaker )
-import Name            ( Name, getOccName, nameOccName, mkInternalName,
-                         localiseName, isExternalName, nameSrcLoc,
-                         isWiredInName, getName
-                       )
+import Name
 import NameSet         ( NameSet, elemNameSet )
 import IfaceEnv                ( allocateGlobalBinder )
 import NameEnv         ( filterNameEnv, mapNameEnv )
@@ -42,11 +47,10 @@ import TyCon                ( TyCon, makeTyConAbstract, tyConDataCons, isNewTyCon,
                          newTyConRep, tyConSelIds, isAlgTyCon,
                          isEnumerationTyCon, isOpenTyCon )
 import Class           ( classSelIds )
-import Module          ( Module )
+import Module
 import HscTypes
 import Maybes          ( orElse, mapCatMaybes )
 import ErrUtils                ( showPass, dumpIfSet_core )
-import PackageConfig   ( PackageId )
 import UniqSupply      ( splitUniqSupply, uniqFromSupply )
 import Outputable
 import FastTypes  hiding ( fastOr )
@@ -123,7 +127,9 @@ mkBootModDetails hsc_env (ModGuts { mg_module    = mod
                                  , mg_exports   = exports
                                  , mg_types     = type_env
                                  , mg_insts     = insts
-                                 , mg_fam_insts = fam_insts })
+                                 , mg_fam_insts = fam_insts
+                                  , mg_modBreaks = modBreaks   
+                                  })
   = do { let dflags = hsc_dflags hsc_env 
        ; showPass dflags "Tidy [hoot] type env"
 
@@ -137,7 +143,9 @@ mkBootModDetails hsc_env (ModGuts { mg_module    = mod
                             , md_insts     = insts'
                             , md_fam_insts = fam_insts
                             , md_rules     = []
-                            , md_exports   = exports })
+                            , md_exports   = exports
+                             , md_vect_info = noVectInfo
+                             })
        }
   where
 
@@ -238,8 +246,11 @@ tidyProgram hsc_env
                                mg_insts = insts, mg_fam_insts = fam_insts,
                                mg_binds = binds, 
                                mg_rules = imp_rules,
+                                mg_vect_info = vect_info,
                                mg_dir_imps = dir_imps, mg_deps = deps, 
-                               mg_foreign = foreign_stubs })
+                               mg_foreign = foreign_stubs,
+                               mg_hpc_info = hpc_info,
+                                mg_modBreaks = modBreaks })
 
   = do { let dflags = hsc_dflags hsc_env
        ; showPass dflags "Tidy Core"
@@ -290,13 +301,17 @@ tidyProgram hsc_env
                           cg_binds    = all_tidy_binds,
                           cg_dir_imps = dir_imps,
                           cg_foreign  = foreign_stubs,
-                          cg_dep_pkgs = dep_pkgs deps }, 
+                          cg_dep_pkgs = dep_pkgs deps,
+                          cg_hpc_info = hpc_info,
+                           cg_modBreaks = modBreaks }, 
 
                   ModDetails { md_types     = tidy_type_env,
                                md_rules     = tidy_rules,
                                md_insts     = tidy_insts,
                                md_fam_insts = fam_insts,
-                               md_exports   = exports })
+                               md_exports   = exports,
+                                md_vect_info = vect_info    -- is already tidy
+                              })
        }
 
 lookup_dfun type_env dfun_id
@@ -661,7 +676,7 @@ tidyTopName mod nc_var ext_ids occ_env id
     global     = isExternalName name
     local      = not global
     internal   = not external
-    loc                = nameSrcLoc name
+    loc                = nameSrcSpan name
 
     (occ_env', occ') = tidyOccName occ_env (nameOccName name)
 
@@ -702,9 +717,10 @@ tidyTopPair ext_ids rhs_tidy_env caf_info name' (bndr, rhs)
     bndr'   = mkVanillaGlobal name' ty' idinfo'
     ty'            = tidyTopType (idType bndr)
     rhs'    = tidyExpr rhs_tidy_env rhs
+    idinfo  = idInfo bndr
     idinfo' = tidyTopIdInfo rhs_tidy_env (isJust maybe_external)
-                           (idInfo bndr) unfold_info arity
-                           caf_info
+                           idinfo unfold_info worker_info
+                           arity caf_info
 
     -- Expose an unfolding if ext_ids tells us to
     -- Remember that ext_ids maps an Id to a Bool: 
@@ -713,6 +729,7 @@ tidyTopPair ext_ids rhs_tidy_env caf_info name' (bndr, rhs)
     show_unfold = maybe_external `orElse` False
     unfold_info | show_unfold = mkTopUnfolding rhs'
                | otherwise   = noUnfolding
+    worker_info = tidyWorker rhs_tidy_env show_unfold (workerInfo idinfo)
 
     -- Usually the Id will have an accurate arity on it, because
     -- the simplifier has just run, but not always. 
@@ -736,7 +753,7 @@ tidyTopPair ext_ids rhs_tidy_env caf_info name' (bndr, rhs)
 --     unfoldings, which are inside Ids imported by GHCi. Ditto RULES.
 --     CoreToStg makes use of this when constructing SRTs.
 
-tidyTopIdInfo tidy_env is_external idinfo unfold_info arity caf_info
+tidyTopIdInfo tidy_env is_external idinfo unfold_info worker_info arity caf_info
   | not is_external    -- For internal Ids (not externally visible)
   = vanillaIdInfo      -- we only need enough info for code generation
                        -- Arity and strictness info are enough;
@@ -752,17 +769,27 @@ tidyTopIdInfo tidy_env is_external idinfo unfold_info arity caf_info
        `setAllStrictnessInfo` newStrictnessInfo idinfo
        `setInlinePragInfo`    inlinePragInfo idinfo
        `setUnfoldingInfo`     unfold_info
-       `setWorkerInfo`        tidyWorker tidy_env (workerInfo idinfo)
+       `setWorkerInfo`        worker_info
                -- NB: we throw away the Rules
                -- They have already been extracted by findExternalRules
 
 
 
 ------------  Worker  --------------
-tidyWorker tidy_env (HasWorker work_id wrap_arity) 
-  = HasWorker (tidyVarOcc tidy_env work_id) wrap_arity
-tidyWorker tidy_env other
+tidyWorker tidy_env show_unfold NoWorker
   = NoWorker
+tidyWorker tidy_env show_unfold (HasWorker work_id wrap_arity) 
+  | show_unfold = HasWorker (tidyVarOcc tidy_env work_id) wrap_arity
+  | otherwise   = WARN( True, ppr work_id ) NoWorker
+    -- NB: do *not* expose the worker if show_unfold is off,
+    --     because that means this thing is a loop breaker or
+    --     marked NOINLINE or something like that
+    -- This is important: if you expose the worker for a loop-breaker
+    -- then you can make the simplifier go into an infinite loop, because
+    -- in effect the unfolding is exposed.  See Trac #1709
+    -- 
+    -- Mind you, it probably should not be w/w'd in the first place; 
+    -- hence the WARN
 \end{code}
 
 %************************************************************************
@@ -789,11 +816,13 @@ CAF list to keep track of non-collectable CAFs.
 \begin{code}
 hasCafRefs  :: PackageId -> VarEnv Var -> Arity -> CoreExpr -> CafInfo
 hasCafRefs this_pkg p arity expr 
-  | is_caf || mentions_cafs = MayHaveCafRefs
+  | is_caf || mentions_cafs 
+                            = MayHaveCafRefs
   | otherwise              = NoCafRefs
  where
   mentions_cafs = isFastTrue (cafRefs p expr)
   is_caf = not (arity > 0 || rhsIsStatic this_pkg expr)
+
   -- NB. we pass in the arity of the expression, which is expected
   -- to be calculated by exprArity.  This is because exprArity
   -- knows how much eta expansion is going to be done by