[project @ 2000-10-25 07:09:52 by simonpj]
[ghc-hetmet.git] / ghc / compiler / rename / RnBinds.lhs
1 %
2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1998
3 %
4 \section[RnBinds]{Renaming and dependency analysis of bindings}
5
6 This module does renaming and dependency analysis on value bindings in
7 the abstract syntax.  It does {\em not} do cycle-checks on class or
8 type-synonym declarations; those cannot be done at this stage because
9 they may be affected by renaming (which isn't fully worked out yet).
10
11 \begin{code}
12 module RnBinds (
13         rnTopBinds, rnTopMonoBinds,
14         rnMethodBinds, renameSigs,
15         rnBinds,
16         unknownSigErr
17    ) where
18
19 #include "HsVersions.h"
20
21 import {-# SOURCE #-} RnSource ( rnHsSigType, rnHsType )
22
23 import HsSyn
24 import HsBinds          ( eqHsSig, sigName, hsSigDoc )
25 import RdrHsSyn
26 import RnHsSyn
27 import RnMonad
28 import RnExpr           ( rnMatch, rnGRHSs, rnPat, checkPrecMatch )
29 import RnEnv            ( bindLocatedLocalsRn, lookupBndrRn, 
30                           lookupGlobalOccRn, lookupSigOccRn,
31                           warnUnusedLocalBinds, mapFvRn, extendTyVarEnvFVRn,
32                           FreeVars, emptyFVs, plusFV, plusFVs, unitFV, addOneFV
33                         )
34 import CmdLineOpts      ( DynFlag(..) )
35 import Digraph          ( stronglyConnComp, SCC(..) )
36 import Name             ( OccName, Name, nameOccName )
37 import NameSet
38 import RdrName          ( RdrName, rdrNameOcc )
39 import BasicTypes       ( RecFlag(..) )
40 import List             ( partition )
41 import Outputable
42 import PrelNames        ( isUnboundName )
43 \end{code}
44
45 -- ToDo: Put the annotations into the monad, so that they arrive in the proper
46 -- place and can be used when complaining.
47
48 The code tree received by the function @rnBinds@ contains definitions
49 in where-clauses which are all apparently mutually recursive, but which may
50 not really depend upon each other. For example, in the top level program
51 \begin{verbatim}
52 f x = y where a = x
53               y = x
54 \end{verbatim}
55 the definitions of @a@ and @y@ do not depend on each other at all.
56 Unfortunately, the typechecker cannot always check such definitions.
57 \footnote{Mycroft, A. 1984. Polymorphic type schemes and recursive
58 definitions. In Proceedings of the International Symposium on Programming,
59 Toulouse, pp. 217-39. LNCS 167. Springer Verlag.}
60 However, the typechecker usually can check definitions in which only the
61 strongly connected components have been collected into recursive bindings.
62 This is precisely what the function @rnBinds@ does.
63
64 ToDo: deal with case where a single monobinds binds the same variable
65 twice.
66
67 The vertag tag is a unique @Int@; the tags only need to be unique
68 within one @MonoBinds@, so that unique-Int plumbing is done explicitly
69 (heavy monad machinery not needed).
70
71 \begin{code}
72 type VertexTag  = Int
73 type Cycle      = [VertexTag]
74 type Edge       = (VertexTag, VertexTag)
75 \end{code}
76
77 %************************************************************************
78 %*                                                                      *
79 %* naming conventions                                                   *
80 %*                                                                      *
81 %************************************************************************
82
83 \subsection[name-conventions]{Name conventions}
84
85 The basic algorithm involves walking over the tree and returning a tuple
86 containing the new tree plus its free variables. Some functions, such
87 as those walking polymorphic bindings (HsBinds) and qualifier lists in
88 list comprehensions (@Quals@), return the variables bound in local
89 environments. These are then used to calculate the free variables of the
90 expression evaluated in these environments.
91
92 Conventions for variable names are as follows:
93 \begin{itemize}
94 \item
95 new code is given a prime to distinguish it from the old.
96
97 \item
98 a set of variables defined in @Exp@ is written @dvExp@
99
100 \item
101 a set of variables free in @Exp@ is written @fvExp@
102 \end{itemize}
103
104 %************************************************************************
105 %*                                                                      *
106 %* analysing polymorphic bindings (HsBinds, Bind, MonoBinds)            *
107 %*                                                                      *
108 %************************************************************************
109
110 \subsubsection[dep-HsBinds]{Polymorphic bindings}
111
112 Non-recursive expressions are reconstructed without any changes at top
113 level, although their component expressions may have to be altered.
114 However, non-recursive expressions are currently not expected as
115 \Haskell{} programs, and this code should not be executed.
116
117 Monomorphic bindings contain information that is returned in a tuple
118 (a @FlatMonoBindsInfo@) containing:
119
120 \begin{enumerate}
121 \item
122 a unique @Int@ that serves as the ``vertex tag'' for this binding.
123
124 \item
125 the name of a function or the names in a pattern. These are a set
126 referred to as @dvLhs@, the defined variables of the left hand side.
127
128 \item
129 the free variables of the body. These are referred to as @fvBody@.
130
131 \item
132 the definition's actual code. This is referred to as just @code@.
133 \end{enumerate}
134
135 The function @nonRecDvFv@ returns two sets of variables. The first is
136 the set of variables defined in the set of monomorphic bindings, while the
137 second is the set of free variables in those bindings.
138
139 The set of variables defined in a non-recursive binding is just the
140 union of all of them, as @union@ removes duplicates. However, the
141 free variables in each successive set of cumulative bindings is the
142 union of those in the previous set plus those of the newest binding after
143 the defined variables of the previous set have been removed.
144
145 @rnMethodBinds@ deals only with the declarations in class and
146 instance declarations.  It expects only to see @FunMonoBind@s, and
147 it expects the global environment to contain bindings for the binders
148 (which are all class operations).
149
150 %************************************************************************
151 %*                                                                      *
152 \subsubsection{ Top-level bindings}
153 %*                                                                      *
154 %************************************************************************
155
156 @rnTopBinds@ assumes that the environment already
157 contains bindings for the binders of this particular binding.
158
159 \begin{code}
160 rnTopBinds    :: RdrNameHsBinds -> RnMS (RenamedHsBinds, FreeVars)
161
162 rnTopBinds EmptyBinds                     = returnRn (EmptyBinds, emptyFVs)
163 rnTopBinds (MonoBind bind sigs _)         = rnTopMonoBinds bind sigs
164   -- The parser doesn't produce other forms
165
166
167 rnTopMonoBinds mbinds sigs
168  =  mapRn lookupBndrRn binder_rdr_names         `thenRn` \ binder_names ->
169     let
170         bndr_name_set = mkNameSet binder_names
171     in
172     renameSigs (okBindSig bndr_name_set) sigs   `thenRn` \ (siglist, sig_fvs) ->
173     doptRn Opt_WarnMissingSigs                  `thenRn` \ warnMissing ->
174     let
175         type_sig_vars   = [n | Sig n _ _ <- siglist]
176         un_sigd_binders | warnMissing = nameSetToList (delListFromNameSet 
177                                                           bndr_name_set type_sig_vars)
178                         | otherwise   = []
179     in
180     mapRn_ (addWarnRn.missingSigWarn) un_sigd_binders   `thenRn_`
181
182     rn_mono_binds siglist mbinds                   `thenRn` \ (final_binds, bind_fvs) ->
183     returnRn (final_binds, bind_fvs `plusFV` sig_fvs)
184   where
185     binder_rdr_names = collectMonoBinders mbinds
186 \end{code}
187
188 %************************************************************************
189 %*                                                                      *
190 %*              Nested binds
191 %*                                                                      *
192 %************************************************************************
193
194 \subsubsection{Nested binds}
195
196 @rnMonoBinds@
197 \begin{itemize}
198 \item collects up the binders for this declaration group,
199 \item checks that they form a set
200 \item extends the environment to bind them to new local names
201 \item calls @rnMonoBinds@ to do the real work
202 \end{itemize}
203 %
204 \begin{code}
205 rnBinds       :: RdrNameHsBinds 
206               -> (RenamedHsBinds -> RnMS (result, FreeVars))
207               -> RnMS (result, FreeVars)
208
209 rnBinds EmptyBinds             thing_inside = thing_inside EmptyBinds
210 rnBinds (MonoBind bind sigs _) thing_inside = rnMonoBinds bind sigs thing_inside
211   -- the parser doesn't produce other forms
212
213
214 rnMonoBinds :: RdrNameMonoBinds 
215             -> [RdrNameSig]
216             -> (RenamedHsBinds -> RnMS (result, FreeVars))
217             -> RnMS (result, FreeVars)
218
219 rnMonoBinds mbinds sigs thing_inside -- Non-empty monobinds
220   =     -- Extract all the binders in this group,
221         -- and extend current scope, inventing new names for the new binders
222         -- This also checks that the names form a set
223     bindLocatedLocalsRn (text "a binding group") 
224                         mbinders_w_srclocs      $ \ new_mbinders ->
225     let
226         binder_set = mkNameSet new_mbinders
227     in
228         -- Rename the signatures
229     renameSigs (okBindSig binder_set) sigs      `thenRn` \ (siglist, sig_fvs) ->
230
231         -- Report the fixity declarations in this group that 
232         -- don't refer to any of the group's binders.
233         -- Then install the fixity declarations that do apply here
234         -- Notice that they scope over thing_inside too
235     let
236         fixity_sigs = [(name,sig) | FixSig sig@(FixitySig name _ _) <- siglist ]
237     in
238     extendFixityEnv fixity_sigs $
239
240     rn_mono_binds siglist mbinds           `thenRn` \ (binds, bind_fvs) ->
241
242     -- Now do the "thing inside", and deal with the free-variable calculations
243     thing_inside binds                     `thenRn` \ (result,result_fvs) ->
244     let
245         all_fvs        = result_fvs `plusFV` bind_fvs `plusFV` sig_fvs
246         unused_binders = nameSetToList (binder_set `minusNameSet` all_fvs)
247     in
248     warnUnusedLocalBinds unused_binders `thenRn_`
249     returnRn (result, delListFromNameSet all_fvs new_mbinders)
250   where
251     mbinders_w_srclocs = collectLocatedMonoBinders mbinds
252 \end{code}
253
254
255 %************************************************************************
256 %*                                                                      *
257 \subsubsection{         MonoBinds -- the main work is done here}
258 %*                                                                      *
259 %************************************************************************
260
261 @rn_mono_binds@ is used by {\em both} top-level and nested bindings.
262 It assumes that all variables bound in this group are already in scope.
263 This is done {\em either} by pass 3 (for the top-level bindings),
264 {\em or} by @rnMonoBinds@ (for the nested ones).
265
266 \begin{code}
267 rn_mono_binds :: [RenamedSig]           -- Signatures attached to this group
268               -> RdrNameMonoBinds       
269               -> RnMS (RenamedHsBinds,  -- 
270                          FreeVars)      -- Free variables
271
272 rn_mono_binds siglist mbinds
273   =
274          -- Rename the bindings, returning a MonoBindsInfo
275          -- which is a list of indivisible vertices so far as
276          -- the strongly-connected-components (SCC) analysis is concerned
277     flattenMonoBinds siglist mbinds             `thenRn` \ mbinds_info ->
278
279          -- Do the SCC analysis
280     let 
281         edges       = mkEdges (mbinds_info `zip` [(0::Int)..])
282         scc_result  = stronglyConnComp edges
283         final_binds = foldr (ThenBinds . reconstructCycle) EmptyBinds scc_result
284
285          -- Deal with bound and free-var calculation
286         rhs_fvs = plusFVs [fvs | (_,fvs,_,_) <- mbinds_info]
287     in
288     returnRn (final_binds, rhs_fvs)
289 \end{code}
290
291 @flattenMonoBinds@ is ever-so-slightly magical in that it sticks
292 unique ``vertex tags'' on its output; minor plumbing required.
293
294 Sigh --- need to pass along the signatures for the group of bindings,
295 in case any of them \fbox{\ ???\ } 
296
297 \begin{code}
298 flattenMonoBinds :: [RenamedSig]                -- Signatures
299                  -> RdrNameMonoBinds
300                  -> RnMS [FlatMonoBindsInfo]
301
302 flattenMonoBinds sigs EmptyMonoBinds = returnRn []
303
304 flattenMonoBinds sigs (AndMonoBinds bs1 bs2)
305   = flattenMonoBinds sigs bs1   `thenRn` \ flat1 ->
306     flattenMonoBinds sigs bs2   `thenRn` \ flat2 ->
307     returnRn (flat1 ++ flat2)
308
309 flattenMonoBinds sigs (PatMonoBind pat grhss locn)
310   = pushSrcLocRn locn                   $
311     rnPat pat                           `thenRn` \ (pat', pat_fvs) ->
312
313          -- Find which things are bound in this group
314     let
315         names_bound_here = mkNameSet (collectPatBinders pat')
316     in
317     sigsForMe names_bound_here sigs     `thenRn` \ sigs_for_me ->
318     rnGRHSs grhss                       `thenRn` \ (grhss', fvs) ->
319     returnRn 
320         [(names_bound_here,
321           fvs `plusFV` pat_fvs,
322           PatMonoBind pat' grhss' locn,
323           sigs_for_me
324          )]
325
326 flattenMonoBinds sigs (FunMonoBind name inf matches locn)
327   = pushSrcLocRn locn                                   $
328     lookupBndrRn name                                   `thenRn` \ new_name ->
329     let
330         names_bound_here = unitNameSet new_name
331     in
332     sigsForMe names_bound_here sigs                     `thenRn` \ sigs_for_me ->
333     mapFvRn rnMatch matches                             `thenRn` \ (new_matches, fvs) ->
334     mapRn_ (checkPrecMatch inf new_name) new_matches    `thenRn_`
335     returnRn
336       [(unitNameSet new_name,
337         fvs,
338         FunMonoBind new_name inf new_matches locn,
339         sigs_for_me
340         )]
341
342
343 sigsForMe names_bound_here sigs
344   = foldlRn check [] (filter (sigForThisGroup names_bound_here) sigs)
345   where
346     check sigs sig = case filter (eqHsSig sig) sigs of
347                         []    -> returnRn (sig:sigs)
348                         other -> dupSigDeclErr sig      `thenRn_`
349                                  returnRn sigs
350 \end{code}
351
352
353 @rnMethodBinds@ is used for the method bindings of a class and an instance
354 declaration.   Like @rnMonoBinds@ but without dependency analysis.
355
356 NOTA BENE: we record each {\em binder} of a method-bind group as a free variable.
357 That's crucial when dealing with an instance decl:
358 \begin{verbatim}
359         instance Foo (T a) where
360            op x = ...
361 \end{verbatim}
362 This might be the {\em sole} occurrence of @op@ for an imported class @Foo@,
363 and unless @op@ occurs we won't treat the type signature of @op@ in the class
364 decl for @Foo@ as a source of instance-decl gates.  But we should!  Indeed,
365 in many ways the @op@ in an instance decl is just like an occurrence, not
366 a binder.
367
368 \begin{code}
369 rnMethodBinds :: [Name]                 -- Names for generic type variables
370               -> RdrNameMonoBinds
371               -> RnMS (RenamedMonoBinds, FreeVars)
372
373 rnMethodBinds gen_tyvars EmptyMonoBinds = returnRn (EmptyMonoBinds, emptyFVs)
374
375 rnMethodBinds gen_tyvars (AndMonoBinds mb1 mb2)
376   = rnMethodBinds gen_tyvars mb1        `thenRn` \ (mb1', fvs1) ->
377     rnMethodBinds gen_tyvars mb2        `thenRn` \ (mb2', fvs2) ->
378     returnRn (mb1' `AndMonoBinds` mb2', fvs1 `plusFV` fvs2)
379
380 rnMethodBinds gen_tyvars (FunMonoBind name inf matches locn)
381   = pushSrcLocRn locn                                   $
382
383     lookupGlobalOccRn name                              `thenRn` \ sel_name -> 
384         -- We use the selector name as the binder
385
386     mapFvRn rn_match matches                            `thenRn` \ (new_matches, fvs) ->
387     mapRn_ (checkPrecMatch inf sel_name) new_matches    `thenRn_`
388     returnRn (FunMonoBind sel_name inf new_matches locn, fvs `addOneFV` sel_name)
389   where
390         -- Gruesome; bring into scope the correct members of the generic type variables
391         -- See comments in RnSource.rnDecl(ClassDecl)
392     rn_match match@(Match _ (TypePatIn ty : _) _ _)
393         = extendTyVarEnvFVRn gen_tvs (rnMatch match)
394         where
395           tvs     = map rdrNameOcc (extractHsTyRdrNames ty)
396           gen_tvs = [tv | tv <- gen_tyvars, nameOccName tv `elem` tvs] 
397
398     rn_match match = rnMatch match
399         
400
401 -- Can't handle method pattern-bindings which bind multiple methods.
402 rnMethodBinds gen_tyvars mbind@(PatMonoBind other_pat _ locn)
403   = pushSrcLocRn locn   $
404     failWithRn (EmptyMonoBinds, emptyFVs) (methodBindErr mbind)
405 \end{code}
406
407
408 %************************************************************************
409 %*                                                                      *
410 \subsection[reconstruct-deps]{Reconstructing dependencies}
411 %*                                                                      *
412 %************************************************************************
413
414 This @MonoBinds@- and @ClassDecls@-specific code is segregated here,
415 as the two cases are similar.
416
417 \begin{code}
418 reconstructCycle :: SCC FlatMonoBindsInfo
419                  -> RenamedHsBinds
420
421 reconstructCycle (AcyclicSCC (_, _, binds, sigs))
422   = MonoBind binds sigs NonRecursive
423
424 reconstructCycle (CyclicSCC cycle)
425   = MonoBind this_gp_binds this_gp_sigs Recursive
426   where
427     this_gp_binds      = foldr1 AndMonoBinds [binds | (_, _, binds, _) <- cycle]
428     this_gp_sigs       = foldr1 (++)         [sigs  | (_, _, _, sigs) <- cycle]
429 \end{code}
430
431 %************************************************************************
432 %*                                                                      *
433 \subsubsection{ Manipulating FlatMonoBindInfo}
434 %*                                                                      *
435 %************************************************************************
436
437 During analysis a @MonoBinds@ is flattened to a @FlatMonoBindsInfo@.
438 The @RenamedMonoBinds@ is always an empty bind, a pattern binding or
439 a function binding, and has itself been dependency-analysed and
440 renamed.
441
442 \begin{code}
443 type FlatMonoBindsInfo
444   = (NameSet,                   -- Set of names defined in this vertex
445      NameSet,                   -- Set of names used in this vertex
446      RenamedMonoBinds,
447      [RenamedSig])              -- Signatures, if any, for this vertex
448
449 mkEdges :: [(FlatMonoBindsInfo, VertexTag)] -> [(FlatMonoBindsInfo, VertexTag, [VertexTag])]
450
451 mkEdges flat_info
452   = [ (info, tag, dest_vertices (nameSetToList names_used))
453     | (info@(names_defined, names_used, mbind, sigs), tag) <- flat_info
454     ]
455   where
456          -- An edge (v,v') indicates that v depends on v'
457     dest_vertices src_mentions = [ target_vertex
458                                  | ((names_defined, _, _, _), target_vertex) <- flat_info,
459                                    mentioned_name <- src_mentions,
460                                    mentioned_name `elemNameSet` names_defined
461                                  ]
462 \end{code}
463
464
465 %************************************************************************
466 %*                                                                      *
467 \subsubsection[dep-Sigs]{Signatures (and user-pragmas for values)}
468 %*                                                                      *
469 %************************************************************************
470
471 @renameSigs@ checks for:
472 \begin{enumerate}
473 \item more than one sig for one thing;
474 \item signatures given for things not bound here;
475 \item with suitably flaggery, that all top-level things have type signatures.
476 \end{enumerate}
477 %
478 At the moment we don't gather free-var info from the types in
479 signatures.  We'd only need this if we wanted to report unused tyvars.
480
481 \begin{code}
482 renameSigs ::  (RenamedSig -> Bool)             -- OK-sig predicate
483             -> [RdrNameSig]
484             -> RnMS ([RenamedSig], FreeVars)
485
486 renameSigs ok_sig []
487   = returnRn ([], emptyFVs)     -- Common shortcut
488
489 renameSigs ok_sig sigs
490   =      -- Rename the signatures
491     mapRn renameSig sigs        `thenRn` \ sigs' ->
492
493         -- Check for (a) duplicate signatures
494         --           (b) signatures for things not in this group
495     let
496         in_scope         = filter is_in_scope sigs'
497         is_in_scope sig  = case sigName sig of
498                                 Just n  -> not (isUnboundName n)
499                                 Nothing -> True
500         (goods, bads)    = partition ok_sig in_scope
501     in
502     mapRn_ unknownSigErr bads                   `thenRn_`
503     returnRn (goods, hsSigFVs goods)
504
505 -- We use lookupSigOccRn in the signatures, which is a little bit unsatisfactory
506 -- because this won't work for:
507 --      instance Foo T where
508 --        {-# INLINE op #-}
509 --        Baz.op = ...
510 -- We'll just rename the INLINE prag to refer to whatever other 'op'
511 -- is in scope.  (I'm assuming that Baz.op isn't in scope unqualified.)
512 -- Doesn't seem worth much trouble to sort this.
513
514 renameSig :: Sig RdrName -> RnMS (Sig Name)
515 -- ClassOpSig is renamed elsewhere.
516 renameSig (Sig v ty src_loc)
517   = pushSrcLocRn src_loc $
518     lookupSigOccRn v                            `thenRn` \ new_v ->
519     rnHsSigType (quotes (ppr v)) ty             `thenRn` \ new_ty ->
520     returnRn (Sig new_v new_ty src_loc)
521
522 renameSig (SpecInstSig ty src_loc)
523   = pushSrcLocRn src_loc $
524     rnHsType (text "A SPECIALISE instance pragma") ty `thenRn` \ new_ty ->
525     returnRn (SpecInstSig new_ty src_loc)
526
527 renameSig (SpecSig v ty src_loc)
528   = pushSrcLocRn src_loc $
529     lookupSigOccRn v                    `thenRn` \ new_v ->
530     rnHsSigType (quotes (ppr v)) ty     `thenRn` \ new_ty ->
531     returnRn (SpecSig new_v new_ty src_loc)
532
533 renameSig (FixSig (FixitySig v fix src_loc))
534   = pushSrcLocRn src_loc $
535     lookupSigOccRn v            `thenRn` \ new_v ->
536     returnRn (FixSig (FixitySig new_v fix src_loc))
537
538 renameSig (InlineSig v p src_loc)
539   = pushSrcLocRn src_loc $
540     lookupSigOccRn v            `thenRn` \ new_v ->
541     returnRn (InlineSig new_v p src_loc)
542
543 renameSig (NoInlineSig v p src_loc)
544   = pushSrcLocRn src_loc $
545     lookupSigOccRn v            `thenRn` \ new_v ->
546     returnRn (NoInlineSig new_v p src_loc)
547 \end{code}
548
549 \begin{code}
550 renameIE :: (RdrName -> RnMS Name) -> IE RdrName -> RnMS (IE Name, FreeVars)
551 renameIE lookup_occ_nm (IEVar v)
552   = lookup_occ_nm v             `thenRn` \ new_v ->
553     returnRn (IEVar new_v, unitFV new_v)
554
555 renameIE lookup_occ_nm (IEThingAbs v)
556   = lookup_occ_nm v             `thenRn` \ new_v ->
557     returnRn (IEThingAbs new_v, unitFV new_v)
558
559 renameIE lookup_occ_nm (IEThingAll v)
560   = lookup_occ_nm v             `thenRn` \ new_v ->
561     returnRn (IEThingAll new_v, unitFV new_v)
562
563 renameIE lookup_occ_nm (IEThingWith v vs)
564   = lookup_occ_nm v             `thenRn` \ new_v ->
565     mapRn lookup_occ_nm vs      `thenRn` \ new_vs ->
566     returnRn (IEThingWith new_v new_vs, plusFVs [ unitFV x | x <- new_v:new_vs ])
567
568 renameIE lookup_occ_nm (IEModuleContents m)
569   = returnRn (IEModuleContents m, emptyFVs)
570 \end{code}
571
572
573 %************************************************************************
574 %*                                                                      *
575 \subsection{Error messages}
576 %*                                                                      *
577 %************************************************************************
578
579 \begin{code}
580 dupSigDeclErr sig
581   = pushSrcLocRn loc $
582     addErrRn (sep [ptext SLIT("Duplicate") <+> ptext what_it_is <> colon,
583                    ppr sig])
584   where
585     (what_it_is, loc) = hsSigDoc sig
586
587 unknownSigErr sig
588   = pushSrcLocRn loc $
589     addErrRn (sep [ptext SLIT("Misplaced") <+> ptext what_it_is <> colon,
590                    ppr sig])
591   where
592     (what_it_is, loc) = hsSigDoc sig
593
594 missingSigWarn var
595   = sep [ptext SLIT("definition but no type signature for"), quotes (ppr var)]
596
597 methodBindErr mbind
598  =  hang (ptext SLIT("Can't handle multiple methods defined by one pattern binding"))
599        4 (ppr mbind)
600 \end{code}