[project @ 2005-02-14 13:27:52 by simonmar]
[ghc-hetmet.git] / ghc / compiler / iface / MkIface.lhs
1 %
2 % (c) The GRASP/AQUA Project, Glasgow University, 1993-1998
3 %
4
5 \begin{code}
6 module MkIface ( 
7         pprModIface, showIface,         -- Print the iface in Foo.hi
8
9         mkUsageInfo,    -- Construct the usage info for a module
10
11         mkIface,        -- Build a ModIface from a ModGuts, 
12                         -- including computing version information
13
14         checkOldIface   -- See if recompilation is required, by
15                         -- comparing version information
16  ) where
17 \end{code}
18
19         -----------------------------------------------
20                 MkIface.lhs deals with versioning
21         -----------------------------------------------
22
23 Here's the version-related info in an interface file
24
25   module Foo 8          -- module-version 
26              3          -- export-list-version
27              2          -- rule-version
28     Usages:     -- Version info for what this compilation of Foo imported
29         Baz 3           -- Module version
30             [4]         -- The export-list version if Foo depended on it
31             (g,2)       -- Function and its version
32             (T,1)       -- Type and its version
33
34     <version> f :: Int -> Int {- Unfolding: \x -> Wib.t[2] x -}
35                 -- The [2] says that f's unfolding 
36                 -- mentions verison 2 of Wib.t
37         
38         -----------------------------------------------
39                         Basic idea
40         -----------------------------------------------
41
42 Basic idea: 
43   * In the mi_usages information in an interface, we record the 
44     version number of each free variable of the module
45
46   * In mkIface, we compute the version number of each exported thing A.f
47     by comparing its A.f's info with its new info, and bumping its 
48     version number if it differs.  If A.f mentions B.g, and B.g's version
49     number has changed, then we count A.f as having changed too.
50
51   * In checkOldIface we compare the mi_usages for the module with
52     the actual version info for all each thing recorded in mi_usages
53
54
55 Fixities
56 ~~~~~~~~
57 We count A.f as changing if its fixity changes
58
59 Rules
60 ~~~~~
61 If a rule changes, we want to recompile any module that might be
62 affected by that rule.  For non-orphan rules, this is relatively easy.
63 If module M defines f, and a rule for f, just arrange that the version
64 number for M.f changes if any of the rules for M.f change.  Any module
65 that does not depend on M.f can't be affected by the rule-change
66 either.
67
68 Orphan rules (ones whose 'head function' is not defined in M) are
69 harder.  Here's what we do.
70
71   * We have a per-module orphan-rule version number which changes if 
72     any orphan rule changes. (It's unaffected by non-orphan rules.)
73
74   * We record usage info for any orphan module 'below' this one,
75     giving the orphan-rule version number.  We recompile if this 
76     changes. 
77
78 The net effect is that if an orphan rule changes, we recompile every
79 module above it.  That's very conservative, but it's devilishly hard
80 to know what it might affect, so we just have to be conservative.
81
82 Instance decls
83 ~~~~~~~~~~~~~~
84 In an iface file we have
85      module A where
86         instance Eq a => Eq [a]  =  dfun29
87         dfun29 :: ... 
88
89 We have a version number for dfun29, covering its unfolding
90 etc. Suppose we are compiling a module M that imports A only
91 indirectly.  If typechecking M uses this instance decl, we record the
92 dependency on A.dfun29 as if it were a free variable of the module
93 (via the tcg_inst_usages accumulator).  That means that A will appear
94 in M's usage list.  If the shape of the instance declaration changes,
95 then so will dfun29's version, triggering a recompilation.
96
97 Adding an instance declaration, or changing an instance decl that is
98 not currently used, is more tricky.  (This really only makes a
99 difference when we have overlapping instance decls, because then the
100 new instance decl might kick in to override the old one.)  We handle
101 this in a very similar way that we handle rules above.
102
103   * For non-orphan instance decls, identify one locally-defined tycon/class
104     mentioned in the decl.  Treat the instance decl as part of the defn of that
105     tycon/class, so that if the shape of the instance decl changes, so does the
106     tycon/class; that in turn will force recompilation of anything that uses
107     that tycon/class.
108
109   * For orphan instance decls, act the same way as for orphan rules.
110     Indeed, we use the same global orphan-rule version number.
111
112 mkUsageInfo
113 ~~~~~~~~~~~
114 mkUsageInfo figures out what the ``usage information'' for this
115 moudule is; that is, what it must record in its interface file as the
116 things it uses.  
117
118 We produce a line for every module B below the module, A, currently being
119 compiled:
120         import B <n> ;
121 to record the fact that A does import B indirectly.  This is used to decide
122 to look to look for B.hi rather than B.hi-boot when compiling a module that
123 imports A.  This line says that A imports B, but uses nothing in it.
124 So we'll get an early bale-out when compiling A if B's version changes.
125
126 The usage information records:
127
128 \begin{itemize}
129 \item   (a) anything reachable from its body code
130 \item   (b) any module exported with a @module Foo@
131 \item   (c) anything reachable from an exported item
132 \end{itemize}
133
134 Why (b)?  Because if @Foo@ changes then this module's export list
135 will change, so we must recompile this module at least as far as
136 making a new interface file --- but in practice that means complete
137 recompilation.
138
139 Why (c)?  Consider this:
140 \begin{verbatim}
141         module A( f, g ) where  |       module B( f ) where
142           import B( f )         |         f = h 3
143           g = ...               |         h = ...
144 \end{verbatim}
145
146 Here, @B.f@ isn't used in A.  Should we nevertheless record @B.f@ in
147 @A@'s usages?  Our idea is that we aren't going to touch A.hi if it is
148 *identical* to what it was before.  If anything about @B.f@ changes
149 than anyone who imports @A@ should be recompiled in case they use
150 @B.f@ (they'll get an early exit if they don't).  So, if anything
151 about @B.f@ changes we'd better make sure that something in A.hi
152 changes, and the convenient way to do that is to record the version
153 number @B.f@ in A.hi in the usage list.  If B.f changes that'll force a
154 complete recompiation of A, which is overkill but it's the only way to 
155 write a new, slightly different, A.hi.
156
157 But the example is tricker.  Even if @B.f@ doesn't change at all,
158 @B.h@ may do so, and this change may not be reflected in @f@'s version
159 number.  But with -O, a module that imports A must be recompiled if
160 @B.h@ changes!  So A must record a dependency on @B.h@.  So we treat
161 the occurrence of @B.f@ in the export list *just as if* it were in the
162 code of A, and thereby haul in all the stuff reachable from it.
163
164         *** Conclusion: if A mentions B.f in its export list,
165             behave just as if A mentioned B.f in its source code,
166             and slurp in B.f and all its transitive closure ***
167
168 [NB: If B was compiled with -O, but A isn't, we should really *still*
169 haul in all the unfoldings for B, in case the module that imports A *is*
170 compiled with -O.  I think this is the case.]
171
172
173 \begin{code}
174 #include "HsVersions.h"
175
176 import HsSyn
177 import Packages         ( isHomeModule, PackageIdH(..) )
178 import IfaceSyn         ( IfaceDecl(..), IfaceClassOp(..), IfaceConDecl(..),
179                           IfaceRule(..), IfaceInst(..), IfaceExtName(..), IfaceTyCon(..),
180                           eqIfDecl, eqIfRule, eqIfInst, IfaceEq(..), (&&&), bool, 
181                           eqMaybeBy, eqListBy, visibleIfConDecls,
182                           tyThingToIfaceDecl, dfunToIfaceInst, coreRuleToIfaceRule )
183 import LoadIface        ( readIface, loadInterface, ifaceInstGates )
184 import BasicTypes       ( Version, initialVersion, bumpVersion )
185 import TcRnMonad
186 import TcRnTypes        ( mkModDeps )
187 import TcType           ( isFFITy )
188 import HscTypes         ( ModIface(..), TyThing(..), 
189                           ModGuts(..), ModGuts, IfaceExport,
190                           GhciMode(..), HscEnv(..), hscEPS,
191                           Dependencies(..), FixItem(..), 
192                           ModSummary(..), msHiFilePath, 
193                           mkIfaceDepCache, mkIfaceFixCache, mkIfaceVerCache,
194                           typeEnvElts, 
195                           GenAvailInfo(..), availName, 
196                           ExternalPackageState(..),
197                           Usage(..), IsBootInterface,
198                           Deprecs(..), IfaceDeprecs, Deprecations,
199                           lookupIfaceByModule
200                         )
201
202
203 import CmdLineOpts
204 import Name             ( Name, nameModule, nameOccName, nameParent,
205                           isExternalName, nameParent_maybe, isWiredInName,
206                           NamedThing(..) )
207 import NameEnv
208 import NameSet
209 import OccName          ( OccName, OccEnv, mkOccEnv, lookupOccEnv, emptyOccEnv,
210                           extendOccEnv_C,
211                           OccSet, emptyOccSet, elemOccSet, occSetElts, 
212                           extendOccSet, extendOccSetList,
213                           isEmptyOccSet, intersectOccSet, intersectsOccSet,
214                           occNameFS, isTcOcc )
215 import TyCon            ( tyConDataCons, isNewTyCon, newTyConRep )
216 import Class            ( classSelIds )
217 import DataCon          ( dataConName, dataConFieldLabels )
218 import Module           ( Module, moduleFS,
219                           ModLocation(..), mkSysModuleFS, moduleUserString,
220                           ModuleEnv, emptyModuleEnv, lookupModuleEnv,
221                           extendModuleEnv_C
222                         )
223 import Outputable
224 import DriverUtil       ( createDirectoryHierarchy, directoryOf )
225 import Util             ( sortLe, seqList )
226 import Binary           ( getBinFileWithDict )
227 import BinIface         ( writeBinIface, v_IgnoreHiWay )
228 import Unique           ( Unique, Uniquable(..) )
229 import ErrUtils         ( dumpIfSet_dyn, showPass )
230 import Digraph          ( stronglyConnComp, SCC(..) )
231 import SrcLoc           ( SrcSpan )
232 import FiniteMap
233 import FastString
234
235 import DATA_IOREF       ( writeIORef )
236 import Monad            ( when )
237 import List             ( insert )
238 import Maybes           ( orElse, mapCatMaybes, isNothing, isJust, 
239                           fromJust, expectJust, MaybeErr(..) )
240 \end{code}
241
242
243
244 %************************************************************************
245 %*                                                                      *
246 \subsection{Completing an interface}
247 %*                                                                      *
248 %************************************************************************
249
250 \begin{code}
251 mkIface :: HscEnv
252         -> ModLocation
253         -> Maybe ModIface       -- The old interface, if we have it
254         -> ModGuts              -- The compiled, tidied module
255         -> IO ModIface          -- The new one, complete with decls and versions
256 -- mkIface 
257 --      a) Builds the ModIface
258 --      b) Writes it out to a file if necessary
259
260 mkIface hsc_env location maybe_old_iface 
261         guts@ModGuts{ mg_module = this_mod,
262                       mg_boot   = is_boot,
263                       mg_usages = usages,
264                       mg_deps   = deps,
265                       mg_exports = exports,
266                       mg_rdr_env = rdr_env,
267                       mg_fix_env = fix_env,
268                       mg_deprecs = src_deprecs,
269                       mg_insts = insts, 
270                       mg_rules = rules,
271                       mg_types = type_env }
272   = do  { eps <- hscEPS hsc_env
273         ; let   { ext_nm_rhs = mkExtNameFn hsc_env eps this_mod
274                 ; ext_nm_lhs = mkLhsNameFn this_mod
275                 ; local_things = [thing | thing <- typeEnvElts type_env,
276                                           not (isWiredInName (getName thing)) ]
277                         -- Do not export anything about wired-in things
278                         --  (GHC knows about them already)
279
280                 ; abstract_tcs :: NameSet -- TyCons and Classes whose representation is not exposed
281                 ; abstract_tcs
282                     | not omit_prags = emptyNameSet             -- In the -O case, nothing is abstract
283                     | otherwise      = mkNameSet [ getName thing 
284                                                  | thing <- local_things
285                                                  , not (mustExposeThing exports thing)]
286
287                 ; decls  = [ tyThingToIfaceDecl omit_prags abstract_tcs ext_nm_rhs thing 
288                            | thing <- local_things, wantDeclFor exports abstract_tcs thing ]
289                                 -- Don't put implicit Ids and class tycons in the interface file
290
291                 ; fixities = [(occ,fix) | FixItem occ fix _ <- nameEnvElts fix_env]
292                 ; deprecs  = mkIfaceDeprec src_deprecs
293                 ; iface_rules 
294                      | omit_prags = []
295                      | otherwise  = sortLe le_rule $
296                                     map (coreRuleToIfaceRule ext_nm_lhs ext_nm_rhs) rules
297                 ; iface_insts = sortLe le_inst (map (dfunToIfaceInst ext_nm_lhs) insts)
298
299                 ; intermediate_iface = ModIface { 
300                         mi_module   = this_mod,
301                         mi_package  = HomePackage,
302                         mi_boot     = is_boot,
303                         mi_deps     = deps,
304                         mi_usages   = usages,
305                         mi_exports  = mkIfaceExports exports,
306                         mi_insts    = iface_insts,
307                         mi_rules    = iface_rules,
308                         mi_fixities = fixities,
309                         mi_deprecs  = deprecs,
310                         mi_globals  = Just rdr_env,
311
312                         -- Left out deliberately: filled in by addVersionInfo
313                         mi_mod_vers  = initialVersion,
314                         mi_exp_vers  = initialVersion,
315                         mi_rule_vers = initialVersion,
316                         mi_orphan    = False,   -- Always set by addVersionInfo, but
317                                                 -- it's a strict field, so we can't omit it.
318                         mi_decls     = deliberatelyOmitted "decls",
319                         mi_ver_fn    = deliberatelyOmitted "ver_fn",
320
321                         -- And build the cached values
322                         mi_dep_fn = mkIfaceDepCache deprecs,
323                         mi_fix_fn = mkIfaceFixCache fixities }
324
325                 -- Add version information
326                 ; (new_iface, no_change_at_all, pp_diffs, pp_orphs) 
327                         = _scc_ "versioninfo" 
328                          addVersionInfo maybe_old_iface intermediate_iface decls
329                 }
330
331                 -- Write the interface file, if necessary
332         ; when (not no_change_at_all && ghci_mode /= Interactive) $ do
333                 createDirectoryHierarchy (directoryOf hi_file_path)
334                 writeBinIface hi_file_path new_iface
335
336                 -- Debug printing
337         ; when (isJust pp_orphs && dopt Opt_WarnOrphans dflags) 
338                (printDump (fromJust pp_orphs))
339         ; when (dopt Opt_D_dump_hi_diffs dflags) (printDump pp_diffs)
340         ; dumpIfSet_dyn dflags Opt_D_dump_hi "FINAL INTERFACE" 
341                         (pprModIface new_iface)
342
343         ; return new_iface }
344   where
345      r1 `le_rule` r2 = ifRuleName r1 <= ifRuleName r2
346      i1 `le_inst` i2 = ifDFun     i1 <= ifDFun     i2
347
348      dflags       = hsc_dflags hsc_env
349      ghci_mode    = hsc_mode hsc_env
350      omit_prags   = dopt Opt_OmitInterfacePragmas dflags
351      hi_file_path = ml_hi_file location
352
353                                               
354 mustExposeThing :: NameSet -> TyThing -> Bool
355 -- We are compiling without -O, and thus trying to write as little as 
356 -- possible into the interface file.  But we must expose the details of
357 -- any data types and classes whose constructors, fields, methods are 
358 -- visible to an importing module
359 mustExposeThing exports (ATyCon tc) 
360   =  any exported_data_con (tyConDataCons tc)
361         -- Expose rep if any datacon or field is exported
362
363   || (isNewTyCon tc && isFFITy (snd (newTyConRep tc)))
364         -- Expose the rep for newtypes if the rep is an FFI type.  
365         -- For a very annoying reason.  'Foreign import' is meant to
366         -- be able to look through newtypes transparently, but it
367         -- can only do that if it can "see" the newtype representation
368   where         
369      exported_data_con con 
370         = any (`elemNameSet` exports) (dataConName con : dataConFieldLabels con)
371                 
372 mustExposeThing exports (AClass cls) 
373   = any exported_class_op (classSelIds cls)
374   where         -- Expose rep if any classs op is exported
375      exported_class_op op = getName op `elemNameSet` exports
376
377 mustExposeThing exports other = False
378
379
380 wantDeclFor :: NameSet  -- User-exported things
381             -> NameSet  -- Abstract things
382             -> TyThing -> Bool
383 wantDeclFor exports abstracts thing
384   | Just parent <- nameParent_maybe name        -- An implicit thing
385   = parent `elemNameSet` abstracts && name `elemNameSet` exports
386   | otherwise
387   = True
388   where
389     name = getName thing
390   
391
392 deliberatelyOmitted x = panic ("Deliberately omitted: " ++ x)
393
394 -----------------------------
395 mkExtNameFn :: HscEnv -> ExternalPackageState -> Module -> Name -> IfaceExtName
396 mkExtNameFn hsc_env eps this_mod
397   = ext_nm
398   where
399     dflags = hsc_dflags hsc_env
400     hpt = hsc_HPT hsc_env
401     pit = eps_PIT eps
402
403     ext_nm name 
404       | mod == this_mod = case nameParent_maybe name of
405                                 Nothing  -> LocalTop occ
406                                 Just par -> LocalTopSub occ (nameOccName par)
407       | isWiredInName name       = ExtPkg  mod occ
408       | isHomeModule dflags mod  = HomePkg mod occ vers
409       | otherwise                = ExtPkg  mod occ
410       where
411         mod      = nameModule name
412         occ      = nameOccName name
413         par_occ  = nameOccName (nameParent name)
414                 -- The version of the *parent* is the one want
415         vers     = lookupVersion mod par_occ
416               
417     lookupVersion :: Module -> OccName -> Version
418         -- Even though we're looking up a home-package thing, in
419         -- one-shot mode the imported interfaces may be in the PIT
420     lookupVersion mod occ
421       = mi_ver_fn iface occ `orElse` 
422         pprPanic "lookupVers1" (ppr mod <+> ppr occ)
423       where
424         iface = lookupIfaceByModule hpt pit mod `orElse` 
425                 pprPanic "lookupVers2" (ppr mod <+> ppr occ)
426
427
428 ---------------------
429 -- mkLhsNameFn ignores versioning info altogether
430 -- It is used for the LHS of instance decls and rules, where we 
431 -- there's no point in recording version info
432 mkLhsNameFn :: Module -> Name -> IfaceExtName
433 mkLhsNameFn this_mod name       
434   | mod == this_mod = LocalTop occ
435   | otherwise       = ExtPkg mod occ
436   where
437     mod = nameModule name
438     occ = nameOccName name
439
440
441 -----------------------------
442 -- Compute version numbers for local decls
443
444 addVersionInfo :: Maybe ModIface        -- The old interface, read from M.hi
445                -> ModIface              -- The new interface decls (lacking decls)
446                -> [IfaceDecl]           -- The new decls
447                -> (ModIface, 
448                    Bool,                -- True <=> no changes at all; no need to write new Iface
449                    SDoc,                -- Differences
450                    Maybe SDoc)          -- Warnings about orphans
451
452 addVersionInfo Nothing new_iface new_decls
453 -- No old interface, so definitely write a new one!
454   = (new_iface { mi_orphan = anyNothing getInstKey (mi_insts new_iface)
455                           || anyNothing getRuleKey (mi_rules new_iface),
456                  mi_decls  = [(initialVersion, decl) | decl <- new_decls],
457                  mi_ver_fn = \n -> Just initialVersion },
458      False, 
459      ptext SLIT("No old interface file"),
460      pprOrphans orph_insts orph_rules)
461   where
462     orph_insts = filter (isNothing . getInstKey) (mi_insts new_iface)
463     orph_rules = filter (isNothing . getRuleKey) (mi_rules new_iface)
464
465 addVersionInfo (Just old_iface@(ModIface { mi_mod_vers  = old_mod_vers, 
466                                            mi_exp_vers  = old_exp_vers, 
467                                            mi_rule_vers = old_rule_vers, 
468                                            mi_decls     = old_decls,
469                                            mi_ver_fn    = old_decl_vers,
470                                            mi_fix_fn    = old_fixities }))
471                new_iface@(ModIface { mi_fix_fn = new_fixities })
472                new_decls
473
474   | no_change_at_all = (old_iface,   True,  ptext SLIT("Interface file unchanged"), pp_orphs)
475   | otherwise        = (final_iface, False, vcat [ptext SLIT("Interface file has changed"),
476                                                   nest 2 pp_diffs], pp_orphs)
477   where
478     final_iface = new_iface { mi_mod_vers  = bump_unless no_output_change old_mod_vers,
479                               mi_exp_vers  = bump_unless no_export_change old_exp_vers,
480                               mi_rule_vers = bump_unless no_rule_change   old_rule_vers,
481                               mi_orphan    = not (null new_orph_rules && null new_orph_insts),
482                               mi_decls     = decls_w_vers,
483                               mi_ver_fn    = mkIfaceVerCache decls_w_vers }
484
485     decls_w_vers = [(add_vers decl, decl) | decl <- new_decls]
486
487     -------------------
488     (old_non_orph_insts, old_orph_insts) = mkRuleMap getInstKey (mi_insts old_iface)
489     (new_non_orph_insts, new_orph_insts) = mkRuleMap getInstKey (mi_insts new_iface)
490     same_insts occ = eqMaybeBy  (eqListBy eqIfInst) 
491                                 (lookupOccEnv old_non_orph_insts occ)
492                                 (lookupOccEnv new_non_orph_insts occ)
493   
494     (old_non_orph_rules, old_orph_rules) = mkRuleMap getRuleKey (mi_rules old_iface)
495     (new_non_orph_rules, new_orph_rules) = mkRuleMap getRuleKey (mi_rules new_iface)
496     same_rules occ = eqMaybeBy  (eqListBy eqIfRule)
497                                 (lookupOccEnv old_non_orph_rules occ)
498                                 (lookupOccEnv new_non_orph_rules occ)
499     -------------------
500     -- Computing what changed
501     no_output_change = no_decl_change   && no_rule_change && 
502                        no_export_change && no_deprec_change
503     no_export_change = mi_exports new_iface == mi_exports old_iface     -- Kept sorted
504     no_decl_change   = isEmptyOccSet changed_occs
505     no_rule_change   = not (changedWrt changed_occs (eqListBy eqIfRule old_orph_rules new_orph_rules)
506                          || changedWrt changed_occs (eqListBy eqIfInst old_orph_insts new_orph_insts))
507     no_deprec_change = mi_deprecs new_iface == mi_deprecs old_iface
508
509         -- If the usages havn't changed either, we don't need to write the interface file
510     no_other_changes = mi_usages new_iface == mi_usages old_iface && 
511                        mi_deps new_iface == mi_deps old_iface
512     no_change_at_all = no_output_change && no_other_changes
513  
514     pp_diffs = vcat [pp_change no_export_change "Export list" 
515                         (ppr old_exp_vers <+> arrow <+> ppr (mi_exp_vers final_iface)),
516                      pp_change no_rule_change "Rules"
517                         (ppr old_rule_vers <+> arrow <+> ppr (mi_rule_vers final_iface)),
518                      pp_change no_deprec_change "Deprecations" empty,
519                      pp_change no_other_changes  "Usages" empty,
520                      pp_decl_diffs]
521     pp_change True  what info = empty
522     pp_change False what info = text what <+> ptext SLIT("changed") <+> info
523
524     -------------------
525     old_decl_env = mkOccEnv [(ifName decl, decl) | (_,decl) <- old_decls]
526     same_fixity n = bool (old_fixities n == new_fixities n)
527
528     -------------------
529     -- Adding version info
530     new_version     = bumpVersion old_mod_vers
531     add_vers decl | occ `elemOccSet` changed_occs = new_version
532                   | otherwise = expectJust "add_vers" (old_decl_vers occ)
533                                 -- If it's unchanged, there jolly well 
534                   where         -- should be an old version number
535                     occ = ifName decl
536
537     -------------------
538     changed_occs :: OccSet
539     changed_occs = computeChangedOccs eq_info
540
541     eq_info :: [(OccName, IfaceEq)]
542     eq_info = map check_eq new_decls
543     check_eq new_decl | Just old_decl <- lookupOccEnv old_decl_env occ 
544                       = (occ, new_decl `eqIfDecl` old_decl &&&
545                               eq_indirects new_decl)
546                       | otherwise {- No corresponding old decl -}      
547                       = (occ, NotEqual) 
548                       where
549                         occ = ifName new_decl
550
551     eq_indirects :: IfaceDecl -> IfaceEq
552                 -- When seeing if two decls are the same, remember to
553                 -- check whether any relevant fixity or rules have changed
554     eq_indirects (IfaceId {ifName = occ}) = eq_ind_occ occ
555     eq_indirects (IfaceClass {ifName = cls_occ, ifSigs = sigs})
556         = same_insts cls_occ &&& 
557           eq_ind_occs [op | IfaceClassOp op _ _ <- sigs] 
558     eq_indirects (IfaceData {ifName = tc_occ, ifCons = cons})
559         = same_insts tc_occ &&& same_fixity tc_occ &&&  -- The TyCon can have a fixity too
560           eq_ind_occs (map ifConOcc (visibleIfConDecls cons))
561     eq_indirects other = Equal  -- Synonyms and foreign declarations
562
563     eq_ind_occ :: OccName -> IfaceEq    -- For class ops and Ids; check fixity and rules
564     eq_ind_occ occ = same_fixity occ &&& same_rules occ
565     eq_ind_occs = foldr ((&&&) . eq_ind_occ) Equal 
566    
567     -------------------
568     -- Diffs
569     pp_decl_diffs :: SDoc       -- Nothing => no changes
570     pp_decl_diffs 
571         | isEmptyOccSet changed_occs = empty
572         | otherwise 
573         = vcat [ptext SLIT("Changed occs:") <+> ppr (occSetElts changed_occs),
574                 ptext SLIT("Version change for these decls:"),
575                 nest 2 (vcat (map show_change new_decls))]
576
577     eq_env = mkOccEnv eq_info
578     show_change new_decl
579         | not (occ `elemOccSet` changed_occs) = empty
580         | otherwise
581         = vcat [ppr occ <+> ppr (old_decl_vers occ) <+> arrow <+> ppr new_version, 
582                 nest 2 why]
583         where
584           occ = ifName new_decl
585           why = case lookupOccEnv eq_env occ of
586                     Just (EqBut occs) -> sep [ppr occ <> colon, ptext SLIT("Free vars (only) changed:"),
587                                               nest 2 (braces (fsep (map ppr (occSetElts 
588                                                 (occs `intersectOccSet` changed_occs)))))]
589                     Just NotEqual  
590                         | Just old_decl <- lookupOccEnv old_decl_env occ 
591                         -> vcat [ptext SLIT("Old:") <+> ppr old_decl,
592                          ptext SLIT("New:") <+> ppr new_decl]
593                         | otherwise 
594                         -> ppr occ <+> ptext SLIT("only in new interface")
595                     other -> pprPanic "MkIface.show_change" (ppr occ)
596         
597     pp_orphs = pprOrphans new_orph_insts new_orph_rules
598
599 pprOrphans insts rules
600   | null insts && null rules = Nothing
601   | otherwise
602   = Just $ vcat [
603         if null insts then empty else
604              hang (ptext SLIT("Warning: orphan instances:"))
605                 2 (vcat (map ppr insts)),
606         if null rules then empty else
607              hang (ptext SLIT("Warning: orphan rules:"))
608                 2 (vcat (map ppr rules))
609     ]
610
611 computeChangedOccs :: [(OccName, IfaceEq)] -> OccSet
612 computeChangedOccs eq_info
613   = foldl add_changes emptyOccSet (stronglyConnComp edges)
614   where
615     edges :: [((OccName,IfaceEq), Unique, [Unique])]
616     edges = [ (node, getUnique occ, map getUnique occs)
617             | node@(occ, iface_eq) <- eq_info
618             , let occs = case iface_eq of
619                            EqBut occ_set -> occSetElts occ_set
620                            other -> [] ]
621
622     -- Changes in declarations
623     add_changes :: OccSet -> SCC (OccName, IfaceEq) -> OccSet
624     add_changes so_far (AcyclicSCC (occ, iface_eq)) 
625         | changedWrt so_far iface_eq                            -- This one has changed
626         = extendOccSet so_far occ
627     add_changes so_far (CyclicSCC pairs)
628         | changedWrt so_far (foldr1 (&&&) (map snd pairs))      -- One of this group has changed
629         = extendOccSetList so_far (map fst pairs)
630     add_changes so_far other = so_far
631
632 changedWrt :: OccSet -> IfaceEq -> Bool
633 changedWrt so_far Equal        = False
634 changedWrt so_far NotEqual     = True
635 changedWrt so_far (EqBut kids) = so_far `intersectsOccSet` kids
636
637 ----------------------
638 -- mkRuleMap partitions instance decls or rules into
639 --      (a) an OccEnv for ones that are not orphans, 
640 --          mapping the local OccName to a list of its decls
641 --      (b) a list of orphan decls
642 mkRuleMap :: (decl -> Maybe OccName)    -- (Just occ) for a non-orphan decl, keyed by occ
643                                         -- Nothing for an orphan decl
644           -> [decl]                     -- Sorted into canonical order
645           -> (OccEnv [decl],            -- Non-orphan decls associated with their key;
646                                         --      each sublist in canonical order
647               [decl])                   -- Orphan decls; in canonical order
648 mkRuleMap get_key decls
649   = foldl go (emptyOccEnv, []) decls
650   where
651     go (non_orphs, orphs) d
652         | Just occ <- get_key d
653         = (extendOccEnv_C (\ ds _ -> d:ds) non_orphs occ [d], orphs)
654         | otherwise = (non_orphs, d:orphs)
655
656 -- getXxKey: find at least one local OccName that belongs to this decl
657
658 getInstKey :: IfaceInst -> Maybe OccName
659 getInstKey (IfaceInst {ifInstHead = inst_ty})
660   = case [occ | LocalTop occ <- cls_ext : tc_exts] of
661         []      -> Nothing
662         (occ:_) -> Just occ
663   where
664     (cls_ext, tcs) = ifaceInstGates inst_ty
665     tc_exts = [tc | IfaceTc tc <- tcs]
666         -- Ignore the wired-in IfaceTyCons; the class will do as the key
667
668 getRuleKey :: IfaceRule -> Maybe OccName
669 getRuleKey (IfaceRule {ifRuleHead = LocalTop occ}) = Just occ
670 getRuleKey other                                   = Nothing
671
672 anyNothing :: (a -> Maybe b) -> [a] -> Bool
673 anyNothing p []     = False
674 anyNothing p (x:xs) = isNothing (p x) || anyNothing p xs
675
676 ----------------------
677 mkIfaceDeprec :: Deprecations -> IfaceDeprecs
678 mkIfaceDeprec NoDeprecs        = NoDeprecs
679 mkIfaceDeprec (DeprecAll t)    = DeprecAll t
680 mkIfaceDeprec (DeprecSome env) = DeprecSome (sortLe (<=) (nameEnvElts env))
681
682 ----------------------
683 bump_unless :: Bool -> Version -> Version
684 bump_unless True  v = v -- True <=> no change
685 bump_unless False v = bumpVersion v
686 \end{code}
687
688
689 %*********************************************************
690 %*                                                      *
691 \subsection{Keeping track of what we've slurped, and version numbers}
692 %*                                                      *
693 %*********************************************************
694
695
696 \begin{code}
697 mkUsageInfo :: HscEnv 
698             -> ModuleEnv (Module, Maybe Bool, SrcSpan)
699             -> [(Module, IsBootInterface)]
700             -> NameSet -> IO [Usage]
701 mkUsageInfo hsc_env dir_imp_mods dep_mods used_names
702   = do  { eps <- hscEPS hsc_env
703         ; let usages = mk_usage_info (eps_PIT eps) hsc_env
704                                      dir_imp_mods dep_mods used_names
705         ; usages `seqList`  return usages }
706          -- seq the list of Usages returned: occasionally these
707          -- don't get evaluated for a while and we can end up hanging on to
708          -- the entire collection of Ifaces.
709
710 mk_usage_info pit hsc_env dir_imp_mods dep_mods proto_used_names
711   = mapCatMaybes mkUsage dep_mods
712         -- ToDo: do we need to sort into canonical order?
713   where
714     dflags = hsc_dflags hsc_env
715     hpt = hsc_HPT hsc_env
716
717     used_names = mkNameSet $                    -- Eliminate duplicates
718                  [ nameParent n                 -- Just record usage on the 'main' names
719                  | n <- nameSetToList proto_used_names
720                  , not (isWiredInName n)        -- Don't record usages for wired-in names
721                  , isExternalName n             -- Ignore internal names
722                  ]
723
724     -- ent_map groups together all the things imported and used
725     -- from a particular module in this package
726     ent_map :: ModuleEnv [OccName]
727     ent_map  = foldNameSet add_mv emptyModuleEnv used_names
728     add_mv name mv_map = extendModuleEnv_C add_item mv_map mod [occ]
729                    where
730                      occ = nameOccName name
731                      mod = nameModule name
732                      add_item occs _ = occ:occs
733     
734     import_all mod = case lookupModuleEnv dir_imp_mods mod of
735                         Just (_,imp_all,_) -> isNothing imp_all
736                         Nothing            -> False
737     
738     -- We want to create a Usage for a home module if 
739     --  a) we used something from; has something in used_names
740     --  b) we imported all of it, even if we used nothing from it
741     --          (need to recompile if its export list changes: export_vers)
742     --  c) is a home-package orphan module (need to recompile if its
743     --          instance decls change: rules_vers)
744     mkUsage :: (Module, Bool) -> Maybe Usage
745     mkUsage (mod_name, _)
746       |  isNothing maybe_iface  -- We can't depend on it if we didn't
747       || not (isHomeModule dflags mod)  -- even open the interface!
748       || (null used_occs
749           && not all_imported
750           && not orphan_mod)
751       = Nothing                 -- Record no usage info
752     
753       | otherwise       
754       = Just (Usage { usg_name     = mod,
755                       usg_mod      = mod_vers,
756                       usg_exports  = export_vers,
757                       usg_entities = ent_vers,
758                       usg_rules    = rules_vers })
759       where
760         maybe_iface  = lookupIfaceByModule hpt pit mod_name
761                 -- In one-shot mode, the interfaces for home-package 
762                 -- modules accumulate in the PIT not HPT.  Sigh.
763
764         Just iface   = maybe_iface
765         mod          = mi_module    iface
766         orphan_mod   = mi_orphan    iface
767         version_env  = mi_ver_fn    iface
768         mod_vers     = mi_mod_vers  iface
769         rules_vers   = mi_rule_vers iface
770         all_imported = import_all mod 
771         export_vers | all_imported = Just (mi_exp_vers iface)
772                     | otherwise    = Nothing
773     
774         -- The sort is to put them into canonical order
775         used_occs = lookupModuleEnv ent_map mod `orElse` []
776         ent_vers :: [(OccName,Version)]
777         ent_vers = [ (occ, version_env occ `orElse` initialVersion) 
778                    | occ <- sortLe (<=) used_occs]
779 \end{code}
780
781 \begin{code}
782 mkIfaceExports :: NameSet -> [(Module, [GenAvailInfo OccName])]
783   -- Group by module and sort by occurrence
784   -- This keeps the list in canonical order
785 mkIfaceExports exports 
786   = [ (mkSysModuleFS fs, eltsFM avails)
787     | (fs, avails) <- fmToList groupFM
788     ]
789   where
790     groupFM :: FiniteMap FastString (FiniteMap FastString (GenAvailInfo OccName))
791         -- Deliberately use the FastString so we
792         -- get a canonical ordering
793     groupFM = foldl add emptyFM (nameSetToList exports)
794
795     add env name = addToFM_C add_avail env mod_fs 
796                              (unitFM avail_fs avail)
797       where
798         occ    = nameOccName name
799         mod_fs = moduleFS (nameModule name)
800         avail | Just p <- nameParent_maybe name = AvailTC (nameOccName p) [occ]
801               | isTcOcc occ                     = AvailTC occ [occ]
802               | otherwise                       = Avail occ
803         avail_fs = occNameFS (availName avail)      
804         add_avail avail_fm _ = addToFM_C add_item avail_fm avail_fs avail
805
806         add_item (AvailTC p occs) _ = AvailTC p (List.insert occ occs)
807         add_item (Avail n)        _ = pprPanic "MkIface.addAvail" (ppr n <+> ppr name)
808 \end{code}
809
810
811 %************************************************************************
812 %*                                                                      *
813         Load the old interface file for this module (unless
814         we have it aleady), and check whether it is up to date
815         
816 %*                                                                      *
817 %************************************************************************
818
819 \begin{code}
820 checkOldIface :: HscEnv
821               -> ModSummary
822               -> Bool                   -- Source unchanged
823               -> Maybe ModIface         -- Old interface from compilation manager, if any
824               -> IO (RecompileRequired, Maybe ModIface)
825
826 checkOldIface hsc_env mod_summary source_unchanged maybe_iface
827   = do  { showPass (hsc_dflags hsc_env) 
828                    ("Checking old interface for " ++ moduleUserString (ms_mod mod_summary)) ;
829
830         ; initIfaceCheck hsc_env $
831           check_old_iface mod_summary source_unchanged maybe_iface
832      }
833
834 check_old_iface mod_summary source_unchanged maybe_iface
835  =      -- CHECK WHETHER THE SOURCE HAS CHANGED
836     ifM (not source_unchanged)
837         (traceHiDiffs (nest 4 (text "Source file changed or recompilation check turned off")))
838                                                 `thenM_`
839
840      -- If the source has changed and we're in interactive mode, avoid reading
841      -- an interface; just return the one we might have been supplied with.
842     getGhciMode                                 `thenM` \ ghci_mode ->
843     if (ghci_mode == Interactive) && not source_unchanged then
844          returnM (outOfDate, maybe_iface)
845     else
846
847     case maybe_iface of {
848        Just old_iface -> -- Use the one we already have
849                          checkVersions source_unchanged old_iface       `thenM` \ recomp ->
850                          returnM (recomp, Just old_iface)
851
852     ;  Nothing ->
853
854         -- Try and read the old interface for the current module
855         -- from the .hi file left from the last time we compiled it
856     let
857         iface_path = msHiFilePath mod_summary
858     in
859     readIface (ms_mod mod_summary) iface_path False     `thenM` \ read_result ->
860     case read_result of {
861        Failed err ->    -- Old interface file not found, or garbled; give up
862                    traceIf (text "FYI: cannot read old interface file:"
863                                  $$ nest 4 err)         `thenM_`
864                    returnM (outOfDate, Nothing)
865
866     ;  Succeeded iface ->       
867
868         -- We have got the old iface; check its versions
869     checkVersions source_unchanged iface        `thenM` \ recomp ->
870     returnM (recomp, Just iface)
871     }}
872 \end{code}
873
874 @recompileRequired@ is called from the HscMain.   It checks whether
875 a recompilation is required.  It needs access to the persistent state,
876 finder, etc, because it may have to load lots of interface files to
877 check their versions.
878
879 \begin{code}
880 type RecompileRequired = Bool
881 upToDate  = False       -- Recompile not required
882 outOfDate = True        -- Recompile required
883
884 checkVersions :: Bool           -- True <=> source unchanged
885               -> ModIface       -- Old interface
886               -> IfG RecompileRequired
887 checkVersions source_unchanged iface
888   | not source_unchanged
889   = returnM outOfDate
890   | otherwise
891   = do  { traceHiDiffs (text "Considering whether compilation is required for" <+> 
892                         ppr (mi_module iface) <> colon)
893
894         -- Source code unchanged and no errors yet... carry on 
895
896         -- First put the dependent-module info, read from the old interface, into the envt, 
897         -- so that when we look for interfaces we look for the right one (.hi or .hi-boot)
898         -- 
899         -- It's just temporary because either the usage check will succeed 
900         -- (in which case we are done with this module) or it'll fail (in which
901         -- case we'll compile the module from scratch anyhow).
902         --      
903         -- We do this regardless of compilation mode
904         ; updateEps_ $ \eps  -> eps { eps_is_boot = mod_deps }
905
906         ; checkList [checkModUsage u | u <- mi_usages iface]
907     }
908   where
909         -- This is a bit of a hack really
910     mod_deps :: ModuleEnv (Module, IsBootInterface)
911     mod_deps = mkModDeps (dep_mods (mi_deps iface))
912
913 checkModUsage :: Usage -> IfG RecompileRequired
914 -- Given the usage information extracted from the old
915 -- M.hi file for the module being compiled, figure out
916 -- whether M needs to be recompiled.
917
918 checkModUsage (Usage { usg_name = mod_name, usg_mod = old_mod_vers,
919                        usg_rules = old_rule_vers,
920                        usg_exports = maybe_old_export_vers, 
921                        usg_entities = old_decl_vers })
922   =     -- Load the imported interface is possible
923     let
924         doc_str = sep [ptext SLIT("need version info for"), ppr mod_name]
925     in
926     traceHiDiffs (text "Checking usages for module" <+> ppr mod_name) `thenM_`
927
928     loadInterface doc_str mod_name ImportBySystem       `thenM` \ mb_iface ->
929         -- Load the interface, but don't complain on failure;
930         -- Instead, get an Either back which we can test
931
932     case mb_iface of {
933         Failed exn ->  (out_of_date (sep [ptext SLIT("Can't find version number for module"), 
934                                        ppr mod_name]));
935                 -- Couldn't find or parse a module mentioned in the
936                 -- old interface file.  Don't complain -- it might just be that
937                 -- the current module doesn't need that import and it's been deleted
938
939         Succeeded iface -> 
940     let
941         new_mod_vers    = mi_mod_vers  iface
942         new_decl_vers   = mi_ver_fn    iface
943         new_export_vers = mi_exp_vers  iface
944         new_rule_vers   = mi_rule_vers iface
945     in
946         -- CHECK MODULE
947     checkModuleVersion old_mod_vers new_mod_vers        `thenM` \ recompile ->
948     if not recompile then
949         returnM upToDate
950     else
951                                  
952         -- CHECK EXPORT LIST
953     if checkExportList maybe_old_export_vers new_export_vers then
954         out_of_date_vers (ptext SLIT("  Export list changed"))
955                          (fromJust maybe_old_export_vers) 
956                          new_export_vers
957     else
958
959         -- CHECK RULES
960     if old_rule_vers /= new_rule_vers then
961         out_of_date_vers (ptext SLIT("  Rules changed")) 
962                          old_rule_vers new_rule_vers
963     else
964
965         -- CHECK ITEMS ONE BY ONE
966     checkList [checkEntityUsage new_decl_vers u | u <- old_decl_vers]   `thenM` \ recompile ->
967     if recompile then
968         returnM outOfDate       -- This one failed, so just bail out now
969     else
970         up_to_date (ptext SLIT("  Great!  The bits I use are up to date"))
971     }
972
973 ------------------------
974 checkModuleVersion old_mod_vers new_mod_vers
975   | new_mod_vers == old_mod_vers
976   = up_to_date (ptext SLIT("Module version unchanged"))
977
978   | otherwise
979   = out_of_date_vers (ptext SLIT("  Module version has changed"))
980                      old_mod_vers new_mod_vers
981
982 ------------------------
983 checkExportList Nothing  new_vers = upToDate
984 checkExportList (Just v) new_vers = v /= new_vers
985
986 ------------------------
987 checkEntityUsage new_vers (name,old_vers)
988   = case new_vers name of
989
990         Nothing       ->        -- We used it before, but it ain't there now
991                           out_of_date (sep [ptext SLIT("No longer exported:"), ppr name])
992
993         Just new_vers   -- It's there, but is it up to date?
994           | new_vers == old_vers -> traceHiDiffs (text "  Up to date" <+> ppr name <+> parens (ppr new_vers)) `thenM_`
995                                     returnM upToDate
996           | otherwise            -> out_of_date_vers (ptext SLIT("  Out of date:") <+> ppr name)
997                                                      old_vers new_vers
998
999 up_to_date  msg = traceHiDiffs msg `thenM_` returnM upToDate
1000 out_of_date msg = traceHiDiffs msg `thenM_` returnM outOfDate
1001 out_of_date_vers msg old_vers new_vers 
1002   = out_of_date (hsep [msg, ppr old_vers, ptext SLIT("->"), ppr new_vers])
1003
1004 ----------------------
1005 checkList :: [IfG RecompileRequired] -> IfG RecompileRequired
1006 -- This helper is used in two places
1007 checkList []             = returnM upToDate
1008 checkList (check:checks) = check        `thenM` \ recompile ->
1009                            if recompile then 
1010                                 returnM outOfDate
1011                            else
1012                                 checkList checks
1013 \end{code}
1014
1015 %************************************************************************
1016 %*                                                                      *
1017                 Printing interfaces
1018 %*                                                                      *
1019 %************************************************************************
1020
1021 \begin{code}
1022 showIface :: FilePath -> IO ()
1023 -- Raad binary interface, and print it out
1024 showIface filename = do
1025    -- skip the version check; we don't want to worry about profiled vs.
1026    -- non-profiled interfaces, for example.
1027    writeIORef v_IgnoreHiWay True
1028    iface <- Binary.getBinFileWithDict filename
1029    printDump (pprModIface iface)
1030  where
1031 \end{code}
1032
1033
1034 \begin{code}
1035 pprModIface :: ModIface -> SDoc
1036 -- Show a ModIface
1037 pprModIface iface
1038  = vcat [ ptext SLIT("interface")
1039                 <+> ppr_package (mi_package iface)
1040                 <+> ppr (mi_module iface) <+> pp_boot 
1041                 <+> ppr (mi_mod_vers iface) <+> pp_sub_vers
1042                 <+> (if mi_orphan iface then ptext SLIT("[orphan module]") else empty)
1043                 <+> int opt_HiVersion
1044                 <+> ptext SLIT("where")
1045         , vcat (map pprExport (mi_exports iface))
1046         , pprDeps (mi_deps iface)
1047         , vcat (map pprUsage (mi_usages iface))
1048         , pprFixities (mi_fixities iface)
1049         , vcat (map pprIfaceDecl (mi_decls iface))
1050         , vcat (map ppr (mi_insts iface))
1051         , vcat (map ppr (mi_rules iface))
1052         , pprDeprecs (mi_deprecs iface)
1053         ]
1054   where
1055     pp_boot | mi_boot iface = ptext SLIT("[boot]")
1056             | otherwise     = empty
1057     ppr_package HomePackage = empty
1058     ppr_package (ExtPackage id) = doubleQuotes (ppr id)
1059
1060     exp_vers  = mi_exp_vers iface
1061     rule_vers = mi_rule_vers iface
1062
1063     pp_sub_vers | exp_vers == initialVersion && rule_vers == initialVersion = empty
1064                 | otherwise = brackets (ppr exp_vers <+> ppr rule_vers)
1065 \end{code}
1066
1067 When printing export lists, we print like this:
1068         Avail   f               f
1069         AvailTC C [C, x, y]     C(x,y)
1070         AvailTC C [x, y]        C!(x,y)         -- Exporting x, y but not C
1071
1072 \begin{code}
1073 pprExport :: IfaceExport -> SDoc
1074 pprExport (mod, items)
1075  = hsep [ ptext SLIT("export"), ppr mod, hsep (map pp_avail items) ]
1076   where
1077     pp_avail :: GenAvailInfo OccName -> SDoc
1078     pp_avail (Avail occ)    = ppr occ
1079     pp_avail (AvailTC _ []) = empty
1080     pp_avail (AvailTC n (n':ns)) 
1081         | n==n'     = ppr n <> pp_export ns
1082         | otherwise = ppr n <> char '|' <> pp_export (n':ns)
1083     
1084     pp_export []    = empty
1085     pp_export names = braces (hsep (map ppr names))
1086
1087 pprUsage :: Usage -> SDoc
1088 pprUsage usage
1089   = hsep [ptext SLIT("import"), ppr (usg_name usage), 
1090           int (usg_mod usage), 
1091           pp_export_version (usg_exports usage),
1092           int (usg_rules usage),
1093           pp_versions (usg_entities usage) ]
1094   where
1095     pp_versions nvs = hsep [ ppr n <+> int v | (n,v) <- nvs ]
1096     pp_export_version Nothing  = empty
1097     pp_export_version (Just v) = int v
1098
1099 pprDeps :: Dependencies -> SDoc
1100 pprDeps (Deps { dep_mods = mods, dep_pkgs = pkgs, dep_orphs = orphs})
1101   = vcat [ptext SLIT("module dependencies:") <+> fsep (map ppr_mod mods),
1102           ptext SLIT("package dependencies:") <+> fsep (map ppr pkgs), 
1103           ptext SLIT("orphans:") <+> fsep (map ppr orphs)
1104         ]
1105   where
1106     ppr_mod (mod_name, boot) = ppr mod_name <+> ppr_boot boot
1107     ppr_boot True  = text "[boot]"
1108     ppr_boot False = empty
1109
1110 pprIfaceDecl :: (Version, IfaceDecl) -> SDoc
1111 pprIfaceDecl (ver, decl)
1112   = ppr_vers ver <+> ppr decl
1113   where
1114         -- Print the version for the decl
1115     ppr_vers v | v == initialVersion = empty
1116                | otherwise           = int v
1117
1118 pprFixities :: [(OccName, Fixity)] -> SDoc
1119 pprFixities []    = empty
1120 pprFixities fixes = ptext SLIT("fixities") <+> pprWithCommas pprFix fixes
1121                   where
1122                     pprFix (occ,fix) = ppr fix <+> ppr occ 
1123
1124 pprDeprecs NoDeprecs        = empty
1125 pprDeprecs (DeprecAll txt)  = ptext SLIT("Deprecate all") <+> doubleQuotes (ftext txt)
1126 pprDeprecs (DeprecSome prs) = ptext SLIT("Deprecate") <+> vcat (map pprDeprec prs)
1127                             where
1128                               pprDeprec (name, txt) = ppr name <+> doubleQuotes (ftext txt)
1129 \end{code}