Robustify the treatement of DFunUnfolding
[ghc-hetmet.git] / compiler / iface / MkIface.lhs
index 9263bae..5c236b3 100644 (file)
@@ -83,7 +83,7 @@ import Digraph
 import SrcLoc
 import Outputable
 import BasicTypes       hiding ( SuccessFlag(..) )
-import LazyUniqFM
+import UniqFM
 import Unique
 import Util             hiding ( eqListBy )
 import FiniteMap
@@ -164,9 +164,8 @@ mkUsedNames
           TcGblEnv{ tcg_inst_uses = dfun_uses_var,
                     tcg_dus = dus
                   }
- = do
-        dfun_uses <- readIORef dfun_uses_var           -- What dfuns are used
-        return (allUses dus `unionNameSets` dfun_uses)
+ = do { dfun_uses <- readIORef dfun_uses_var           -- What dfuns are used
+      ; return (allUses dus `unionNameSets` dfun_uses) }
         
 mkDependencies :: TcGblEnv -> IO Dependencies
 mkDependencies
@@ -661,6 +660,24 @@ freeNamesDeclExtras IfaceOtherDeclExtras
 freeNamesSub :: (Fixity,[IfaceRule]) -> NameSet
 freeNamesSub (_,rules) = unionManyNameSets (map freeNamesIfRule rules)
 
+instance Outputable IfaceDeclExtras where
+  ppr IfaceOtherDeclExtras       = empty
+  ppr (IfaceIdExtras  fix rules) = ppr_id_extras fix rules
+  ppr (IfaceSynExtras fix)       = ppr fix
+  ppr (IfaceDataExtras fix insts stuff)  = vcat [ppr fix, ppr_insts insts,
+                                                 ppr_id_extras_s stuff]
+  ppr (IfaceClassExtras fix insts stuff) = vcat [ppr fix, ppr_insts insts,
+                                                 ppr_id_extras_s stuff]
+
+ppr_insts :: [IfaceInstABI] -> SDoc
+ppr_insts _ = ptext (sLit "<insts>")
+
+ppr_id_extras_s :: [(Fixity, [IfaceRule])] -> SDoc
+ppr_id_extras_s stuff = vcat [ppr_id_extras f r | (f,r)<- stuff]
+
+ppr_id_extras :: Fixity -> [IfaceRule] -> SDoc
+ppr_id_extras fix rules = ppr fix $$ vcat (map ppr rules)
+
 -- This instance is used only to compute fingerprints
 instance Binary IfaceDeclExtras where
   get _bh = panic "no get for IfaceDeclExtras"
@@ -838,7 +855,7 @@ mk_usage_info pit hsc_env this_mod direct_imports used_names
         | isWiredInName name = mv_map  -- ignore wired-in names
         | otherwise
         = case nameModule_maybe name of
-             Nothing  -> pprTrace "mkUsageInfo: internal name?" (ppr name) mv_map
+             Nothing  -> pprPanic "mkUsageInfo: internal name?" (ppr name)
              Just mod -> -- We use this fiddly lambda function rather than
                          -- (++) as the argument to extendModuleEnv_C to
                          -- avoid quadratic behaviour (trac #2680)
@@ -1316,7 +1333,7 @@ tyThingToIfaceDecl (AClass clas)
 
     toIfaceClassOp (sel_id, def_meth)
        = ASSERT(sel_tyvars == clas_tyvars)
-         IfaceClassOp (getOccName sel_id) def_meth (toIfaceType op_ty)
+         IfaceClassOp (getOccName sel_id) (toDmSpec def_meth) (toIfaceType op_ty)
        where
                -- Be careful when splitting the type, because of things
                -- like         class Foo a where
@@ -1326,6 +1343,10 @@ tyThingToIfaceDecl (AClass clas)
          (sel_tyvars, rho_ty) = splitForAllTys (idType sel_id)
          op_ty                = funResultTy rho_ty
 
+    toDmSpec NoDefMeth   = NoDM
+    toDmSpec GenDefMeth  = GenericDM
+    toDmSpec (DefMeth _) = VanillaDM
+
     toIfaceFD (tvs1, tvs2) = (map getFS tvs1, map getFS tvs2)
 
 tyThingToIfaceDecl (ATyCon tycon)
@@ -1524,7 +1545,7 @@ toIfUnfolding lb unf@(CoreUnfolding { uf_tmpl = rhs, uf_arity = arity
        -- have stuck in NoUnfolding.  For supercompilation we want 
        -- to see that unfolding!
 
-toIfUnfolding lb (DFunUnfolding _con ops)
+toIfUnfolding lb (DFunUnfolding _ar _con ops)
   = Just (HsUnfold lb (IfDFunUnfold (map toIfaceExpr ops)))
       -- No need to serialise the data constructor; 
       -- we can recover it from the type of the dfun