2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1996
4 \section[RnSource]{Main pass of renamer}
7 #include "HsVersions.h"
9 module RnSource ( rnDecl, rnHsType, rnHsSigType ) where
11 IMPORT_1_3(List(partition))
14 #if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ <= 201
15 IMPORT_DELOOPER(RnLoop) -- *check* the RnPass/RnExpr/RnBinds loop-breaking
17 import {-# SOURCE #-} RnExpr
21 import HsDecls ( HsIdInfo(..) )
23 import HsTypes ( getTyVarName )
27 import CmdLineOpts ( opt_IgnoreIfacePragmas )
29 import RnBinds ( rnTopBinds, rnMethodBinds )
30 import RnEnv ( bindTyVarsRn, lookupBndrRn, lookupOccRn, lookupImplicitOccRn, bindLocalsRn,
31 newSysName, newDfunName, checkDupOrQualNames, checkDupNames,
32 listType_RDR, tupleType_RDR )
35 import Name ( Name, isLocallyDefined,
36 OccName(..), occNameString, prefixOccName,
39 SYN_IE(NameSet), unionNameSets, emptyNameSet, mkNameSet, unitNameSet,
42 import ErrUtils ( addErrLoc, addShortErrLocLine, addShortWarnLocLine )
43 import FiniteMap ( emptyFM, lookupFM, addListToFM_C )
44 import Id ( GenId{-instance NamedThing-} )
45 import IdInfo ( IdInfo, StrictnessInfo(..), FBTypeInfo, DemandInfo, ArgUsageInfo )
46 import SpecEnv ( SpecEnv )
47 import Lex ( isLexCon )
48 import CoreUnfold ( Unfolding(..), SimpleUnfolding )
49 import MagicUFs ( MagicUnfoldingFun )
50 import PrelInfo ( derivingOccurrences, evalClass_RDR, numClass_RDR, allClass_NAME )
51 import ListSetOps ( unionLists, minusList )
52 import Maybes ( maybeToBool, catMaybes )
53 import Bag ( emptyBag, unitBag, consBag, unionManyBags, unionBags, listToBag, bagToList )
54 import Outputable ( PprStyle(..), Outputable(..){-instances-} )
56 import SrcLoc ( SrcLoc )
57 import Unique ( Unique )
58 import UniqSet ( SYN_IE(UniqSet) )
59 import UniqFM ( UniqFM, lookupUFM )
64 rnDecl `renames' declarations.
65 It simultaneously performs dependency analysis and precedence parsing.
66 It also does the following error checks:
69 Checks that tyvars are used properly. This includes checking
70 for undefined tyvars, and tyvars in contexts that are ambiguous.
72 Checks that all variable occurences are defined.
74 Checks the (..) etc constraints in the export list.
78 %*********************************************************
80 \subsection{Value declarations}
82 %*********************************************************
85 rnDecl :: RdrNameHsDecl -> RnMS s RenamedHsDecl
87 rnDecl (ValD binds) = rnTopBinds binds `thenRn` \ new_binds ->
88 returnRn (ValD new_binds)
91 rnDecl (SigD (IfaceSig name ty id_infos loc))
93 lookupBndrRn name `thenRn` \ name' ->
94 rnHsType ty `thenRn` \ ty' ->
95 -- Get the pragma info (if any).
96 setModeRn (InterfaceMode Optional) $
97 -- In all the rest of the signature we read in optional mode,
98 -- so that (a) we don't die
99 mapRn rnIdInfo id_infos `thenRn` \ id_infos' ->
100 returnRn (SigD (IfaceSig name' ty' id_infos' loc))
103 %*********************************************************
105 \subsection{Type declarations}
107 %*********************************************************
109 @rnTyDecl@ uses the `global name function' to create a new type
110 declaration in which local names have been replaced by their original
111 names, reporting any unknown names.
113 Renaming type variables is a pain. Because they now contain uniques,
114 it is necessary to pass in an association list which maps a parsed
115 tyvar to its Name representation. In some cases (type signatures of
116 values), it is even necessary to go over the type first in order to
117 get the set of tyvars used by it, make an assoc list, and then go over
118 it again to rename the tyvars! However, we can also do some scoping
119 checks at the same time.
122 rnDecl (TyD (TyData new_or_data context tycon tyvars condecls derivings pragmas src_loc))
123 = pushSrcLocRn src_loc $
124 lookupBndrRn tycon `thenRn` \ tycon' ->
125 bindTyVarsRn data_doc tyvars $ \ tyvars' ->
126 rnContext context `thenRn` \ context' ->
127 checkDupOrQualNames data_doc con_names `thenRn_`
128 mapRn rnConDecl condecls `thenRn` \ condecls' ->
129 rnDerivs derivings `thenRn` \ derivings' ->
130 ASSERT(isNoDataPragmas pragmas)
131 returnRn (TyD (TyData new_or_data context' tycon' tyvars' condecls' derivings' noDataPragmas src_loc))
133 data_doc sty = text "the data type declaration for" <+> ppr sty tycon
134 con_names = map conDeclName condecls
136 rnDecl (TyD (TySynonym name tyvars ty src_loc))
137 = pushSrcLocRn src_loc $
138 lookupBndrRn name `thenRn` \ name' ->
139 bindTyVarsRn syn_doc tyvars $ \ tyvars' ->
140 rnHsType ty `thenRn` \ ty' ->
141 returnRn (TyD (TySynonym name' tyvars' ty' src_loc))
143 syn_doc sty = text "the declaration for type synonym" <+> ppr sty name
146 %*********************************************************
148 \subsection{Class declarations}
150 %*********************************************************
152 @rnClassDecl@ uses the `global name function' to create a new
153 class declaration in which local names have been replaced by their
154 original names, reporting any unknown names.
157 rnDecl (ClD (ClassDecl context cname tyvar sigs mbinds pragmas src_loc))
158 = pushSrcLocRn src_loc $
159 bindTyVarsRn cls_doc [tyvar] ( \ [tyvar'] ->
160 rnContext context `thenRn` \ context' ->
161 lookupBndrRn cname `thenRn` \ cname' ->
163 -- Check the signatures
164 checkDupOrQualNames sig_doc sig_names `thenRn_`
165 mapRn (rn_op cname' (getTyVarName tyvar')) sigs `thenRn` \ sigs' ->
166 returnRn (tyvar', context', cname', sigs')
167 ) `thenRn` \ (tyvar', context', cname', sigs') ->
170 checkDupOrQualNames meth_doc meth_names `thenRn_`
171 rnMethodBinds mbinds `thenRn` \ mbinds' ->
173 -- Typechecker is responsible for checking that we only
174 -- give default-method bindings for things in this class.
175 -- The renamer *could* check this for class decls, but can't
176 -- for instance decls.
178 ASSERT(isNoClassPragmas pragmas)
179 returnRn (ClD (ClassDecl context' cname' tyvar' sigs' mbinds' NoClassPragmas src_loc))
181 cls_doc sty = text "the declaration for class" <+> ppr sty cname
182 sig_doc sty = text "the signatures for class" <+> ppr sty cname
183 meth_doc sty = text "the default-methods for class" <+> ppr sty cname
185 sig_names = [(op,locn) | ClassOpSig op _ _ locn <- sigs]
186 meth_names = bagToList (collectMonoBinders mbinds)
188 rn_op clas clas_tyvar sig@(ClassOpSig op _ ty locn)
189 = pushSrcLocRn locn $
190 lookupBndrRn op `thenRn` \ op_name ->
191 rnHsSigType (\sty -> ppr sty op) ty `thenRn` \ new_ty ->
193 -- Call up interface info for default method, if such info exists
195 dm_occ = prefixOccName SLIT("$m") (rdrNameOcc op)
197 newSysName dm_occ Exported locn `thenRn` \ dm_name ->
198 setModeRn (InterfaceMode Optional) (
199 addOccurrenceName dm_name
204 (ctxt, op_ty) = case new_ty of
205 HsForAllTy tvs ctxt op_ty -> (ctxt, op_ty)
206 other -> ([], new_ty)
207 ctxt_fvs = extractCtxtTyNames ctxt
208 op_ty_fvs = extractHsTyNames op_ty -- Includes tycons/classes but we
209 -- don't care about that
211 -- Check that class tyvar appears in op_ty
212 checkRn (clas_tyvar `elemNameSet` op_ty_fvs)
213 (classTyVarNotInOpTyErr clas_tyvar sig)
216 returnRn (ClassOpSig op_name dm_name new_ty locn)
220 %*********************************************************
222 \subsection{Instance declarations}
224 %*********************************************************
227 rnDecl (InstD (InstDecl inst_ty mbinds uprags maybe_dfun src_loc))
228 = pushSrcLocRn src_loc $
229 rnHsSigType (\sty -> text "an instance decl") inst_ty `thenRn` \ inst_ty' ->
232 -- Rename the bindings
233 -- NB meth_names can be qualified!
234 checkDupNames meth_doc meth_names `thenRn_`
235 rnMethodBinds mbinds `thenRn` \ mbinds' ->
236 mapRn rn_uprag uprags `thenRn` \ new_uprags ->
238 newDfunName maybe_dfun src_loc `thenRn` \ dfun_name ->
239 addOccurrenceName dfun_name `thenRn_`
240 -- The dfun is not optional, because we use its version number
241 -- to identify the version of the instance declaration
243 -- The typechecker checks that all the bindings are for the right class.
244 returnRn (InstD (InstDecl inst_ty' mbinds' new_uprags (Just dfun_name) src_loc))
246 meth_doc sty = text "the bindings in an instance declaration"
247 meth_names = bagToList (collectMonoBinders mbinds)
249 rn_uprag (SpecSig op ty using locn)
250 = pushSrcLocRn src_loc $
251 lookupBndrRn op `thenRn` \ op_name ->
252 rnHsSigType (\sty -> ppr sty op) ty `thenRn` \ new_ty ->
253 rn_using using `thenRn` \ new_using ->
254 returnRn (SpecSig op_name new_ty new_using locn)
256 rn_uprag (InlineSig op locn)
257 = pushSrcLocRn locn $
258 lookupBndrRn op `thenRn` \ op_name ->
259 returnRn (InlineSig op_name locn)
261 rn_uprag (DeforestSig op locn)
262 = pushSrcLocRn locn $
263 lookupBndrRn op `thenRn` \ op_name ->
264 returnRn (DeforestSig op_name locn)
266 rn_uprag (MagicUnfoldingSig op str locn)
267 = pushSrcLocRn locn $
268 lookupBndrRn op `thenRn` \ op_name ->
269 returnRn (MagicUnfoldingSig op_name str locn)
271 rn_using Nothing = returnRn Nothing
272 rn_using (Just v) = lookupOccRn v `thenRn` \ new_v ->
273 returnRn (Just new_v)
276 %*********************************************************
278 \subsection{Default declarations}
280 %*********************************************************
283 rnDecl (DefD (DefaultDecl tys src_loc))
284 = pushSrcLocRn src_loc $
285 mapRn rnHsType tys `thenRn` \ tys' ->
286 lookupImplicitOccRn numClass_RDR `thenRn_`
287 returnRn (DefD (DefaultDecl tys' src_loc))
290 %*********************************************************
292 \subsection{Support code for type/data declarations}
294 %*********************************************************
297 rnDerivs :: Maybe [RdrName] -> RnMS s (Maybe [Name])
299 rnDerivs Nothing -- derivs not specified
300 = lookupImplicitOccRn evalClass_RDR `thenRn_`
304 = lookupImplicitOccRn evalClass_RDR `thenRn_`
305 mapRn rn_deriv ds `thenRn` \ derivs ->
306 returnRn (Just derivs)
309 = lookupOccRn clas `thenRn` \ clas_name ->
311 -- Now add extra "occurrences" for things that
312 -- the deriving mechanism will later need in order to
313 -- generate code for this class.
314 case lookupUFM derivingOccurrences clas_name of
315 Nothing -> addErrRn (derivingNonStdClassErr clas_name) `thenRn_`
318 Just occs -> mapRn lookupImplicitOccRn occs `thenRn_`
323 conDeclName :: RdrNameConDecl -> (RdrName, SrcLoc)
324 conDeclName (ConDecl n _ _ l) = (n,l)
326 rnConDecl :: RdrNameConDecl -> RnMS s RenamedConDecl
327 rnConDecl (ConDecl name cxt details locn)
328 = pushSrcLocRn locn $
329 checkConName name `thenRn_`
330 lookupBndrRn name `thenRn` \ new_name ->
331 rnConDetails name locn details `thenRn` \ new_details ->
332 rnContext cxt `thenRn` \ new_context ->
333 returnRn (ConDecl new_name new_context new_details locn)
335 rnConDetails con locn (VanillaCon tys)
336 = mapRn rnBangTy tys `thenRn` \ new_tys ->
337 returnRn (VanillaCon new_tys)
339 rnConDetails con locn (InfixCon ty1 ty2)
340 = rnBangTy ty1 `thenRn` \ new_ty1 ->
341 rnBangTy ty2 `thenRn` \ new_ty2 ->
342 returnRn (InfixCon new_ty1 new_ty2)
344 rnConDetails con locn (NewCon ty)
345 = rnHsType ty `thenRn` \ new_ty ->
346 returnRn (NewCon new_ty)
348 rnConDetails con locn (RecCon fields)
349 = checkDupOrQualNames fld_doc field_names `thenRn_`
350 mapRn rnField fields `thenRn` \ new_fields ->
351 returnRn (RecCon new_fields)
353 fld_doc sty = text "the fields of constructor" <> ppr sty con
354 field_names = [(fld, locn) | (flds, _) <- fields, fld <- flds]
357 = mapRn lookupBndrRn names `thenRn` \ new_names ->
358 rnBangTy ty `thenRn` \ new_ty ->
359 returnRn (new_names, new_ty)
362 = rnHsType ty `thenRn` \ new_ty ->
363 returnRn (Banged new_ty)
365 rnBangTy (Unbanged ty)
366 = rnHsType ty `thenRn` \ new_ty ->
367 returnRn (Unbanged new_ty)
369 -- This data decl will parse OK
371 -- treating "a" as the constructor.
372 -- It is really hard to make the parser spot this malformation.
373 -- So the renamer has to check that the constructor is legal
375 -- We can get an operator as the constructor, even in the prefix form:
376 -- data T = :% Int Int
377 -- from interface files, which always print in prefix form
380 = checkRn (isLexCon (occNameString (rdrNameOcc name)))
385 %*********************************************************
387 \subsection{Support code to rename types}
389 %*********************************************************
392 rnHsSigType :: (PprStyle -> Doc) -> RdrNameHsType -> RnMS s RenamedHsType
393 -- rnHsSigType is used for source-language type signatures,
394 -- which use *implicit* universal quantification.
396 -- Given the signature C => T we universally quantify over FV(T) \ {in-scope-tyvars}
398 -- We insist that the universally quantified type vars is a superset of FV(C)
399 -- It follows that FV(T) is a superset of FV(C), so that the context constrains
400 -- no type variables that don't appear free in the tau-type part.
402 rnHsSigType doc_str full_ty@(HsPreForAllTy ctxt ty) -- From source code (no kinds on tyvars)
403 = getNameEnv `thenRn` \ name_env ->
405 mentioned_tyvars = extractHsTyVars ty
406 forall_tyvars = filter (not . in_scope) mentioned_tyvars
407 in_scope tv = maybeToBool (lookupFM name_env tv)
409 constrained_tyvars = nub (concat (map (extractHsTyVars . snd) ctxt))
410 constrained_and_in_scope = filter in_scope constrained_tyvars
411 constrained_and_not_mentioned = filter (not . (`elem` mentioned_tyvars)) constrained_tyvars
413 -- Zap the context if there's a problem, to avoid duplicate error message.
414 ctxt' | null constrained_and_in_scope && null constrained_and_not_mentioned = ctxt
417 checkRn (null constrained_and_in_scope)
418 (ctxtErr1 sig_doc constrained_and_in_scope) `thenRn_`
419 checkRn (null constrained_and_not_mentioned)
420 (ctxtErr2 sig_doc constrained_and_not_mentioned ty) `thenRn_`
422 (bindTyVarsRn sig_doc (map UserTyVar forall_tyvars) $ \ new_tyvars ->
423 rnContext ctxt' `thenRn` \ new_ctxt ->
424 rnHsType ty `thenRn` \ new_ty ->
425 returnRn (HsForAllTy new_tyvars new_ctxt new_ty)
428 sig_doc sty = text "the type signature for" <+> doc_str sty
431 rnHsSigType doc_str other_ty = rnHsType other_ty
433 rnHsType :: RdrNameHsType -> RnMS s RenamedHsType
434 rnHsType (HsForAllTy tvs ctxt ty) -- From an interface file (tyvars may be kinded)
435 = rn_poly_help tvs ctxt ty
437 rnHsType full_ty@(HsPreForAllTy ctxt ty) -- A (context => ty) embedded in a type.
438 -- Universally quantify over tyvars in context
439 = getNameEnv `thenRn` \ name_env ->
441 forall_tyvars = foldr unionLists [] (map (extractHsTyVars . snd) ctxt)
443 rn_poly_help (map UserTyVar forall_tyvars) ctxt ty
445 rnHsType (MonoTyVar tyvar)
446 = lookupOccRn tyvar `thenRn` \ tyvar' ->
447 returnRn (MonoTyVar tyvar')
449 rnHsType (MonoFunTy ty1 ty2)
450 = andRn MonoFunTy (rnHsType ty1) (rnHsType ty2)
452 rnHsType (MonoListTy _ ty)
453 = lookupImplicitOccRn listType_RDR `thenRn` \ tycon_name ->
454 rnHsType ty `thenRn` \ ty' ->
455 returnRn (MonoListTy tycon_name ty')
457 rnHsType (MonoTupleTy _ tys)
458 = lookupImplicitOccRn (tupleType_RDR (length tys)) `thenRn` \ tycon_name ->
459 mapRn rnHsType tys `thenRn` \ tys' ->
460 returnRn (MonoTupleTy tycon_name tys')
462 rnHsType (MonoTyApp ty1 ty2)
463 = rnHsType ty1 `thenRn` \ ty1' ->
464 rnHsType ty2 `thenRn` \ ty2' ->
465 returnRn (MonoTyApp ty1' ty2')
467 rnHsType (MonoDictTy clas ty)
468 = lookupOccRn clas `thenRn` \ clas' ->
469 rnHsType ty `thenRn` \ ty' ->
470 returnRn (MonoDictTy clas' ty')
472 rn_poly_help :: [HsTyVar RdrName] -- Universally quantified tyvars
475 -> RnMS s RenamedHsType
476 rn_poly_help tyvars ctxt ty
477 = bindTyVarsRn sig_doc tyvars $ \ new_tyvars ->
478 rnContext ctxt `thenRn` \ new_ctxt ->
479 rnHsType ty `thenRn` \ new_ty ->
480 returnRn (HsForAllTy new_tyvars new_ctxt new_ty)
482 sig_doc sty = text "a nested for-all type"
487 rnContext :: RdrNameContext -> RnMS s RenamedContext
490 = mapRn rn_ctxt ctxt `thenRn` \ result ->
492 (_, dup_asserts) = removeDups cmp_assert result
493 (alls, theta) = partition (\(c,_) -> c == allClass_NAME) result
494 non_tyvar_alls = [(c,t) | (c,t) <- alls, not (is_tyvar t)]
497 -- Check for duplicate assertions
498 -- If this isn't an error, then it ought to be:
499 mapRn (addWarnRn . dupClassAssertWarn theta) dup_asserts `thenRn_`
501 -- Check for All constraining a non-type-variable
502 mapRn (addWarnRn . allOfNonTyVar) non_tyvar_alls `thenRn_`
504 -- Done. Return a theta omitting all the "All" constraints.
505 -- They have done done their work by ensuring that we universally
506 -- quantify over their tyvar.
510 = -- Mini hack here. If the class is our pseudo-class "All",
511 -- then we don't want to record it as an occurrence, otherwise
512 -- we try to slurp it in later and it doesn't really exist at all.
513 -- Easiest thing is simply not to put it in the occurrence set.
514 lookupBndrRn clas `thenRn` \ clas_name ->
515 (if clas_name /= allClass_NAME then
516 addOccurrenceName clas_name
520 rnHsType ty `thenRn` \ ty' ->
521 returnRn (clas_name, ty')
523 cmp_assert (c1,ty1) (c2,ty2)
524 = (c1 `cmp` c2) `thenCmp` (cmpHsType cmp ty1 ty2)
526 is_tyvar (MonoTyVar _) = True
527 is_tyvar other = False
531 %*********************************************************
535 %*********************************************************
538 rnIdInfo (HsStrictness strict)
539 = rnStrict strict `thenRn` \ strict' ->
540 returnRn (HsStrictness strict')
542 rnIdInfo (HsUnfold inline expr) = rnCoreExpr expr `thenRn` \ expr' ->
543 returnRn (HsUnfold inline expr')
544 rnIdInfo (HsArity arity) = returnRn (HsArity arity)
545 rnIdInfo (HsUpdate update) = returnRn (HsUpdate update)
546 rnIdInfo (HsFBType fb) = returnRn (HsFBType fb)
547 rnIdInfo (HsArgUsage au) = returnRn (HsArgUsage au)
548 rnIdInfo (HsDeforest df) = returnRn (HsDeforest df)
550 rnStrict (StrictnessInfo demands (Just (worker,cons)))
551 -- The sole purpose of the "cons" field is so that we can mark the constructors
552 -- needed to build the wrapper as "needed", so that their data type decl will be
553 -- slurped in. After that their usefulness is o'er, so we just put in the empty list.
554 = lookupOccRn worker `thenRn` \ worker' ->
555 mapRn lookupOccRn cons `thenRn_`
556 returnRn (StrictnessInfo demands (Just (worker',[])))
558 -- Boring, but necessary for the type checker.
559 rnStrict (StrictnessInfo demands Nothing) = returnRn (StrictnessInfo demands Nothing)
560 rnStrict BottomGuaranteed = returnRn BottomGuaranteed
561 rnStrict NoStrictnessInfo = returnRn NoStrictnessInfo
568 = lookupOccRn v `thenRn` \ v' ->
571 rnCoreExpr (UfLit lit) = returnRn (UfLit lit)
573 rnCoreExpr (UfCon con args)
574 = lookupOccRn con `thenRn` \ con' ->
575 mapRn rnCoreArg args `thenRn` \ args' ->
576 returnRn (UfCon con' args')
578 rnCoreExpr (UfPrim prim args)
579 = rnCorePrim prim `thenRn` \ prim' ->
580 mapRn rnCoreArg args `thenRn` \ args' ->
581 returnRn (UfPrim prim' args')
583 rnCoreExpr (UfApp fun arg)
584 = rnCoreExpr fun `thenRn` \ fun' ->
585 rnCoreArg arg `thenRn` \ arg' ->
586 returnRn (UfApp fun' arg')
588 rnCoreExpr (UfCase scrut alts)
589 = rnCoreExpr scrut `thenRn` \ scrut' ->
590 rnCoreAlts alts `thenRn` \ alts' ->
591 returnRn (UfCase scrut' alts')
593 rnCoreExpr (UfSCC cc expr)
594 = rnCoreExpr expr `thenRn` \ expr' ->
595 returnRn (UfSCC cc expr')
597 rnCoreExpr(UfCoerce coercion ty body)
598 = rnCoercion coercion `thenRn` \ coercion' ->
599 rnHsType ty `thenRn` \ ty' ->
600 rnCoreExpr body `thenRn` \ body' ->
601 returnRn (UfCoerce coercion' ty' body')
603 rnCoreExpr (UfLam bndr body)
604 = rnCoreBndr bndr $ \ bndr' ->
605 rnCoreExpr body `thenRn` \ body' ->
606 returnRn (UfLam bndr' body')
608 rnCoreExpr (UfLet (UfNonRec bndr rhs) body)
609 = rnCoreExpr rhs `thenRn` \ rhs' ->
610 rnCoreBndr bndr $ \ bndr' ->
611 rnCoreExpr body `thenRn` \ body' ->
612 returnRn (UfLet (UfNonRec bndr' rhs') body')
614 rnCoreExpr (UfLet (UfRec pairs) body)
615 = rnCoreBndrs bndrs $ \ bndrs' ->
616 mapRn rnCoreExpr rhss `thenRn` \ rhss' ->
617 rnCoreExpr body `thenRn` \ body' ->
618 returnRn (UfLet (UfRec (bndrs' `zip` rhss')) body')
620 (bndrs, rhss) = unzip pairs
624 rnCoreBndr (UfValBinder name ty) thing_inside
625 = rnHsType ty `thenRn` \ ty' ->
626 bindLocalsRn "unfolding value" [name] $ \ [name'] ->
627 thing_inside (UfValBinder name' ty')
629 rnCoreBndr (UfTyBinder name kind) thing_inside
630 = bindLocalsRn "unfolding tyvar" [name] $ \ [name'] ->
631 thing_inside (UfTyBinder name' kind)
633 rnCoreBndr (UfUsageBinder name) thing_inside
634 = bindLocalsRn "unfolding usage" [name] $ \ [name'] ->
635 thing_inside (UfUsageBinder name')
637 rnCoreBndrs bndrs thing_inside -- Expect them all to be ValBinders
638 = mapRn rnHsType tys `thenRn` \ tys' ->
639 bindLocalsRn "unfolding value" names $ \ names' ->
640 thing_inside (zipWith UfValBinder names' tys')
642 names = map (\ (UfValBinder name _) -> name) bndrs
643 tys = map (\ (UfValBinder _ ty) -> ty) bndrs
645 rnCoreBndrNamess names thing_inside
646 = bindLocalsRn "unfolding value" names $ \ names' ->
651 rnCoreArg (UfVarArg v) = lookupOccRn v `thenRn` \ v' -> returnRn (UfVarArg v')
652 rnCoreArg (UfUsageArg u) = lookupOccRn u `thenRn` \ u' -> returnRn (UfUsageArg u')
653 rnCoreArg (UfTyArg ty) = rnHsType ty `thenRn` \ ty' -> returnRn (UfTyArg ty')
654 rnCoreArg (UfLitArg lit) = returnRn (UfLitArg lit)
656 rnCoreAlts (UfAlgAlts alts deflt)
657 = mapRn rn_alt alts `thenRn` \ alts' ->
658 rnCoreDefault deflt `thenRn` \ deflt' ->
659 returnRn (UfAlgAlts alts' deflt')
661 rn_alt (con, bndrs, rhs) = lookupOccRn con `thenRn` \ con' ->
662 bindLocalsRn "unfolding alt" bndrs $ \ bndrs' ->
663 rnCoreExpr rhs `thenRn` \ rhs' ->
664 returnRn (con', bndrs', rhs')
666 rnCoreAlts (UfPrimAlts alts deflt)
667 = mapRn rn_alt alts `thenRn` \ alts' ->
668 rnCoreDefault deflt `thenRn` \ deflt' ->
669 returnRn (UfPrimAlts alts' deflt')
671 rn_alt (lit, rhs) = rnCoreExpr rhs `thenRn` \ rhs' ->
674 rnCoreDefault UfNoDefault = returnRn UfNoDefault
675 rnCoreDefault (UfBindDefault bndr rhs) = bindLocalsRn "unfolding default" [bndr] $ \ [bndr'] ->
676 rnCoreExpr rhs `thenRn` \ rhs' ->
677 returnRn (UfBindDefault bndr' rhs')
679 rnCoercion (UfIn n) = lookupOccRn n `thenRn` \ n' -> returnRn (UfIn n')
680 rnCoercion (UfOut n) = lookupOccRn n `thenRn` \ n' -> returnRn (UfOut n')
682 rnCorePrim (UfOtherOp op)
683 = lookupOccRn op `thenRn` \ op' ->
684 returnRn (UfOtherOp op')
686 rnCorePrim (UfCCallOp str casm gc arg_tys res_ty)
687 = mapRn rnHsType arg_tys `thenRn` \ arg_tys' ->
688 rnHsType res_ty `thenRn` \ res_ty' ->
689 returnRn (UfCCallOp str casm gc arg_tys' res_ty')
692 %*********************************************************
696 %*********************************************************
699 derivingNonStdClassErr clas sty
700 = hsep [ptext SLIT("non-standard class"), ppr sty clas, ptext SLIT("in deriving clause")]
702 classTyVarNotInOpTyErr clas_tyvar sig sty
703 = hang (hsep [ptext SLIT("Class type variable"),
705 ptext SLIT("does not appear in method signature")])
708 dupClassAssertWarn ctxt dups sty
709 = hang (hcat [ptext SLIT("Duplicate class assertion `"),
711 ptext SLIT("' in context:")])
715 = hsep [ptext SLIT("Illegal data constructor name:"), ppr sty name]
718 = hsep [ptext SLIT("`All' applied to a non-type variable:"), ppr sty ty]
720 ctxtErr1 doc tyvars sty
721 = hsep [ptext SLIT("Context constrains in-scope type variable(s)"),
722 hsep (punctuate comma (map (ppr sty) tyvars))]
724 nest 4 (ptext SLIT("in") <+> doc sty)
726 ctxtErr2 doc tyvars ty sty
727 = (ptext SLIT("Context constrains type variable(s)")
728 <+> hsep (punctuate comma (map (ppr sty) tyvars)))
730 nest 4 (vcat [ptext SLIT("that do not appear in") <+> ppr sty ty,
731 ptext SLIT("in") <+> doc sty])