Remove the distinction between data and newtype families
[ghc-hetmet.git] / compiler / iface / IfaceSyn.lhs
1 %
2 % (c) The University of Glasgow 2006
3 % (c) The GRASP/AQUA Project, Glasgow University, 1993-1998
4 %
5
6 \begin{code}
7 module IfaceSyn (
8         module IfaceType,               -- Re-export all this
9
10         IfaceDecl(..), IfaceClassOp(..), IfaceConDecl(..), IfaceConDecls(..),
11         IfaceExpr(..), IfaceAlt, IfaceNote(..), IfaceLetBndr(..),
12         IfaceBinding(..), IfaceConAlt(..), IfaceIdInfo(..),
13         IfaceInfoItem(..), IfaceRule(..), IfaceInst(..), IfaceFamInst(..),
14
15         -- Misc
16         ifaceDeclSubBndrs, visibleIfConDecls,
17
18         -- Equality
19         GenIfaceEq(..), IfaceEq, (&&&), bool, eqListBy, eqMaybeBy,
20         eqIfDecl, eqIfInst, eqIfFamInst, eqIfRule, checkBootDecl,
21         
22         -- Pretty printing
23         pprIfaceExpr, pprIfaceDeclHead 
24     ) where
25
26 #include "HsVersions.h"
27
28 import CoreSyn
29 import IfaceType
30
31 import NewDemand
32 import Class
33 import UniqFM
34 import NameSet 
35 import Name
36 import CostCentre
37 import Literal
38 import ForeignCall
39 import BasicTypes
40 import Outputable
41 import FastString
42
43 import Data.List
44 import Data.Maybe
45
46 infixl 3 &&&
47 infix  4 `eqIfExt`, `eqIfIdInfo`, `eqIfType`
48 \end{code}
49
50
51 %************************************************************************
52 %*                                                                      *
53                 Data type declarations
54 %*                                                                      *
55 %************************************************************************
56
57 \begin{code}
58 data IfaceDecl 
59   = IfaceId { ifName   :: OccName,
60               ifType   :: IfaceType, 
61               ifIdInfo :: IfaceIdInfo }
62
63   | IfaceData { ifName       :: OccName,        -- Type constructor
64                 ifTyVars     :: [IfaceTvBndr],  -- Type variables
65                 ifCtxt       :: IfaceContext,   -- The "stupid theta"
66                 ifCons       :: IfaceConDecls,  -- Includes new/data info
67                 ifRec        :: RecFlag,        -- Recursive or not?
68                 ifGadtSyntax :: Bool,           -- True <=> declared using
69                                                 -- GADT syntax 
70                 ifGeneric    :: Bool,           -- True <=> generic converter
71                                                 --          functions available
72                                                 -- We need this for imported
73                                                 -- data decls, since the
74                                                 -- imported modules may have
75                                                 -- been compiled with
76                                                 -- different flags to the
77                                                 -- current compilation unit 
78                 ifFamInst    :: Maybe (IfaceTyCon, [IfaceType])
79                                                 -- Just <=> instance of family
80     }
81
82   | IfaceSyn  { ifName    :: OccName,           -- Type constructor
83                 ifTyVars  :: [IfaceTvBndr],     -- Type variables
84                 ifOpenSyn :: Bool,              -- Is an open family?
85                 ifSynRhs  :: IfaceType          -- Type for an ordinary
86                                                 -- synonym and kind for an
87                                                 -- open family
88     }
89
90   | IfaceClass { ifCtxt    :: IfaceContext,     -- Context...
91                  ifName    :: OccName,          -- Name of the class
92                  ifTyVars  :: [IfaceTvBndr],    -- Type variables
93                  ifFDs     :: [FunDep FastString], -- Functional dependencies
94                  ifATs     :: [IfaceDecl],      -- Associated type families
95                  ifSigs    :: [IfaceClassOp],   -- Method signatures
96                  ifRec     :: RecFlag           -- Is newtype/datatype associated with the class recursive?
97     }
98
99   | IfaceForeign { ifName :: OccName,           -- Needs expanding when we move
100                                                 -- beyond .NET
101                    ifExtName :: Maybe FastString }
102
103 data IfaceClassOp = IfaceClassOp OccName DefMeth IfaceType
104         -- Nothing    => no default method
105         -- Just False => ordinary polymorphic default method
106         -- Just True  => generic default method
107
108 data IfaceConDecls
109   = IfAbstractTyCon             -- No info
110   | IfOpenDataTyCon             -- Open data family
111   | IfDataTyCon [IfaceConDecl]  -- data type decls
112   | IfNewTyCon  IfaceConDecl    -- newtype decls
113
114 visibleIfConDecls :: IfaceConDecls -> [IfaceConDecl]
115 visibleIfConDecls IfAbstractTyCon  = []
116 visibleIfConDecls IfOpenDataTyCon  = []
117 visibleIfConDecls (IfDataTyCon cs) = cs
118 visibleIfConDecls (IfNewTyCon c)   = [c]
119
120 data IfaceConDecl 
121   = IfCon {
122         ifConOcc     :: OccName,                -- Constructor name
123         ifConInfix   :: Bool,                   -- True <=> declared infix
124         ifConUnivTvs :: [IfaceTvBndr],          -- Universal tyvars
125         ifConExTvs   :: [IfaceTvBndr],          -- Existential tyvars
126         ifConEqSpec  :: [(OccName,IfaceType)],  -- Equality contraints
127         ifConCtxt    :: IfaceContext,           -- Non-stupid context
128         ifConArgTys  :: [IfaceType],            -- Arg types
129         ifConFields  :: [OccName],              -- ...ditto... (field labels)
130         ifConStricts :: [StrictnessMark]}       -- Empty (meaning all lazy),
131                                                 -- or 1-1 corresp with arg tys
132
133 data IfaceInst 
134   = IfaceInst { ifInstCls  :: Name,                     -- See comments with
135                 ifInstTys  :: [Maybe IfaceTyCon],       -- the defn of Instance
136                 ifDFun     :: Name,                     -- The dfun
137                 ifOFlag    :: OverlapFlag,              -- Overlap flag
138                 ifInstOrph :: Maybe OccName }           -- See Note [Orphans]
139         -- There's always a separate IfaceDecl for the DFun, which gives 
140         -- its IdInfo with its full type and version number.
141         -- The instance declarations taken together have a version number,
142         -- and we don't want that to wobble gratuitously
143         -- If this instance decl is *used*, we'll record a usage on the dfun;
144         -- and if the head does not change it won't be used if it wasn't before
145
146 data IfaceFamInst
147   = IfaceFamInst { ifFamInstFam   :: Name                -- Family tycon
148                  , ifFamInstTys   :: [Maybe IfaceTyCon]  -- Rough match types
149                  , ifFamInstTyCon :: IfaceTyCon          -- Instance decl
150                  }
151
152 data IfaceRule
153   = IfaceRule { 
154         ifRuleName   :: RuleName,
155         ifActivation :: Activation,
156         ifRuleBndrs  :: [IfaceBndr],    -- Tyvars and term vars
157         ifRuleHead   :: Name,           -- Head of lhs
158         ifRuleArgs   :: [IfaceExpr],    -- Args of LHS
159         ifRuleRhs    :: IfaceExpr,
160         ifRuleOrph   :: Maybe OccName   -- Just like IfaceInst
161     }
162
163 data IfaceIdInfo
164   = NoInfo                      -- When writing interface file without -O
165   | HasInfo [IfaceInfoItem]     -- Has info, and here it is
166
167 -- Here's a tricky case:
168 --   * Compile with -O module A, and B which imports A.f
169 --   * Change function f in A, and recompile without -O
170 --   * When we read in old A.hi we read in its IdInfo (as a thunk)
171 --      (In earlier GHCs we used to drop IdInfo immediately on reading,
172 --       but we do not do that now.  Instead it's discarded when the
173 --       ModIface is read into the various decl pools.)
174 --   * The version comparsion sees that new (=NoInfo) differs from old (=HasInfo *)
175 --      and so gives a new version.
176
177 data IfaceInfoItem
178   = HsArity      Arity
179   | HsStrictness StrictSig
180   | HsInline     Activation
181   | HsUnfold     IfaceExpr
182   | HsNoCafRefs
183   | HsWorker     Name Arity     -- Worker, if any see IdInfo.WorkerInfo
184                                         -- for why we want arity here.
185         -- NB: we need IfaceExtName (not just OccName) because the worker
186         --     can simplify to a function in another module.
187 -- NB: Specialisations and rules come in separately and are
188 -- only later attached to the Id.  Partial reason: some are orphans.
189
190 --------------------------------
191 data IfaceExpr
192   = IfaceLcl    FastString
193   | IfaceExt    Name
194   | IfaceType   IfaceType
195   | IfaceTuple  Boxity [IfaceExpr]              -- Saturated; type arguments omitted
196   | IfaceLam    IfaceBndr IfaceExpr
197   | IfaceApp    IfaceExpr IfaceExpr
198   | IfaceCase   IfaceExpr FastString IfaceType [IfaceAlt]
199   | IfaceLet    IfaceBinding  IfaceExpr
200   | IfaceNote   IfaceNote IfaceExpr
201   | IfaceCast   IfaceExpr IfaceCoercion
202   | IfaceLit    Literal
203   | IfaceFCall  ForeignCall IfaceType
204
205 data IfaceNote = IfaceSCC CostCentre
206                | IfaceInlineMe
207                | IfaceCoreNote String
208
209 type IfaceAlt = (IfaceConAlt, [FastString], IfaceExpr)
210         -- Note: FastString, not IfaceBndr (and same with the case binder)
211         -- We reconstruct the kind/type of the thing from the context
212         -- thus saving bulk in interface files
213
214 data IfaceConAlt = IfaceDefault
215                  | IfaceDataAlt Name
216                  | IfaceTupleAlt Boxity
217                  | IfaceLitAlt Literal
218
219 data IfaceBinding
220   = IfaceNonRec IfaceLetBndr IfaceExpr
221   | IfaceRec    [(IfaceLetBndr, IfaceExpr)]
222
223 -- IfaceLetBndr is like IfaceIdBndr, but has IdInfo too
224 -- It's used for *non-top-level* let/rec binders
225 -- See Note [IdInfo on nested let-bindings]
226 data IfaceLetBndr = IfLetBndr FastString IfaceType IfaceIdInfo
227 \end{code}
228
229 Note [IdInfo on nested let-bindings]
230 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
231 Occasionally we want to preserve IdInfo on nested let bindings The one
232 that came up was a NOINLINE pragma on a let-binding inside an INLINE
233 function.  The user (Duncan Coutts) really wanted the NOINLINE control
234 to cross the separate compilation boundary.
235
236 So a IfaceLetBndr keeps a trimmed-down list of IfaceIdInfo stuff.
237 Currently we only actually retain InlinePragInfo, but in principle we could
238 add strictness etc.
239
240
241 Note [Orphans]: the ifInstOrph and ifRuleOrph fields
242 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
243 If a module contains any "orphans", then its interface file is read
244 regardless, so that its instances are not missed.
245
246 Roughly speaking, an instance is an orphan if its head (after the =>)
247 mentions nothing defined in this module.  Functional dependencies
248 complicate the situation though. Consider
249
250   module M where { class C a b | a -> b }
251
252 and suppose we are compiling module X:
253
254   module X where
255         import M
256         data T = ...
257         instance C Int T where ...
258
259 This instance is an orphan, because when compiling a third module Y we
260 might get a constraint (C Int v), and we'd want to improve v to T.  So
261 we must make sure X's instances are loaded, even if we do not directly
262 use anything from X.
263
264 More precisely, an instance is an orphan iff
265
266   If there are no fundeps, then at least of the names in
267   the instance head is locally defined.
268
269   If there are fundeps, then for every fundep, at least one of the
270   names free in a *non-determined* part of the instance head is
271   defined in this module.  
272
273 (Note that these conditions hold trivially if the class is locally
274 defined.)
275
276 Note [Versioning of instances]
277 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
278 Now consider versioning.  If we *use* an instance decl in one compilation,
279 we'll depend on the dfun id for that instance, so we'll recompile if it changes.
280 But suppose we *don't* (currently) use an instance!  We must recompile if
281 the instance is changed in such a way that it becomes important.  (This would
282 only matter with overlapping instances, else the importing module wouldn't have
283 compiled before and the recompilation check is irrelevant.)
284
285 The is_orph field is set to (Just n) if the instance is not an orphan.
286 The 'n' is *any* of the locally-defined names mentioned anywhere in the
287 instance head.  This name is used for versioning; the instance decl is
288 considered part of the defn of this 'n'.
289
290 I'm worried about whether this works right if we pick a name from
291 a functionally-dependent part of the instance decl.  E.g.
292
293   module M where { class C a b | a -> b }
294
295 and suppose we are compiling module X:
296
297   module X where
298         import M
299         data S  = ...
300         data T = ...
301         instance C S T where ...
302
303 If we base the instance verion on T, I'm worried that changing S to S'
304 would change T's version, but not S or S'.  But an importing module might
305 not depend on T, and so might not be recompiled even though the new instance
306 (C S' T) might be relevant.  I have not been able to make a concrete example,
307 and it seems deeply obscure, so I'm going to leave it for now.
308
309
310 Note [Versioning of rules]
311 ~~~~~~~~~~~~~~~~~~~~~~~~~~
312 A rule that is not an orphan has an ifRuleOrph field of (Just n), where
313 n appears on the LHS of the rule; any change in the rule changes the version of n.
314
315
316 \begin{code}
317 -- -----------------------------------------------------------------------------
318 -- Utils on IfaceSyn
319
320 ifaceDeclSubBndrs :: IfaceDecl -> [OccName]
321 --  *Excludes* the 'main' name, but *includes* the implicitly-bound names
322 -- Deeply revolting, because it has to predict what gets bound,
323 -- especially the question of whether there's a wrapper for a datacon
324
325 ifaceDeclSubBndrs (IfaceClass {ifCtxt = sc_ctxt, ifName = cls_occ, 
326                                ifSigs = sigs, ifATs = ats })
327   = co_occs ++
328     [tc_occ, dc_occ, dcww_occ] ++
329     [op | IfaceClassOp op  _ _ <- sigs] ++
330     [ifName at | at <- ats ] ++
331     [mkSuperDictSelOcc n cls_occ | n <- [1..n_ctxt]] 
332   where
333     n_ctxt = length sc_ctxt
334     n_sigs = length sigs
335     tc_occ  = mkClassTyConOcc cls_occ
336     dc_occ  = mkClassDataConOcc cls_occ 
337     co_occs | is_newtype = [mkNewTyCoOcc tc_occ]
338             | otherwise  = []
339     dcww_occ -- | is_newtype = mkDataConWrapperOcc dc_occ       -- Newtypes have wrapper but no worker
340              | otherwise  = mkDataConWorkerOcc dc_occ   -- Otherwise worker but no wrapper
341     is_newtype = n_sigs + n_ctxt == 1                   -- Sigh 
342
343 ifaceDeclSubBndrs IfaceData {ifCons = IfAbstractTyCon}
344   = []
345 -- Newtype
346 ifaceDeclSubBndrs (IfaceData {ifName = tc_occ,
347                               ifCons = IfNewTyCon (
348                                          IfCon { ifConOcc = con_occ, 
349                                                            ifConFields = fields
350                                                          }),
351                               ifFamInst = famInst}) 
352   = fields ++ [con_occ, mkDataConWorkerOcc con_occ, mkNewTyCoOcc tc_occ]
353     ++ famInstCo famInst tc_occ
354
355 ifaceDeclSubBndrs (IfaceData {ifName = tc_occ,
356                               ifCons = IfDataTyCon cons, 
357                               ifFamInst = famInst})
358   = nub (concatMap ifConFields cons)    -- Eliminate duplicate fields
359     ++ concatMap dc_occs cons
360     ++ famInstCo famInst tc_occ
361   where
362     dc_occs con_decl
363         | has_wrapper = [con_occ, work_occ, wrap_occ]
364         | otherwise   = [con_occ, work_occ]
365         where
366           con_occ = ifConOcc con_decl
367           strs    = ifConStricts con_decl
368           wrap_occ = mkDataConWrapperOcc con_occ
369           work_occ = mkDataConWorkerOcc con_occ
370           has_wrapper = any isMarkedStrict strs -- See MkId.mkDataConIds (sigh)
371                         || not (null . ifConEqSpec $ con_decl)
372                         || isJust famInst
373                 -- ToDo: may miss strictness in existential dicts
374
375 ifaceDeclSubBndrs _other = []
376
377 -- coercion for data/newtype family instances
378 famInstCo Nothing  baseOcc = []
379 famInstCo (Just _) baseOcc = [mkInstTyCoOcc baseOcc]
380
381 ----------------------------- Printing IfaceDecl ------------------------------
382
383 instance Outputable IfaceDecl where
384   ppr = pprIfaceDecl
385
386 pprIfaceDecl (IfaceId {ifName = var, ifType = ty, ifIdInfo = info})
387   = sep [ ppr var <+> dcolon <+> ppr ty, 
388           nest 2 (ppr info) ]
389
390 pprIfaceDecl (IfaceForeign {ifName = tycon})
391   = hsep [ptext SLIT("foreign import type dotnet"), ppr tycon]
392
393 pprIfaceDecl (IfaceSyn {ifName = tycon, ifTyVars = tyvars, 
394                         ifOpenSyn = False, ifSynRhs = mono_ty})
395   = hang (ptext SLIT("type") <+> pprIfaceDeclHead [] tycon tyvars)
396        4 (equals <+> ppr mono_ty)
397
398 pprIfaceDecl (IfaceSyn {ifName = tycon, ifTyVars = tyvars, 
399                         ifOpenSyn = True, ifSynRhs = mono_ty})
400   = hang (ptext SLIT("type family") <+> pprIfaceDeclHead [] tycon tyvars)
401        4 (dcolon <+> ppr mono_ty)
402
403 pprIfaceDecl (IfaceData {ifName = tycon, ifGeneric = gen, ifCtxt = context,
404                          ifTyVars = tyvars, ifCons = condecls, 
405                          ifRec = isrec, ifFamInst = mbFamInst})
406   = hang (pp_nd <+> pprIfaceDeclHead context tycon tyvars)
407        4 (vcat [pprRec isrec, pprGen gen, pp_condecls tycon condecls,
408                 pprFamily mbFamInst])
409   where
410     pp_nd = case condecls of
411                 IfAbstractTyCon -> ptext SLIT("data")
412                 IfOpenDataTyCon -> ptext SLIT("data family")
413                 IfDataTyCon _   -> ptext SLIT("data")
414                 IfNewTyCon _    -> ptext SLIT("newtype")
415
416 pprIfaceDecl (IfaceClass {ifCtxt = context, ifName = clas, ifTyVars = tyvars, 
417                           ifFDs = fds, ifATs = ats, ifSigs = sigs, 
418                           ifRec = isrec})
419   = hang (ptext SLIT("class") <+> pprIfaceDeclHead context clas tyvars <+> pprFundeps fds)
420        4 (vcat [pprRec isrec,
421                 sep (map ppr ats),
422                 sep (map ppr sigs)])
423
424 pprRec isrec = ptext SLIT("RecFlag") <+> ppr isrec
425 pprGen True  = ptext SLIT("Generics: yes")
426 pprGen False = ptext SLIT("Generics: no")
427
428 pprFamily Nothing        = ptext SLIT("FamilyInstance: none")
429 pprFamily (Just famInst) = ptext SLIT("FamilyInstance:") <+> ppr famInst
430
431 instance Outputable IfaceClassOp where
432    ppr (IfaceClassOp n dm ty) = ppr n <+> ppr dm <+> dcolon <+> ppr ty
433
434 pprIfaceDeclHead :: IfaceContext -> OccName -> [IfaceTvBndr] -> SDoc
435 pprIfaceDeclHead context thing tyvars
436   = hsep [pprIfaceContext context, parenSymOcc thing (ppr thing), 
437           pprIfaceTvBndrs tyvars]
438
439 pp_condecls tc IfAbstractTyCon  = ptext SLIT("{- abstract -}")
440 pp_condecls tc (IfNewTyCon c)   = equals <+> pprIfaceConDecl tc c
441 pp_condecls tc IfOpenDataTyCon  = empty
442 pp_condecls tc (IfDataTyCon cs) = equals <+> sep (punctuate (ptext SLIT(" |"))
443                                                              (map (pprIfaceConDecl tc) cs))
444
445 pprIfaceConDecl :: OccName -> IfaceConDecl -> SDoc
446 pprIfaceConDecl tc
447         (IfCon { ifConOcc = name, ifConInfix = is_infix, 
448                  ifConUnivTvs = univ_tvs, ifConExTvs = ex_tvs, 
449                  ifConEqSpec = eq_spec, ifConCtxt = ctxt, ifConArgTys = arg_tys, 
450                  ifConStricts = strs, ifConFields = fields })
451   = sep [main_payload,
452          if is_infix then ptext SLIT("Infix") else empty,
453          if null strs then empty 
454               else nest 4 (ptext SLIT("Stricts:") <+> hsep (map ppr strs)),
455          if null fields then empty
456               else nest 4 (ptext SLIT("Fields:") <+> hsep (map ppr fields))]
457   where
458     main_payload = ppr name <+> dcolon <+> 
459                    pprIfaceForAllPart (univ_tvs ++ ex_tvs) (eq_ctxt ++ ctxt) pp_tau
460
461     eq_ctxt = [(IfaceEqPred (IfaceTyVar (occNameFS tv)) ty) 
462               | (tv,ty) <- eq_spec] 
463
464         -- A bit gruesome this, but we can't form the full con_tau, and ppr it,
465         -- because we don't have a Name for the tycon, only an OccName
466     pp_tau = case map pprParendIfaceType arg_tys ++ [pp_res_ty] of
467                 (t:ts) -> fsep (t : map (arrow <+>) ts)
468                 []     -> panic "pp_con_taus"
469
470     pp_res_ty = ppr tc <+> fsep [ppr tv | (tv,_) <- univ_tvs]
471
472 instance Outputable IfaceRule where
473   ppr (IfaceRule { ifRuleName = name, ifActivation = act, ifRuleBndrs = bndrs,
474                    ifRuleHead = fn, ifRuleArgs = args, ifRuleRhs = rhs }) 
475     = sep [hsep [doubleQuotes (ftext name), ppr act,
476                  ptext SLIT("forall") <+> pprIfaceBndrs bndrs],
477            nest 2 (sep [ppr fn <+> sep (map (pprIfaceExpr parens) args),
478                         ptext SLIT("=") <+> ppr rhs])
479       ]
480
481 instance Outputable IfaceInst where
482   ppr (IfaceInst {ifDFun = dfun_id, ifOFlag = flag, 
483                   ifInstCls = cls, ifInstTys = mb_tcs})
484     = hang (ptext SLIT("instance") <+> ppr flag 
485                 <+> ppr cls <+> brackets (pprWithCommas ppr_rough mb_tcs))
486          2 (equals <+> ppr dfun_id)
487
488 instance Outputable IfaceFamInst where
489   ppr (IfaceFamInst {ifFamInstFam = fam, ifFamInstTys = mb_tcs,
490                      ifFamInstTyCon = tycon_id})
491     = hang (ptext SLIT("family instance") <+> 
492             ppr fam <+> brackets (pprWithCommas ppr_rough mb_tcs))
493          2 (equals <+> ppr tycon_id)
494
495 ppr_rough :: Maybe IfaceTyCon -> SDoc
496 ppr_rough Nothing   = dot
497 ppr_rough (Just tc) = ppr tc
498 \end{code}
499
500
501 ----------------------------- Printing IfaceExpr ------------------------------------
502
503 \begin{code}
504 instance Outputable IfaceExpr where
505     ppr e = pprIfaceExpr noParens e
506
507 pprIfaceExpr :: (SDoc -> SDoc) -> IfaceExpr -> SDoc
508         -- The function adds parens in context that need
509         -- an atomic value (e.g. function args)
510
511 pprIfaceExpr add_par (IfaceLcl v)       = ppr v
512 pprIfaceExpr add_par (IfaceExt v)       = ppr v
513 pprIfaceExpr add_par (IfaceLit l)       = ppr l
514 pprIfaceExpr add_par (IfaceFCall cc ty) = braces (ppr cc <+> ppr ty)
515 pprIfaceExpr add_par (IfaceType ty)     = char '@' <+> pprParendIfaceType ty
516
517 pprIfaceExpr add_par app@(IfaceApp _ _) = add_par (pprIfaceApp app [])
518 pprIfaceExpr add_par (IfaceTuple c as)  = tupleParens c (interpp'SP as)
519
520 pprIfaceExpr add_par e@(IfaceLam _ _)   
521   = add_par (sep [char '\\' <+> sep (map ppr bndrs) <+> arrow,
522                   pprIfaceExpr noParens body])
523   where 
524     (bndrs,body) = collect [] e
525     collect bs (IfaceLam b e) = collect (b:bs) e
526     collect bs e              = (reverse bs, e)
527
528 pprIfaceExpr add_par (IfaceCase scrut bndr ty [(con, bs, rhs)])
529   = add_par (sep [ptext SLIT("case") <+> char '@' <+> pprParendIfaceType ty
530                         <+> pprIfaceExpr noParens scrut <+> ptext SLIT("of") 
531                         <+> ppr bndr <+> char '{' <+> ppr_con_bs con bs <+> arrow,
532                   pprIfaceExpr noParens rhs <+> char '}'])
533
534 pprIfaceExpr add_par (IfaceCase scrut bndr ty alts)
535   = add_par (sep [ptext SLIT("case") <+> char '@' <+> pprParendIfaceType ty
536                         <+> pprIfaceExpr noParens scrut <+> ptext SLIT("of") 
537                         <+> ppr bndr <+> char '{',
538                   nest 2 (sep (map ppr_alt alts)) <+> char '}'])
539
540 pprIfaceExpr add_par (IfaceCast expr co)
541   = sep [pprIfaceExpr parens expr,
542          nest 2 (ptext SLIT("`cast`")),
543          pprParendIfaceType co]
544
545 pprIfaceExpr add_par (IfaceLet (IfaceNonRec b rhs) body)
546   = add_par (sep [ptext SLIT("let {"), 
547                   nest 2 (ppr_bind (b, rhs)),
548                   ptext SLIT("} in"), 
549                   pprIfaceExpr noParens body])
550
551 pprIfaceExpr add_par (IfaceLet (IfaceRec pairs) body)
552   = add_par (sep [ptext SLIT("letrec {"),
553                   nest 2 (sep (map ppr_bind pairs)), 
554                   ptext SLIT("} in"),
555                   pprIfaceExpr noParens body])
556
557 pprIfaceExpr add_par (IfaceNote note body) = add_par (ppr note <+> pprIfaceExpr parens body)
558
559 ppr_alt (con, bs, rhs) = sep [ppr_con_bs con bs, 
560                               arrow <+> pprIfaceExpr noParens rhs]
561
562 ppr_con_bs (IfaceTupleAlt tup_con) bs = tupleParens tup_con (interpp'SP bs)
563 ppr_con_bs con bs                     = ppr con <+> hsep (map ppr bs)
564   
565 ppr_bind (IfLetBndr b ty info, rhs) 
566   = sep [hang (ppr b <+> dcolon <+> ppr ty) 2 (ppr info),
567          equals <+> pprIfaceExpr noParens rhs]
568
569 ------------------
570 pprIfaceApp (IfaceApp fun arg) args = pprIfaceApp fun (nest 2 (pprIfaceExpr parens arg) : args)
571 pprIfaceApp fun                args = sep (pprIfaceExpr parens fun : args)
572
573 ------------------
574 instance Outputable IfaceNote where
575     ppr (IfaceSCC cc)     = pprCostCentreCore cc
576     ppr IfaceInlineMe     = ptext SLIT("__inline_me")
577     ppr (IfaceCoreNote s) = ptext SLIT("__core_note") <+> pprHsString (mkFastString s)
578
579
580 instance Outputable IfaceConAlt where
581     ppr IfaceDefault      = text "DEFAULT"
582     ppr (IfaceLitAlt l)   = ppr l
583     ppr (IfaceDataAlt d)  = ppr d
584     ppr (IfaceTupleAlt b) = panic "ppr IfaceConAlt" 
585         -- IfaceTupleAlt is handled by the case-alternative printer
586
587 ------------------
588 instance Outputable IfaceIdInfo where
589   ppr NoInfo       = empty
590   ppr (HasInfo is) = ptext SLIT("{-") <+> fsep (map ppr is) <+> ptext SLIT("-}")
591
592 instance Outputable IfaceInfoItem where
593   ppr (HsUnfold unf)     = ptext SLIT("Unfolding:") <+>
594                                         parens (pprIfaceExpr noParens unf)
595   ppr (HsInline act)     = ptext SLIT("Inline:") <+> ppr act
596   ppr (HsArity arity)    = ptext SLIT("Arity:") <+> int arity
597   ppr (HsStrictness str) = ptext SLIT("Strictness:") <+> pprIfaceStrictSig str
598   ppr HsNoCafRefs        = ptext SLIT("HasNoCafRefs")
599   ppr (HsWorker w a)     = ptext SLIT("Worker:") <+> ppr w <+> int a
600 \end{code}
601
602
603 %************************************************************************
604 %*                                                                      *
605         Equality, for interface file version generaion only
606 %*                                                                      *
607 %************************************************************************
608
609 Equality over IfaceSyn returns an IfaceEq, not a Bool.  The new
610 constructor is EqBut, which gives the set of things whose version must
611 be equal for the whole thing to be equal.  So the key function is
612 eqIfExt, which compares Names.
613
614 Of course, equality is also done modulo alpha conversion.
615
616 \begin{code}
617 data GenIfaceEq a
618   = Equal               -- Definitely exactly the same
619   | NotEqual            -- Definitely different
620   | EqBut a       -- The same provided these Names have not changed
621
622 type IfaceEq = GenIfaceEq NameSet
623
624 instance Outputable IfaceEq where
625   ppr Equal          = ptext SLIT("Equal")
626   ppr NotEqual       = ptext SLIT("NotEqual")
627   ppr (EqBut occset) = ptext SLIT("EqBut") <+> ppr (nameSetToList occset)
628
629 bool :: Bool -> IfaceEq
630 bool True  = Equal
631 bool False = NotEqual
632
633 toBool :: IfaceEq -> Bool
634 toBool Equal     = True
635 toBool (EqBut _) = True
636 toBool NotEqual  = False
637
638 zapEq :: IfaceEq -> IfaceEq     -- Used to forget EqBut information
639 zapEq (EqBut _) = Equal
640 zapEq other     = other
641
642 (&&&) :: IfaceEq -> IfaceEq -> IfaceEq
643 Equal       &&& x           = x
644 NotEqual    &&& x           = NotEqual
645 EqBut nms   &&& Equal       = EqBut nms
646 EqBut nms   &&& NotEqual    = NotEqual
647 EqBut nms1  &&& EqBut nms2  = EqBut (nms1 `unionNameSets` nms2)
648
649 -- This function is the core of the EqBut stuff
650 -- ASSUMPTION: The left-hand argument is the NEW CODE, and hence
651 -- any Names in the left-hand arg have the correct parent in them.
652 eqIfExt :: Name -> Name -> IfaceEq
653 eqIfExt name1 name2 
654   | name1 == name2 = EqBut (unitNameSet name1)
655   | otherwise      = NotEqual
656
657 ---------------------
658 checkBootDecl :: IfaceDecl      -- The boot decl
659               -> IfaceDecl      -- The real decl
660               -> Bool           -- True <=> compatible
661 checkBootDecl (IfaceId s1 t1 _) (IfaceId s2 t2 _)
662   = ASSERT( s1==s2 ) toBool (t1 `eqIfType` t2)
663
664 checkBootDecl d1@(IfaceForeign {}) d2@(IfaceForeign {})
665   = ASSERT (ifName d1 == ifName d2 ) ifExtName d1 == ifExtName d2
666
667 checkBootDecl d1@(IfaceSyn {}) d2@(IfaceSyn {})
668   = ASSERT( ifName d1 == ifName d2 )
669     toBool $ eqWith (ifTyVars d1) (ifTyVars d2) $ \ env -> 
670           eq_ifType env (ifSynRhs d1) (ifSynRhs d2)
671
672 checkBootDecl d1@(IfaceData {}) d2@(IfaceData {})
673 -- We don't check the recursion flags because the boot-one is
674 -- recursive, to be conservative, but the real one may not be.
675 -- I'm not happy with the way recursive flags are dealt with.
676   = ASSERT( ifName d1    == ifName d2 ) 
677     toBool $ eqWith (ifTyVars d1) (ifTyVars d2) $ \ env -> 
678         eq_ifContext env (ifCtxt d1) (ifCtxt d2) &&& 
679         case ifCons d1 of
680             IfAbstractTyCon -> Equal
681             cons1           -> eq_hsCD env cons1 (ifCons d2)
682
683 checkBootDecl d1@(IfaceClass {}) d2@(IfaceClass {})
684   = ASSERT( ifName d1 == ifName d2 )
685     toBool $ eqWith (ifTyVars d1) (ifTyVars d2) $ \ env -> 
686           eqListBy (eq_hsFD env)    (ifFDs d1)  (ifFDs d2) &&&
687           case (ifCtxt d1, ifSigs d1) of
688              ([], [])      -> Equal
689              (cxt1, sigs1) -> eq_ifContext env cxt1 (ifCtxt d2)  &&&
690                               eqListBy (eq_cls_sig env) sigs1 (ifSigs d2)
691
692 checkBootDecl _ _ = False       -- default case
693
694 ---------------------
695 eqIfDecl :: IfaceDecl -> IfaceDecl -> IfaceEq
696 eqIfDecl (IfaceId s1 t1 i1) (IfaceId s2 t2 i2)
697   = bool (s1 == s2) &&& (t1 `eqIfType` t2) &&& (i1 `eqIfIdInfo` i2)
698
699 eqIfDecl d1@(IfaceForeign {}) d2@(IfaceForeign {})
700   = bool (ifName d1 == ifName d2 && ifExtName d1 == ifExtName d2)
701
702 eqIfDecl d1@(IfaceData {}) d2@(IfaceData {})
703   = bool (ifName d1    == ifName d2 && 
704           ifRec d1     == ifRec   d2 && 
705           ifGadtSyntax d1 == ifGadtSyntax   d2 && 
706           ifGeneric d1 == ifGeneric d2) &&&
707     ifFamInst d1 `eqIfTc_fam` ifFamInst d2 &&&
708     eqWith (ifTyVars d1) (ifTyVars d2) (\ env -> 
709             eq_ifContext env (ifCtxt d1) (ifCtxt d2) &&& 
710             eq_hsCD env (ifCons d1) (ifCons d2) 
711         )
712         -- The type variables of the data type do not scope
713         -- over the constructors (any more), but they do scope
714         -- over the stupid context in the IfaceConDecls
715   where
716     Nothing             `eqIfTc_fam` Nothing             = Equal
717     (Just (fam1, tys1)) `eqIfTc_fam` (Just (fam2, tys2)) = 
718       fam1 `eqIfTc` fam2 &&& eqListBy eqIfType tys1 tys2
719     _                   `eqIfTc_fam` _                   = NotEqual
720
721 eqIfDecl d1@(IfaceSyn {}) d2@(IfaceSyn {})
722   = bool (ifName d1 == ifName d2) &&&
723     eqWith (ifTyVars d1) (ifTyVars d2) (\ env -> 
724           eq_ifType env (ifSynRhs d1) (ifSynRhs d2)
725         )
726
727 eqIfDecl d1@(IfaceClass {}) d2@(IfaceClass {})
728   = bool (ifName d1 == ifName d2 && 
729           ifRec d1  == ifRec  d2) &&&
730     eqWith (ifTyVars d1) (ifTyVars d2) (\ env -> 
731           eq_ifContext env (ifCtxt d1) (ifCtxt d2)  &&&
732           eqListBy (eq_hsFD env)    (ifFDs d1)  (ifFDs d2) &&&
733           eqListBy eqIfDecl         (ifATs d1)  (ifATs d2) &&&
734           eqListBy (eq_cls_sig env) (ifSigs d1) (ifSigs d2)
735        )
736
737 eqIfDecl _ _ = NotEqual -- default case
738
739 -- Helper
740 eqWith :: [IfaceTvBndr] -> [IfaceTvBndr] -> (EqEnv -> IfaceEq) -> IfaceEq
741 eqWith = eq_ifTvBndrs emptyEqEnv
742
743 -----------------------
744 eqIfInst d1 d2 = bool (ifDFun d1 == ifDFun d2 && ifOFlag d1 == ifOFlag d2)
745 -- All other changes are handled via the version info on the dfun
746
747 eqIfFamInst d1 d2 = bool (ifFamInstTyCon d1 == ifFamInstTyCon d2)
748 -- All other changes are handled via the version info on the tycon
749
750 eqIfRule (IfaceRule n1 a1 bs1 f1 es1 rhs1 o1)
751          (IfaceRule n2 a2 bs2 f2 es2 rhs2 o2)
752        = bool (n1==n2 && a1==a2 && o1 == o2) &&&
753          f1 `eqIfExt` f2 &&&
754          eq_ifBndrs emptyEqEnv bs1 bs2 (\env -> 
755          zapEq (eqListBy (eq_ifaceExpr env) es1 es2) &&&
756                 -- zapEq: for the LHSs, ignore the EqBut part
757          eq_ifaceExpr env rhs1 rhs2)
758
759 eq_hsCD env (IfDataTyCon c1) (IfDataTyCon c2) 
760   = eqListBy (eq_ConDecl env) c1 c2
761
762 eq_hsCD env (IfNewTyCon c1)  (IfNewTyCon c2)  = eq_ConDecl env c1 c2
763 eq_hsCD env IfAbstractTyCon  IfAbstractTyCon  = Equal
764 eq_hsCD env IfOpenDataTyCon  IfOpenDataTyCon  = Equal
765 eq_hsCD env d1               d2               = NotEqual
766
767 eq_ConDecl env c1 c2
768   = bool (ifConOcc c1     == ifConOcc c2 && 
769           ifConInfix c1   == ifConInfix c2 && 
770           ifConStricts c1 == ifConStricts c2 && 
771           ifConFields c1  == ifConFields c2) &&&
772     eq_ifTvBndrs env (ifConUnivTvs c1) (ifConUnivTvs c2) (\ env ->
773     eq_ifTvBndrs env (ifConExTvs c1) (ifConExTvs c2) (\ env ->
774         eq_ifContext env (ifConCtxt c1) (ifConCtxt c2) &&&
775         eq_ifTypes env (ifConArgTys c1) (ifConArgTys c2)))
776
777 eq_hsFD env (ns1,ms1) (ns2,ms2)
778   = eqListBy (eqIfOcc env) ns1 ns2 &&& eqListBy (eqIfOcc env) ms1 ms2
779
780 eq_cls_sig env (IfaceClassOp n1 dm1 ty1) (IfaceClassOp n2 dm2 ty2)
781   = bool (n1==n2 && dm1 == dm2) &&& eq_ifType env ty1 ty2
782 \end{code}
783
784
785 \begin{code}
786 -----------------
787 eqIfIdInfo NoInfo        NoInfo        = Equal
788 eqIfIdInfo (HasInfo is1) (HasInfo is2) = eqListBy eq_item is1 is2
789 eqIfIdInfo i1            i2 = NotEqual
790
791 eq_item (HsInline a1)      (HsInline a2)      = bool (a1 == a2)
792 eq_item (HsArity a1)       (HsArity a2)       = bool (a1 == a2)
793 eq_item (HsStrictness s1)  (HsStrictness s2)  = bool (s1 == s2)
794 eq_item (HsUnfold u1)   (HsUnfold u2)         = eq_ifaceExpr emptyEqEnv u1 u2
795 eq_item HsNoCafRefs        HsNoCafRefs        = Equal
796 eq_item (HsWorker wkr1 a1) (HsWorker wkr2 a2) = bool (a1==a2) &&& (wkr1 `eqIfExt` wkr2)
797 eq_item _ _ = NotEqual
798
799 -----------------
800 eq_ifaceExpr :: EqEnv -> IfaceExpr -> IfaceExpr -> IfaceEq
801 eq_ifaceExpr env (IfaceLcl v1)        (IfaceLcl v2)        = eqIfOcc env v1 v2
802 eq_ifaceExpr env (IfaceExt v1)        (IfaceExt v2)        = eqIfExt v1 v2
803 eq_ifaceExpr env (IfaceLit l1)        (IfaceLit l2)        = bool (l1 == l2)
804 eq_ifaceExpr env (IfaceFCall c1 ty1)  (IfaceFCall c2 ty2)  = bool (c1==c2) &&& eq_ifType env ty1 ty2
805 eq_ifaceExpr env (IfaceType ty1)      (IfaceType ty2)      = eq_ifType env ty1 ty2
806 eq_ifaceExpr env (IfaceTuple n1 as1)  (IfaceTuple n2 as2)  = bool (n1==n2) &&& eqListBy (eq_ifaceExpr env) as1 as2
807 eq_ifaceExpr env (IfaceLam b1 body1)  (IfaceLam b2 body2)  = eq_ifBndr env b1 b2 (\env -> eq_ifaceExpr env body1 body2)
808 eq_ifaceExpr env (IfaceApp f1 a1)     (IfaceApp f2 a2)     = eq_ifaceExpr env f1 f2 &&& eq_ifaceExpr env a1 a2
809 eq_ifaceExpr env (IfaceCast e1 co1)   (IfaceCast e2 co2)   = eq_ifaceExpr env e1 e2 &&& eq_ifType env co1 co2
810 eq_ifaceExpr env (IfaceNote n1 r1)    (IfaceNote n2 r2)    = eq_ifaceNote env n1 n2 &&& eq_ifaceExpr env r1 r2
811
812 eq_ifaceExpr env (IfaceCase s1 b1 ty1 as1) (IfaceCase s2 b2 ty2 as2)
813   = eq_ifaceExpr env s1 s2 &&&
814     eq_ifType env ty1 ty2 &&&
815     eq_ifNakedBndr env b1 b2 (\env -> eqListBy (eq_ifaceAlt env) as1 as2)
816   where
817     eq_ifaceAlt env (c1,bs1,r1) (c2,bs2,r2)
818         = bool (eq_ifaceConAlt c1 c2) &&& 
819           eq_ifNakedBndrs env bs1 bs2 (\env -> eq_ifaceExpr env r1 r2)
820
821 eq_ifaceExpr env (IfaceLet (IfaceNonRec b1 r1) x1) (IfaceLet (IfaceNonRec b2 r2) x2)
822   = eq_ifaceExpr env r1 r2 &&& eq_ifLetBndr env b1 b2 (\env -> eq_ifaceExpr env x1 x2)
823
824 eq_ifaceExpr env (IfaceLet (IfaceRec as1) x1) (IfaceLet (IfaceRec as2) x2)
825   = eq_ifLetBndrs env bs1 bs2 (\env -> eqListBy (eq_ifaceExpr env) rs1 rs2 &&& eq_ifaceExpr env x1 x2)
826   where
827     (bs1,rs1) = unzip as1
828     (bs2,rs2) = unzip as2
829
830
831 eq_ifaceExpr env _ _ = NotEqual
832
833 -----------------
834 eq_ifaceConAlt :: IfaceConAlt -> IfaceConAlt -> Bool
835 eq_ifaceConAlt IfaceDefault       IfaceDefault          = True
836 eq_ifaceConAlt (IfaceDataAlt n1)  (IfaceDataAlt n2)     = n1==n2
837 eq_ifaceConAlt (IfaceTupleAlt c1) (IfaceTupleAlt c2)    = c1==c2
838 eq_ifaceConAlt (IfaceLitAlt l1)   (IfaceLitAlt l2)      = l1==l2
839 eq_ifaceConAlt _ _ = False
840
841 -----------------
842 eq_ifaceNote :: EqEnv -> IfaceNote -> IfaceNote -> IfaceEq
843 eq_ifaceNote env (IfaceSCC c1)    (IfaceSCC c2)        = bool (c1==c2)
844 eq_ifaceNote env IfaceInlineMe    IfaceInlineMe        = Equal
845 eq_ifaceNote env (IfaceCoreNote s1) (IfaceCoreNote s2) = bool (s1==s2)
846 eq_ifaceNote env _ _ = NotEqual
847 \end{code}
848
849 \begin{code}
850 ---------------------
851 eqIfType t1 t2 = eq_ifType emptyEqEnv t1 t2
852
853 -------------------
854 eq_ifType env (IfaceTyVar n1)         (IfaceTyVar n2)         = eqIfOcc env n1 n2
855 eq_ifType env (IfaceAppTy s1 t1)      (IfaceAppTy s2 t2)      = eq_ifType env s1 s2 &&& eq_ifType env t1 t2
856 eq_ifType env (IfacePredTy st1)       (IfacePredTy st2)       = eq_ifPredType env st1 st2
857 eq_ifType env (IfaceTyConApp tc1 ts1) (IfaceTyConApp tc2 ts2) = tc1 `eqIfTc` tc2 &&& eq_ifTypes env ts1 ts2
858 eq_ifType env (IfaceForAllTy tv1 t1)  (IfaceForAllTy tv2 t2)  = eq_ifTvBndr env tv1 tv2 (\env -> eq_ifType env t1 t2)
859 eq_ifType env (IfaceFunTy s1 t1)      (IfaceFunTy s2 t2)      = eq_ifType env s1 s2 &&& eq_ifType env t1 t2
860 eq_ifType env _ _ = NotEqual
861
862 -------------------
863 eq_ifTypes env = eqListBy (eq_ifType env)
864
865 -------------------
866 eq_ifContext env a b = eqListBy (eq_ifPredType env) a b
867
868 -------------------
869 eq_ifPredType env (IfaceClassP c1 tys1) (IfaceClassP c2 tys2) = c1 `eqIfExt` c2 &&&  eq_ifTypes env tys1 tys2
870 eq_ifPredType env (IfaceIParam n1 ty1) (IfaceIParam n2 ty2)   = bool (n1 == n2) &&& eq_ifType env ty1 ty2
871 eq_ifPredType env _ _ = NotEqual
872
873 -------------------
874 eqIfTc (IfaceTc tc1) (IfaceTc tc2) = tc1 `eqIfExt` tc2
875 eqIfTc IfaceIntTc    IfaceIntTc    = Equal
876 eqIfTc IfaceCharTc   IfaceCharTc   = Equal
877 eqIfTc IfaceBoolTc   IfaceBoolTc   = Equal
878 eqIfTc IfaceListTc   IfaceListTc   = Equal
879 eqIfTc IfacePArrTc   IfacePArrTc   = Equal
880 eqIfTc (IfaceTupTc bx1 ar1) (IfaceTupTc bx2 ar2) = bool (bx1==bx2 && ar1==ar2)
881 eqIfTc IfaceLiftedTypeKindTc   IfaceLiftedTypeKindTc   = Equal
882 eqIfTc IfaceOpenTypeKindTc     IfaceOpenTypeKindTc     = Equal
883 eqIfTc IfaceUnliftedTypeKindTc IfaceUnliftedTypeKindTc = Equal
884 eqIfTc IfaceUbxTupleKindTc     IfaceUbxTupleKindTc     = Equal
885 eqIfTc IfaceArgTypeKindTc      IfaceArgTypeKindTc      = Equal
886 eqIfTc _                       _                       = NotEqual
887 \end{code}
888
889 -----------------------------------------------------------
890         Support code for equality checking
891 -----------------------------------------------------------
892
893 \begin{code}
894 ------------------------------------
895 type EqEnv = UniqFM FastString  -- Tracks the mapping from L-variables to R-variables
896
897 eqIfOcc :: EqEnv -> FastString -> FastString -> IfaceEq
898 eqIfOcc env n1 n2 = case lookupUFM env n1 of
899                         Just n1 -> bool (n1 == n2)
900                         Nothing -> bool (n1 == n2)
901
902 extendEqEnv :: EqEnv -> FastString -> FastString -> EqEnv
903 extendEqEnv env n1 n2 | n1 == n2  = env
904                       | otherwise = addToUFM env n1 n2
905
906 emptyEqEnv :: EqEnv
907 emptyEqEnv = emptyUFM
908
909 ------------------------------------
910 type ExtEnv bndr = EqEnv -> bndr -> bndr -> (EqEnv -> IfaceEq) -> IfaceEq
911
912 eq_ifNakedBndr :: ExtEnv FastString
913 eq_ifBndr      :: ExtEnv IfaceBndr
914 eq_ifTvBndr    :: ExtEnv IfaceTvBndr
915 eq_ifIdBndr    :: ExtEnv IfaceIdBndr
916
917 eq_ifNakedBndr env n1 n2 k = k (extendEqEnv env n1 n2)
918
919 eq_ifBndr env (IfaceIdBndr b1) (IfaceIdBndr b2) k = eq_ifIdBndr env b1 b2 k
920 eq_ifBndr env (IfaceTvBndr b1) (IfaceTvBndr b2) k = eq_ifTvBndr env b1 b2 k
921 eq_ifBndr _ _ _ _ = NotEqual
922
923 eq_ifTvBndr env (v1, k1) (v2, k2) k = eq_ifType env k1 k2 &&& k (extendEqEnv env v1 v2)
924 eq_ifIdBndr env (v1, t1) (v2, t2) k = eq_ifType env t1 t2 &&& k (extendEqEnv env v1 v2)
925
926 eq_ifLetBndr env (IfLetBndr v1 t1 i1) (IfLetBndr v2 t2 i2) k 
927   = eq_ifType env t1 t2 &&& eqIfIdInfo i1 i2 &&& k (extendEqEnv env v1 v2)
928
929 eq_ifBndrs      :: ExtEnv [IfaceBndr]
930 eq_ifLetBndrs   :: ExtEnv [IfaceLetBndr]
931 eq_ifTvBndrs    :: ExtEnv [IfaceTvBndr]
932 eq_ifNakedBndrs :: ExtEnv [FastString]
933 eq_ifBndrs      = eq_bndrs_with eq_ifBndr
934 eq_ifTvBndrs    = eq_bndrs_with eq_ifTvBndr
935 eq_ifNakedBndrs = eq_bndrs_with eq_ifNakedBndr
936 eq_ifLetBndrs   = eq_bndrs_with eq_ifLetBndr
937
938 eq_bndrs_with eq env []       []       k = k env
939 eq_bndrs_with eq env (b1:bs1) (b2:bs2) k = eq env b1 b2 (\env -> eq_bndrs_with eq env bs1 bs2 k)
940 eq_bndrs_with eq env _        _        _ = NotEqual
941 \end{code}
942
943 \begin{code}
944 eqListBy :: (a->a->IfaceEq) -> [a] -> [a] -> IfaceEq
945 eqListBy eq []     []     = Equal
946 eqListBy eq (x:xs) (y:ys) = eq x y &&& eqListBy eq xs ys
947 eqListBy eq xs     ys     = NotEqual
948
949 eqMaybeBy :: (a->a->IfaceEq) -> Maybe a -> Maybe a -> IfaceEq
950 eqMaybeBy eq Nothing Nothing   = Equal
951 eqMaybeBy eq (Just x) (Just y) = eq x y
952 eqMaybeBy eq x        y        = NotEqual
953 \end{code}