[project @ 2003-03-27 08:18:21 by simonpj]
[ghc-hetmet.git] / ghc / compiler / main / MkIface.lhs
index 4317be4..67363ca 100644 (file)
@@ -24,12 +24,12 @@ import NewDemand    ( isTopSig )
 import TcRnMonad
 import TcRnTypes       ( ImportAvails(..) )
 import RnHsSyn         ( RenamedInstDecl, RenamedTyClDecl )
-import HscTypes                ( VersionInfo(..), ModIface(..), HomeModInfo(..),
+import HscTypes                ( VersionInfo(..), ModIface(..), 
                          ModGuts(..), ModGuts, 
-                         GhciMode(..), HscEnv(..),
+                         GhciMode(..), HscEnv(..), Dependencies(..),
                          FixityEnv, lookupFixity, collectFixities,
                          IfaceDecls, mkIfaceDecls, dcl_tycl, dcl_rules, dcl_insts,
-                         TyThing(..), DFunId, Dependencies,
+                         TyThing(..), DFunId, 
                          Avails, AvailInfo, GenAvailInfo(..), availName, 
                          ExternalPackageState(..),
                          ParsedIface(..), Usage(..),
@@ -38,8 +38,9 @@ import HscTypes               ( VersionInfo(..), ModIface(..), HomeModInfo(..),
                        )
 
 import CmdLineOpts
-import Id              ( idType, idInfo, isImplicitId, idCgInfo )
-import DataCon         ( dataConSig, dataConFieldLabels, dataConStrictMarks )
+import Id              ( idType, idInfo, isImplicitId, idCafInfo )
+import DataCon         ( dataConName, dataConSig, dataConFieldLabels,
+                         dataConStrictMarks, dataConWrapId )
 import IdInfo          -- Lots
 import CoreSyn         ( CoreRule(..), IdCoreRule )
 import CoreFVs         ( ruleLhsFreeNames )
@@ -53,23 +54,24 @@ import TyCon                ( DataConDetails(..), tyConTyVars, tyConDataCons, tyConTheta,
                          isFunTyCon, isPrimTyCon, isNewTyCon, isClassTyCon, 
                          isSynTyCon, isAlgTyCon, isForeignTyCon,
                          getSynTyConDefn, tyConGenInfo, tyConDataConDetails, tyConArity )
-import Class           ( classExtraBigSig, classTyCon, DefMeth(..) )
+import Class           ( classExtraBigSig, classTyCon )
 import FieldLabel      ( fieldLabelType )
-import TcType          ( tcSplitSigmaTy, tidyTopType, deNoteType, tyClsNamesOfDFunHead )
+import TcType          ( tcSplitForAllTys, tcFunResultTy, tidyTopType, deNoteType, tyClsNamesOfDFunHead )
 import SrcLoc          ( noSrcLoc )
 import Module          ( Module, ModuleName, moduleNameFS, moduleName, isHomeModule,
                          ModLocation(..), mkSysModuleNameFS, 
-                         ModuleEnv, emptyModuleEnv, foldModuleEnv, lookupModuleEnv,
-                         extendModuleEnv_C, elemModuleSet, moduleEnvElts, elemModuleEnv
+                         ModuleEnv, emptyModuleEnv, lookupModuleEnv,
+                         extendModuleEnv_C, moduleEnvElts 
                        )
 import Outputable
 import Util            ( sortLt, dropList, seqList )
 import Binary          ( getBinFileWithDict )
-import BinIface                ( writeBinIface )
+import BinIface                ( writeBinIface, v_IgnoreHiVersion )
 import ErrUtils                ( dumpIfSet_dyn )
 import FiniteMap
 import FastString
 
+import DATA_IOREF      ( writeIORef )
 import Monad           ( when )
 import Maybe           ( catMaybes, isJust, isNothing )
 import Maybes          ( orElse )
@@ -86,6 +88,9 @@ import IO             ( putStrLn )
 \begin{code}
 showIface :: FilePath -> IO ()
 showIface filename = do
+   -- skip the version check; we don't want to worry about profiled vs.
+   -- non-profiled interfaces, for example.
+   writeIORef v_IgnoreHiVersion True
    parsed_iface <- Binary.getBinFileWithDict filename
    let ParsedIface{
       pi_mod=pi_mod, pi_pkg=pi_pkg, pi_vers=pi_vers,
@@ -220,6 +225,8 @@ we miss them out of the accumulating parameter here.
 
 \begin{code}
 ifaceTyThing_acc :: TyThing -> [RenamedTyClDecl] -> [RenamedTyClDecl]
+-- Don't put implicit things into the result
+ifaceTyThing_acc (ADataCon dc) so_far                = so_far
 ifaceTyThing_acc (AnId   id) so_far | isImplicitId id = so_far
 ifaceTyThing_acc (ATyCon id) so_far | isClassTyCon id = so_far
 ifaceTyThing_acc other so_far = ifaceTyThing other : so_far
@@ -246,13 +253,15 @@ ifaceTyThing (AClass clas) = cls_decl
 
     toClassOpSig (sel_id, def_meth)
        = ASSERT(sel_tyvars == clas_tyvars)
-         ClassOpSig (getName sel_id) def_meth' (toHsType op_ty) noSrcLoc
+         ClassOpSig (getName sel_id) def_meth (toHsType op_ty) noSrcLoc
        where
-         (sel_tyvars, _, op_ty) = tcSplitSigmaTy (idType sel_id)
-         def_meth' = case def_meth of
-                        NoDefMeth  -> NoDefMeth
-                        GenDefMeth -> GenDefMeth
-                        DefMeth id -> DefMeth (getName id)
+               -- Be careful when splitting the type, because of things
+               -- like         class Foo a where
+               --                op :: (?x :: String) => a -> a
+               -- and          class Baz a where
+               --                op :: (Ord a) => a -> a
+         (sel_tyvars, rho_ty) = tcSplitForAllTys (idType sel_id)
+         op_ty                = tcFunResultTy rho_ty
 
 ifaceTyThing (ATyCon tycon) = ty_decl
   where
@@ -302,7 +311,7 @@ ifaceTyThing (ATyCon tycon) = ty_decl
     ifaceConDecls (DataCons cs) = DataCons (map ifaceConDecl cs)
 
     ifaceConDecl data_con 
-       = ConDecl (getName data_con)
+       = ConDecl (dataConName data_con)
                  (toHsTyVars ex_tyvars)
                  (toHsContext ex_theta)
                  details noSrcLoc
@@ -331,9 +340,8 @@ ifaceTyThing (AnId id) = iface_sig
 
     id_type = idType id
     id_info = idInfo id
-    cg_info = idCgInfo id
     arity_info = arityInfo id_info
-    caf_info   = cgCafInfo cg_info
+    caf_info   = idCafInfo id
 
     hs_idinfo | opt_OmitInterfacePragmas
              = []
@@ -373,6 +381,11 @@ ifaceTyThing (AnId id) = iface_sig
     unfold_hsinfo |  neverUnfold unfold_info 
                  || has_worker = Nothing
                  | otherwise   = Just (HsUnfold inline_prag (toUfExpr rhs))
+
+
+ifaceTyThing (ADataCon dc) = ifaceTyThing (AnId (dataConWrapId dc))
+       -- This case only happens in the call to ifaceThing in InteractiveUI
+       -- Otherwise DataCons are filtered out in ifaceThing_acc
 \end{code}
 
 \begin{code}
@@ -476,7 +489,7 @@ mkUsageInfo :: HscEnv -> ExternalPackageState
 
 mkUsageInfo hsc_env eps
            (ImportAvails { imp_mods = dir_imp_mods,
-                           dep_mods = dep_mods })
+                           imp_dep_mods = dep_mods })
            used_names
   = -- seq the list of Usages returned: occasionally these
     -- don't get evaluated for a while and we can end up hanging on to
@@ -484,7 +497,7 @@ mkUsageInfo hsc_env eps
     usages `seqList` usages
   where
     usages = catMaybes [ mkUsage mod_name 
-                      | (mod_name,_,_) <- moduleEnvElts dep_mods]
+                      | (mod_name,_) <- moduleEnvElts dep_mods]
 
     hpt = hsc_HPT hsc_env
     pit = eps_PIT eps
@@ -781,16 +794,15 @@ pprUsage getOcc usage
 
 
 pprDeps :: Dependencies -> SDoc
-pprDeps (mods, pkgs)
+pprDeps (Deps { dep_mods = mods, dep_pkgs = pkgs, dep_orphs = orphs})
   = vcat [ptext SLIT("module dependencies:") <+> fsep (map ppr_mod mods),
-         ptext SLIT("package dependencies:") <+> fsep (map ppr pkgs)]
+         ptext SLIT("package dependencies:") <+> fsep (map ppr pkgs), 
+         ptext SLIT("orphans:") <+> fsep (map ppr orphs)
+       ]
   where
-    ppr_mod (mod_name, orph, boot)
-      = ppr mod_name <+> ppr_orphan orph <+> ppr_boot boot
+    ppr_mod (mod_name, boot) = ppr mod_name <+> ppr_boot boot
    
-    ppr_orphan True  = char '!'
-    ppr_orphan False = empty
-    ppr_boot   True  = char '@'
+    ppr_boot   True  = text "[boot]"
     ppr_boot   False = empty
 \end{code}