2 % (c) The GRASP Project, Glasgow University, 1992-2002
6 TcRnIf, TcRn, TcM, RnM, IfM, IfL, IfG, -- The monad is opaque outside this module
9 -- The environment types
11 TcGblEnv(..), TcLclEnv(..),
12 IfGblEnv(..), IfLclEnv(..),
15 EntityUsage, emptyUsages, ErrCtxt,
16 ImportAvails(..), emptyImportAvails, plusImportAvails,
17 plusAvail, pruneAvails,
18 AvailEnv, emptyAvailEnv, unitAvailEnv, plusAvailEnv,
19 mkAvailEnv, lookupAvailEnv, lookupAvailEnv_maybe, availEnvElts, addAvail,
20 WhereFrom(..), mkModDeps,
26 ThStage(..), topStage, topSpliceStage,
27 ThLevel, impLevel, topLevel,
30 ArrowCtxt(..), topArrowCtxt, ProcLevel, topProcLevel,
33 Inst(..), InstOrigin(..), InstLoc(..), pprInstLoc, instLocSrcLoc,
34 LIE, emptyLIE, unitLIE, plusLIE, consLIE,
35 plusLIEs, mkLIE, isEmptyLIE, lieToList, listToLIE,
41 #include "HsVersions.h"
43 import HsSyn ( PendingSplice, HsOverLit, MonoBinds, RuleDecl, ForeignDecl )
44 import RnHsSyn ( RenamedPat, RenamedArithSeqInfo )
45 import HscTypes ( FixityEnv,
46 HscEnv, TypeEnv, TyThing,
47 Avails, GenAvailInfo(..), AvailInfo,
48 availName, IsBootInterface, Deprecations )
49 import Packages ( PackageName )
50 import TcType ( TcTyVarSet, TcType, TcTauType, TcThetaType,
51 TcPredType, TcKind, tcCmpPred, tcCmpType, tcCmpTypes )
52 import InstEnv ( DFunId, InstEnv )
54 import RdrName ( GlobalRdrEnv, LocalRdrEnv )
57 import NameSet ( NameSet, emptyNameSet, DefUses )
58 import OccName ( OccEnv )
60 import Class ( Class )
61 import Var ( Id, TyVar )
62 import VarEnv ( TidyEnv )
64 import SrcLoc ( SrcLoc )
65 import VarSet ( IdSet )
66 import ErrUtils ( Messages, Message )
67 import UniqSupply ( UniqSupply )
68 import BasicTypes ( IPName )
69 import Util ( thenCmp )
72 import Maybe ( mapMaybe )
73 import ListSetOps ( unionLists )
77 %************************************************************************
79 Standard monad definition for TcRn
80 All the combinators for the monad can be found in TcRnMonad
82 %************************************************************************
84 The monad itself has to be defined here, because it is mentioned by ErrCtxt
87 type TcRef a = IORef a
88 type TcId = Id -- Type may be a TcType
91 type TcRnIf a b c = IOEnv (Env a b) c
92 type IfM lcl a = TcRnIf IfGblEnv lcl a -- Iface stuff
93 type IfG a = IfM () a -- Top level
94 type IfL a = IfM IfLclEnv a -- Nested
95 type TcRn a = TcRnIf TcGblEnv TcLclEnv a
96 type RnM a = TcRn a -- Historical
97 type TcM a = TcRn a -- Historical
101 %************************************************************************
103 The main environment types
105 %************************************************************************
108 data Env gbl lcl -- Changes as we move into an expression
110 env_top :: HscEnv, -- Top-level stuff that never changes
111 -- Includes all info about imported things
113 env_us :: TcRef UniqSupply, -- Unique supply for local varibles
115 env_gbl :: gbl, -- Info about things defined at the top level
116 -- of the module being compiled
118 env_lcl :: lcl -- Nested stuff -- changes as we go into
122 -- TcGblEnv describes the top-level of the module at the
123 -- point at which the typechecker is finished work.
124 -- It is this structure that is handed on to the desugarer
128 tcg_mod :: Module, -- Module being compiled
129 tcg_rdr_env :: GlobalRdrEnv, -- Top level envt; used during renaming
130 tcg_default :: Maybe [Type], -- Types used for defaulting
131 -- Nothing => no 'default' decl
133 tcg_fix_env :: FixityEnv, -- Just for things in this module
135 tcg_type_env :: TypeEnv, -- Global type env for the module we are compiling now
136 -- All TyCons and Classes (for this module) end up in here right away,
137 -- along with their derived constructors, selectors.
139 -- (Ids defined in this module start in the local envt,
140 -- though they move to the global envt during zonking)
142 tcg_type_env_var :: TcRef TypeEnv,
143 -- Used only to initialise the interface-file
144 -- typechecker in initIfaceTcRn, so that it can see stuff
145 -- bound in this module when dealing with hi-boot recursions
146 -- Updated at intervals (e.g. after dealing with types and classes)
148 tcg_inst_env :: InstEnv, -- Instance envt for *home-package* modules
149 -- Includes the dfuns in tcg_insts
150 tcg_inst_uses :: TcRef NameSet, -- Home-package Dfuns actually used
151 -- Used to generate version dependencies
152 -- This records usages, rather like tcg_dus, but it has to
153 -- be a mutable variable so it can be augmented
154 -- when we look up an instance. These uses of dfuns are
155 -- rather like the free variables of the program, but
156 -- are implicit instead of explicit.
158 -- Now a bunch of things about this module that are simply
159 -- accumulated, but never consulted until the end.
160 -- Nevertheless, it's convenient to accumulate them along
161 -- with the rest of the info from this module.
162 tcg_exports :: Avails, -- What is exported
163 tcg_imports :: ImportAvails, -- Information about what was imported
164 -- from where, including things bound
167 tcg_dus :: DefUses, -- What is defined in this module and what is used.
168 -- The latter is used to generate
169 -- (a) version tracking; no need to recompile if these
170 -- things have not changed version stamp
171 -- (b) unused-import info
173 tcg_keep :: NameSet, -- Set of names to keep alive, and to expose in the
174 -- interface file (but not to export to the user).
175 -- These are typically extra definitions generated from
176 -- data type declarations which would otherwise be
177 -- dropped as dead code.
179 -- The next fields accumulate the payload of the module
180 -- The binds, rules and foreign-decl fiels are collected
181 -- initially in un-zonked form and are finally zonked in tcRnSrcDecls
182 tcg_binds :: MonoBinds Id, -- Value bindings in this module
183 tcg_deprecs :: Deprecations, -- ...Deprecations
184 tcg_insts :: [DFunId], -- ...Instances
185 tcg_rules :: [RuleDecl Id], -- ...Rules
186 tcg_fords :: [ForeignDecl Id] -- ...Foreign import & exports
190 %************************************************************************
192 The interface environments
193 Used when dealing with IfaceDecls
195 %************************************************************************
200 -- The type environment for the module being compiled,
201 -- in case the interface refers back to it via a reference that
202 -- was originally a hi-boot file.
203 -- We need the module name so we can test when it's appropriate
204 -- to look in this env.
205 if_rec_types :: Maybe (Module, IfG TypeEnv),
206 -- Allows a read effect, so it can be in a mutable
207 -- variable; c.f. handling the external package type env
208 -- Nothing => interactive stuff, no loops possible
210 if_is_boot :: ModuleEnv (ModuleName, IsBootInterface)
211 -- Tells what we know about boot interface files
212 -- When we're importing a module we know absolutely
213 -- nothing about, so we assume it's from
214 -- another package, where we aren't doing
215 -- dependency tracking. So it won't be a hi-boot file.
220 -- The module for the current IfaceDecl
221 -- So if we see f = \x -> x
222 -- it means M.f = \x -> x, where M is the if_mod
223 if_mod :: ModuleName,
225 if_tv_env :: OccEnv TyVar, -- Nested tyvar bindings
226 if_id_env :: OccEnv Id -- Nested id binding
231 %************************************************************************
233 The local typechecker environment
235 %************************************************************************
237 The Global-Env/Local-Env story
238 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
239 During type checking, we keep in the tcg_type_env
240 * All types and classes
241 * All Ids derived from types and classes (constructors, selectors)
243 At the end of type checking, we zonk the local bindings,
244 and as we do so we add to the tcg_type_env
245 * Locally defined top-level Ids
247 Why? Because they are now Ids not TcIds. This final GlobalEnv is
248 a) fed back (via the knot) to typechecking the
249 unfoldings of interface signatures
250 b) used in the ModDetails of this module
253 data TcLclEnv -- Changes as we move inside an expression
254 -- Discarded after typecheck/rename; not passed on to desugarer
256 tcl_loc :: SrcLoc, -- Source location
257 tcl_ctxt :: ErrCtxt, -- Error context
258 tcl_errs :: TcRef Messages, -- Place to accumulate errors
260 tcl_th_ctxt :: ThStage, -- Template Haskell context
261 tcl_arrow_ctxt :: ArrowCtxt, -- Arrow-notation context
263 tcl_rdr :: LocalRdrEnv, -- Local name envt
264 -- Maintained during renaming, of course, but also during
265 -- type checking, solely so that when renaming a Template-Haskell
266 -- splice we have the right environment for the renamer.
268 -- Does *not* include global name envt; may shadow it
269 -- Includes both ordinary variables and type variables;
270 -- they are kept distinct because tyvar have a different
271 -- occurrence contructor (Name.TvOcc)
272 -- We still need the unsullied global name env so that
273 -- we can look up record field names
275 tcl_env :: NameEnv TcTyThing, -- The local type environment: Ids and TyVars
276 -- defined in this module
278 tcl_tyvars :: TcRef TcTyVarSet, -- The "global tyvars"
279 -- Namely, the in-scope TyVars bound in tcl_lenv,
280 -- plus the tyvars mentioned in the types of Ids bound in tcl_lenv
281 -- Why mutable? see notes with tcGetGlobalTyVars
283 tcl_lie :: TcRef LIE -- Place to accumulate type constraints
286 ---------------------------
287 -- Template Haskell levels
288 ---------------------------
290 type ThLevel = Int -- Always >= 0
293 = Comp -- Ordinary compiling, at level topLevel
294 | Splice ThLevel -- Inside a splice
295 | Brack ThLevel -- Inside brackets;
296 (TcRef [PendingSplice]) -- accumulate pending splices here
297 (TcRef LIE) -- and type constraints here
298 topStage, topSpliceStage :: ThStage
300 topSpliceStage = Splice (topLevel - 1) -- Stage for the body of a top-level splice
303 impLevel, topLevel :: ThLevel
304 topLevel = 1 -- Things defined at top level of this module
305 impLevel = 0 -- Imported things; they can be used inside a top level splice
309 -- g1 = $(map ...) is OK
310 -- g2 = $(f ...) is not OK; because we havn't compiled f yet
313 ---------------------------
314 -- Arrow-notation stages
315 ---------------------------
317 -- In arrow notation, a variable bound by a proc (or enclosed let/kappa)
318 -- is not in scope to the left of an arrow tail (-<). For example
320 -- proc x -> (e1 -< e2)
322 -- Here, x is not in scope in e1, but it is in scope in e2. This can get
323 -- a bit complicated:
326 -- prox y -> (proc z -> e1) -< e2
328 -- Here, x and z are in scope in e1, but y is not. Here's how we track this:
329 -- a) Assign an "proc level" to each proc, being the number of
330 -- lexically-enclosing procs + 1.
331 -- b) Assign to each local variable the proc-level of its lexically
333 -- c) Keep a list of out-of-scope procs. When moving to the left of
334 -- an arrow-tail, add the proc-level of the immediately enclosing
336 -- d) When looking up a variable, complain if its proc-level is in
339 type ProcLevel = Int -- Always >= 0
340 topProcLevel = 0 -- Not inside any proc
342 data ArrowCtxt = ArrCtxt { proc_level :: ProcLevel, -- Current level
343 proc_banned :: [ProcLevel] } -- Out of scope proc-levels
345 topArrowCtxt = ArrCtxt { proc_level = topProcLevel, proc_banned = [] }
347 ---------------------------
349 ---------------------------
352 = AGlobal TyThing -- Used only in the return type of a lookup
353 | ATcId TcId ThLevel ProcLevel -- Ids defined in this module; may not be fully zonked
354 | ATyVar TyVar -- Type variables
355 | ARecTyCon TcKind -- Used temporarily, during kind checking, for the
356 | ARecClass TcKind -- tycons and clases in this recursive group
358 instance Outputable TcTyThing where -- Debugging only
359 ppr (AGlobal g) = text "AGlobal" <+> ppr g
360 ppr (ATcId g tl pl) = text "ATcId" <+> ppr g <+> ppr tl <+> ppr pl
361 ppr (ATyVar t) = text "ATyVar" <+> ppr t
362 ppr (ARecTyCon k) = text "ARecTyCon" <+> ppr k
363 ppr (ARecClass k) = text "ARecClass" <+> ppr k
367 type ErrCtxt = [TidyEnv -> TcM (TidyEnv, Message)]
368 -- Innermost first. Monadic so that we have a chance
369 -- to deal with bound type variables just before error
370 -- message construction
374 %************************************************************************
378 %************************************************************************
380 EntityUsage tells what things are actually need in order to compile this
381 module. It is used for generating the usage-version field of the ModIface.
383 Note that we do not record version info for entities from
384 other (non-home) packages. If the package changes, GHC doesn't help.
387 type EntityUsage = NameSet
388 -- The Names are all the (a) home-package
389 -- (b) "big" (i.e. no data cons, class ops)
390 -- (c) non-locally-defined
392 -- names that have been slurped in so far.
393 -- This is used to generate the "usage" information for this module.
395 emptyUsages :: EntityUsage
396 emptyUsages = emptyNameSet
400 %************************************************************************
402 Operations over ImportAvails
404 %************************************************************************
406 ImportAvails summarises what was imported from where, irrespective
407 of whether the imported things are actually used or not
408 It is used * when processing the export list
409 * when constructing usage info for the inteface file
410 * to identify the list of directly imported modules
411 for initialisation purposes
412 * when figuring out what things are really unused
418 -- All the things that are available from the import
419 -- Its domain is all the "main" things;
420 -- i.e. *excluding* class ops and constructors
421 -- (which appear inside their parent AvailTC)
423 imp_qual :: ModuleEnv AvailEnv,
424 -- Used to figure out "module M" export specifiers
425 -- (see 1.4 Report Section 5.1.1). Ultimately, we want to find
426 -- everything that is unambiguously in scope as 'M.x'
427 -- and where plain 'x' is (perhaps ambiguously) in scope.
428 -- So the starting point is all things that are in scope as 'M.x',
429 -- which is what this field tells us.
431 -- Domain is the *module qualifier* for imports.
432 -- e.g. import List as Foo
433 -- would add a binding Foo |-> ...stuff from List...
435 -- We keep the stuff as an AvailEnv so that it's easy to
436 -- combine stuff coming from different (unqualified)
437 -- imports of the same module
439 imp_mods :: ModuleEnv (Module, Maybe Bool),
440 -- Domain is all directly-imported modules
441 -- Maybe value answers the question "is the import restricted?"
442 -- Nothing => unrestricted import (e.g., "import Foo")
443 -- Just True => restricted import, at least one entity (e.g., "import Foo(x)")
444 -- Just False => fully restricted import (e.g., "import Foo ()")
446 -- A distinction is made between the first and the third in order
447 -- to more precisely emit warnings about unused imports.
449 -- We need the Module in the range because we can't get
450 -- the keys of a ModuleEnv
452 -- (a) to help construct the usage information in
453 -- the interface file; if we import everything we
454 -- need to recompile if the module version changes
455 -- (b) to specify what child modules to initialise
457 imp_dep_mods :: ModuleEnv (ModuleName, IsBootInterface),
458 -- Home-package modules needed by the module being compiled
460 -- It doesn't matter whether any of these dependencies are actually
461 -- *used* when compiling the module; they are listed if they are below
462 -- it at all. For example, suppose M imports A which imports X. Then
463 -- compiling M might not need to consult X.hi, but X is still listed
464 -- in M's dependencies.
466 imp_dep_pkgs :: [PackageName],
467 -- Packages needed by the module being compiled, whether
468 -- directly, or via other modules in this package, or via
469 -- modules imported from other packages.
471 imp_orphs :: [ModuleName]
472 -- Orphan modules below us in the import tree
475 mkModDeps :: [(ModuleName, IsBootInterface)]
476 -> ModuleEnv (ModuleName, IsBootInterface)
477 mkModDeps deps = foldl add emptyModuleEnv deps
479 add env elt@(m,_) = extendModuleEnvByName env m elt
481 emptyImportAvails :: ImportAvails
482 emptyImportAvails = ImportAvails { imp_env = emptyAvailEnv,
483 imp_qual = emptyModuleEnv,
484 imp_mods = emptyModuleEnv,
485 imp_dep_mods = emptyModuleEnv,
489 plusImportAvails :: ImportAvails -> ImportAvails -> ImportAvails
491 (ImportAvails { imp_env = env1, imp_qual = unqual1, imp_mods = mods1,
492 imp_dep_mods = dmods1, imp_dep_pkgs = dpkgs1, imp_orphs = orphs1 })
493 (ImportAvails { imp_env = env2, imp_qual = unqual2, imp_mods = mods2,
494 imp_dep_mods = dmods2, imp_dep_pkgs = dpkgs2, imp_orphs = orphs2 })
495 = ImportAvails { imp_env = env1 `plusAvailEnv` env2,
496 imp_qual = plusModuleEnv_C plusAvailEnv unqual1 unqual2,
497 imp_mods = mods1 `plusModuleEnv` mods2,
498 imp_dep_mods = plusModuleEnv_C plus_mod_dep dmods1 dmods2,
499 imp_dep_pkgs = dpkgs1 `unionLists` dpkgs2,
500 imp_orphs = orphs1 `unionLists` orphs2 }
502 plus_mod_dep (m1, boot1) (m2, boot2)
503 = WARN( not (m1 == m2), (ppr m1 <+> ppr m2) $$ (ppr boot1 <+> ppr boot2) )
504 -- Check mod-names match
505 (m1, boot1 && boot2) -- If either side can "see" a non-hi-boot interface, use that
508 %************************************************************************
510 Avails, AvailEnv, etc
512 v%************************************************************************
515 plusAvail (Avail n1) (Avail n2) = Avail n1
516 plusAvail (AvailTC n1 ns1) (AvailTC n2 ns2) = AvailTC n2 (ns1 `unionLists` ns2)
519 plusAvail a1 a2 = pprPanic "RnEnv.plusAvail" (hsep [ppr a1,ppr a2])
522 -------------------------
523 pruneAvails :: (Name -> Bool) -- Keep if this is True
526 pruneAvails keep avails
527 = mapMaybe del avails
529 del :: AvailInfo -> Maybe AvailInfo -- Nothing => nothing left!
530 del (Avail n) | keep n = Just (Avail n)
531 | otherwise = Nothing
532 del (AvailTC n ns) | null ns' = Nothing
533 | otherwise = Just (AvailTC n ns')
538 ---------------------------------------
540 ---------------------------------------
543 type AvailEnv = NameEnv AvailInfo -- Maps a Name to the AvailInfo that contains it
545 emptyAvailEnv :: AvailEnv
546 emptyAvailEnv = emptyNameEnv
548 unitAvailEnv :: AvailInfo -> AvailEnv
549 unitAvailEnv a = unitNameEnv (availName a) a
551 plusAvailEnv :: AvailEnv -> AvailEnv -> AvailEnv
552 plusAvailEnv = plusNameEnv_C plusAvail
554 lookupAvailEnv_maybe :: AvailEnv -> Name -> Maybe AvailInfo
555 lookupAvailEnv_maybe = lookupNameEnv
557 lookupAvailEnv :: AvailEnv -> Name -> AvailInfo
558 lookupAvailEnv env n = case lookupNameEnv env n of
560 Nothing -> pprPanic "lookupAvailEnv" (ppr n)
562 availEnvElts = nameEnvElts
564 addAvail :: AvailEnv -> AvailInfo -> AvailEnv
565 addAvail avails avail = extendNameEnv_C plusAvail avails (availName avail) avail
567 mkAvailEnv :: [AvailInfo] -> AvailEnv
568 -- 'avails' may have several items with the same availName
569 -- E.g import Ix( Ix(..), index )
570 -- will give Ix(Ix,index,range) and Ix(index)
571 -- We want to combine these; addAvail does that
572 mkAvailEnv avails = foldl addAvail emptyAvailEnv avails
575 %************************************************************************
577 \subsection{Where from}
579 %************************************************************************
581 The @WhereFrom@ type controls where the renamer looks for an interface file
585 = ImportByUser IsBootInterface -- Ordinary user import (perhaps {-# SOURCE #-})
586 | ImportBySystem -- Non user import.
588 instance Outputable WhereFrom where
589 ppr (ImportByUser is_boot) | is_boot = ptext SLIT("{- SOURCE -}")
591 ppr ImportBySystem = ptext SLIT("{- SYSTEM -}")
595 %************************************************************************
597 \subsection[Inst-types]{@Inst@ types}
599 v%************************************************************************
601 An @Inst@ is either a dictionary, an instance of an overloaded
602 literal, or an instance of an overloaded value. We call the latter a
603 ``method'' even though it may not correspond to a class operation.
604 For example, we might have an instance of the @double@ function at
605 type Int, represented by
607 Method 34 doubleId [Int] origin
619 TcId -- The overloaded function
620 -- This function will be a global, local, or ClassOpId;
621 -- inside instance decls (only) it can also be an InstId!
622 -- The id needn't be completely polymorphic.
623 -- You'll probably find its name (for documentation purposes)
624 -- inside the InstOrigin
626 [TcType] -- The types to which its polymorphic tyvars
627 -- should be instantiated.
628 -- These types must saturate the Id's foralls.
630 TcThetaType -- The (types of the) dictionaries to which the function
631 -- must be applied to get the method
633 TcTauType -- The tau-type of the method
637 -- INVARIANT 1: in (Method u f tys theta tau loc)
638 -- type of (f tys dicts(from theta)) = tau
640 -- INVARIANT 2: tau must not be of form (Pred -> Tau)
641 -- Reason: two methods are considerd equal if the
642 -- base Id matches, and the instantiating types
643 -- match. The TcThetaType should then match too.
644 -- This only bites in the call to tcInstClassOp in TcClassDcl.mkMethodBind
648 HsOverLit -- The literal from the occurrence site
649 -- INVARIANT: never a rebindable-syntax literal
650 -- Reason: tcSyntaxName does unification, and we
651 -- don't want to deal with that during tcSimplify
652 TcType -- The type at which the literal is used
656 @Insts@ are ordered by their class/type info, rather than by their
657 unique. This allows the context-reduction mechanism to use standard finite
658 maps to do their stuff.
661 instance Ord Inst where
664 instance Eq Inst where
665 (==) i1 i2 = case i1 `cmpInst` i2 of
669 cmpInst (Dict _ pred1 _) (Dict _ pred2 _) = pred1 `tcCmpPred` pred2
670 cmpInst (Dict _ _ _) other = LT
672 cmpInst (Method _ _ _ _ _ _) (Dict _ _ _) = GT
673 cmpInst (Method _ id1 tys1 _ _ _) (Method _ id2 tys2 _ _ _) = (id1 `compare` id2) `thenCmp` (tys1 `tcCmpTypes` tys2)
674 cmpInst (Method _ _ _ _ _ _) other = LT
676 cmpInst (LitInst _ _ _ _) (Dict _ _ _) = GT
677 cmpInst (LitInst _ _ _ _) (Method _ _ _ _ _ _) = GT
678 cmpInst (LitInst _ lit1 ty1 _) (LitInst _ lit2 ty2 _) = (lit1 `compare` lit2) `thenCmp` (ty1 `tcCmpType` ty2)
682 %************************************************************************
684 \subsection[Inst-collections]{LIE: a collection of Insts}
686 %************************************************************************
691 isEmptyLIE = isEmptyBag
693 unitLIE inst = unitBag inst
694 mkLIE insts = listToBag insts
695 plusLIE lie1 lie2 = lie1 `unionBags` lie2
696 consLIE inst lie = inst `consBag` lie
697 plusLIEs lies = unionManyBags lies
698 lieToList = bagToList
699 listToLIE = listToBag
703 %************************************************************************
705 \subsection[Inst-origin]{The @InstOrigin@ type}
707 %************************************************************************
709 The @InstOrigin@ type gives information about where a dictionary came from.
710 This is important for decent error message reporting because dictionaries
711 don't appear in the original source code. Doubtless this type will evolve...
713 It appears in TcMonad because there are a couple of error-message-generation
714 functions that deal with it.
717 data InstLoc = InstLoc InstOrigin SrcLoc ErrCtxt
719 instLocSrcLoc :: InstLoc -> SrcLoc
720 instLocSrcLoc (InstLoc _ src_loc _) = src_loc
723 = OccurrenceOf Name -- Occurrence of an overloaded identifier
725 | IPOcc (IPName Name) -- Occurrence of an implicit parameter
726 | IPBind (IPName Name) -- Binding site of an implicit parameter
730 | DataDeclOrigin -- Typechecking a data declaration
732 | InstanceDeclOrigin -- Typechecking an instance decl
734 | LiteralOrigin HsOverLit -- Occurrence of a literal
736 | PatOrigin RenamedPat
738 | ArithSeqOrigin RenamedArithSeqInfo -- [x..], [x..y] etc
739 | PArrSeqOrigin RenamedArithSeqInfo -- [:x..y:] and [:x,y..z:]
741 | SignatureOrigin -- A dict created from a type signature
742 | Rank2Origin -- A dict created when typechecking the argument
743 -- of a rank-2 typed function
745 | DoOrigin -- The monad for a do expression
746 | ProcOrigin -- A proc expression
748 | ClassDeclOrigin -- Manufactured during a class decl
750 | InstanceSpecOrigin Class -- in a SPECIALIZE instance pragma
753 -- When specialising instances the instance info attached to
754 -- each class is not yet ready, so we record it inside the
755 -- origin information. This is a bit of a hack, but it works
756 -- fine. (Patrick is to blame [WDP].)
758 | ValSpecOrigin Name -- in a SPECIALIZE pragma for a value
760 -- Argument or result of a ccall
761 -- Dictionaries with this origin aren't actually mentioned in the
762 -- translated term, and so need not be bound. Nor should they
763 -- be abstracted over.
765 | UnknownOrigin -- Help! I give up...
769 pprInstLoc :: InstLoc -> SDoc
770 pprInstLoc (InstLoc orig locn ctxt)
771 = hsep [text "arising from", pp_orig orig, text "at", ppr locn]
773 pp_orig (OccurrenceOf name)
774 = hsep [ptext SLIT("use of"), quotes (ppr name)]
776 = hsep [ptext SLIT("use of implicit parameter"), quotes (ppr name)]
777 pp_orig (IPBind name)
778 = hsep [ptext SLIT("binding for implicit parameter"), quotes (ppr name)]
779 pp_orig RecordUpdOrigin
780 = ptext SLIT("a record update")
781 pp_orig DataDeclOrigin
782 = ptext SLIT("the data type declaration")
783 pp_orig InstanceDeclOrigin
784 = ptext SLIT("the instance declaration")
785 pp_orig (LiteralOrigin lit)
786 = hsep [ptext SLIT("the literal"), quotes (ppr lit)]
787 pp_orig (PatOrigin pat)
788 = hsep [ptext SLIT("the pattern"), quotes (ppr pat)]
789 pp_orig (ArithSeqOrigin seq)
790 = hsep [ptext SLIT("the arithmetic sequence"), quotes (ppr seq)]
791 pp_orig (PArrSeqOrigin seq)
792 = hsep [ptext SLIT("the parallel array sequence"), quotes (ppr seq)]
793 pp_orig (SignatureOrigin)
794 = ptext SLIT("a type signature")
795 pp_orig (Rank2Origin)
796 = ptext SLIT("a function with an overloaded argument type")
798 = ptext SLIT("a do statement")
800 = ptext SLIT("a proc expression")
801 pp_orig (ClassDeclOrigin)
802 = ptext SLIT("a class declaration")
803 pp_orig (InstanceSpecOrigin clas ty)
804 = hsep [text "a SPECIALIZE instance pragma; class",
805 quotes (ppr clas), text "type:", ppr ty]
806 pp_orig (ValSpecOrigin name)
807 = hsep [ptext SLIT("a SPECIALIZE user-pragma for"), quotes (ppr name)]
808 pp_orig (UnknownOrigin)
809 = ptext SLIT("...oops -- I don't know where the overloading came from!")