View patterns, record wildcards, and record puns
[ghc-hetmet.git] / compiler / iface / MkIface.lhs
index 489c2f7..407f3ea 100644 (file)
@@ -4,6 +4,13 @@
 %
 
 \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 MkIface ( 
        mkUsageInfo,    -- Construct the usage info for a module
 
@@ -258,7 +265,7 @@ mkIface hsc_env maybe_old_iface
 --     put exactly the info into the TypeEnv that we want
 --     to expose in the interface
 
-  = do { eps <- hscEPS hsc_env
+  = do {eps <- hscEPS hsc_env
        ; let   { entities = typeEnvElts type_env ;
                   decls  = [ tyThingToIfaceDecl entity
                           | entity <- entities,
@@ -270,8 +277,8 @@ mkIface hsc_env maybe_old_iface
                             nameIsLocalOrFrom this_mod name  ]
                                -- Sigh: see Note [Root-main Id] in TcRnDriver
 
-               ; fixities    = [(occ,fix) | FixItem occ fix _ <- nameEnvElts fix_env]
-               ; deprecs     = mkIfaceDeprec src_deprecs
+               ; fixities    = [(occ,fix) | FixItem occ fix <- nameEnvElts fix_env]
+               ; deprecs     = src_deprecs
                ; iface_rules = map (coreRuleToIfaceRule this_mod) rules
                ; iface_insts = map instanceToIfaceInst insts
                ; iface_fam_insts = map famInstToIfaceFamInst fam_insts
@@ -312,7 +319,7 @@ mkIface hsc_env maybe_old_iface
                        mi_fix_fn = mkIfaceFixCache fixities }
 
                -- Add version information
-                ; ext_ver_fn = mkParentVerFun hsc_env eps
+              ; ext_ver_fn = mkParentVerFun hsc_env eps
                ; (new_iface, no_change_at_all, pp_diffs, pp_orphs) 
                        = {-# SCC "versioninfo" #-}
                         addVersionInfo ext_ver_fn maybe_old_iface
@@ -684,12 +691,6 @@ mkOrphMap get_key decls
        | otherwise = (non_orphs, d:orphs)
 
 ----------------------
-mkIfaceDeprec :: Deprecations -> IfaceDeprecs
-mkIfaceDeprec NoDeprecs        = NoDeprecs
-mkIfaceDeprec (DeprecAll t)    = DeprecAll t
-mkIfaceDeprec (DeprecSome env) = DeprecSome (sortLe (<=) (nameEnvElts env))
-
-----------------------
 bump_unless :: Bool -> Version -> Version
 bump_unless True  v = v        -- True <=> no change
 bump_unless False v = bumpVersion v
@@ -705,7 +706,7 @@ bump_unless False v = bumpVersion v
 
 \begin{code}
 mkUsageInfo :: HscEnv 
-           -> ModuleEnv (Module, Bool, SrcSpan)
+           -> ModuleEnv (Module, [(ModuleName, Bool, SrcSpan)])
            -> [(ModuleName, IsBootInterface)]
            -> NameSet -> IO [Usage]
 mkUsageInfo hsc_env dir_imp_mods dep_mods used_names
@@ -717,6 +718,12 @@ mkUsageInfo hsc_env dir_imp_mods dep_mods used_names
         -- don't get evaluated for a while and we can end up hanging on to
         -- the entire collection of Ifaces.
 
+mk_usage_info :: PackageIfaceTable
+              -> HscEnv
+              -> ModuleEnv (Module, [(ModuleName, Bool, SrcSpan)])
+              -> [(ModuleName, IsBootInterface)]
+              -> NameSet
+              -> [Usage]
 mk_usage_info pit hsc_env dir_imp_mods dep_mods used_names
   = mapCatMaybes mkUsage dep_mods
        -- ToDo: do we need to sort into canonical order?
@@ -739,8 +746,8 @@ mk_usage_info pit hsc_env dir_imp_mods dep_mods used_names
                     add_item occs _ = occ:occs
     
     depend_on_exports mod = case lookupModuleEnv dir_imp_mods mod of
-                               Just (_,no_imp,_) -> not no_imp
-                               Nothing           -> True
+                               Just (_, xs) -> any (\(_, no_imp, _) -> not no_imp) xs
+                               Nothing          -> True
     
     -- We want to create a Usage for a home module if 
     -- a) we used something from; has something in used_names
@@ -834,7 +841,8 @@ mkIfaceExports exports
                -- Usually just one, but see Note [Original module]
 
        add_for_mod env mod
-           = add_one env mod (AvailTC tc_occ names_from_mod)
+           = add_one env mod (AvailTC tc_occ (sort names_from_mod))
+              -- NB. sort the children, we need a canonical order
            where
              names_from_mod = [nameOccName n | n <- ns, nameModule n == mod]
 \end{code}
@@ -1212,7 +1220,7 @@ tyThingToIfaceDecl (ATyCon tycon)
                    ifConUnivTvs = toIfaceTvBndrs (dataConUnivTyVars data_con),
                    ifConExTvs   = toIfaceTvBndrs (dataConExTyVars data_con),
                    ifConEqSpec  = to_eq_spec (dataConEqSpec data_con),
-                   ifConCtxt    = toIfaceContext (dataConTheta data_con),
+                   ifConCtxt    = toIfaceContext (dataConEqTheta data_con ++ dataConDictTheta data_con),
                    ifConArgTys  = map toIfaceType (dataConOrigArgTys data_con),
                    ifConFields  = map getOccName 
                                       (dataConFieldLabels data_con),
@@ -1321,7 +1329,7 @@ toIfaceIdInfo id_info
 
     ------------  Worker  --------------
     work_info   = workerInfo id_info
-    has_worker  = case work_info of { HasWorker _ _ -> True; other -> False }
+    has_worker  = workerExists work_info
     wrkr_hsinfo = case work_info of
                    HasWorker work_id wrap_arity -> 
                        Just (HsWorker ((idName work_id)) wrap_arity)