3 TyThing(..), TyThingDetails(..), TcTyThing(..), TcId,
5 -- Instance environment, and InstInfo type
7 InstInfo(..), pprInstInfo, pprInstInfoDetails,
8 simpleInstInfoTy, simpleInstInfoTyCon,
14 tcExtendGlobalTypeEnv,
15 tcLookupTyCon, tcLookupClass, tcLookupDataCon,
16 tcLookupGlobal_maybe, tcLookupGlobal, tcLookupGlobalId,
21 tcExtendTyVarEnv, tcExtendTyVarEnv2,
22 tcExtendLocalValEnv, tcExtendLocalValEnv2,
23 tcLookup, tcLookupLocalIds, tcLookup_maybe,
25 lclEnvElts, getInLocalScope, findGlobals,
27 -- Instance environment
28 tcExtendLocalInstEnv, tcExtendInstEnv, tcExtendTempInstEnv, tcWithTempInstEnv,
33 -- Global type variables
36 -- Template Haskell stuff
37 checkWellStaged, spliceOK, bracketOK, tcMetaTy, thLevel,
44 newLocalName, newDFunName,
50 #include "HsVersions.h"
52 import RnHsSyn ( RenamedMonoBinds, RenamedSig )
53 import HsSyn ( RuleDecl(..), ifaceRuleDeclName )
55 import TcMType ( zonkTcType, zonkTcTyVar, zonkTcTyVarsAndFV )
56 import TcType ( Type, ThetaType, TcKind, TcTyVar, TcTyVarSet,
57 tyVarsOfType, tyVarsOfTypes, tcSplitDFunTy, mkGenTyConApp,
58 getDFunTyKey, tcTyConAppTyCon, tyVarBindingInfo,
59 tidyOpenType, tidyOpenTyVar
61 import qualified Type ( getTyVar_maybe )
62 import Rules ( extendRuleBase )
63 import Id ( idName, isLocalId )
64 import Var ( TyVar, Id, idType )
67 import CoreSyn ( IdCoreRule )
68 import DataCon ( DataCon )
69 import TyCon ( TyCon, DataConDetails )
70 import Class ( Class, ClassOpItem )
71 import Name ( Name, NamedThing(..),
72 getSrcLoc, mkInternalName, nameIsLocalOrFrom
75 import OccName ( mkDFunOcc, occNameString )
76 import HscTypes ( DFunId, TypeEnv, extendTypeEnvList, lookupType,
77 TyThing(..), ExternalPackageState(..) )
78 import Rules ( RuleBase )
79 import BasicTypes ( EP )
80 import Module ( Module )
81 import InstEnv ( InstEnv, extendInstEnv )
82 import SrcLoc ( SrcLoc )
84 import Maybe ( isJust )
85 import List ( partition )
89 %************************************************************************
91 Arrow notation proc levels
93 %************************************************************************
96 checkProcLevel :: TcId -> ProcLevel -> TcM ()
97 checkProcLevel id id_lvl
98 = do { banned <- getBannedProcLevels
99 ; checkTc (not (id_lvl `elem` banned))
100 (procLevelErr id id_lvl) }
102 procLevelErr id id_lvl
103 = hang (ptext SLIT("Command-bound variable") <+> quotes (ppr id) <+> ptext SLIT("is not in scope here"))
104 4 (ptext SLIT("Reason: it is used in the left argument of (-<)"))
108 %************************************************************************
112 %************************************************************************
115 instance Outputable ThStage where
116 ppr Comp = text "Comp"
117 ppr (Brack l _ _) = text "Brack" <+> int l
118 ppr (Splice l) = text "Splice" <+> int l
121 thLevel :: ThStage -> ThLevel
122 thLevel Comp = topLevel
123 thLevel (Splice l) = l
124 thLevel (Brack l _ _) = l
127 checkWellStaged :: SDoc -- What the stage check is for
128 -> ThLevel -- Binding level
129 -> ThStage -- Use stage
130 -> TcM () -- Fail if badly staged, adding an error
131 checkWellStaged pp_thing bind_lvl use_stage
132 | bind_lvl <= use_lvl -- OK!
135 | bind_lvl == topLevel -- GHC restriction on top level splices
137 sep [ptext SLIT("GHC stage restriction:") <+> pp_thing,
138 nest 2 (ptext SLIT("is used in a top-level splice, and must be imported, not defined locally"))]
140 | otherwise -- Badly staged
142 ptext SLIT("Stage error:") <+> pp_thing <+>
143 hsep [ptext SLIT("is bound at stage") <+> ppr bind_lvl,
144 ptext SLIT("but used at stage") <+> ppr use_lvl]
146 use_lvl = thLevel use_stage
149 topIdLvl :: Id -> ThLevel
150 -- Globals may either be imported, or may be from an earlier "chunk"
151 -- (separated by declaration splices) of this module. The former
152 -- *can* be used inside a top-level splice, but the latter cannot.
153 -- Hence we give the former impLevel, but the latter topLevel
157 -- By the time we are prcessing the $(f x), the binding for "x"
158 -- will be in the global env, not the local one.
159 topIdLvl id | isLocalId id = topLevel
160 | otherwise = impLevel
162 -- Indicates the legal transitions on bracket( [| |] ).
163 bracketOK :: ThStage -> Maybe ThLevel
164 bracketOK (Brack _ _ _) = Nothing -- Bracket illegal inside a bracket
165 bracketOK stage = (Just (thLevel stage + 1))
167 -- Indicates the legal transitions on splice($).
168 spliceOK :: ThStage -> Maybe ThLevel
169 spliceOK (Splice _) = Nothing -- Splice illegal inside splice
170 spliceOK stage = Just (thLevel stage - 1)
172 tcMetaTy :: Name -> TcM Type
173 -- Given the name of a Template Haskell data type,
175 -- E.g. given the name "Expr" return the type "Expr"
177 = tcLookupTyCon tc_name `thenM` \ t ->
178 returnM (mkGenTyConApp t [])
179 -- Use mkGenTyConApp because it might be a synonym
183 %************************************************************************
185 \subsection{TyThingDetails}
187 %************************************************************************
189 This data type is used to help tie the knot
190 when type checking type and class declarations
193 data TyThingDetails = SynTyDetails Type
194 | DataTyDetails ThetaType (DataConDetails DataCon) [Id] (Maybe (EP Id))
195 | ClassDetails ThetaType [Id] [ClassOpItem] DataCon Name
196 -- The Name is the Name of the implicit TyCon for the class
197 | ForeignTyDetails -- Nothing yet
201 %************************************************************************
203 \subsection{Making new Ids}
205 %************************************************************************
210 newLocalName :: Name -> TcM Name
211 newLocalName name -- Make a clone
212 = newUnique `thenM` \ uniq ->
213 returnM (mkInternalName uniq (getOccName name) (getSrcLoc name))
216 Make a name for the dict fun for an instance decl. It's a *local*
217 name for the moment. The CoreTidy pass will externalise it. Even in
218 --make and ghci stuff, we rebuild the instance environment each time,
219 so the dfun id is internal to begin with, and external when compiling
223 newDFunName :: Class -> [Type] -> SrcLoc -> TcM Name
224 newDFunName clas (ty:_) loc
225 = newUnique `thenM` \ uniq ->
226 returnM (mkInternalName uniq (mkDFunOcc dfun_string) loc)
228 -- Any string that is somewhat unique will do
229 dfun_string = occNameString (getOccName clas) ++ occNameString (getDFunTyKey ty)
231 newDFunName clas [] loc = pprPanic "newDFunName" (ppr clas <+> ppr loc)
235 isLocalThing :: NamedThing a => Module -> a -> Bool
236 isLocalThing mod thing = nameIsLocalOrFrom mod (getName thing)
239 %************************************************************************
241 \subsection{The global environment}
243 %************************************************************************
246 tcExtendGlobalEnv :: [TyThing] -> TcM r -> TcM r
247 -- Given a mixture of Ids, TyCons, Classes, perhaps from the
248 -- module being compiled, perhaps from a package module,
249 -- extend the global environment, and update the EPS
250 tcExtendGlobalEnv things thing_inside
254 ; let mod = tcg_mod env
255 (lcl_things, pkg_things) = partition (isLocalThing mod) things
256 ge' = extendTypeEnvList (tcg_type_env env) lcl_things
257 eps' = eps { eps_PTE = extendTypeEnvList (eps_PTE eps) pkg_things }
259 ; setGblEnv (env {tcg_type_env = ge'}) thing_inside }
261 tcExtendGlobalValEnv :: [Id] -> TcM a -> TcM a
262 -- Same deal as tcExtendGlobalEnv, but for Ids
263 tcExtendGlobalValEnv ids thing_inside
264 = tcExtendGlobalEnv [AnId id | id <- ids] thing_inside
266 tcExtendGlobalTypeEnv :: TypeEnv -> TcM r -> TcM r
267 -- Top-level things of the interactive context
268 -- No need to extend the package env
269 tcExtendGlobalTypeEnv extra_env thing_inside
270 = do { env <- getGblEnv
271 ; let ge' = tcg_type_env env `plusNameEnv` extra_env
272 ; setGblEnv (env {tcg_type_env = ge'}) thing_inside }
277 tcLookupGlobal_maybe :: Name -> TcRn m (Maybe TyThing)
278 -- This is a rather heavily-used function, so I've inlined a few things (e.g. getEps)
279 -- Notice that for imported things we read the current version from the EPS
280 -- mutable variable. This is important in situations like
281 -- ...$(e1)...$(e2)...
282 -- where the code that e1 expands to might import some defns that
283 -- also turn out to be needed by the code that e2 expands to.
284 tcLookupGlobal_maybe name
285 = do { env <- getGblEnv
286 ; if nameIsLocalOrFrom (tcg_mod env) name then
287 -- Defined in this module
288 return (lookupNameEnv (tcg_type_env env) name)
290 do { env <- getTopEnv
291 ; eps <- readMutVar (top_eps env)
292 ; return (lookupType (top_hpt env) (eps_PTE eps) name) }}
295 A variety of global lookups, when we know what we are looking for.
298 tcLookupGlobal :: Name -> TcM TyThing
300 = tcLookupGlobal_maybe name `thenM` \ maybe_thing ->
302 Just thing -> returnM thing
303 other -> notFound "tcLookupGlobal" name
305 tcLookupGlobalId :: Name -> TcM Id
306 -- Never used for Haskell-source DataCons, hence no ADataCon case
307 tcLookupGlobalId name
308 = tcLookupGlobal_maybe name `thenM` \ maybe_thing ->
310 Just (AnId id) -> returnM id
311 other -> notFound "tcLookupGlobal (id)" name
313 tcLookupDataCon :: Name -> TcM DataCon
314 tcLookupDataCon con_name
315 = tcLookupGlobal_maybe con_name `thenM` \ maybe_thing ->
317 Just (ADataCon data_con) -> returnM data_con
318 other -> notFound "tcLookupDataCon" con_name
320 tcLookupClass :: Name -> TcM Class
322 = tcLookupGlobal_maybe name `thenM` \ maybe_clas ->
324 Just (AClass clas) -> returnM clas
325 other -> notFound "tcLookupClass" name
327 tcLookupTyCon :: Name -> TcM TyCon
329 = tcLookupGlobal_maybe name `thenM` \ maybe_tc ->
331 Just (ATyCon tc) -> returnM tc
332 other -> notFound "tcLookupTyCon" name
335 getInGlobalScope :: TcRn m (Name -> Bool)
336 -- Get all things in the global environment; used for deciding what
337 -- rules to suck in. Anything defined in this module (nameIsLocalOrFrom)
338 -- is certainly in the envt, so we don't bother to look.
340 = do { mod <- getModule
343 ; return (\n -> nameIsLocalOrFrom mod n ||
344 isJust (lookupType hpt (eps_PTE eps) n)) }
348 %************************************************************************
350 \subsection{The local environment}
352 %************************************************************************
355 tcLookup_maybe :: Name -> TcM (Maybe TcTyThing)
357 = getLclEnv `thenM` \ local_env ->
358 case lookupNameEnv (tcl_env local_env) name of
359 Just thing -> returnM (Just thing)
360 Nothing -> tcLookupGlobal_maybe name `thenM` \ mb_res ->
361 returnM (case mb_res of
362 Just thing -> Just (AGlobal thing)
365 tcLookup :: Name -> TcM TcTyThing
367 = tcLookup_maybe name `thenM` \ maybe_thing ->
369 Just thing -> returnM thing
370 other -> notFound "tcLookup" name
371 -- Extract the IdInfo from an IfaceSig imported from an interface file
373 tcLookupId :: Name -> TcM Id
374 -- Used when we aren't interested in the binding level
375 -- Never a DataCon. (Why does that matter? see TcExpr.tcId)
377 = tcLookup name `thenM` \ thing ->
379 ATcId tc_id _ _ -> returnM tc_id
380 AGlobal (AnId id) -> returnM id
381 other -> pprPanic "tcLookupId" (ppr name)
383 tcLookupLocalIds :: [Name] -> TcM [TcId]
384 -- We expect the variables to all be bound, and all at
385 -- the same level as the lookup. Only used in one place...
387 = getLclEnv `thenM` \ env ->
388 returnM (map (lookup (tcl_env env) (thLevel (tcl_th_ctxt env))) ns)
391 = case lookupNameEnv lenv name of
392 Just (ATcId id lvl1 _) -> ASSERT( lvl == lvl1 ) id
393 other -> pprPanic "tcLookupLocalIds" (ppr name)
395 lclEnvElts :: TcLclEnv -> [TcTyThing]
396 lclEnvElts env = nameEnvElts (tcl_env env)
398 getInLocalScope :: TcM (Name -> Bool)
400 getInLocalScope = getLclEnv `thenM` \ env ->
402 lcl_env = tcl_env env
404 return (`elemNameEnv` lcl_env)
408 tcExtendKindEnv :: [(Name,TcKind)] -> TcM r -> TcM r
409 tcExtendKindEnv pairs thing_inside
410 = updLclEnv upd thing_inside
412 upd lcl_env = lcl_env { tcl_env = extend (tcl_env lcl_env) }
413 extend env = extendNameEnvList env [(n, AThing k) | (n,k) <- pairs]
414 -- No need to extend global tyvars for kind checking
416 tcExtendTyVarEnv :: [TyVar] -> TcM r -> TcM r
417 tcExtendTyVarEnv tvs thing_inside
418 = tc_extend_tv_env [(getName tv, ATyVar tv) | tv <- tvs] tvs thing_inside
420 tcExtendTyVarEnv2 :: [(TyVar,TcTyVar)] -> TcM r -> TcM r
421 tcExtendTyVarEnv2 tv_pairs thing_inside
422 = tc_extend_tv_env [(getName tv1, ATyVar tv2) | (tv1,tv2) <- tv_pairs]
423 [tv | (_,tv) <- tv_pairs]
426 tc_extend_tv_env binds tyvars thing_inside
427 = getLclEnv `thenM` \ env@(TcLclEnv {tcl_env = le, tcl_tyvars = gtvs}) ->
429 le' = extendNameEnvList le binds
430 new_tv_set = mkVarSet tyvars
432 -- It's important to add the in-scope tyvars to the global tyvar set
434 -- f (x::r) = let g y = y::r in ...
435 -- Here, g mustn't be generalised. This is also important during
436 -- class and instance decls, when we mustn't generalise the class tyvars
437 -- when typechecking the methods.
438 tc_extend_gtvs gtvs new_tv_set `thenM` \ gtvs' ->
439 setLclEnv (env {tcl_env = le', tcl_tyvars = gtvs'}) thing_inside
444 tcExtendLocalValEnv :: [TcId] -> TcM a -> TcM a
445 tcExtendLocalValEnv ids thing_inside
446 = getLclEnv `thenM` \ env ->
448 extra_global_tyvars = tyVarsOfTypes [idType id | id <- ids]
449 th_lvl = thLevel (tcl_th_ctxt env)
450 proc_lvl = proc_level (tcl_arrow_ctxt env)
451 extra_env = [(idName id, ATcId id th_lvl proc_lvl) | id <- ids]
452 le' = extendNameEnvList (tcl_env env) extra_env
454 tc_extend_gtvs (tcl_tyvars env) extra_global_tyvars `thenM` \ gtvs' ->
455 setLclEnv (env {tcl_env = le', tcl_tyvars = gtvs'}) thing_inside
457 tcExtendLocalValEnv2 :: [(Name,TcId)] -> TcM a -> TcM a
458 tcExtendLocalValEnv2 names_w_ids thing_inside
459 = getLclEnv `thenM` \ env ->
461 extra_global_tyvars = tyVarsOfTypes [idType id | (name,id) <- names_w_ids]
462 th_lvl = thLevel (tcl_th_ctxt env)
463 proc_lvl = proc_level (tcl_arrow_ctxt env)
464 extra_env = [(name, ATcId id th_lvl proc_lvl) | (name,id) <- names_w_ids]
465 le' = extendNameEnvList (tcl_env env) extra_env
467 tc_extend_gtvs (tcl_tyvars env) extra_global_tyvars `thenM` \ gtvs' ->
468 setLclEnv (env {tcl_env = le', tcl_tyvars = gtvs'}) thing_inside
473 -----------------------
474 -- findGlobals looks at the value environment and finds values
475 -- whose types mention the offending type variable. It has to be
476 -- careful to zonk the Id's type first, so it has to be in the monad.
477 -- We must be careful to pass it a zonked type variable, too.
479 findGlobals :: TcTyVarSet
481 -> TcM (TidyEnv, [SDoc])
483 findGlobals tvs tidy_env
484 = getLclEnv `thenM` \ lcl_env ->
485 go tidy_env [] (lclEnvElts lcl_env)
487 go tidy_env acc [] = returnM (tidy_env, acc)
488 go tidy_env acc (thing : things)
489 = find_thing ignore_it tidy_env thing `thenM` \ (tidy_env1, maybe_doc) ->
491 Just d -> go tidy_env1 (d:acc) things
492 Nothing -> go tidy_env1 acc things
494 ignore_it ty = not (tvs `intersectsVarSet` tyVarsOfType ty)
496 -----------------------
497 find_thing ignore_it tidy_env (ATcId id _ _)
498 = zonkTcType (idType id) `thenM` \ id_ty ->
499 if ignore_it id_ty then
500 returnM (tidy_env, Nothing)
502 (tidy_env', tidy_ty) = tidyOpenType tidy_env id_ty
503 msg = sep [ppr id <+> dcolon <+> ppr tidy_ty,
504 nest 2 (parens (ptext SLIT("bound at") <+>
505 ppr (getSrcLoc id)))]
507 returnM (tidy_env', Just msg)
509 find_thing ignore_it tidy_env (ATyVar tv)
510 = zonkTcTyVar tv `thenM` \ tv_ty ->
511 if ignore_it tv_ty then
512 returnM (tidy_env, Nothing)
514 (tidy_env1, tv1) = tidyOpenTyVar tidy_env tv
515 (tidy_env2, tidy_ty) = tidyOpenType tidy_env1 tv_ty
516 msg = sep [ppr tv1 <+> eq_stuff, nest 2 bound_at]
518 eq_stuff | Just tv' <- Type.getTyVar_maybe tv_ty, tv == tv' = empty
519 | otherwise = equals <+> ppr tv_ty
520 -- It's ok to use Type.getTyVar_maybe because ty is zonked by now
522 bound_at = tyVarBindingInfo tv
524 returnM (tidy_env2, Just msg)
528 %************************************************************************
530 \subsection{The global tyvars}
532 %************************************************************************
535 tc_extend_gtvs gtvs extra_global_tvs
536 = readMutVar gtvs `thenM` \ global_tvs ->
537 newMutVar (global_tvs `unionVarSet` extra_global_tvs)
540 @tcGetGlobalTyVars@ returns a fully-zonked set of tyvars free in the environment.
541 To improve subsequent calls to the same function it writes the zonked set back into
545 tcGetGlobalTyVars :: TcM TcTyVarSet
547 = getLclEnv `thenM` \ (TcLclEnv {tcl_tyvars = gtv_var}) ->
548 readMutVar gtv_var `thenM` \ gbl_tvs ->
549 zonkTcTyVarsAndFV (varSetElems gbl_tvs) `thenM` \ gbl_tvs' ->
550 writeMutVar gtv_var gbl_tvs' `thenM_`
555 %************************************************************************
557 \subsection{The instance environment}
559 %************************************************************************
561 The TcGblEnv holds a mutable variable containing the current full, instance environment.
562 The ExtendInstEnv functions extend this environment by side effect, in case we are
563 sucking in new instance declarations deep in the body of a TH splice, which are needed
564 in another TH splice. The tcg_insts field of the TcGblEnv contains just the dfuns
568 tcGetInstEnv :: TcM InstEnv
569 tcGetInstEnv = do { env <- getGblEnv; readMutVar (tcg_inst_env env) }
571 tcExtendInstEnv :: [DFunId] -> TcM a -> TcM a
572 -- Add instances from local or imported
573 -- instances, and refresh the instance-env cache
574 tcExtendInstEnv dfuns thing_inside
575 = do { dflags <- getDOpts
578 ; let ie_var = tcg_inst_env env
579 ; inst_env <- readMutVar ie_var
581 -- Extend the total inst-env with the new dfuns
582 (inst_env', errs) = extendInstEnv dflags inst_env dfuns
584 -- Sort the ones from this module from the others
585 (lcl_dfuns, pkg_dfuns) = partition (isLocalThing mod) dfuns
588 -- And add the pieces to the right places
589 (eps_inst_env', _) = extendInstEnv dflags (eps_inst_env eps) pkg_dfuns
590 eps' = eps { eps_inst_env = eps_inst_env' }
592 env' = env { tcg_insts = lcl_dfuns ++ tcg_insts env }
596 ; writeMutVar ie_var inst_env'
598 ; setGblEnv env' thing_inside }
600 tcExtendLocalInstEnv :: [InstInfo] -> TcM a -> TcM a
601 -- Special case for local instance decls
602 tcExtendLocalInstEnv infos thing_inside
603 = do { dflags <- getDOpts
605 ; let ie_var = tcg_inst_env env
606 ; inst_env <- readMutVar ie_var
608 dfuns = map iDFunId infos
609 (inst_env', errs) = extendInstEnv dflags inst_env dfuns
610 env' = env { tcg_insts = dfuns ++ tcg_insts env }
613 ; writeMutVar ie_var inst_env'
614 ; setGblEnv env' thing_inside }
616 tcExtendTempInstEnv :: [DFunId] -> TcM a -> TcM a
617 -- Extend the instance envt, but with *no* permanent
618 -- effect on mutable variables; also ignore errors
619 -- Used during 'deriving' stuff
620 tcExtendTempInstEnv dfuns thing_inside
621 = do { dflags <- getDOpts
623 ; let ie_var = tcg_inst_env env
624 ; inst_env <- readMutVar ie_var
625 ; let (inst_env', errs) = extendInstEnv dflags inst_env dfuns
626 -- Ignore the errors about duplicate instances.
627 -- We don't want repeated error messages
628 -- They'll appear later, when we do the top-level extendInstEnvs
629 ; writeMutVar ie_var inst_env'
630 ; result <- thing_inside
631 ; writeMutVar ie_var inst_env -- Restore!
634 tcWithTempInstEnv :: TcM a -> TcM a
635 -- Run thing_inside, discarding any effects on the instance environment
636 tcWithTempInstEnv thing_inside
637 = do { env <- getGblEnv
638 ; let ie_var = tcg_inst_env env
639 ; old_ie <- readMutVar ie_var
640 ; result <- thing_inside
641 ; writeMutVar ie_var old_ie -- Restore
645 = traceTc (text "Adding instances:" <+> vcat (map pp dfuns))
647 pp dfun = ppr dfun <+> dcolon <+> ppr (idType dfun)
651 %************************************************************************
655 %************************************************************************
658 tcExtendRules :: [RuleDecl Id] -> TcM a -> TcM a
659 -- Just pop the new rules into the EPS and envt resp
660 -- All the rules come from an interface file, not soruce
661 -- Nevertheless, some may be for this module, if we read
662 -- its interface instead of its source code
663 tcExtendRules rules thing_inside
667 (lcl_rules, pkg_rules) = partition is_local_rule rules
668 is_local_rule = isLocalThing mod . ifaceRuleDeclName
671 core_rules = [(id,rule) | IfaceRuleOut id rule <- pkg_rules]
672 eps' = eps { eps_rule_base = addIfaceRules (eps_rule_base eps) core_rules }
673 -- All the rules from an interface are of the IfaceRuleOut form
675 env' = env { tcg_rules = lcl_rules ++ tcg_rules env }
678 ; setGblEnv env' thing_inside }
680 addIfaceRules :: RuleBase -> [IdCoreRule] -> RuleBase
681 addIfaceRules rule_base rules
682 = foldl extendRuleBase rule_base rules
686 %************************************************************************
688 \subsection{The InstInfo type}
690 %************************************************************************
692 The InstInfo type summarises the information in an instance declaration
694 instance c => k (t tvs) where b
696 It is used just for *local* instance decls (not ones from interface files).
697 But local instance decls includes
700 as well as explicit user written ones.
705 iDFunId :: DFunId, -- The dfun id
706 iBinds :: InstBindings
710 = VanillaInst -- The normal case
711 RenamedMonoBinds -- Bindings
712 [RenamedSig] -- User pragmas recorded for generating
713 -- specialised instances
715 | NewTypeDerived -- Used for deriving instances of newtypes, where the
716 [Type] -- witness dictionary is identical to the argument
717 -- dictionary. Hence no bindings, no pragmas
718 -- The [Type] are the representation types
719 -- See notes in TcDeriv
721 pprInstInfo info = vcat [ptext SLIT("InstInfo:") <+> ppr (idType (iDFunId info))]
723 pprInstInfoDetails (InstInfo { iBinds = VanillaInst b _ }) = ppr b
724 pprInstInfoDetails (InstInfo { iBinds = NewTypeDerived _}) = text "Derived from the representation type"
726 simpleInstInfoTy :: InstInfo -> Type
727 simpleInstInfoTy info = case tcSplitDFunTy (idType (iDFunId info)) of
728 (_, _, _, [ty]) -> ty
730 simpleInstInfoTyCon :: InstInfo -> TyCon
731 -- Gets the type constructor for a simple instance declaration,
732 -- i.e. one of the form instance (...) => C (T a b c) where ...
733 simpleInstInfoTyCon inst = tcTyConAppTyCon (simpleInstInfoTy inst)
737 %************************************************************************
741 %************************************************************************
744 badCon con_id = quotes (ppr con_id) <+> ptext SLIT("is not a data constructor")
746 notFound wheRe name = failWithTc (text wheRe <> colon <+> quotes (ppr name) <+>
747 ptext SLIT("is not in scope"))