4 TcTauType, TcPredType, TcThetaType, TcRhoType,
5 TcTyVar, TcTyVarSet, TcClassContext,
8 TcM, NF_TcM, TcDown, TcEnv,
11 returnTc, thenTc, thenTc_, mapTc, mapTc_, listTc,
12 foldrTc, foldlTc, mapAndUnzipTc, mapAndUnzip3Tc,
13 mapBagTc, fixTc, tryTc, tryTc_, getErrsTc,
18 returnNF_Tc, thenNF_Tc, thenNF_Tc_, mapNF_Tc,
19 fixNF_Tc, forkNF_Tc, foldrNF_Tc, foldlNF_Tc,
21 listNF_Tc, mapAndUnzipNF_Tc, mapBagNF_Tc,
23 checkTc, checkTcM, checkMaybeTc, checkMaybeTcM,
24 failTc, failWithTc, addErrTc, addErrsTc, warnTc,
25 recoverTc, checkNoErrsTc, recoverNF_Tc, discardErrsTc,
26 addErrTcM, addInstErrTcM, failWithTcM,
29 tcGetDefaultTys, tcSetDefaultTys,
30 tcGetUnique, tcGetUniques,
33 tcAddSrcLoc, tcGetSrcLoc, tcGetInstLoc,
34 tcAddErrCtxtM, tcSetErrCtxtM,
35 tcAddErrCtxt, tcSetErrCtxt,
37 tcNewMutVar, tcNewSigTyVar, tcReadMutVar, tcWriteMutVar, TcRef,
38 tcNewMutTyVar, tcReadMutTyVar, tcWriteMutTyVar,
40 InstOrigin(..), InstLoc, pprInstLoc,
42 TcError, TcWarning, TidyEnv, emptyTidyEnv,
46 #include "HsVersions.h"
48 import {-# SOURCE #-} TcEnv ( TcEnv )
50 import RnHsSyn ( RenamedPat, RenamedArithSeqInfo, RenamedHsExpr, RenamedHsOverLit )
51 import Type ( Type, Kind, PredType, ThetaType, RhoType, TauType,
53 import ErrUtils ( addShortErrLocLine, addShortWarnLocLine, ErrMsg, Message, WarnMsg )
55 import Bag ( Bag, emptyBag, isEmptyBag,
56 foldBag, unitBag, unionBags, snocBag )
57 import Class ( Class, ClassContext )
59 import Var ( Id, TyVar, newMutTyVar, newSigTyVar, readMutTyVar, writeMutTyVar )
60 import VarEnv ( TidyEnv, emptyTidyEnv )
61 import VarSet ( TyVarSet )
62 import UniqSupply ( UniqSupply, uniqFromSupply, uniqsFromSupply,
63 splitUniqSupply, mkSplitUniqSupply,
65 import SrcLoc ( SrcLoc, noSrcLoc )
66 import UniqFM ( emptyUFM )
67 import Unique ( Unique )
71 import IOExts ( IORef, newIORef, readIORef, writeIORef,
72 unsafeInterleaveIO, fixIO
76 infixr 9 `thenTc`, `thenTc_`, `thenNF_Tc`, `thenNF_Tc_`
80 %************************************************************************
84 %************************************************************************
87 type TcTyVar = TyVar -- Might be a mutable tyvar
88 type TcTyVarSet = TyVarSet
90 type TcType = Type -- A TcType can have mutable type variables
91 -- Invariant on ForAllTy in TcTypes:
93 -- a cannot occur inside a MutTyVar in T; that is,
94 -- T is "flattened" before quantifying over a
96 type TcClassContext = ClassContext
97 type TcPredType = PredType
98 type TcThetaType = ThetaType
99 type TcRhoType = RhoType
100 type TcTauType = TauType
105 %************************************************************************
107 \subsection{The main monads: TcM, NF_TcM}
109 %************************************************************************
112 type NF_TcM r = TcDown -> TcEnv -> IO r -- Can't raise UserError
113 type TcM r = TcDown -> TcEnv -> IO r -- Can raise UserError
115 type Either_TcM r = TcDown -> TcEnv -> IO r -- Either NF_TcM or TcM
116 -- Used only in this file for type signatures which
117 -- have a part that's polymorphic in whether it's NF_TcM or TcM
120 type TcRef a = IORef a
128 -> IO (Maybe r, (Bag WarnMsg, Bag ErrMsg))
130 initTc dflags tc_env do_this
132 us <- mkSplitUniqSupply 'a' ;
133 us_var <- newIORef us ;
134 errs_var <- newIORef (emptyBag,emptyBag) ;
135 tvs_var <- newIORef emptyUFM ;
138 init_down = TcDown { tc_dflags = dflags, tc_def = [],
139 tc_us = us_var, tc_loc = noSrcLoc,
140 tc_ctxt = [], tc_errs = errs_var }
143 maybe_res <- catch (do { res <- do_this init_down tc_env ;
145 (\_ -> return Nothing) ;
147 (warns,errs) <- readIORef errs_var ;
148 return (maybe_res, (warns, errs))
151 -- Monadic operations
153 returnNF_Tc :: a -> NF_TcM a
154 returnTc :: a -> TcM a
155 returnTc v down env = return v
157 thenTc :: TcM a -> (a -> TcM b) -> TcM b
158 thenNF_Tc :: NF_TcM a -> (a -> Either_TcM b) -> Either_TcM b
159 thenTc m k down env = do { r <- m down env; k r down env }
161 thenTc_ :: TcM a -> TcM b -> TcM b
162 thenNF_Tc_ :: NF_TcM a -> Either_TcM b -> Either_TcM b
163 thenTc_ m k down env = do { m down env; k down env }
165 listTc :: [TcM a] -> TcM [a]
166 listNF_Tc :: [NF_TcM a] -> NF_TcM [a]
167 listTc [] = returnTc []
168 listTc (x:xs) = x `thenTc` \ r ->
169 listTc xs `thenTc` \ rs ->
172 mapTc :: (a -> TcM b) -> [a] -> TcM [b]
173 mapTc_ :: (a -> TcM b) -> [a] -> TcM ()
174 mapNF_Tc :: (a -> NF_TcM b) -> [a] -> NF_TcM [b]
175 mapTc f [] = returnTc []
176 mapTc f (x:xs) = f x `thenTc` \ r ->
177 mapTc f xs `thenTc` \ rs ->
179 mapTc_ f xs = mapTc f xs `thenTc_` returnTc ()
182 foldrTc :: (a -> b -> TcM b) -> b -> [a] -> TcM b
183 foldrNF_Tc :: (a -> b -> NF_TcM b) -> b -> [a] -> NF_TcM b
184 foldrTc k z [] = returnTc z
185 foldrTc k z (x:xs) = foldrTc k z xs `thenTc` \r ->
188 foldlTc :: (a -> b -> TcM a) -> a -> [b] -> TcM a
189 foldlNF_Tc :: (a -> b -> NF_TcM a) -> a -> [b] -> NF_TcM a
190 foldlTc k z [] = returnTc z
191 foldlTc k z (x:xs) = k z x `thenTc` \r ->
194 mapAndUnzipTc :: (a -> TcM (b,c)) -> [a] -> TcM ([b],[c])
195 mapAndUnzipNF_Tc :: (a -> NF_TcM (b,c)) -> [a] -> NF_TcM ([b],[c])
196 mapAndUnzipTc f [] = returnTc ([],[])
197 mapAndUnzipTc f (x:xs) = f x `thenTc` \ (r1,r2) ->
198 mapAndUnzipTc f xs `thenTc` \ (rs1,rs2) ->
199 returnTc (r1:rs1, r2:rs2)
201 mapAndUnzip3Tc :: (a -> TcM (b,c,d)) -> [a] -> TcM ([b],[c],[d])
202 mapAndUnzip3Tc f [] = returnTc ([],[],[])
203 mapAndUnzip3Tc f (x:xs) = f x `thenTc` \ (r1,r2,r3) ->
204 mapAndUnzip3Tc f xs `thenTc` \ (rs1,rs2,rs3) ->
205 returnTc (r1:rs1, r2:rs2, r3:rs3)
207 mapBagTc :: (a -> TcM b) -> Bag a -> TcM (Bag b)
208 mapBagNF_Tc :: (a -> NF_TcM b) -> Bag a -> NF_TcM (Bag b)
210 = foldBag (\ b1 b2 -> b1 `thenTc` \ r1 ->
212 returnTc (unionBags r1 r2))
213 (\ a -> f a `thenTc` \ r -> returnTc (unitBag r))
217 fixTc :: (a -> TcM a) -> TcM a
218 fixNF_Tc :: (a -> NF_TcM a) -> NF_TcM a
219 fixTc m env down = fixIO (\ loop -> m loop env down)
221 recoverTc :: TcM r -> TcM r -> TcM r
222 recoverNF_Tc :: NF_TcM r -> TcM r -> NF_TcM r
223 recoverTc recover m down env
224 = catch (m down env) (\ _ -> recover down env)
226 returnNF_Tc = returnTc
230 recoverNF_Tc = recoverTc
235 mapAndUnzipNF_Tc = mapAndUnzipTc
236 mapBagNF_Tc = mapBagTc
239 @forkNF_Tc@ runs a sub-typecheck action *lazily* in a separate state
240 thread. Ideally, this elegantly ensures that it can't zap any type
241 variables that belong to the main thread. But alas, the environment
242 contains TyCon and Class environments that include TcKind stuff,
243 which is a Royal Pain. By the time this fork stuff is used they'll
244 have been unified down so there won't be any kind variables, but we
245 can't express that in the current typechecker framework.
247 So we compromise and use unsafeInterleaveIO.
249 We throw away any error messages!
252 forkNF_Tc :: NF_TcM r -> NF_TcM r
253 forkNF_Tc m down@(TcDown { tc_us = u_var }) env
255 -- Get a fresh unique supply
256 us <- readIORef u_var
257 let (us1, us2) = splitUniqSupply us
260 unsafeInterleaveIO (do {
261 us_var' <- newIORef us2 ;
262 err_var' <- newIORef (emptyBag,emptyBag) ;
263 let { down' = down { tc_us = us_var', tc_errs = err_var' } };
265 -- ToDo: optionally dump any error messages
270 traceTc :: SDoc -> NF_TcM ()
271 traceTc doc (TcDown { tc_dflags=dflags }) env
272 | dopt Opt_D_dump_rn_trace dflags = printDump doc
273 | otherwise = return ()
275 ioToTc :: IO a -> NF_TcM a
276 ioToTc io down env = io
280 %************************************************************************
282 \subsection{Error handling}
284 %************************************************************************
287 getErrsTc :: NF_TcM (Bag WarnMsg, Bag ErrMsg)
289 = readIORef (getTcErrs down)
292 failTc down env = give_up
295 give_up = IOERROR (userError "Typecheck failed")
297 failWithTc :: Message -> TcM a -- Add an error message and fail
298 failWithTc err_msg = failWithTcM (emptyTidyEnv, err_msg)
300 addErrTc :: Message -> NF_TcM ()
301 addErrTc err_msg = addErrTcM (emptyTidyEnv, err_msg)
303 addErrsTc :: [Message] -> NF_TcM ()
304 addErrsTc [] = returnNF_Tc ()
305 addErrsTc err_msgs = listNF_Tc (map addErrTc err_msgs) `thenNF_Tc_` returnNF_Tc ()
307 -- The 'M' variants do the TidyEnv bit
308 failWithTcM :: (TidyEnv, Message) -> TcM a -- Add an error message and fail
309 failWithTcM env_and_msg
310 = addErrTcM env_and_msg `thenNF_Tc_`
313 checkTc :: Bool -> Message -> TcM () -- Check that the boolean is true
314 checkTc True err = returnTc ()
315 checkTc False err = failWithTc err
317 checkTcM :: Bool -> TcM () -> TcM () -- Check that the boolean is true
318 checkTcM True err = returnTc ()
319 checkTcM False err = err
321 checkMaybeTc :: Maybe val -> Message -> TcM val
322 checkMaybeTc (Just val) err = returnTc val
323 checkMaybeTc Nothing err = failWithTc err
325 checkMaybeTcM :: Maybe val -> TcM val -> TcM val
326 checkMaybeTcM (Just val) err = returnTc val
327 checkMaybeTcM Nothing err = err
329 addErrTcM :: (TidyEnv, Message) -> NF_TcM () -- Add an error message but don't fail
330 addErrTcM (tidy_env, err_msg) down env
331 = add_err_tcm tidy_env err_msg ctxt loc down env
333 ctxt = getErrCtxt down
336 addInstErrTcM :: InstLoc -> (TidyEnv, Message) -> NF_TcM () -- Add an error message but don't fail
337 addInstErrTcM inst_loc@(_, loc, ctxt) (tidy_env, err_msg) down env
338 = add_err_tcm tidy_env err_msg full_ctxt loc down env
340 full_ctxt = (\env -> returnNF_Tc (env, pprInstLoc inst_loc)) : ctxt
342 add_err_tcm tidy_env err_msg ctxt loc down env
344 (warns, errs) <- readIORef errs_var
345 ctxt_msgs <- do_ctxt tidy_env ctxt down env
346 let err = addShortErrLocLine loc $
347 vcat (err_msg : ctxt_to_use ctxt_msgs)
348 writeIORef errs_var (warns, errs `snocBag` err)
350 errs_var = getTcErrs down
352 do_ctxt tidy_env [] down env
354 do_ctxt tidy_env (c:cs) down env
356 (tidy_env', m) <- c tidy_env down env
357 ms <- do_ctxt tidy_env' cs down env
360 -- warnings don't have an 'M' variant
361 warnTc :: Bool -> Message -> NF_TcM ()
362 warnTc warn_if_true warn_msg down env
365 (warns,errs) <- readIORef errs_var
366 ctxt_msgs <- do_ctxt emptyTidyEnv ctxt down env
367 let warn = addShortWarnLocLine loc $
368 vcat (warn_msg : ctxt_to_use ctxt_msgs)
369 writeIORef errs_var (warns `snocBag` warn, errs)
373 errs_var = getTcErrs down
374 ctxt = getErrCtxt down
377 -- (tryTc r m) succeeds if m succeeds and generates no errors
378 -- If m fails then r is invoked, passing the warnings and errors from m
379 -- If m succeeds, (tryTc r m) checks whether m generated any errors messages
380 -- (it might have recovered internally)
381 -- If so, then r is invoked, passing the warnings and errors from m
383 tryTc :: ((Bag WarnMsg, Bag ErrMsg) -> TcM r) -- Recovery action
384 -> TcM r -- Thing to try
386 tryTc recover main down env
388 m_errs_var <- newIORef (emptyBag,emptyBag)
389 catch (my_main m_errs_var) (\ _ -> my_recover m_errs_var)
391 my_recover m_errs_var
392 = do warns_and_errs <- readIORef m_errs_var
393 recover warns_and_errs down env
396 = do result <- main (setTcErrs down m_errs_var) env
398 -- Check that m has no errors; if it has internal recovery
399 -- mechanisms it might "succeed" but having found a bunch of
400 -- errors along the way.
401 (m_warns, m_errs) <- readIORef m_errs_var
402 if isEmptyBag m_errs then
405 give_up -- This triggers the catch
408 -- (checkNoErrsTc m) succeeds iff m succeeds and generates no errors
409 -- If m fails then (checkNoErrsTc m) fails.
410 -- If m succeeds, it checks whether m generated any errors messages
411 -- (it might have recovered internally)
412 -- If so, it fails too.
413 -- Regardless, any errors generated by m are propagated to the enclosing context.
414 checkNoErrsTc :: TcM r -> TcM r
416 = tryTc my_recover main
418 my_recover (m_warns, m_errs) down env
419 = do (warns, errs) <- readIORef errs_var
420 writeIORef errs_var (warns `unionBags` m_warns,
421 errs `unionBags` m_errs)
424 errs_var = getTcErrs down
427 -- (tryTc_ r m) tries m; if it succeeds it returns it,
428 -- otherwise it returns r. Any error messages added by m are discarded,
429 -- whether or not m succeeds.
430 tryTc_ :: TcM r -> TcM r -> TcM r
432 = tryTc my_recover main
434 my_recover warns_and_errs = recover
436 -- (discardErrsTc m) runs m, but throw away all its error messages.
437 discardErrsTc :: Either_TcM r -> Either_TcM r
438 discardErrsTc main down env
439 = do new_errs_var <- newIORef (emptyBag,emptyBag)
440 main (setTcErrs down new_errs_var) env
445 %************************************************************************
447 \subsection{Mutable variables}
449 %************************************************************************
452 tcNewMutVar :: a -> NF_TcM (TcRef a)
453 tcNewMutVar val down env = newIORef val
455 tcWriteMutVar :: TcRef a -> a -> NF_TcM ()
456 tcWriteMutVar var val down env = writeIORef var val
458 tcReadMutVar :: TcRef a -> NF_TcM a
459 tcReadMutVar var down env = readIORef var
461 tcNewMutTyVar :: Name -> Kind -> NF_TcM TyVar
462 tcNewMutTyVar name kind down env = newMutTyVar name kind
464 tcNewSigTyVar :: Name -> Kind -> NF_TcM TyVar
465 tcNewSigTyVar name kind down env = newSigTyVar name kind
467 tcReadMutTyVar :: TyVar -> NF_TcM (Maybe Type)
468 tcReadMutTyVar tyvar down env = readMutTyVar tyvar
470 tcWriteMutTyVar :: TyVar -> Maybe Type -> NF_TcM ()
471 tcWriteMutTyVar tyvar val down env = writeMutTyVar tyvar val
475 %************************************************************************
477 \subsection{The environment}
479 %************************************************************************
482 tcGetEnv :: NF_TcM TcEnv
483 tcGetEnv down env = return env
485 tcSetEnv :: TcEnv -> Either_TcM a -> Either_TcM a
486 tcSetEnv new_env m down old_env = m down new_env
490 %************************************************************************
492 \subsection{Source location}
494 %************************************************************************
497 tcGetDefaultTys :: NF_TcM [Type]
498 tcGetDefaultTys down env = return (getDefaultTys down)
500 tcSetDefaultTys :: [Type] -> TcM r -> TcM r
501 tcSetDefaultTys tys m down env = m (setDefaultTys down tys) env
503 tcAddSrcLoc :: SrcLoc -> Either_TcM a -> Either_TcM a
504 tcAddSrcLoc loc m down env = m (setLoc down loc) env
506 tcGetSrcLoc :: NF_TcM SrcLoc
507 tcGetSrcLoc down env = return (getLoc down)
509 tcGetInstLoc :: InstOrigin -> NF_TcM InstLoc
510 tcGetInstLoc origin down env = return (origin, getLoc down, getErrCtxt down)
512 tcSetErrCtxtM, tcAddErrCtxtM :: (TidyEnv -> NF_TcM (TidyEnv, Message))
514 tcSetErrCtxtM msg m down env = m (setErrCtxt down msg) env
515 tcAddErrCtxtM msg m down env = m (addErrCtxt down msg) env
517 tcSetErrCtxt, tcAddErrCtxt :: Message -> Either_TcM r -> Either_TcM r
519 tcSetErrCtxt msg m down env = m (setErrCtxt down (\env -> returnNF_Tc (env, msg))) env
520 tcAddErrCtxt msg m down env = m (addErrCtxt down (\env -> returnNF_Tc (env, msg))) env
524 %************************************************************************
526 \subsection{Unique supply}
528 %************************************************************************
531 tcGetUnique :: NF_TcM Unique
533 = do uniq_supply <- readIORef u_var
534 let (new_uniq_supply, uniq_s) = splitUniqSupply uniq_supply
535 uniq = uniqFromSupply uniq_s
536 writeIORef u_var new_uniq_supply
539 u_var = getUniqSupplyVar down
541 tcGetUniques :: Int -> NF_TcM [Unique]
542 tcGetUniques n down env
543 = do uniq_supply <- readIORef u_var
544 let (new_uniq_supply, uniq_s) = splitUniqSupply uniq_supply
545 uniqs = uniqsFromSupply n uniq_s
546 writeIORef u_var new_uniq_supply
549 u_var = getUniqSupplyVar down
551 uniqSMToTcM :: UniqSM a -> NF_TcM a
552 uniqSMToTcM m down env
553 = do uniq_supply <- readIORef u_var
554 let (new_uniq_supply, uniq_s) = splitUniqSupply uniq_supply
555 writeIORef u_var new_uniq_supply
556 return (initUs_ uniq_s m)
558 u_var = getUniqSupplyVar down
563 %************************************************************************
567 %************************************************************************
572 tc_dflags :: DynFlags,
573 tc_def :: [Type], -- Types used for defaulting
574 tc_us :: (TcRef UniqSupply), -- Unique supply
575 tc_loc :: SrcLoc, -- Source location
576 tc_ctxt :: ErrCtxt, -- Error context
577 tc_errs :: (TcRef (Bag WarnMsg, Bag ErrMsg))
580 type ErrCtxt = [TidyEnv -> NF_TcM (TidyEnv, Message)]
581 -- Innermost first. Monadic so that we have a chance
582 -- to deal with bound type variables just before error
583 -- message construction
586 -- These selectors are *local* to TcMonad.lhs
589 getTcErrs (TcDown{tc_errs=errs}) = errs
590 setTcErrs down errs = down{tc_errs=errs}
592 getDefaultTys (TcDown{tc_def=def}) = def
593 setDefaultTys down def = down{tc_def=def}
595 getLoc (TcDown{tc_loc=loc}) = loc
596 setLoc down loc = down{tc_loc=loc}
598 getUniqSupplyVar (TcDown{tc_us=us}) = us
600 getErrCtxt (TcDown{tc_ctxt=ctxt}) = ctxt
601 setErrCtxt down msg = down{tc_ctxt=[msg]}
602 addErrCtxt down msg = down{tc_ctxt = msg : tc_ctxt down}
604 doptsTc :: DynFlag -> TcM Bool
605 doptsTc dflag (TcDown{tc_dflags=dflags}) env_down
606 = return (dopt dflag dflags)
608 getDOptsTc :: TcM DynFlags
609 getDOptsTc (TcDown{tc_dflags=dflags}) env_down
616 %************************************************************************
618 \subsection{TypeChecking Errors}
620 %************************************************************************
623 type TcError = Message
624 type TcWarning = Message
626 ctxt_to_use ctxt | opt_PprStyle_Debug = ctxt
627 | otherwise = takeAtMost 3 ctxt
629 takeAtMost :: Int -> [a] -> [a]
632 takeAtMost n (x:xs) = x:takeAtMost (n-1) xs
634 arityErr kind name n m
635 = hsep [ text kind, quotes (ppr name), ptext SLIT("should have"),
636 n_arguments <> comma, text "but has been given", int m]
638 n_arguments | n == 0 = ptext SLIT("no arguments")
639 | n == 1 = ptext SLIT("1 argument")
640 | True = hsep [int n, ptext SLIT("arguments")]
645 %************************************************************************
647 \subsection[Inst-origin]{The @InstOrigin@ type}
649 %************************************************************************
651 The @InstOrigin@ type gives information about where a dictionary came from.
652 This is important for decent error message reporting because dictionaries
653 don't appear in the original source code. Doubtless this type will evolve...
655 It appears in TcMonad because there are a couple of error-message-generation
656 functions that deal with it.
659 type InstLoc = (InstOrigin, SrcLoc, ErrCtxt)
662 = OccurrenceOf Id -- Occurrence of an overloaded identifier
664 | IPOcc Name -- Occurrence of an implicit parameter
665 | IPBind Name -- Binding site of an implicit parameter
669 | DataDeclOrigin -- Typechecking a data declaration
671 | InstanceDeclOrigin -- Typechecking an instance decl
673 | LiteralOrigin RenamedHsOverLit -- Occurrence of a literal
675 | PatOrigin RenamedPat
677 | ArithSeqOrigin RenamedArithSeqInfo -- [x..], [x..y] etc
679 | SignatureOrigin -- A dict created from a type signature
680 | Rank2Origin -- A dict created when typechecking the argument
681 -- of a rank-2 typed function
683 | DoOrigin -- The monad for a do expression
685 | ClassDeclOrigin -- Manufactured during a class decl
687 | InstanceSpecOrigin Class -- in a SPECIALIZE instance pragma
690 -- When specialising instances the instance info attached to
691 -- each class is not yet ready, so we record it inside the
692 -- origin information. This is a bit of a hack, but it works
693 -- fine. (Patrick is to blame [WDP].)
695 | ValSpecOrigin Name -- in a SPECIALIZE pragma for a value
697 -- Argument or result of a ccall
698 -- Dictionaries with this origin aren't actually mentioned in the
699 -- translated term, and so need not be bound. Nor should they
700 -- be abstracted over.
702 | CCallOrigin String -- CCall label
703 (Maybe RenamedHsExpr) -- Nothing if it's the result
704 -- Just arg, for an argument
706 | LitLitOrigin String -- the litlit
708 | UnknownOrigin -- Help! I give up...
712 pprInstLoc :: InstLoc -> SDoc
713 pprInstLoc (orig, locn, ctxt)
714 = hsep [text "arising from", pp_orig orig, text "at", ppr locn]
716 pp_orig (OccurrenceOf id)
717 = hsep [ptext SLIT("use of"), quotes (ppr id)]
719 = hsep [ptext SLIT("use of implicit parameter"), quotes (char '?' <> ppr name)]
720 pp_orig (IPBind name)
721 = hsep [ptext SLIT("binding for implicit parameter"), quotes (char '?' <> ppr name)]
722 pp_orig (LiteralOrigin lit)
723 = hsep [ptext SLIT("the literal"), quotes (ppr lit)]
724 pp_orig (PatOrigin pat)
725 = hsep [ptext SLIT("the pattern"), quotes (ppr pat)]
726 pp_orig (InstanceDeclOrigin)
727 = ptext SLIT("an instance declaration")
728 pp_orig (ArithSeqOrigin seq)
729 = hsep [ptext SLIT("the arithmetic sequence"), quotes (ppr seq)]
730 pp_orig (SignatureOrigin)
731 = ptext SLIT("a type signature")
732 pp_orig (Rank2Origin)
733 = ptext SLIT("a function with an overloaded argument type")
735 = ptext SLIT("a do statement")
736 pp_orig (ClassDeclOrigin)
737 = ptext SLIT("a class declaration")
738 pp_orig (InstanceSpecOrigin clas ty)
739 = hsep [text "a SPECIALIZE instance pragma; class",
740 quotes (ppr clas), text "type:", ppr ty]
741 pp_orig (ValSpecOrigin name)
742 = hsep [ptext SLIT("a SPECIALIZE user-pragma for"), quotes (ppr name)]
743 pp_orig (CCallOrigin clabel Nothing{-ccall result-})
744 = hsep [ptext SLIT("the result of the _ccall_ to"), quotes (text clabel)]
745 pp_orig (CCallOrigin clabel (Just arg_expr))
746 = hsep [ptext SLIT("an argument in the _ccall_ to"), quotes (text clabel) <> comma,
747 text "namely", quotes (ppr arg_expr)]
748 pp_orig (LitLitOrigin s)
749 = hsep [ptext SLIT("the ``literal-literal''"), quotes (text s)]
750 pp_orig (UnknownOrigin)
751 = ptext SLIT("...oops -- I don't know where the overloading came from!")