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