2 % (c) The GRASP/AQUA Project, Glasgow University, 1993-1995
4 \section[MkIface]{Print an interface for a module}
7 #include "HsVersions.h"
9 module MkIface {-( mkInterface )-} where
13 import Bag ( emptyBag, snocBag, bagToList )
14 import Class ( GenClass{-instance NamedThing-} )
15 import CmdLineOpts ( opt_ProduceHi )
17 import Id ( GenId{-instance NamedThing/Outputable-} )
18 import Name ( nameOrigName, origName,
19 exportFlagOn, nameExportFlag, ExportFlag(..),
20 ltLexical, isExported,
21 RdrName{-instance Outputable-}
23 import PprStyle ( PprStyle(..) )
24 import PprType ( pprType, TyCon{-instance Outputable-}, GenClass{-ditto-} )
25 import Pretty -- quite a bit
26 import RnHsSyn ( RenamedHsModule(..), RnName{-instance NamedThing-} )
27 import RnIfaces ( VersionInfo(..) )
28 import TcModule ( TcIfaceInfo(..) )
29 import TcInstUtil ( InstInfo(..) )
30 import TyCon ( TyCon{-instance NamedThing-} )
31 import Type ( mkSigmaTy, mkDictTy, getAppTyCon )
32 import Util ( sortLt, assertPanic )
34 ppSemid x = ppBeside (ppr PprInterface x) ppSemi -- micro util
37 We have a function @startIface@ to open the output file and put
38 (something like) ``interface Foo N'' in it. It gives back a handle
39 for subsequent additions to the interface file.
41 We then have one-function-per-block-of-interface-stuff, e.g.,
42 @ifaceExportList@ produces the @__exports__@ section; it appends
43 to the handle provided by @startIface@.
47 -> IO (Maybe Handle) -- Nothing <=> don't do an interface
48 endIface :: Maybe Handle -> IO ()
65 ifaceDecls :: Maybe Handle
66 -> TcIfaceInfo -- info produced by typechecker, for interfaces
70 -> TcIfaceInfo -- as above
77 = case opt_ProduceHi of
78 Nothing -> return Nothing -- not producing any .hi file
80 openFile fn WriteMode >>= \ if_hdl ->
81 hPutStr if_hdl ("interface "++ _UNPK_ mod ++" 1\n") >>
84 endIface Nothing = return ()
85 endIface (Just if_hdl) = hPutStr if_hdl "\n" >> hClose if_hdl
89 ifaceVersions Nothing{-no iface handle-} _ = return ()
91 ifaceVersions (Just if_hdl) version_info
92 = hPutStr if_hdl "__versions__\nFoo(1)" -- a stub, obviously
96 ifaceInstanceModules Nothing{-no iface handle-} _ = return ()
97 ifaceInstanceModules (Just _) [] = return ()
99 ifaceInstanceModules (Just if_hdl) imods
100 = hPutStr if_hdl "\n__instance_modules__\n" >>
101 hPutStr if_hdl (ppShow 100 (ppCat (map ppPStr imods)))
104 Export list: grab the Names of things that are marked Exported, sort
105 (so the interface file doesn't ``wobble'' from one compilation to the
106 next...), and print. Note that the ``module'' now contains all the
107 imported things that we are dealing with, thus including any entities
108 that we are re-exporting from somewhere else.
110 ifaceExportList Nothing{-no iface handle-} _ = return ()
112 ifaceExportList (Just if_hdl)
113 (HsModule _ _ _ _ _ typedecls _ classdecls _ _ _ binds sigs _)
115 name_flag_pairs :: Bag (Name, ExportFlag)
120 (from_binds binds emptyBag{-init accum-})
125 sorted_pairs = sortLt lexical_lt (bagToList name_flag_pairs)
128 hPutStr if_hdl "\n__exports__\n" >>
129 hPutStr if_hdl (ppShow 100 (ppAboves (map pp_pair sorted_pairs)))
131 from_ty (TyData _ n _ _ _ _ _) acc = maybe_add acc n
132 from_ty (TyNew _ n _ _ _ _ _) acc = maybe_add acc n
133 from_ty (TySynonym n _ _ _) acc = maybe_add acc n
135 from_cls (ClassDecl _ n _ _ _ _ _) acc = maybe_add acc n
137 from_sig (Sig n _ _ _) acc = maybe_add acc n
139 from_binds bs acc = maybe_add_list acc (collectTopLevelBinders bs)
142 maybe_add :: Bag (Name, ExportFlag) -> RnName -> Bag (Name, ExportFlag)
145 | exportFlagOn ef = acc `snocBag` (n, ef)
149 ef = nameExportFlag n
152 maybe_add_list acc [] = acc
153 maybe_add_list acc (n:ns) = maybe_add (maybe_add_list acc ns) n
156 lexical_lt (n1,_) (n2,_) = nameOrigName n1 < nameOrigName n2
160 = ppBeside (ppr PprInterface (nameOrigName n)) (pp_export ef)
162 pp_export ExportAll = ppPStr SLIT("(..)")
163 pp_export ExportAbs = ppNil
167 ifaceFixities Nothing{-no iface handle-} _ = return ()
169 ifaceFixities (Just if_hdl) (HsModule _ _ _ _ fixities _ _ _ _ _ _ _ _ _)
170 = if null fixities then
173 hPutStr if_hdl "\n__fixities__\n" >>
174 hPutStr if_hdl (ppShow 100 (ppAboves (map ppSemid fixities)))
178 ifaceDecls Nothing{-no iface handle-} _ = return ()
180 ifaceDecls (Just if_hdl) (vals, tycons, classes, _)
182 exported_classes = filter isExported classes
183 exported_tycons = filter isExported tycons
184 exported_vals = filter isExported vals
186 sorted_classes = sortLt ltLexical exported_classes
187 sorted_tycons = sortLt ltLexical exported_tycons
188 sorted_vals = sortLt ltLexical exported_vals
190 ASSERT(not (null exported_classes && null exported_tycons && null exported_vals))
192 hPutStr if_hdl "\n__declarations__\n" >>
193 hPutStr if_hdl (ppShow 100 (ppAboves [
194 ppAboves (map ppSemid sorted_classes),
195 ppAboves (map ppSemid sorted_tycons),
196 ppAboves (map ppSemid sorted_vals)]))
200 ifaceInstances Nothing{-no iface handle-} _ = return ()
202 ifaceInstances (Just if_hdl) (_, _, _, insts)
204 exported_insts = filter is_exported_inst (bagToList insts)
206 sorted_insts = sortLt lt_inst exported_insts
208 if null exported_insts then
211 hPutStr if_hdl "\n__instances__\n" >>
212 hPutStr if_hdl (ppShow 100 (ppAboves (map pp_inst sorted_insts)))
214 is_exported_inst (InstInfo clas _ ty _ _ _ _ _ from_here _ _ _)
215 = from_here -- && ...
218 lt_inst (InstInfo clas1 _ ty1 _ _ _ _ _ _ _ _ _)
219 (InstInfo clas2 _ ty2 _ _ _ _ _ _ _ _ _)
221 tycon1 = fst (getAppTyCon ty1)
222 tycon2 = fst (getAppTyCon ty2)
224 case (origName clas1 `cmp` origName clas2) of
227 EQ_ -> origName tycon1 < origName tycon2
230 pp_inst (InstInfo clas tvs ty theta _ _ _ _ _ _ _ _)
231 = ppBeside (ppPStr SLIT("instance "))
232 (pprType PprInterface (mkSigmaTy tvs theta (mkDictTy clas ty)))
235 === ALL OLD BELOW HERE ==============
237 %************************************************************************
239 \subsection[main-MkIface]{Main routine for making interfaces}
241 %************************************************************************
246 We get the general what-to-export information from the ``environments''
247 produced by the typechecker (the \tr{[RenamedFixityDecl]} through
248 \tr{Bag InstInfo} arguments).
251 {\em However:} Whereas (for example) an \tr{InstInfo} will have
252 \tr{Ids} in it that identify the constant methods for that instance,
253 those particular \tr{Ids} {\em do not have} the best @IdInfos@!!!
254 Those @IdInfos@ were figured out long after the \tr{InstInfo} was
257 That's why we actually look at the final \tr{StgBindings} that go
258 into the code-generator: they have the best @IdInfos@ on them.
259 Whenever, we are about to print info about an @Id@, we look in the
260 Ids-from-STG-bindings list to see if we have an ``equivalent'' @Id@
261 with presumably-better @IdInfo@.
264 We play this same game whether for values, classes (for their
265 method-selectors and default-methods), or instances (for their
266 @DictFunIds@ or constant-methods).
268 Of course, for imported things, what we got from the typechecker is
272 We {\em sort} things in the interface into some ``canonical'' order;
273 otherwise, with heavily-recursive modules, you can have (unchanged)
274 information ``move around'' in the interface file---deeply unfriendly
280 mkInterface :: FAST_STRING
281 -> (FAST_STRING -> Bool, -- is something in export list, explicitly?
282 FAST_STRING -> Bool) -- is a module among the "dotdot" exported modules?
283 -> IdEnv UnfoldingDetails
284 -> FiniteMap TyCon [(Bool, [Maybe Type])]
285 -> ([RenamedFixityDecl], -- interface info from the typecheck
293 mkInterface modname export_list_fns inline_env tycon_specs
294 (fixity_decls, global_ids, ce, tce, inst_infos)
297 -- first, gather up the things we want to export:
299 exported_tycons = [ tc | tc <- rngTCE tce,
301 is_exportable_tycon_or_class export_list_fns tc ]
302 exported_classes = [ c | c <- rngCE ce,
304 is_exportable_tycon_or_class export_list_fns c ]
305 exported_inst_infos = [ i | i <- bagToList inst_infos,
306 is_exported_inst_info export_list_fns i ]
308 = [ v | v <- global_ids,
309 isExported v && not (isDataCon v) && not (isClassOpId v) ]
311 -- We also have to worry about TyCons/Classes that are
312 -- *mentioned* in exported things (e.g., values' types or
313 -- instances), so that we can be sure to do an import decl for
314 -- them, for original-naming purposes:
316 (mentioned_tycons, mentioned_classes)
317 = foldr ( \ (tcs1, cls1) (tcs2, cls2)
318 -> (tcs1 `unionBags` tcs2, cls1 `unionBags` cls2) )
320 (map getMentionedTyConsAndClassesFromClass exported_classes ++
321 map getMentionedTyConsAndClassesFromTyCon exported_tycons ++
322 map getMentionedTyConsAndClassesFromId exported_vals ++
323 map getMentionedTyConsAndClassesFromInstInfo exported_inst_infos)
326 = filter is_mentionable (bagToList mentioned_classes)
328 = [ tc | tc <- bagToList mentioned_tycons,
330 not (isPrimTyCon tc) ]
332 nondup_mentioned_tycons = fst (removeDups cmp mentionable_tycons)
333 nondup_mentioned_classes = fst (removeDups cmp mentionable_classes)
335 -- Next: as discussed in the notes, we want the top-level
336 -- Ids straight from the final STG code, so we can use
337 -- their IdInfos to print pragmas; we slurp them out here,
338 -- then pass them to the printing functions, which may
341 better_ids = collectExportedStgBinders stg_binds
343 -- Make a lookup function for convenient access:
346 = if not (isLocallyDefined i)
347 then i -- can't be among our "better_ids"
350 eq_fn = if isTopLevId i -- can't trust uniqs
351 then (\ x y -> origName x == origName y)
354 case [ x | x <- better_ids, x `eq_fn` i ] of
355 [] -> pprPanic "better_id_fn:" (ppr PprShowAll i)
358 _ -> panic "better_id_fn"
360 -- Finally, we sort everything lexically, so that we always
361 -- get the same interface from the same information:
363 sorted_mentioned_tycons = sortLt ltLexical nondup_mentioned_tycons
364 sorted_mentioned_classes = sortLt ltLexical nondup_mentioned_classes
366 sorted_tycons = sortLt ltLexical exported_tycons
367 sorted_classes = sortLt ltLexical exported_classes
368 sorted_vals = sortLt ltLexical exported_vals
369 sorted_inst_infos = sortLt lt_lexical_inst_info exported_inst_infos
371 if (any_purely_local sorted_tycons sorted_classes sorted_vals) then
372 -- this will be less of a HACK when we teach
373 -- mkInterface to do I/O (WDP 94/10)
374 error "Can't produce interface file because of errors!\n"
377 [ppPStr SLIT("{-# GHC_PRAGMA INTERFACE VERSION 7 #-}"),
378 ppCat [ppPStr SLIT("interface"), ppPStr modname, ppPStr SLIT("where")],
380 do_import_decls modname
381 sorted_vals sorted_mentioned_classes sorted_mentioned_tycons,
382 -- Mustn't give the data constructors to do_import_decls,
383 -- because they aren't explicitly imported; their tycon is.
385 ppAboves (map do_fixity fixity_decls),
386 ppAboves (map (pprIfaceClass better_id_fn inline_env) sorted_classes),
387 ppAboves (map (do_tycon tycon_specs) sorted_tycons),
388 ppAboves (map (do_value better_id_fn inline_env) sorted_vals),
389 ppAboves (map (do_instance better_id_fn inline_env) sorted_inst_infos),
394 any_purely_local tycons classes vals
395 = any bad_tc tycons || any bad_cl classes || any bad_id vals
398 = case (maybePurelyLocalClass cl) of
400 Just xs -> naughty_trace cl xs
403 = case (maybePurelyLocalType (idType id)) of
405 Just xs -> naughty_trace id xs
408 = case (maybePurelyLocalTyCon tc) of
410 Just xs -> if exported_abs then False else naughty_trace tc xs
412 exported_abs = case (getExportFlag tc) of { ExportAbs -> True; _ -> False }
414 naughty_trace x things
415 = pprTrace "Can't export -- `"
416 (ppBesides [ppr PprForUser x, ppStr "' mentions purely local things: ",
417 ppInterleave pp'SP things])
421 %************************************************************************
423 \subsection[imports-MkIface]{Generating `import' declarations in an interface}
425 %************************************************************************
427 We gather up lots of (module, name) pairs for which we might print an
428 import declaration. We sort them, for the usual canonicalisation
429 reasons. NB: We {\em assume} the lists passed in don't have duplicates in
432 All rather horribly turgid (WDP).
437 -> [Id] -> [Class] -> [TyCon]
440 do_import_decls mod_name vals classes tycons
442 -- Conjure up (module, name) pairs for all
443 -- the potentially import-decls things:
445 vals_names, classes_names, tycons_names :: [(FAST_STRING, FAST_STRING, [Maybe FAST_STRING])]
446 vals_names = map get_val_pair vals
447 classes_names = map get_class_pair classes
448 tycons_names = map get_tycon_pair tycons
450 -- sort the (module, name) pairs and chop
451 -- them into per-module groups:
453 ie_list = sortLt lt (tycons_names ++ classes_names ++ vals_names)
455 per_module_groups = runs same_module ie_list
457 ppAboves (map print_a_decl per_module_groups)
459 lt, same_module :: (FAST_STRING, FAST_STRING)
460 -> (FAST_STRING, FAST_STRING) -> Bool
463 = case (_CMP_STRING_ m1 m2) of { LT_ -> True; EQ_ -> ie1 < ie2; GT__ -> False }
465 same_module (m1, _, _) (m2, _, _) = m1 == m2
467 compiling_the_prelude = opt_CompilingPrelude
469 print_a_decl :: [(FAST_STRING, FAST_STRING, [Maybe FAST_STRING])] -> Pretty
471 Obviously, if the module in question is this one,
472 don't print an import declaration.
474 If it's a Prelude* module, we don't print the TyCons/
475 Classes, because the compiler supposedly knows about
476 them already (and they are PreludeCore things anyway).
478 But if we are compiling a Prelude module, then we
479 try to do it as "normally" as possible.
481 print_a_decl (ielist@((m,_,_) : _))
483 || (not compiling_the_prelude &&
484 ({-OLD:m == pRELUDE_CORE ||-} m == pRELUDE_BUILTIN))
488 = ppBesides [ppPStr SLIT("import "), ppPStr m, ppLparen,
489 ppIntersperse pp'SP{-'-} (map pp_str [n | (_,n,_) <- ielist]),
493 isnt_tycon_ish :: FAST_STRING -> Bool
494 isnt_tycon_ish str = not (isLexCon str)
496 grab_non_Nothings :: [[Maybe FAST_STRING]] -> [FAST_STRING]
498 grab_non_Nothings rns = catMaybes (concat rns)
500 pp_str :: FAST_STRING -> Pretty
502 = if isLexVarSym pstr then ppStr ("("++str++")") else ppPStr pstr
508 get_val_pair :: Id -> (FAST_STRING, FAST_STRING)
509 get_class_pair :: Class -> (FAST_STRING, FAST_STRING)
510 get_tycon_pair :: TyCon -> (FAST_STRING, FAST_STRING)
516 = case (generic_pair clas) of { (orig_mod, orig_nm) ->
518 nm_to_print = case (getExportFlag clas) of
519 ExportAll -> orig_nm _APPEND_ SLIT("(..)") -- nothing like a good HACK!
521 NotExported -> orig_nm
523 (orig_mod, nm_to_print) }
526 = case (generic_pair tycon) of { (orig_mod, orig_nm) ->
528 nm_to_print = case (getExportFlag tycon) of
529 ExportAll -> orig_nm _APPEND_ SLIT("(..)") -- nothing like a good HACK!
531 NotExported -> orig_nm
533 cons = tyConDataCons tycon
535 (orig_mod, nm_to_print) }
538 = case (moduleNamePair thing) of { (orig_mod, orig_nm) ->
539 case (getOccName thing) of { occur_name ->
540 (orig_mod, orig_nm) }}
543 %************************************************************************
545 \subsection[fixities-MkIface]{Generating fixity declarations in an interface}
547 %************************************************************************
551 do_fixity :: -> RenamedFixityDecl -> Pretty
553 do_fixity fixity_decl
554 = case (isLocallyDefined name, getExportFlag name) of
555 (True, ExportAll) -> ppr PprInterface fixity_decl
558 name = get_name fixity_decl
559 get_name (InfixL n _) = n
560 get_name (InfixR n _) = n
561 get_name (InfixN n _) = n
564 %************************************************************************
566 \subsection[tycons-MkIface]{Generating tycon declarations in an interface}
568 %************************************************************************
571 do_tycon :: FiniteMap TyCon [(Bool, [Maybe Type])] -> TyCon -> Pretty
573 do_tycon tycon_specs_map tycon
574 = pprTyCon PprInterface tycon tycon_specs
576 tycon_specs = map snd (lookupWithDefaultFM tycon_specs_map [] tycon)
579 %************************************************************************
581 \subsection[values-MkIface]{Generating a value's signature in an interface}
583 %************************************************************************
586 do_value :: (Id -> Id)
587 -> IdEnv UnfoldingDetails
591 do_value better_id_fn inline_env val
594 better_val = better_id_fn val
595 name_str = getOccName better_val -- NB: not orig name!
597 id_info = getIdInfo better_val
601 final_ty = idType better_val
603 -- ASSERT (orig_ty == final_ty || mkLiftTy orig_ty == final_ty)
604 ASSERT (if (orig_ty == final_ty || mkLiftTy orig_ty == final_ty) then True else pprTrace "do_value:" (ppCat [ppr PprDebug val, ppr PprDebug better_val]) False)
607 -- Note: We export the type of the original val
608 -- The type of an unboxed val will have been *lifted* by the desugarer
609 -- In this case we export an unlifted type, but id_info which assumes
610 -- a lifted Id i.e. extracted from better_val (above)
611 -- The importing module must lift the Id before using the imported id_info
614 = if opt_OmitInterfacePragmas
615 || boringIdInfo id_info
617 else ppCat [ppPStr SLIT("\t{-# GHC_PRAGMA"),
618 ppIdInfo sty better_val True{-yes specs-}
619 better_id_fn inline_env id_info,
622 ppAbove (ppCat [ppr_non_op name_str,
623 ppPStr SLIT("::"), pprGenType sty val_ty])
626 -- sadly duplicates Name.pprNonSym (ToDo)
629 = if isLexVarSym str -- NOT NEEDED: || isAconop
630 then ppBesides [ppLparen, ppPStr str, ppRparen]
634 %************************************************************************
636 \subsection[instances-MkIface]{Generating instance declarations in an interface}
638 %************************************************************************
640 The types of ``dictionary functions'' (dfuns) have just the required
641 info for instance declarations in interfaces. However, the dfuns that
642 GHC really uses have {\em extra} dictionaries passed to them (for
643 efficiency). When we print interfaces, we want to omit that
644 dictionary information. (It can be reconsituted on the other end,
645 from instance and class decls).
648 do_instance :: (Id -> Id)
649 -> IdEnv UnfoldingDetails
653 do_instance better_id_fn inline_env
654 (InstInfo clas tv_tmpls ty inst_decl_theta dfun_theta dfun_id constm_ids _ from_here modname _ _)
658 better_dfun = better_id_fn dfun_id
659 better_dfun_info = getIdInfo better_dfun
660 better_constms = map better_id_fn constm_ids
662 class_op_strs = map classOpString (classOps clas)
665 = ppCat [ppPStr SLIT("\t{-# GHC_PRAGMA"), pp_modname, ppPStr SLIT("{-dfun-}"),
666 ppIdInfo sty better_dfun False{-NO specs-}
667 better_id_fn inline_env better_dfun_info]
669 pragma_end = ppPStr SLIT("#-}")
671 pp_modname = if _NULL_ modname
673 else ppCat [ppStr "_M_", ppPStr modname]
676 = pp_the_list [ ppCat [ppChar '\t', ppr_non_op op, ppEquals,
678 ppIdInfo sty constm True{-YES, specs-}
679 better_id_fn inline_env
682 | (op, constm) <- class_op_strs `zip` better_constms ]
685 pp_the_list [] = panic "MkIface: no class_ops or better_constms?"
688 pp_the_list (p:ps) = ppAbove (ppBeside p ppComma) (pp_the_list ps)
691 = ppCat [ppPStr SLIT("instance"),
692 ppr sty (mkSigmaTy tv_tmpls inst_decl_theta (mkDictTy clas ty))]
694 if opt_OmitInterfacePragmas
695 || boringIdInfo better_dfun_info
697 else ppAbove real_stuff
698 ({-ppNest 8 -} -- ppNest does nothing
699 if null better_constms
700 then ppCat [pragma_begin, pragma_end]
701 else ppAbove pragma_begin (ppCat [name_pragma_pairs, pragma_end])
705 %************************************************************************
707 \subsection[utils-InstInfos]{Utility functions for @InstInfos@}
709 %************************************************************************
713 Classes/TyCons are ``known,'' more-or-less. Prelude TyCons are
714 ``completely'' known---they don't need to be mentioned in interfaces.
715 Classes usually don't need to be mentioned in interfaces, but if we're
716 compiling the prelude, then we treat them without special favours.
718 is_exportable_tycon_or_class export_list_fns tc
719 = if not (fromPreludeCore tc) then
722 in_export_list_or_among_dotdot_modules
723 opt_CompilingPrelude -- ignore M.. stuff if compiling prelude
726 in_export_list_or_among_dotdot_modules ignore_Mdotdots (in_export_list, among_dotdot_modules) tc
727 = if in_export_list (getOccName tc) then
730 -- pprTrace "in_export:" (ppAbove (ppr PprDebug ignore_Mdotdots) (ppPStr (getOccName tc))) (
731 if ignore_Mdotdots then
734 any among_dotdot_modules (getInformingModules tc)
738 = not (from_PreludeCore_or_Builtin tc) || opt_CompilingPrelude
740 from_PreludeCore_or_Builtin thing
742 mod_name = fst (moduleNamePair thing)
744 mod_name == pRELUDE_CORE || mod_name == pRELUDE_BUILTIN
746 is_exported_inst_info export_list_fns
747 (InstInfo clas _ ty _ _ _ _ _ from_here _ _ _)
749 seems_exported = instanceIsExported clas ty from_here
750 (tycon, _, _) = getAppTyCon ty
752 if (opt_OmitReexportedInstances && not from_here) then
753 False -- Flag says to violate Haskell rules, blatantly
755 else if not opt_CompilingPrelude
756 || not (isFunTyCon tycon || fromPreludeCore tycon)
757 || not (fromPreludeCore clas) then
758 seems_exported -- take what we got
760 else -- compiling Prelude & tycon/class are Prelude things...
762 || in_export_list_or_among_dotdot_modules True{-ignore M..s-} export_list_fns clas
763 || in_export_list_or_among_dotdot_modules True{-ignore M..s-} export_list_fns tycon
767 lt_lexical_inst_info (InstInfo _ _ _ _ _ dfun1 _ _ _ _ _ _) (InstInfo _ _ _ _ _ dfun2 _ _ _ _ _ _)
768 = ltLexical dfun1 dfun2
772 getMentionedTyConsAndClassesFromInstInfo (InstInfo clas _ ty _ dfun_theta _ _ _ _ _ _ _)
773 = case (getMentionedTyConsAndClassesFromType ty) of { (ts, cs) ->
774 case [ c | (c, _) <- dfun_theta ] of { theta_classes ->
775 (ts, (cs `unionBags` listToBag theta_classes) `snocBag` clas)
777 OLD from the beginning -}