2 % (c) The GRASP Project, Glasgow University, 1992-2002
6 TcRn, TcM, RnM, -- The monad is opaque outside this module
8 -- Standard monadic operations
9 thenM, thenM_, returnM, failM,
11 -- Non-standard operations
12 runTcRn, fixM, tryM, ioToTcRn,
13 newMutVar, readMutVar, writeMutVar,
14 getEnv, setEnv, updEnv, unsafeInterleaveM,
16 -- The environment types
17 Env(..), TopEnv(..), TcGblEnv(..),
18 TcLclEnv(..), RnLclEnv(..),
21 RnMode(..), isInterfaceMode, isCmdLineMode,
22 Usages(..), emptyUsages, ErrCtxt,
23 ImportAvails(..), emptyImportAvails, plusImportAvails, mkImportAvails,
24 plusAvail, pruneAvails,
25 AvailEnv, emptyAvailEnv, unitAvailEnv, plusAvailEnv, lookupAvailEnv, availEnvElts, addAvail,
32 Stage(..), topStage, topSpliceStage,
33 Level, impLevel, topLevel,
36 Inst(..), InstOrigin(..), InstLoc, pprInstLoc,
37 LIE, emptyLIE, unitLIE, plusLIE, consLIE,
38 plusLIEs, mkLIE, isEmptyLIE, lieToList, listToLIE,
44 #include "HsVersions.h"
46 import HsSyn ( PendingSplice, HsOverLit, MonoBinds, RuleDecl, ForeignDecl )
47 import RnHsSyn ( RenamedHsExpr, RenamedPat, RenamedArithSeqInfo )
48 import HscTypes ( GhciMode, ExternalPackageState, HomePackageTable, NameCache,
49 GlobalRdrEnv, LocalRdrEnv, FixityEnv, TypeEnv, TyThing,
50 Avails, GenAvailInfo(..), AvailInfo, availName,
51 IsBootInterface, Deprecations )
52 import TcType ( TcTyVarSet, TcType, TcTauType, TcThetaType, TcPredType, TcKind,
53 tcCmpPred, tcCmpType, tcCmpTypes )
54 import InstEnv ( DFunId, InstEnv )
57 import NameSet ( NameSet, emptyNameSet )
59 import Class ( Class )
60 import Var ( Id, TyVar )
61 import VarEnv ( TidyEnv )
63 import SrcLoc ( SrcLoc )
64 import VarSet ( IdSet )
65 import ErrUtils ( Messages, Message )
66 import CmdLineOpts ( DynFlags )
67 import UniqSupply ( UniqSupply )
68 import BasicTypes ( IPName )
69 import Util ( thenCmp )
72 import DATA_IOREF ( IORef, newIORef, readIORef, writeIORef )
73 import UNSAFE_IO ( unsafeInterleaveIO )
74 import FIX_IO ( fixIO )
75 import EXCEPTION ( Exception )
76 import Maybe ( mapMaybe )
78 import Panic ( tryMost )
83 type TcRef a = IORef a
84 type TcId = Id -- Type may be a TcType
88 %************************************************************************
90 Standard monad definition for TcRn
91 All the combinators for the monad can be found in TcRnMonad
93 %************************************************************************
95 The monad itself has to be defined here,
96 because it is mentioned by ErrCtxt
99 newtype TcRn m a = TcRn (Env m -> IO a)
102 type TcM a = TcRn TcLclEnv a
103 type RnM a = TcRn RnLclEnv a
105 returnM :: a -> TcRn m a
106 returnM a = TcRn (\ env -> return a)
108 thenM :: TcRn m a -> (a -> TcRn m b) -> TcRn m b
109 thenM (TcRn m) f = TcRn (\ env -> do { r <- m env ;
112 thenM_ :: TcRn m a -> TcRn m b -> TcRn m b
113 thenM_ (TcRn m) f = TcRn (\ env -> do { m env ; unTcRn f env })
116 failM = TcRn (\ env -> ioError (userError "TcRn failure"))
118 instance Monad (TcRn m) where
122 fail s = failM -- Ignore the string
126 %************************************************************************
128 Fundmantal combinators specific to the monad
130 %************************************************************************
135 runTcRn :: Env m -> TcRn m a -> IO a
136 runTcRn env (TcRn m) = m env
139 The fixpoint combinator
142 {-# NOINLINE fixM #-}
143 -- Aargh! Not inlining fixTc alleviates a space leak problem.
144 -- Normally fixTc is used with a lazy tuple match: if the optimiser is
145 -- shown the definition of fixTc, it occasionally transforms the code
146 -- in such a way that the code generator doesn't spot the selector
149 fixM :: (a -> TcRn m a) -> TcRn m a
150 fixM f = TcRn (\ env -> fixIO (\ r -> unTcRn (f r) env))
156 tryM :: TcRn m r -> TcRn m (Either Exception r)
157 -- Reflect exception into TcRn monad
158 tryM (TcRn thing) = TcRn (\ env -> tryMost (thing env))
164 unsafeInterleaveM :: TcRn m a -> TcRn m a
165 unsafeInterleaveM (TcRn m) = TcRn (\ env -> unsafeInterleaveIO (m env))
170 Performing arbitrary I/O, plus the read/write var (for efficiency)
173 ioToTcRn :: IO a -> TcRn m a
174 ioToTcRn io = TcRn (\ env -> io)
176 newMutVar :: a -> TcRn m (TcRef a)
177 newMutVar val = TcRn (\ env -> newIORef val)
179 writeMutVar :: TcRef a -> a -> TcRn m ()
180 writeMutVar var val = TcRn (\ env -> writeIORef var val)
182 readMutVar :: TcRef a -> TcRn m a
183 readMutVar var = TcRn (\ env -> readIORef var)
186 Getting the environment
189 getEnv :: TcRn m (Env m)
190 {-# INLINE getEnv #-}
191 getEnv = TcRn (\ env -> return env)
193 setEnv :: Env n -> TcRn n a -> TcRn m a
194 {-# INLINE setEnv #-}
195 setEnv new_env (TcRn m) = TcRn (\ env -> m new_env)
197 updEnv :: (Env m -> Env n) -> TcRn n a -> TcRn m a
198 {-# INLINE updEnv #-}
199 updEnv upd (TcRn m) = TcRn (\ env -> m (upd env))
203 %************************************************************************
205 The main environment types
207 %************************************************************************
210 data Env a -- Changes as we move into an expression
212 env_top :: TopEnv, -- Top-level stuff that never changes
213 -- Mainly a bunch of updatable refs
214 -- Includes all info about imported things
215 env_gbl :: TcGblEnv, -- Info about things defined at the top leve
216 -- of the module being compiled
218 env_lcl :: a, -- Different for the type checker
221 env_loc :: SrcLoc -- Source location
224 data TopEnv -- Built once at top level then does not change
225 -- Concerns imported stuff
226 -- Exceptions: error recovery points, meta computation points
228 top_mode :: GhciMode,
229 top_dflags :: DynFlags,
231 -- Stuff about imports
232 top_eps :: TcRef ExternalPackageState,
233 -- PIT, ImportedModuleInfo
234 -- DeclsMap, IfaceRules, IfaceInsts, InstGates
235 -- TypeEnv, InstEnv, RuleBase
237 top_hpt :: HomePackageTable,
238 -- The home package table that we've accumulated while
239 -- compiling the home package,
240 -- *excluding* the module we are compiling right now.
241 -- (In one-shot mode the current module is the only
242 -- home-package module, so tc_hpt is empty. All other
243 -- modules count as "external-package" modules.)
244 -- tc_hpt is not mutable because we only demand-load
245 -- external packages; the home package is eagerly
246 -- loaded by the compilation manager.
248 -- The global name supply
249 top_nc :: TcRef NameCache, -- Maps original names to Names
250 top_us :: TcRef UniqSupply, -- Unique supply for this module
251 top_errs :: TcRef Messages
254 -- TcGblEnv describes the top-level of the module at the
255 -- point at which the typechecker is finished work.
256 -- It is this structure that is handed on to the desugarer
260 tcg_mod :: Module, -- Module being compiled
261 tcg_usages :: TcRef Usages, -- What version of what entities
262 -- have been used from other modules
263 -- (whether home or ext-package modules)
264 tcg_rdr_env :: GlobalRdrEnv, -- Top level envt; used during renaming
265 tcg_fix_env :: FixityEnv, -- Ditto
266 tcg_default :: [Type], -- Types used for defaulting
268 tcg_type_env :: TypeEnv, -- Global type env for the module we are compiling now
269 -- All TyCons and Classes (for this module) end up in here right away,
270 -- along with their derived constructors, selectors.
272 -- (Ids defined in this module start in the local envt,
273 -- though they move to the global envt during zonking)
276 tcg_ist :: Name -> Maybe TyThing, -- Imported symbol table
277 -- Global type env: a combination of tcg_eps, tcg_hpt
278 -- (but *not* tcg_type_env; no deep reason)
279 -- When the PCS changes this must be refreshed,
280 -- notably after running some compile-time code
282 tcg_inst_env :: InstEnv, -- Global instance env: a combination of
283 -- tc_pcs, tc_hpt, *and* tc_insts
285 -- Now a bunch of things about this module that are simply
286 -- accumulated, but never consulted until the end.
287 -- Nevertheless, it's convenient to accumulate them along
288 -- with the rest of the info from this module.
289 tcg_exports :: Avails, -- What is exported
290 tcg_imports :: ImportAvails, -- Information about what was imported
291 -- from where, including things bound
293 -- The next fields are always fully zonked
294 tcg_binds :: MonoBinds Id, -- Value bindings in this module
295 tcg_deprecs :: Deprecations, -- ...Deprecations
296 tcg_insts :: [DFunId], -- ...Instances
297 tcg_rules :: [RuleDecl Id], -- ...Rules
298 tcg_fords :: [ForeignDecl Id] -- ...Foreign import & exports
303 %************************************************************************
305 The local typechecker environment
307 %************************************************************************
309 The Global-Env/Local-Env story
310 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
311 During type checking, we keep in the tcg_type_env
312 * All types and classes
313 * All Ids derived from types and classes (constructors, selectors)
315 At the end of type checking, we zonk the local bindings,
316 and as we do so we add to the tcg_type_env
317 * Locally defined top-level Ids
319 Why? Because they are now Ids not TcIds. This final GlobalEnv is
320 a) fed back (via the knot) to typechecking the
321 unfoldings of interface signatures
322 b) used in the ModDetails of this module
327 tcl_ctxt :: ErrCtxt, -- Error context
329 tcl_level :: Stage, -- Template Haskell context
331 tcl_env :: NameEnv TcTyThing, -- The local type environment: Ids and TyVars
332 -- defined in this module
334 tcl_tyvars :: TcRef TcTyVarSet, -- The "global tyvars"
335 -- Namely, the in-scope TyVars bound in tcl_lenv,
336 -- plus the tyvars mentioned in the types of
337 -- Ids bound in tcl_lenv
338 -- Why mutable? see notes with tcGetGlobalTyVars
340 tcl_lie :: TcRef LIE -- Place to accumulate type constraints
346 = Comp -- Ordinary compiling, at level topLevel
347 | Splice Level -- Inside a splice
348 | Brack Level -- Inside brackets;
349 (TcRef [PendingSplice]) -- accumulate pending splices here
350 (TcRef LIE) -- and type constraints here
351 topStage, topSpliceStage :: Stage
353 topSpliceStage = Splice (topLevel - 1) -- Stage for the body of a top-level splice
356 impLevel, topLevel :: Level
357 topLevel = 1 -- Things dedined at top level of this module
358 impLevel = 0 -- Imported things; they can be used inside a top level splice
362 -- g1 = $(map ...) is OK
363 -- g2 = $(f ...) is not OK; because we havn't compiled f yet
366 = AGlobal TyThing -- Used only in the return type of a lookup
367 | ATcId TcId Level -- Ids defined in this module; may not be fully zonked
368 | ATyVar TyVar -- Type variables
369 | AThing TcKind -- Used temporarily, during kind checking
370 -- Here's an example of how the AThing guy is used
371 -- Suppose we are checking (forall a. T a Int):
372 -- 1. We first bind (a -> AThink kv), where kv is a kind variable.
373 -- 2. Then we kind-check the (T a Int) part.
374 -- 3. Then we zonk the kind variable.
375 -- 4. Now we know the kind for 'a', and we add (a -> ATyVar a::K) to the environment
379 type ErrCtxt = [TidyEnv -> TcM (TidyEnv, Message)]
380 -- Innermost first. Monadic so that we have a chance
381 -- to deal with bound type variables just before error
382 -- message construction
386 %************************************************************************
388 The local renamer environment
390 %************************************************************************
396 rn_lenv :: LocalRdrEnv -- Local name envt
397 -- Does *not* include global name envt; may shadow it
398 -- Includes both ordinary variables and type variables;
399 -- they are kept distinct because tyvar have a different
400 -- occurrence contructor (Name.TvOcc)
401 -- We still need the unsullied global name env so that
402 -- we can look up record field names
405 data RnMode = SourceMode -- Renaming source code
406 | InterfaceMode Module -- Renaming interface declarations from M
407 | CmdLineMode -- Renaming a command-line expression
409 isInterfaceMode (InterfaceMode _) = True
410 isInterfaceMode _ = False
412 isCmdLineMode CmdLineMode = True
413 isCmdLineMode _ = False
417 %************************************************************************
421 %************************************************************************
423 Usages tells what things are actually need in order to compile this
425 * for generating the usages field of the ModIface
426 * for reporting unused things in scope
431 usg_ext :: ModuleSet,
432 -- The non-home-package modules from which we have
433 -- slurped at least one name.
436 -- The Names are all the (a) home-package
437 -- (b) "big" (i.e. no data cons, class ops)
438 -- (c) non-locally-defined
440 -- names that have been slurped in so far.
441 -- This is used to generate the "usage" information for this module.
444 emptyUsages :: Usages
445 emptyUsages = Usages { usg_ext = emptyModuleSet,
446 usg_home = emptyNameSet }
450 %************************************************************************
452 Operations over ImportAvails
454 %************************************************************************
456 ImportAvails summarises what was imported from where, irrespective
457 of whether the imported htings are actually used or not
458 It is used * when porcessing the export list
459 * when constructing usage info for the inteface file
460 * to identify the list of directly imported modules
461 for initialisation purposes
467 -- All the things that are available from the import
468 -- Its domain is all the "main" things;
469 -- i.e. *excluding* class ops and constructors
470 -- (which appear inside their parent AvailTC)
472 imp_unqual :: ModuleEnv AvailEnv,
473 -- Used to figure out "module M" export specifiers
474 -- Domain is only modules with *unqualified* imports
475 -- (see 1.4 Report Section 5.1.1)
476 -- We keep the stuff as an AvailEnv so that it's easy to
477 -- combine stuff coming from different (unqualified)
478 -- imports of the same module
480 imp_mods :: ModuleEnv (Module, Bool)
481 -- Domain is all directly-imported modules
482 -- Bool is True if there was an unrestricted import
483 -- (i.e. not a selective list)
484 -- We need the Module in the range because we can't get
485 -- the keys of a ModuleEnv
487 -- (a) to help construct the usage information in
488 -- the interface file; if we import everything we
489 -- need to recompile if the module version changes
490 -- (b) to specify what child modules to initialise
493 emptyImportAvails :: ImportAvails
494 emptyImportAvails = ImportAvails { imp_env = emptyAvailEnv,
495 imp_unqual = emptyModuleEnv,
496 imp_mods = emptyModuleEnv }
498 plusImportAvails :: ImportAvails -> ImportAvails -> ImportAvails
500 (ImportAvails { imp_env = env1, imp_unqual = unqual1, imp_mods = mods1 })
501 (ImportAvails { imp_env = env2, imp_unqual = unqual2, imp_mods = mods2 })
502 = ImportAvails { imp_env = env1 `plusAvailEnv` env2,
503 imp_unqual = plusModuleEnv_C plusAvailEnv unqual1 unqual2,
504 imp_mods = mods1 `plusModuleEnv` mods2 }
506 mkImportAvails :: ModuleName -> Bool
507 -> [AvailInfo] -> ImportAvails
508 mkImportAvails mod_name unqual_imp avails
509 = ImportAvails { imp_unqual = mod_avail_env,
510 imp_env = entity_avail_env,
511 imp_mods = emptyModuleEnv }-- Stays empty for module being compiled;
512 -- gets updated for imported modules
514 mod_avail_env = unitModuleEnvByName mod_name unqual_avails
516 -- unqual_avails is the Avails that are visible in *unqualified* form
517 -- We need to know this so we know what to export when we see
518 -- module M ( module P ) where ...
519 -- Then we must export whatever came from P unqualified.
521 unqual_avails | not unqual_imp = emptyAvailEnv -- Qualified import
522 | otherwise = entity_avail_env -- Unqualified import
524 entity_avail_env = foldl insert emptyAvailEnv avails
525 insert env avail = extendNameEnv_C plusAvail env (availName avail) avail
526 -- 'avails' may have several items with the same availName
527 -- E.g import Ix( Ix(..), index )
528 -- will give Ix(Ix,index,range) and Ix(index)
529 -- We want to combine these
532 %************************************************************************
534 Avails, AvailEnv, etc
536 v%************************************************************************
539 plusAvail (Avail n1) (Avail n2) = Avail n1
540 plusAvail (AvailTC n1 ns1) (AvailTC n2 ns2) = AvailTC n2 (nub (ns1 ++ ns2))
543 plusAvail a1 a2 = pprPanic "RnEnv.plusAvail" (hsep [ppr a1,ppr a2])
546 -------------------------
547 pruneAvails :: (Name -> Bool) -- Keep if this is True
550 pruneAvails keep avails
551 = mapMaybe del avails
553 del :: AvailInfo -> Maybe AvailInfo -- Nothing => nothing left!
554 del (Avail n) | keep n = Just (Avail n)
555 | otherwise = Nothing
556 del (AvailTC n ns) | null ns' = Nothing
557 | otherwise = Just (AvailTC n ns')
562 ---------------------------------------
564 ---------------------------------------
567 type AvailEnv = NameEnv AvailInfo -- Maps a Name to the AvailInfo that contains it
569 emptyAvailEnv :: AvailEnv
570 emptyAvailEnv = emptyNameEnv
572 unitAvailEnv :: AvailInfo -> AvailEnv
573 unitAvailEnv a = unitNameEnv (availName a) a
575 plusAvailEnv :: AvailEnv -> AvailEnv -> AvailEnv
576 plusAvailEnv = plusNameEnv_C plusAvail
578 lookupAvailEnv = lookupNameEnv
580 availEnvElts = nameEnvElts
582 addAvail :: AvailEnv -> AvailInfo -> AvailEnv
583 addAvail avails avail = extendNameEnv_C plusAvail avails (availName avail) avail
586 %************************************************************************
588 \subsection{Where from}
590 %************************************************************************
592 The @WhereFrom@ type controls where the renamer looks for an interface file
596 = ImportByUser IsBootInterface -- Ordinary user import (perhaps {-# SOURCE #-})
598 | ImportForUsage IsBootInterface -- Import when chasing usage info from an interaface file
599 -- Failure in this case is not an error
601 | ImportBySystem -- Non user import. Use eps_mod_info to decide whether
602 -- the module this module depends on, or is a system-ish module;
603 -- M.hi-boot otherwise
605 instance Outputable WhereFrom where
606 ppr (ImportByUser is_boot) | is_boot = ptext SLIT("{- SOURCE -}")
608 ppr (ImportForUsage is_boot) | is_boot = ptext SLIT("{- USAGE SOURCE -}")
609 | otherwise = ptext SLIT("{- USAGE -}")
610 ppr ImportBySystem = ptext SLIT("{- SYSTEM -}")
614 %************************************************************************
616 \subsection[Inst-types]{@Inst@ types}
618 v%************************************************************************
620 An @Inst@ is either a dictionary, an instance of an overloaded
621 literal, or an instance of an overloaded value. We call the latter a
622 ``method'' even though it may not correspond to a class operation.
623 For example, we might have an instance of the @double@ function at
624 type Int, represented by
626 Method 34 doubleId [Int] origin
638 TcId -- The overloaded function
639 -- This function will be a global, local, or ClassOpId;
640 -- inside instance decls (only) it can also be an InstId!
641 -- The id needn't be completely polymorphic.
642 -- You'll probably find its name (for documentation purposes)
643 -- inside the InstOrigin
645 [TcType] -- The types to which its polymorphic tyvars
646 -- should be instantiated.
647 -- These types must saturate the Id's foralls.
649 TcThetaType -- The (types of the) dictionaries to which the function
650 -- must be applied to get the method
652 TcTauType -- The type of the method
656 -- INVARIANT: in (Method u f tys theta tau loc)
657 -- type of (f tys dicts(from theta)) = tau
661 HsOverLit -- The literal from the occurrence site
662 -- INVARIANT: never a rebindable-syntax literal
663 -- Reason: tcSyntaxName does unification, and we
664 -- don't want to deal with that during tcSimplify
665 TcType -- The type at which the literal is used
669 @Insts@ are ordered by their class/type info, rather than by their
670 unique. This allows the context-reduction mechanism to use standard finite
671 maps to do their stuff.
674 instance Ord Inst where
677 instance Eq Inst where
678 (==) i1 i2 = case i1 `cmpInst` i2 of
682 cmpInst (Dict _ pred1 _) (Dict _ pred2 _) = pred1 `tcCmpPred` pred2
683 cmpInst (Dict _ _ _) other = LT
685 cmpInst (Method _ _ _ _ _ _) (Dict _ _ _) = GT
686 cmpInst (Method _ id1 tys1 _ _ _) (Method _ id2 tys2 _ _ _) = (id1 `compare` id2) `thenCmp` (tys1 `tcCmpTypes` tys2)
687 cmpInst (Method _ _ _ _ _ _) other = LT
689 cmpInst (LitInst _ _ _ _) (Dict _ _ _) = GT
690 cmpInst (LitInst _ _ _ _) (Method _ _ _ _ _ _) = GT
691 cmpInst (LitInst _ lit1 ty1 _) (LitInst _ lit2 ty2 _) = (lit1 `compare` lit2) `thenCmp` (ty1 `tcCmpType` ty2)
695 %************************************************************************
697 \subsection[Inst-collections]{LIE: a collection of Insts}
699 %************************************************************************
704 isEmptyLIE = isEmptyBag
706 unitLIE inst = unitBag inst
707 mkLIE insts = listToBag insts
708 plusLIE lie1 lie2 = lie1 `unionBags` lie2
709 consLIE inst lie = inst `consBag` lie
710 plusLIEs lies = unionManyBags lies
711 lieToList = bagToList
712 listToLIE = listToBag
716 %************************************************************************
718 \subsection[Inst-origin]{The @InstOrigin@ type}
720 %************************************************************************
722 The @InstOrigin@ type gives information about where a dictionary came from.
723 This is important for decent error message reporting because dictionaries
724 don't appear in the original source code. Doubtless this type will evolve...
726 It appears in TcMonad because there are a couple of error-message-generation
727 functions that deal with it.
730 type InstLoc = (InstOrigin, SrcLoc, ErrCtxt)
733 = OccurrenceOf Name -- Occurrence of an overloaded identifier
735 | IPOcc (IPName Name) -- Occurrence of an implicit parameter
736 | IPBind (IPName Name) -- Binding site of an implicit parameter
740 | DataDeclOrigin -- Typechecking a data declaration
742 | InstanceDeclOrigin -- Typechecking an instance decl
744 | LiteralOrigin HsOverLit -- Occurrence of a literal
746 | PatOrigin RenamedPat
748 | ArithSeqOrigin RenamedArithSeqInfo -- [x..], [x..y] etc
749 | PArrSeqOrigin RenamedArithSeqInfo -- [:x..y:] and [:x,y..z:]
751 | SignatureOrigin -- A dict created from a type signature
752 | Rank2Origin -- A dict created when typechecking the argument
753 -- of a rank-2 typed function
755 | DoOrigin -- The monad for a do expression
757 | ClassDeclOrigin -- Manufactured during a class decl
759 | InstanceSpecOrigin Class -- in a SPECIALIZE instance pragma
762 -- When specialising instances the instance info attached to
763 -- each class is not yet ready, so we record it inside the
764 -- origin information. This is a bit of a hack, but it works
765 -- fine. (Patrick is to blame [WDP].)
767 | ValSpecOrigin Name -- in a SPECIALIZE pragma for a value
769 -- Argument or result of a ccall
770 -- Dictionaries with this origin aren't actually mentioned in the
771 -- translated term, and so need not be bound. Nor should they
772 -- be abstracted over.
774 | CCallOrigin String -- CCall label
775 (Maybe RenamedHsExpr) -- Nothing if it's the result
776 -- Just arg, for an argument
778 | LitLitOrigin String -- the litlit
780 | UnknownOrigin -- Help! I give up...
784 pprInstLoc :: InstLoc -> SDoc
785 pprInstLoc (orig, locn, ctxt)
786 = hsep [text "arising from", pp_orig orig, text "at", ppr locn]
788 pp_orig (OccurrenceOf name)
789 = hsep [ptext SLIT("use of"), quotes (ppr name)]
791 = hsep [ptext SLIT("use of implicit parameter"), quotes (ppr name)]
792 pp_orig (IPBind name)
793 = hsep [ptext SLIT("binding for implicit parameter"), quotes (ppr name)]
794 pp_orig RecordUpdOrigin
795 = ptext SLIT("a record update")
796 pp_orig DataDeclOrigin
797 = ptext SLIT("the data type declaration")
798 pp_orig InstanceDeclOrigin
799 = ptext SLIT("the instance declaration")
800 pp_orig (LiteralOrigin lit)
801 = hsep [ptext SLIT("the literal"), quotes (ppr lit)]
802 pp_orig (PatOrigin pat)
803 = hsep [ptext SLIT("the pattern"), quotes (ppr pat)]
804 pp_orig (ArithSeqOrigin seq)
805 = hsep [ptext SLIT("the arithmetic sequence"), quotes (ppr seq)]
806 pp_orig (PArrSeqOrigin seq)
807 = hsep [ptext SLIT("the parallel array sequence"), quotes (ppr seq)]
808 pp_orig (SignatureOrigin)
809 = ptext SLIT("a type signature")
810 pp_orig (Rank2Origin)
811 = ptext SLIT("a function with an overloaded argument type")
813 = ptext SLIT("a do statement")
814 pp_orig (ClassDeclOrigin)
815 = ptext SLIT("a class declaration")
816 pp_orig (InstanceSpecOrigin clas ty)
817 = hsep [text "a SPECIALIZE instance pragma; class",
818 quotes (ppr clas), text "type:", ppr ty]
819 pp_orig (ValSpecOrigin name)
820 = hsep [ptext SLIT("a SPECIALIZE user-pragma for"), quotes (ppr name)]
821 pp_orig (CCallOrigin clabel Nothing{-ccall result-})
822 = hsep [ptext SLIT("the result of the _ccall_ to"), quotes (text clabel)]
823 pp_orig (CCallOrigin clabel (Just arg_expr))
824 = hsep [ptext SLIT("an argument in the _ccall_ to"), quotes (text clabel) <> comma,
825 text "namely", quotes (ppr arg_expr)]
826 pp_orig (LitLitOrigin s)
827 = hsep [ptext SLIT("the ``literal-literal''"), quotes (text s)]
828 pp_orig (UnknownOrigin)
829 = ptext SLIT("...oops -- I don't know where the overloading came from!")