2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1996
4 \section[RnSource]{Main pass of renamer}
7 module RnSource ( rnDecl, rnHsType, rnHsSigType ) where
9 #include "HsVersions.h"
13 import HsDecls ( HsIdInfo(..), HsStrictnessInfo(..) )
15 import HsTypes ( getTyVarName, pprClassAssertion, cmpHsTypes )
19 import CmdLineOpts ( opt_IgnoreIfacePragmas )
21 import RnBinds ( rnTopBinds, rnMethodBinds, renameSigs )
22 import RnEnv ( bindTyVarsRn, lookupBndrRn, lookupOccRn, lookupImplicitOccRn, bindLocalsRn,
23 newDfunName, checkDupOrQualNames, checkDupNames, lookupGlobalOccRn,
24 newLocallyDefinedGlobalName, newImportedGlobalName, ifaceFlavour,
25 listType_RDR, tupleType_RDR, addImplicitOccRn
29 import Name ( Name, OccName(..), occNameString, prefixOccName,
30 ExportFlag(..), Provenance(..), NameSet, mkNameSet,
31 elemNameSet, nameOccName, NamedThing(..)
33 import BasicTypes ( TopLevelFlag(..) )
34 import FiniteMap ( lookupFM )
35 import Id ( GenId{-instance NamedThing-} )
36 import IdInfo ( FBTypeInfo, ArgUsageInfo )
37 import Lex ( isLexCon )
38 import PrelInfo ( derivingOccurrences, evalClass_RDR, numClass_RDR, allClass_NAME )
39 import Maybes ( maybeToBool )
40 import Bag ( bagToList )
42 import SrcLoc ( SrcLoc )
43 import Unique ( Unique )
44 import UniqSet ( UniqSet )
45 import UniqFM ( UniqFM, lookupUFM )
47 import List ( partition, nub )
50 rnDecl `renames' declarations.
51 It simultaneously performs dependency analysis and precedence parsing.
52 It also does the following error checks:
55 Checks that tyvars are used properly. This includes checking
56 for undefined tyvars, and tyvars in contexts that are ambiguous.
58 Checks that all variable occurences are defined.
60 Checks the (..) etc constraints in the export list.
64 %*********************************************************
66 \subsection{Value declarations}
68 %*********************************************************
71 rnDecl :: RdrNameHsDecl -> RnMS s RenamedHsDecl
73 rnDecl (ValD binds) = rnTopBinds binds `thenRn` \ new_binds ->
74 returnRn (ValD new_binds)
77 rnDecl (SigD (IfaceSig name ty id_infos loc))
79 lookupBndrRn name `thenRn` \ name' ->
80 rnHsType ty `thenRn` \ ty' ->
82 -- Get the pragma info (if any).
83 getModeRn `thenRn` \ (InterfaceMode _ print_unqual) ->
84 setModeRn (InterfaceMode Optional print_unqual) $
85 -- In all the rest of the signature we read in optional mode,
86 -- so that (a) we don't die
87 mapRn rnIdInfo id_infos `thenRn` \ id_infos' ->
88 returnRn (SigD (IfaceSig name' ty' id_infos' loc))
91 %*********************************************************
93 \subsection{Type declarations}
95 %*********************************************************
97 @rnTyDecl@ uses the `global name function' to create a new type
98 declaration in which local names have been replaced by their original
99 names, reporting any unknown names.
101 Renaming type variables is a pain. Because they now contain uniques,
102 it is necessary to pass in an association list which maps a parsed
103 tyvar to its Name representation. In some cases (type signatures of
104 values), it is even necessary to go over the type first in order to
105 get the set of tyvars used by it, make an assoc list, and then go over
106 it again to rename the tyvars! However, we can also do some scoping
107 checks at the same time.
110 rnDecl (TyD (TyData new_or_data context tycon tyvars condecls derivings pragmas src_loc))
111 = pushSrcLocRn src_loc $
112 lookupBndrRn tycon `thenRn` \ tycon' ->
113 bindTyVarsRn data_doc tyvars $ \ tyvars' ->
114 rnContext context `thenRn` \ context' ->
115 checkDupOrQualNames data_doc con_names `thenRn_`
116 mapRn rnConDecl condecls `thenRn` \ condecls' ->
117 rnDerivs derivings `thenRn` \ derivings' ->
118 ASSERT(isNoDataPragmas pragmas)
119 returnRn (TyD (TyData new_or_data context' tycon' tyvars' condecls' derivings' noDataPragmas src_loc))
121 data_doc = text "the data type declaration for" <+> ppr tycon
122 con_names = map conDeclName condecls
124 rnDecl (TyD (TySynonym name tyvars ty src_loc))
125 = pushSrcLocRn src_loc $
126 lookupBndrRn name `thenRn` \ name' ->
127 bindTyVarsRn syn_doc tyvars $ \ tyvars' ->
128 rnHsType ty `thenRn` \ ty' ->
129 returnRn (TyD (TySynonym name' tyvars' ty' src_loc))
131 syn_doc = text "the declaration for type synonym" <+> ppr name
134 %*********************************************************
136 \subsection{Class declarations}
138 %*********************************************************
140 @rnClassDecl@ uses the `global name function' to create a new
141 class declaration in which local names have been replaced by their
142 original names, reporting any unknown names.
145 rnDecl (ClD (ClassDecl context cname tyvars sigs mbinds pragmas tname dname src_loc))
146 = pushSrcLocRn src_loc $
148 lookupBndrRn cname `thenRn` \ cname' ->
149 lookupBndrRn tname `thenRn` \ tname' ->
150 lookupBndrRn dname `thenRn` \ dname' ->
152 bindTyVarsRn cls_doc tyvars ( \ tyvars' ->
153 rnContext context `thenRn` \ context' ->
155 -- Check the signatures
157 clas_tyvar_names = map getTyVarName tyvars'
159 checkDupOrQualNames sig_doc sig_rdr_names_w_locs `thenRn_`
160 mapRn (rn_op cname' clas_tyvar_names) sigs `thenRn` \ sigs' ->
161 returnRn (tyvars', context', sigs')
162 ) `thenRn` \ (tyvars', context', sigs') ->
165 checkDupOrQualNames meth_doc meth_rdr_names_w_locs `thenRn_`
166 rnMethodBinds mbinds `thenRn` \ mbinds' ->
168 -- Typechecker is responsible for checking that we only
169 -- give default-method bindings for things in this class.
170 -- The renamer *could* check this for class decls, but can't
171 -- for instance decls.
173 ASSERT(isNoClassPragmas pragmas)
174 returnRn (ClD (ClassDecl context' cname' tyvars' sigs' mbinds' NoClassPragmas tname' dname' src_loc))
176 cls_doc = text "the declaration for class" <+> ppr cname
177 sig_doc = text "the signatures for class" <+> ppr cname
178 meth_doc = text "the default-methods for class" <+> ppr cname
180 sig_rdr_names_w_locs = [(op,locn) | ClassOpSig op _ _ locn <- sigs]
181 meth_rdr_names_w_locs = bagToList (collectMonoBinders mbinds)
182 meth_rdr_names = map fst meth_rdr_names_w_locs
184 rn_op clas clas_tyvars sig@(ClassOpSig op maybe_dm ty locn)
185 = pushSrcLocRn locn $
186 lookupBndrRn op `thenRn` \ op_name ->
187 rnHsSigType (quotes (ppr op)) ty `thenRn` \ new_ty ->
189 -- Make the default-method name
191 dm_occ = prefixOccName SLIT("$m") (rdrNameOcc op)
193 getModuleRn `thenRn` \ mod_name ->
194 getModeRn `thenRn` \ mode ->
195 (case (mode, maybe_dm) of
196 (SourceMode, _) | op `elem` meth_rdr_names
197 -> -- There's an explicit method decl
198 newLocallyDefinedGlobalName mod_name dm_occ
199 (\_ -> Exported) locn `thenRn` \ dm_name ->
200 returnRn (Just dm_name)
202 (InterfaceMode _ _, Just _)
203 -> -- Imported class that has a default method decl
204 newImportedGlobalName mod_name dm_occ (ifaceFlavour clas) `thenRn` \ dm_name ->
205 addOccurrenceName dm_name `thenRn_`
206 returnRn (Just dm_name)
208 other -> returnRn Nothing
209 ) `thenRn` \ maybe_dm_name ->
211 -- Check that each class tyvar appears in op_ty
213 (ctxt, op_ty) = case new_ty of
214 HsForAllTy tvs ctxt op_ty -> (ctxt, op_ty)
215 other -> ([], new_ty)
216 ctxt_fvs = extractHsCtxtTyNames ctxt -- Includes tycons/classes but we
217 op_ty_fvs = extractHsTyNames op_ty -- don't care about that
219 check_in_op_ty clas_tyvar = checkRn (clas_tyvar `elemNameSet` op_ty_fvs)
220 (classTyVarNotInOpTyErr clas_tyvar sig)
222 mapRn check_in_op_ty clas_tyvars `thenRn_`
224 returnRn (ClassOpSig op_name maybe_dm_name new_ty locn)
228 %*********************************************************
230 \subsection{Instance declarations}
232 %*********************************************************
235 rnDecl (InstD (InstDecl inst_ty mbinds uprags maybe_dfun src_loc))
236 = pushSrcLocRn src_loc $
237 rnHsSigType (text "an instance decl") inst_ty `thenRn` \ inst_ty' ->
240 -- Rename the bindings
241 -- NB meth_names can be qualified!
242 checkDupNames meth_doc meth_names `thenRn_`
243 rnMethodBinds mbinds `thenRn` \ mbinds' ->
245 binders = mkNameSet (map fst (bagToList (collectMonoBinders mbinds')))
247 renameSigs NotTopLevel True binders uprags `thenRn` \ new_uprags ->
250 -- We use the class name and the name of the first
251 -- type constructor the class is applied to.
252 (cl_nm, tycon_nm) = mkDictPrefix inst_ty'
254 mkDictPrefix (MonoDictTy cl tys) =
256 [] -> (c_nm, nilOccName )
257 (ty:_) -> (c_nm, getInstHeadTy ty)
259 c_nm = nameOccName (getName cl)
261 mkDictPrefix (HsPreForAllTy _ ty) = mkDictPrefix ty
262 mkDictPrefix (HsForAllTy _ _ ty) = mkDictPrefix ty -- can this
263 mkDictPrefix _ = (nilOccName, nilOccName)
267 MonoTyVar tv -> nameOccName (getName tv)
268 MonoTyApp t _ -> getInstHeadTy t
270 -- I cannot see how the rest of HsType constructors
271 -- can occur, but this isn't really a failure condition,
272 -- so we return silently.
274 nilOccName = (VarOcc _NIL_) -- ToDo: add OccName constructor fun for this.
276 newDfunName cl_nm tycon_nm maybe_dfun src_loc `thenRn` \ dfun_name ->
277 addOccurrenceName dfun_name `thenRn_`
278 -- The dfun is not optional, because we use its version number
279 -- to identify the version of the instance declaration
281 -- The typechecker checks that all the bindings are for the right class.
282 returnRn (InstD (InstDecl inst_ty' mbinds' new_uprags (Just dfun_name) src_loc))
284 meth_doc = text "the bindings in an instance declaration"
285 meth_names = bagToList (collectMonoBinders mbinds)
288 %*********************************************************
290 \subsection{Default declarations}
292 %*********************************************************
295 rnDecl (DefD (DefaultDecl tys src_loc))
296 = pushSrcLocRn src_loc $
297 mapRn rnHsType tys `thenRn` \ tys' ->
298 lookupImplicitOccRn numClass_RDR `thenRn_`
299 returnRn (DefD (DefaultDecl tys' src_loc))
302 %*********************************************************
304 \subsection{Foreign declarations}
306 %*********************************************************
309 rnDecl (ForD (ForeignDecl name imp_exp ty ext_nm cconv src_loc))
310 = pushSrcLocRn src_loc $
311 lookupBndrRn name `thenRn` \ name' ->
313 addImplicitOccRn name'
315 returnRn name') `thenRn_`
316 rnHsSigType fo_decl_msg ty `thenRn` \ ty' ->
317 returnRn (ForD (ForeignDecl name' imp_exp ty' ext_nm cconv src_loc))
319 fo_decl_msg = ptext SLIT("a foreign declaration")
320 is_export = not (maybeToBool imp_exp) && not (isDynamic ext_nm)
324 %*********************************************************
326 \subsection{Support code for type/data declarations}
328 %*********************************************************
331 rnDerivs :: Maybe [RdrName] -> RnMS s (Maybe [Name])
333 rnDerivs Nothing -- derivs not specified
334 = lookupImplicitOccRn evalClass_RDR `thenRn_`
338 = lookupImplicitOccRn evalClass_RDR `thenRn_`
339 mapRn rn_deriv ds `thenRn` \ derivs ->
340 returnRn (Just derivs)
343 = lookupOccRn clas `thenRn` \ clas_name ->
345 -- Now add extra "occurrences" for things that
346 -- the deriving mechanism will later need in order to
347 -- generate code for this class.
348 case lookupUFM derivingOccurrences clas_name of
349 Nothing -> addErrRn (derivingNonStdClassErr clas_name) `thenRn_`
352 Just occs -> mapRn lookupImplicitOccRn occs `thenRn_`
357 conDeclName :: RdrNameConDecl -> (RdrName, SrcLoc)
358 conDeclName (ConDecl n _ _ l) = (n,l)
360 rnConDecl :: RdrNameConDecl -> RnMS s RenamedConDecl
361 rnConDecl (ConDecl name cxt details locn)
362 = pushSrcLocRn locn $
363 checkConName name `thenRn_`
364 lookupBndrRn name `thenRn` \ new_name ->
365 rnConDetails name locn details `thenRn` \ new_details ->
366 rnContext cxt `thenRn` \ new_context ->
367 returnRn (ConDecl new_name new_context new_details locn)
369 rnConDetails con locn (VanillaCon tys)
370 = mapRn rnBangTy tys `thenRn` \ new_tys ->
371 returnRn (VanillaCon new_tys)
373 rnConDetails con locn (InfixCon ty1 ty2)
374 = rnBangTy ty1 `thenRn` \ new_ty1 ->
375 rnBangTy ty2 `thenRn` \ new_ty2 ->
376 returnRn (InfixCon new_ty1 new_ty2)
378 rnConDetails con locn (NewCon ty)
379 = rnHsType ty `thenRn` \ new_ty ->
380 returnRn (NewCon new_ty)
382 rnConDetails con locn (RecCon fields)
383 = checkDupOrQualNames fld_doc field_names `thenRn_`
384 mapRn rnField fields `thenRn` \ new_fields ->
385 returnRn (RecCon new_fields)
387 fld_doc = text "the fields of constructor" <> ppr con
388 field_names = [(fld, locn) | (flds, _) <- fields, fld <- flds]
391 = mapRn lookupBndrRn names `thenRn` \ new_names ->
392 rnBangTy ty `thenRn` \ new_ty ->
393 returnRn (new_names, new_ty)
396 = rnHsType ty `thenRn` \ new_ty ->
397 returnRn (Banged new_ty)
399 rnBangTy (Unbanged ty)
400 = rnHsType ty `thenRn` \ new_ty ->
401 returnRn (Unbanged new_ty)
403 -- This data decl will parse OK
405 -- treating "a" as the constructor.
406 -- It is really hard to make the parser spot this malformation.
407 -- So the renamer has to check that the constructor is legal
409 -- We can get an operator as the constructor, even in the prefix form:
410 -- data T = :% Int Int
411 -- from interface files, which always print in prefix form
414 = checkRn (isLexCon (occNameString (rdrNameOcc name)))
419 %*********************************************************
421 \subsection{Support code to rename types}
423 %*********************************************************
426 rnHsSigType :: SDoc -> RdrNameHsType -> RnMS s RenamedHsType
427 -- rnHsSigType is used for source-language type signatures,
428 -- which use *implicit* universal quantification.
430 -- Given the signature C => T we universally quantify over FV(T) \ {in-scope-tyvars}
432 -- We insist that the universally quantified type vars is a superset of FV(C)
433 -- It follows that FV(T) is a superset of FV(C), so that the context constrains
434 -- no type variables that don't appear free in the tau-type part.
436 rnHsSigType doc_str full_ty@(HsPreForAllTy ctxt ty) -- From source code (no kinds on tyvars)
437 = getLocalNameEnv `thenRn` \ name_env ->
439 mentioned_tyvars = extractHsTyVars ty
440 forall_tyvars = filter (not . in_scope) mentioned_tyvars
441 in_scope tv = maybeToBool (lookupFM name_env tv)
443 constrained_tyvars = extractHsCtxtTyVars ctxt
444 constrained_and_in_scope = filter in_scope constrained_tyvars
445 constrained_and_not_mentioned = filter (not . (`elem` mentioned_tyvars)) constrained_tyvars
447 -- Zap the context if there's a problem, to avoid duplicate error message.
448 ctxt' | null constrained_and_in_scope && null constrained_and_not_mentioned = ctxt
451 checkRn (null constrained_and_in_scope)
452 (ctxtErr1 sig_doc constrained_and_in_scope) `thenRn_`
453 checkRn (null constrained_and_not_mentioned)
454 (ctxtErr2 sig_doc constrained_and_not_mentioned ty) `thenRn_`
456 (bindTyVarsRn sig_doc (map UserTyVar forall_tyvars) $ \ new_tyvars ->
457 rnContext ctxt' `thenRn` \ new_ctxt ->
458 rnHsType ty `thenRn` \ new_ty ->
459 returnRn (HsForAllTy new_tyvars new_ctxt new_ty)
462 sig_doc = text "the type signature for" <+> doc_str
465 rnHsSigType doc_str other_ty = rnHsType other_ty
467 rnHsType :: RdrNameHsType -> RnMS s RenamedHsType
468 rnHsType (HsForAllTy tvs ctxt ty) -- From an interface file (tyvars may be kinded)
469 = rn_poly_help tvs ctxt ty
471 rnHsType full_ty@(HsPreForAllTy ctxt ty) -- A (context => ty) embedded in a type.
472 -- Universally quantify over tyvars in context
473 = getLocalNameEnv `thenRn` \ name_env ->
475 forall_tyvars = extractHsCtxtTyVars ctxt
477 rn_poly_help (map UserTyVar forall_tyvars) ctxt ty
479 rnHsType (MonoTyVar tyvar)
480 = lookupOccRn tyvar `thenRn` \ tyvar' ->
481 returnRn (MonoTyVar tyvar')
483 rnHsType (MonoFunTy ty1 ty2)
484 = andRn MonoFunTy (rnHsType ty1) (rnHsType ty2)
486 rnHsType (MonoListTy _ ty)
487 = lookupImplicitOccRn listType_RDR `thenRn` \ tycon_name ->
488 rnHsType ty `thenRn` \ ty' ->
489 returnRn (MonoListTy tycon_name ty')
491 rnHsType (MonoTupleTy _ tys)
492 = lookupImplicitOccRn (tupleType_RDR (length tys)) `thenRn` \ tycon_name ->
493 mapRn rnHsType tys `thenRn` \ tys' ->
494 returnRn (MonoTupleTy tycon_name tys')
496 rnHsType (MonoTyApp ty1 ty2)
497 = rnHsType ty1 `thenRn` \ ty1' ->
498 rnHsType ty2 `thenRn` \ ty2' ->
499 returnRn (MonoTyApp ty1' ty2')
501 rnHsType (MonoDictTy clas tys)
502 = lookupOccRn clas `thenRn` \ clas' ->
503 mapRn rnHsType tys `thenRn` \ tys' ->
504 returnRn (MonoDictTy clas' tys')
506 rn_poly_help :: [HsTyVar RdrName] -- Universally quantified tyvars
509 -> RnMS s RenamedHsType
510 rn_poly_help tyvars ctxt ty
511 = bindTyVarsRn sig_doc tyvars $ \ new_tyvars ->
512 rnContext ctxt `thenRn` \ new_ctxt ->
513 rnHsType ty `thenRn` \ new_ty ->
514 returnRn (HsForAllTy new_tyvars new_ctxt new_ty)
516 sig_doc = text "a nested for-all type"
521 rnContext :: RdrNameContext -> RnMS s RenamedContext
524 = mapRn rn_ctxt ctxt `thenRn` \ result ->
526 (_, dup_asserts) = removeDups cmp_assert result
527 (alls, theta) = partition (\(c,_) -> c == allClass_NAME) result
530 -- Check for duplicate assertions
531 -- If this isn't an error, then it ought to be:
532 mapRn (addWarnRn . dupClassAssertWarn theta) dup_asserts `thenRn_`
534 -- Check for All constraining a non-type-variable
535 mapRn check_All alls `thenRn_`
537 -- Done. Return a theta omitting all the "All" constraints.
538 -- They have done done their work by ensuring that we universally
539 -- quantify over their tyvar.
543 = -- Mini hack here. If the class is our pseudo-class "All",
544 -- then we don't want to record it as an occurrence, otherwise
545 -- we try to slurp it in later and it doesn't really exist at all.
546 -- Easiest thing is simply not to put it in the occurrence set.
547 lookupBndrRn clas `thenRn` \ clas_name ->
548 (if clas_name /= allClass_NAME then
549 addOccurrenceName clas_name
553 mapRn rnHsType tys `thenRn` \ tys' ->
554 returnRn (clas_name, tys')
557 cmp_assert (c1,tys1) (c2,tys2)
558 = (c1 `compare` c2) `thenCmp` (cmpHsTypes compare tys1 tys2)
560 check_All (c, [MonoTyVar _]) = returnRn () -- OK!
561 check_All assertion = addErrRn (wierdAllErr assertion)
565 %*********************************************************
569 %*********************************************************
572 rnIdInfo (HsStrictness strict)
573 = rnStrict strict `thenRn` \ strict' ->
574 returnRn (HsStrictness strict')
576 rnIdInfo (HsUnfold inline expr) = rnCoreExpr expr `thenRn` \ expr' ->
577 returnRn (HsUnfold inline expr')
578 rnIdInfo (HsArity arity) = returnRn (HsArity arity)
579 rnIdInfo (HsUpdate update) = returnRn (HsUpdate update)
580 rnIdInfo (HsFBType fb) = returnRn (HsFBType fb)
581 rnIdInfo (HsArgUsage au) = returnRn (HsArgUsage au)
582 rnIdInfo (HsSpecialise tyvars tys expr)
583 = bindTyVarsRn doc tyvars $ \ tyvars' ->
584 rnCoreExpr expr `thenRn` \ expr' ->
585 mapRn rnHsType tys `thenRn` \ tys' ->
586 returnRn (HsSpecialise tyvars' tys' expr')
588 doc = text "Specialise in interface pragma"
591 rnStrict (HsStrictnessInfo demands (Just (worker,cons)))
592 -- The sole purpose of the "cons" field is so that we can mark the constructors
593 -- needed to build the wrapper as "needed", so that their data type decl will be
594 -- slurped in. After that their usefulness is o'er, so we just put in the empty list.
595 = lookupOccRn worker `thenRn` \ worker' ->
596 mapRn lookupOccRn cons `thenRn_`
597 returnRn (HsStrictnessInfo demands (Just (worker',[])))
599 -- Boring, but necessary for the type checker.
600 rnStrict (HsStrictnessInfo demands Nothing) = returnRn (HsStrictnessInfo demands Nothing)
601 rnStrict HsBottom = returnRn HsBottom
608 = lookupOccRn v `thenRn` \ v' ->
611 rnCoreExpr (UfLit lit) = returnRn (UfLit lit)
613 rnCoreExpr (UfCon con args)
614 = lookupOccRn con `thenRn` \ con' ->
615 mapRn rnCoreArg args `thenRn` \ args' ->
616 returnRn (UfCon con' args')
618 rnCoreExpr (UfPrim prim args)
619 = rnCorePrim prim `thenRn` \ prim' ->
620 mapRn rnCoreArg args `thenRn` \ args' ->
621 returnRn (UfPrim prim' args')
623 rnCoreExpr (UfApp fun arg)
624 = rnCoreExpr fun `thenRn` \ fun' ->
625 rnCoreArg arg `thenRn` \ arg' ->
626 returnRn (UfApp fun' arg')
628 rnCoreExpr (UfCase scrut alts)
629 = rnCoreExpr scrut `thenRn` \ scrut' ->
630 rnCoreAlts alts `thenRn` \ alts' ->
631 returnRn (UfCase scrut' alts')
633 rnCoreExpr (UfNote note expr)
634 = rnNote note `thenRn` \ note' ->
635 rnCoreExpr expr `thenRn` \ expr' ->
636 returnRn (UfNote note' expr')
638 rnCoreExpr (UfLam bndr body)
639 = rnCoreBndr bndr $ \ bndr' ->
640 rnCoreExpr body `thenRn` \ body' ->
641 returnRn (UfLam bndr' body')
643 rnCoreExpr (UfLet (UfNonRec bndr rhs) body)
644 = rnCoreExpr rhs `thenRn` \ rhs' ->
645 rnCoreBndr bndr $ \ bndr' ->
646 rnCoreExpr body `thenRn` \ body' ->
647 returnRn (UfLet (UfNonRec bndr' rhs') body')
649 rnCoreExpr (UfLet (UfRec pairs) body)
650 = rnCoreBndrs bndrs $ \ bndrs' ->
651 mapRn rnCoreExpr rhss `thenRn` \ rhss' ->
652 rnCoreExpr body `thenRn` \ body' ->
653 returnRn (UfLet (UfRec (bndrs' `zip` rhss')) body')
655 (bndrs, rhss) = unzip pairs
659 rnCoreBndr (UfValBinder name ty) thing_inside
660 = rnHsType ty `thenRn` \ ty' ->
661 bindLocalsRn "unfolding value" [name] $ \ [name'] ->
662 thing_inside (UfValBinder name' ty')
664 rnCoreBndr (UfTyBinder name kind) thing_inside
665 = bindLocalsRn "unfolding tyvar" [name] $ \ [name'] ->
666 thing_inside (UfTyBinder name' kind)
668 rnCoreBndrs bndrs thing_inside -- Expect them all to be ValBinders
669 = mapRn rnHsType tys `thenRn` \ tys' ->
670 bindLocalsRn "unfolding value" names $ \ names' ->
671 thing_inside (zipWith UfValBinder names' tys')
673 names = map (\ (UfValBinder name _) -> name) bndrs
674 tys = map (\ (UfValBinder _ ty) -> ty) bndrs
676 rnCoreBndrNamess names thing_inside
677 = bindLocalsRn "unfolding value" names $ \ names' ->
682 rnCoreArg (UfVarArg v) = lookupOccRn v `thenRn` \ v' -> returnRn (UfVarArg v')
683 rnCoreArg (UfTyArg ty) = rnHsType ty `thenRn` \ ty' -> returnRn (UfTyArg ty')
684 rnCoreArg (UfLitArg lit) = returnRn (UfLitArg lit)
686 rnCoreAlts (UfAlgAlts alts deflt)
687 = mapRn rn_alt alts `thenRn` \ alts' ->
688 rnCoreDefault deflt `thenRn` \ deflt' ->
689 returnRn (UfAlgAlts alts' deflt')
691 rn_alt (con, bndrs, rhs) = lookupOccRn con `thenRn` \ con' ->
692 bindLocalsRn "unfolding alt" bndrs $ \ bndrs' ->
693 rnCoreExpr rhs `thenRn` \ rhs' ->
694 returnRn (con', bndrs', rhs')
696 rnCoreAlts (UfPrimAlts alts deflt)
697 = mapRn rn_alt alts `thenRn` \ alts' ->
698 rnCoreDefault deflt `thenRn` \ deflt' ->
699 returnRn (UfPrimAlts alts' deflt')
701 rn_alt (lit, rhs) = rnCoreExpr rhs `thenRn` \ rhs' ->
704 rnCoreDefault UfNoDefault = returnRn UfNoDefault
705 rnCoreDefault (UfBindDefault bndr rhs) = bindLocalsRn "unfolding default" [bndr] $ \ [bndr'] ->
706 rnCoreExpr rhs `thenRn` \ rhs' ->
707 returnRn (UfBindDefault bndr' rhs')
710 = rnHsType ty `thenRn` \ ty' ->
711 returnRn (UfCoerce ty')
713 rnNote (UfSCC cc) = returnRn (UfSCC cc)
714 rnNote UfInlineCall = returnRn UfInlineCall
716 rnCorePrim (UfOtherOp op)
717 = lookupOccRn op `thenRn` \ op' ->
718 returnRn (UfOtherOp op')
720 rnCorePrim (UfCCallOp str casm gc arg_tys res_ty)
721 = mapRn rnHsType arg_tys `thenRn` \ arg_tys' ->
722 rnHsType res_ty `thenRn` \ res_ty' ->
723 returnRn (UfCCallOp str casm gc arg_tys' res_ty')
726 %*********************************************************
730 %*********************************************************
733 derivingNonStdClassErr clas
734 = hsep [ptext SLIT("non-standard class"), ppr clas, ptext SLIT("in deriving clause")]
736 classTyVarNotInOpTyErr clas_tyvar sig
737 = hang (hsep [ptext SLIT("Class type variable"),
738 quotes (ppr clas_tyvar),
739 ptext SLIT("does not appear in method signature")])
742 dupClassAssertWarn ctxt (assertion : dups)
743 = sep [hsep [ptext SLIT("Duplicate class assertion"),
744 quotes (pprClassAssertion assertion),
745 ptext SLIT("in the context:")],
746 nest 4 (pprContext ctxt)]
749 = hsep [ptext SLIT("Illegal data constructor name"), quotes (ppr name)]
751 wierdAllErr assertion
752 = ptext SLIT("Mal-formed use of `All':") <+> pprClassAssertion assertion
755 = hsep [ptext SLIT("Context constrains in-scope type variable(s)"),
756 pprQuotedList tyvars]
758 nest 4 (ptext SLIT("in") <+> doc)
760 ctxtErr2 doc tyvars ty
761 = (ptext SLIT("Context constrains type variable(s)")
762 <+> pprQuotedList tyvars)
764 nest 4 (vcat [ptext SLIT("that do not appear in") <+> quotes (ppr ty),
765 ptext SLIT("in") <+> doc])