2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1998
4 \section[RnSource]{Main pass of renamer}
7 module RnSource ( rnDecl, rnHsSigType ) where
9 #include "HsVersions.h"
13 import HsDecls ( HsIdInfo(..), HsStrictnessInfo(..) )
15 import HsTypes ( getTyVarName, pprClassAssertion, cmpHsTypes )
20 import RnBinds ( rnTopBinds, rnMethodBinds, renameSigs )
21 import RnEnv ( bindTyVarsRn, lookupBndrRn, lookupOccRn,
22 lookupImplicitOccRn, addImplicitOccRn,
24 newDfunName, checkDupOrQualNames, checkDupNames,
25 newLocallyDefinedGlobalName, newImportedGlobalName,
26 ifaceFlavour, listTyCon_name, tupleTyCon_name )
29 import Name ( Name, OccName(..), occNameString, prefixOccName,
30 ExportFlag(..), Provenance(..),
31 nameOccName, NamedThing(..), isLexCon,
35 import BasicTypes ( TopLevelFlag(..) )
36 import FiniteMap ( elemFM )
37 import PrelInfo ( derivingOccurrences, numClass_RDR,
38 deRefStablePtr_NAME, makeStablePtr_NAME,
41 import Bag ( bagToList )
43 import SrcLoc ( SrcLoc )
44 import UniqFM ( lookupUFM )
45 import Maybes ( maybeToBool )
49 rnDecl `renames' declarations.
50 It simultaneously performs dependency analysis and precedence parsing.
51 It also does the following error checks:
54 Checks that tyvars are used properly. This includes checking
55 for undefined tyvars, and tyvars in contexts that are ambiguous.
57 Checks that all variable occurences are defined.
59 Checks the (..) etc constraints in the export list.
63 %*********************************************************
65 \subsection{Value declarations}
67 %*********************************************************
70 rnDecl :: RdrNameHsDecl -> RnMS s RenamedHsDecl
72 rnDecl (ValD binds) = rnTopBinds binds `thenRn` \ new_binds ->
73 returnRn (ValD new_binds)
76 rnDecl (SigD (IfaceSig name ty id_infos loc))
78 lookupBndrRn name `thenRn` \ name' ->
79 rnHsType doc_str ty `thenRn` \ ty' ->
81 -- Get the pragma info (if any).
82 getModeRn `thenRn` \ (InterfaceMode _ print_unqual) ->
83 setModeRn (InterfaceMode Optional print_unqual) $
84 -- In all the rest of the signature we read in optional mode,
85 -- so that (a) we don't die
86 mapRn rnIdInfo id_infos `thenRn` \ id_infos' ->
87 returnRn (SigD (IfaceSig name' ty' id_infos' loc))
89 doc_str = text "the interface signature for" <+> quotes (ppr name)
92 %*********************************************************
94 \subsection{Type declarations}
96 %*********************************************************
98 @rnTyDecl@ uses the `global name function' to create a new type
99 declaration in which local names have been replaced by their original
100 names, reporting any unknown names.
102 Renaming type variables is a pain. Because they now contain uniques,
103 it is necessary to pass in an association list which maps a parsed
104 tyvar to its Name representation. In some cases (type signatures of
105 values), it is even necessary to go over the type first in order to
106 get the set of tyvars used by it, make an assoc list, and then go over
107 it again to rename the tyvars! However, we can also do some scoping
108 checks at the same time.
111 rnDecl (TyD (TyData new_or_data context tycon tyvars condecls derivings pragmas src_loc))
112 = pushSrcLocRn src_loc $
113 lookupBndrRn tycon `thenRn` \ tycon' ->
114 bindTyVarsRn data_doc tyvars $ \ tyvars' ->
115 rnContext data_doc context `thenRn` \ context' ->
116 checkDupOrQualNames data_doc con_names `thenRn_`
117 mapRn rnConDecl condecls `thenRn` \ condecls' ->
118 rnDerivs derivings `thenRn` \ derivings' ->
119 ASSERT(isNoDataPragmas pragmas)
120 returnRn (TyD (TyData new_or_data context' tycon' tyvars' condecls' derivings' noDataPragmas src_loc))
122 data_doc = text "the data type declaration for" <+> ppr tycon
123 con_names = map conDeclName condecls
125 rnDecl (TyD (TySynonym name tyvars ty src_loc))
126 = pushSrcLocRn src_loc $
127 lookupBndrRn name `thenRn` \ name' ->
128 bindTyVarsRn syn_doc tyvars $ \ tyvars' ->
129 rnHsType syn_doc ty `thenRn` \ ty' ->
130 returnRn (TyD (TySynonym name' tyvars' ty' src_loc))
132 syn_doc = text "the declaration for type synonym" <+> quotes (ppr name)
135 %*********************************************************
137 \subsection{Class declarations}
139 %*********************************************************
141 @rnClassDecl@ uses the `global name function' to create a new
142 class declaration in which local names have been replaced by their
143 original names, reporting any unknown names.
146 rnDecl (ClD (ClassDecl context cname tyvars sigs mbinds pragmas tname dname src_loc))
147 = pushSrcLocRn src_loc $
149 lookupBndrRn cname `thenRn` \ cname' ->
150 lookupBndrRn tname `thenRn` \ tname' ->
151 lookupBndrRn dname `thenRn` \ dname' ->
153 bindTyVarsRn cls_doc tyvars ( \ tyvars' ->
154 rnContext cls_doc context `thenRn` \ context' ->
156 -- Check the signatures
158 clas_tyvar_names = map getTyVarName tyvars'
160 checkDupOrQualNames sig_doc sig_rdr_names_w_locs `thenRn_`
161 mapRn (rn_op cname' clas_tyvar_names) sigs `thenRn` \ sigs' ->
162 returnRn (tyvars', context', sigs')
163 ) `thenRn` \ (tyvars', context', sigs') ->
166 checkDupOrQualNames meth_doc meth_rdr_names_w_locs `thenRn_`
167 rnMethodBinds mbinds `thenRn` \ mbinds' ->
169 -- Typechecker is responsible for checking that we only
170 -- give default-method bindings for things in this class.
171 -- The renamer *could* check this for class decls, but can't
172 -- for instance decls.
174 ASSERT(isNoClassPragmas pragmas)
175 returnRn (ClD (ClassDecl context' cname' tyvars' sigs' mbinds' NoClassPragmas tname' dname' src_loc))
177 cls_doc = text "the declaration for class" <+> ppr cname
178 sig_doc = text "the signatures for class" <+> ppr cname
179 meth_doc = text "the default-methods for class" <+> ppr cname
181 sig_rdr_names_w_locs = [(op,locn) | ClassOpSig op _ _ locn <- sigs]
182 meth_rdr_names_w_locs = bagToList (collectMonoBinders mbinds)
183 meth_rdr_names = map fst meth_rdr_names_w_locs
185 rn_op clas clas_tyvars sig@(ClassOpSig op maybe_dm ty locn)
186 = pushSrcLocRn locn $
187 lookupBndrRn op `thenRn` \ op_name ->
188 rnHsSigType (quotes (ppr op)) ty `thenRn` \ new_ty ->
190 -- Make the default-method name
192 dm_occ = mkDefaultMethodName (rdrNameOcc op)
194 getModuleRn `thenRn` \ mod_name ->
195 getModeRn `thenRn` \ mode ->
196 (case (mode, maybe_dm) of
197 (SourceMode, _) | op `elem` meth_rdr_names
198 -> -- There's an explicit method decl
199 newLocallyDefinedGlobalName mod_name dm_occ
200 (\_ -> Exported) locn `thenRn` \ dm_name ->
201 returnRn (Just dm_name)
203 (InterfaceMode _ _, Just _)
204 -> -- Imported class that has a default method decl
205 newImportedGlobalName mod_name dm_occ (ifaceFlavour clas) `thenRn` \ dm_name ->
206 addOccurrenceName dm_name `thenRn_`
207 returnRn (Just dm_name)
209 other -> returnRn Nothing
210 ) `thenRn` \ maybe_dm_name ->
212 -- Check that each class tyvar appears in op_ty
214 (ctxt, op_ty) = case new_ty of
215 HsForAllTy tvs ctxt op_ty -> (ctxt, op_ty)
216 other -> ([], new_ty)
217 ctxt_fvs = extractHsCtxtTyNames ctxt -- Includes tycons/classes but we
218 op_ty_fvs = extractHsTyNames op_ty -- don't care about that
220 check_in_op_ty clas_tyvar = checkRn (clas_tyvar `elemNameSet` op_ty_fvs)
221 (classTyVarNotInOpTyErr clas_tyvar sig)
223 mapRn check_in_op_ty clas_tyvars `thenRn_`
225 returnRn (ClassOpSig op_name maybe_dm_name new_ty locn)
229 %*********************************************************
231 \subsection{Instance declarations}
233 %*********************************************************
236 rnDecl (InstD (InstDecl inst_ty mbinds uprags maybe_dfun src_loc))
237 = pushSrcLocRn src_loc $
238 rnHsSigType (text "an instance decl") inst_ty `thenRn` \ inst_ty' ->
241 -- Rename the bindings
242 -- NB meth_names can be qualified!
243 checkDupNames meth_doc meth_names `thenRn_`
244 rnMethodBinds mbinds `thenRn` \ mbinds' ->
246 binders = mkNameSet (map fst (bagToList (collectMonoBinders mbinds')))
248 renameSigs NotTopLevel True binders uprags `thenRn` \ new_uprags ->
251 -- We use the class name and the name of the first
252 -- type constructor the class is applied to.
253 (cl_nm, tycon_nm) = mkDictPrefix inst_ty'
255 mkDictPrefix (MonoDictTy cl tys) =
257 [] -> (c_nm, nilOccName )
258 (ty:_) -> (c_nm, getInstHeadTy ty)
260 c_nm = nameOccName (getName cl)
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 doc_str) tys `thenRn` \ tys' ->
298 lookupImplicitOccRn numClass_RDR `thenRn_`
299 returnRn (DefD (DefaultDecl tys' src_loc))
301 doc_str = text "a `default' declaration"
304 %*********************************************************
306 \subsection{Foreign declarations}
308 %*********************************************************
311 rnDecl (ForD (ForeignDecl name imp_exp ty ext_nm cconv src_loc))
312 = pushSrcLocRn src_loc $
313 lookupBndrRn name `thenRn` \ name' ->
315 FoImport _ | not isDyn -> addImplicitOccRn name'
316 FoLabel -> addImplicitOccRn name'
318 addImplicitOccRn makeStablePtr_NAME `thenRn_`
319 addImplicitOccRn deRefStablePtr_NAME `thenRn_`
320 addImplicitOccRn bindIO_NAME `thenRn_`
322 _ -> returnRn name') `thenRn_`
323 rnHsSigType fo_decl_msg ty `thenRn` \ ty' ->
324 returnRn (ForD (ForeignDecl name' imp_exp ty' ext_nm cconv src_loc))
326 fo_decl_msg = ptext SLIT("a foreign declaration")
327 isDyn = isDynamic ext_nm
331 %*********************************************************
333 \subsection{Support code for type/data declarations}
335 %*********************************************************
338 rnDerivs :: Maybe [RdrName] -> RnMS s (Maybe [Name])
340 rnDerivs Nothing -- derivs not specified
344 = mapRn rn_deriv ds `thenRn` \ derivs ->
345 returnRn (Just derivs)
348 = lookupOccRn clas `thenRn` \ clas_name ->
350 -- Now add extra "occurrences" for things that
351 -- the deriving mechanism will later need in order to
352 -- generate code for this class.
353 case lookupUFM derivingOccurrences clas_name of
354 Nothing -> addErrRn (derivingNonStdClassErr clas_name) `thenRn_`
357 Just occs -> mapRn lookupImplicitOccRn occs `thenRn_`
362 conDeclName :: RdrNameConDecl -> (RdrName, SrcLoc)
363 conDeclName (ConDecl n _ _ _ l) = (n,l)
365 rnConDecl :: RdrNameConDecl -> RnMS s RenamedConDecl
366 rnConDecl (ConDecl name tvs cxt details locn)
367 = pushSrcLocRn locn $
368 checkConName name `thenRn_`
369 lookupBndrRn name `thenRn` \ new_name ->
370 bindTyVarsRn doc tvs $ \ new_tyvars ->
371 rnContext doc cxt `thenRn` \ new_context ->
372 rnConDetails doc locn details `thenRn` \ new_details ->
373 returnRn (ConDecl new_name new_tyvars new_context new_details locn)
375 doc = text "the definition of data constructor" <+> quotes (ppr name)
377 rnConDetails doc locn (VanillaCon tys)
378 = mapRn (rnBangTy doc) tys `thenRn` \ new_tys ->
379 returnRn (VanillaCon new_tys)
381 rnConDetails doc locn (InfixCon ty1 ty2)
382 = rnBangTy doc ty1 `thenRn` \ new_ty1 ->
383 rnBangTy doc ty2 `thenRn` \ new_ty2 ->
384 returnRn (InfixCon new_ty1 new_ty2)
386 rnConDetails doc locn (NewCon ty)
387 = rnHsType doc ty `thenRn` \ new_ty ->
388 returnRn (NewCon new_ty)
390 rnConDetails doc locn (RecCon fields)
391 = checkDupOrQualNames doc field_names `thenRn_`
392 mapRn (rnField doc) fields `thenRn` \ new_fields ->
393 returnRn (RecCon new_fields)
395 field_names = [(fld, locn) | (flds, _) <- fields, fld <- flds]
397 rnField doc (names, ty)
398 = mapRn lookupBndrRn names `thenRn` \ new_names ->
399 rnBangTy doc ty `thenRn` \ new_ty ->
400 returnRn (new_names, new_ty)
402 rnBangTy doc (Banged ty)
403 = rnHsType doc ty `thenRn` \ new_ty ->
404 returnRn (Banged new_ty)
406 rnBangTy doc (Unbanged ty)
407 = rnHsType doc ty `thenRn` \ new_ty ->
408 returnRn (Unbanged new_ty)
410 -- This data decl will parse OK
412 -- treating "a" as the constructor.
413 -- It is really hard to make the parser spot this malformation.
414 -- So the renamer has to check that the constructor is legal
416 -- We can get an operator as the constructor, even in the prefix form:
417 -- data T = :% Int Int
418 -- from interface files, which always print in prefix form
421 = checkRn (isLexCon (occNameString (rdrNameOcc name)))
426 %*********************************************************
428 \subsection{Support code to rename types}
430 %*********************************************************
433 rnHsSigType :: SDoc -> RdrNameHsType -> RnMS s RenamedHsType
434 -- rnHsSigType is used for source-language type signatures,
435 -- which use *implicit* universal quantification.
436 rnHsSigType doc_str ty = rnHsType (text "the type signature for" <+> doc_str) ty
441 rnHsType :: SDoc -> RdrNameHsType -> RnMS s RenamedHsType
443 rnHsType doc (HsForAllTy [] ctxt ty)
444 -- From source code (no kinds on tyvars)
446 -- Given the signature C => T we universally quantify
447 -- over FV(T) \ {in-scope-tyvars}
449 -- We insist that the universally quantified type vars is a superset of FV(C)
450 -- It follows that FV(T) is a superset of FV(C), so that the context constrains
451 -- no type variables that don't appear free in the tau-type part.
453 = getLocalNameEnv `thenRn` \ name_env ->
455 mentioned_tyvars = extractHsTyVars ty
456 forall_tyvars = filter (not . (`elemFM` name_env)) mentioned_tyvars
458 ctxt_w_ftvs :: [((RdrName,[RdrNameHsType]), [RdrName])]
459 ctxt_w_ftvs = [ (constraint, foldr ((++) . extractHsTyVars) [] tys)
460 | constraint@(_,tys) <- ctxt]
462 -- A 'non-poly constraint' is one that does not mention *any*
463 -- of the forall'd type variables
464 non_poly_constraints = filter non_poly ctxt_w_ftvs
465 non_poly (c,ftvs) = not (any (`elem` forall_tyvars) ftvs)
467 -- A 'non-mentioned' constraint is one that mentions a
468 -- type variable that does not appear in 'ty'
469 non_mentioned_constraints = filter non_mentioned ctxt_w_ftvs
470 non_mentioned (c,ftvs) = any (not . (`elem` mentioned_tyvars)) ftvs
472 -- Zap the context if there's a problem, to avoid duplicate error message.
473 ctxt' | null non_poly_constraints && null non_mentioned_constraints = ctxt
476 mapRn (ctxtErr1 doc forall_tyvars ty) non_poly_constraints `thenRn_`
477 mapRn (ctxtErr2 doc ty) non_mentioned_constraints `thenRn_`
479 (bindTyVarsRn doc (map UserTyVar forall_tyvars) $ \ new_tyvars ->
480 rnContext doc ctxt' `thenRn` \ new_ctxt ->
481 rnHsType doc ty `thenRn` \ new_ty ->
482 returnRn (mkHsForAllTy new_tyvars new_ctxt new_ty))
484 rnHsType doc (HsForAllTy tvs ctxt ty)
485 -- tvs are non-empty, hence must be from an interface file
486 -- (tyvars may be kinded)
487 = bindTyVarsRn doc tvs $ \ new_tyvars ->
488 rnContext doc ctxt `thenRn` \ new_ctxt ->
489 rnHsType doc ty `thenRn` \ new_ty ->
490 returnRn (mkHsForAllTy new_tyvars new_ctxt new_ty)
493 rnHsType doc (MonoTyVar tyvar)
494 = lookupOccRn tyvar `thenRn` \ tyvar' ->
495 returnRn (MonoTyVar tyvar')
497 rnHsType doc (MonoFunTy ty1 ty2)
498 = andRn MonoFunTy (rnHsType doc ty1) (rnHsType doc ty2)
500 rnHsType doc (MonoListTy ty)
501 = addImplicitOccRn listTyCon_name `thenRn_`
502 rnHsType doc ty `thenRn` \ ty' ->
503 returnRn (MonoListTy ty')
505 rnHsType doc (MonoTupleTy tys boxed)
506 = addImplicitOccRn (tupleTyCon_name boxed (length tys)) `thenRn_`
507 mapRn (rnHsType doc) tys `thenRn` \ tys' ->
508 returnRn (MonoTupleTy tys' boxed)
510 rnHsType doc (MonoTyApp ty1 ty2)
511 = rnHsType doc ty1 `thenRn` \ ty1' ->
512 rnHsType doc ty2 `thenRn` \ ty2' ->
513 returnRn (MonoTyApp ty1' ty2')
515 rnHsType doc (MonoDictTy clas tys)
516 = lookupOccRn clas `thenRn` \ clas' ->
517 mapRn (rnHsType doc) tys `thenRn` \ tys' ->
518 returnRn (MonoDictTy clas' tys')
523 rnContext :: SDoc -> RdrNameContext -> RnMS s RenamedContext
526 = mapRn rn_ctxt ctxt `thenRn` \ theta ->
528 (_, dup_asserts) = removeDups cmp_assert theta
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_`
537 = lookupBndrRn clas `thenRn` \ clas_name ->
538 addOccurrenceName clas_name `thenRn_`
539 mapRn (rnHsType doc) tys `thenRn` \ tys' ->
540 returnRn (clas_name, tys')
542 cmp_assert (c1,tys1) (c2,tys2)
543 = (c1 `compare` c2) `thenCmp` (cmpHsTypes compare tys1 tys2)
547 %*********************************************************
551 %*********************************************************
554 rnIdInfo (HsStrictness strict)
555 = rnStrict strict `thenRn` \ strict' ->
556 returnRn (HsStrictness strict')
558 rnIdInfo (HsUnfold inline (Just expr)) = rnCoreExpr expr `thenRn` \ expr' ->
559 returnRn (HsUnfold inline (Just expr'))
560 rnIdInfo (HsUnfold inline Nothing) = returnRn (HsUnfold inline Nothing)
561 rnIdInfo (HsArity arity) = returnRn (HsArity arity)
562 rnIdInfo (HsUpdate update) = returnRn (HsUpdate update)
563 rnIdInfo (HsNoCafRefs) = returnRn (HsNoCafRefs)
564 rnIdInfo (HsSpecialise tyvars tys expr)
565 = bindTyVarsRn doc tyvars $ \ tyvars' ->
566 rnCoreExpr expr `thenRn` \ expr' ->
567 mapRn (rnHsType doc) tys `thenRn` \ tys' ->
568 returnRn (HsSpecialise tyvars' tys' expr')
570 doc = text "Specialise in interface pragma"
573 rnStrict (HsStrictnessInfo demands (Just (worker,cons)))
574 -- The sole purpose of the "cons" field is so that we can mark the constructors
575 -- needed to build the wrapper as "needed", so that their data type decl will be
576 -- slurped in. After that their usefulness is o'er, so we just put in the empty list.
577 = lookupOccRn worker `thenRn` \ worker' ->
578 mapRn lookupOccRn cons `thenRn_`
579 returnRn (HsStrictnessInfo demands (Just (worker',[])))
581 -- Boring, but necessary for the type checker.
582 rnStrict (HsStrictnessInfo demands Nothing) = returnRn (HsStrictnessInfo demands Nothing)
583 rnStrict HsBottom = returnRn HsBottom
589 rnCoreExpr (UfType ty)
590 = rnHsType (text "unfolding type") ty `thenRn` \ ty' ->
591 returnRn (UfType ty')
594 = lookupOccRn v `thenRn` \ v' ->
597 rnCoreExpr (UfCon con args)
598 = rnUfCon con `thenRn` \ con' ->
599 mapRn rnCoreExpr args `thenRn` \ args' ->
600 returnRn (UfCon con' args')
602 rnCoreExpr (UfTuple con args)
603 = lookupOccRn con `thenRn` \ con' ->
604 mapRn rnCoreExpr args `thenRn` \ args' ->
605 returnRn (UfTuple con' args')
607 rnCoreExpr (UfApp fun arg)
608 = rnCoreExpr fun `thenRn` \ fun' ->
609 rnCoreExpr arg `thenRn` \ arg' ->
610 returnRn (UfApp fun' arg')
612 rnCoreExpr (UfCase scrut bndr alts)
613 = rnCoreExpr scrut `thenRn` \ scrut' ->
614 bindLocalsRn "UfCase" [bndr] $ \ [bndr'] ->
615 mapRn rnCoreAlt alts `thenRn` \ alts' ->
616 returnRn (UfCase scrut' bndr' alts')
618 rnCoreExpr (UfNote note expr)
619 = rnNote note `thenRn` \ note' ->
620 rnCoreExpr expr `thenRn` \ expr' ->
621 returnRn (UfNote note' expr')
623 rnCoreExpr (UfLam bndr body)
624 = rnCoreBndr bndr $ \ bndr' ->
625 rnCoreExpr body `thenRn` \ body' ->
626 returnRn (UfLam bndr' body')
628 rnCoreExpr (UfLet (UfNonRec bndr rhs) body)
629 = rnCoreExpr rhs `thenRn` \ rhs' ->
630 rnCoreBndr bndr $ \ bndr' ->
631 rnCoreExpr body `thenRn` \ body' ->
632 returnRn (UfLet (UfNonRec bndr' rhs') body')
634 rnCoreExpr (UfLet (UfRec pairs) body)
635 = rnCoreBndrs bndrs $ \ bndrs' ->
636 mapRn rnCoreExpr rhss `thenRn` \ rhss' ->
637 rnCoreExpr body `thenRn` \ body' ->
638 returnRn (UfLet (UfRec (bndrs' `zip` rhss')) body')
640 (bndrs, rhss) = unzip pairs
644 rnCoreBndr (UfValBinder name ty) thing_inside
645 = rnHsType (text str) ty `thenRn` \ ty' ->
646 bindLocalsRn str [name] $ \ [name'] ->
647 thing_inside (UfValBinder name' ty')
651 rnCoreBndr (UfTyBinder name kind) thing_inside
652 = bindLocalsRn "unfolding tyvar" [name] $ \ [name'] ->
653 thing_inside (UfTyBinder name' kind)
655 rnCoreBndrs bndrs thing_inside -- Expect them all to be ValBinders
656 = mapRn (rnHsType (text str)) tys `thenRn` \ tys' ->
657 bindLocalsRn str names $ \ names' ->
658 thing_inside (zipWith UfValBinder names' tys')
661 names = map (\ (UfValBinder name _ ) -> name) bndrs
662 tys = map (\ (UfValBinder _ ty) -> ty) bndrs
666 rnCoreAlt (con, bndrs, rhs)
667 = rnUfCon con `thenRn` \ con' ->
668 bindLocalsRn "unfolding alt" bndrs $ \ bndrs' ->
669 rnCoreExpr rhs `thenRn` \ rhs' ->
670 returnRn (con', bndrs', rhs')
674 = rnHsType (text "unfolding coerce") ty `thenRn` \ ty' ->
675 returnRn (UfCoerce ty')
677 rnNote (UfSCC cc) = returnRn (UfSCC cc)
678 rnNote UfInlineCall = returnRn UfInlineCall
684 rnUfCon (UfDataCon con)
685 = lookupOccRn con `thenRn` \ con' ->
686 returnRn (UfDataCon con')
688 rnUfCon (UfLitCon lit)
689 = returnRn (UfLitCon lit)
691 rnUfCon (UfLitLitCon lit ty)
692 = rnHsType (text "litlit") ty `thenRn` \ ty' ->
693 returnRn (UfLitLitCon lit ty')
695 rnUfCon (UfPrimOp op)
696 = lookupOccRn op `thenRn` \ op' ->
697 returnRn (UfPrimOp op')
699 rnUfCon (UfCCallOp str casm gc)
700 = returnRn (UfCCallOp str casm gc)
703 %*********************************************************
707 %*********************************************************
710 derivingNonStdClassErr clas
711 = hsep [ptext SLIT("non-standard class"), ppr clas, ptext SLIT("in deriving clause")]
713 classTyVarNotInOpTyErr clas_tyvar sig
714 = hang (hsep [ptext SLIT("Class type variable"),
715 quotes (ppr clas_tyvar),
716 ptext SLIT("does not appear in method signature")])
719 dupClassAssertWarn ctxt (assertion : dups)
720 = sep [hsep [ptext SLIT("Duplicate class assertion"),
721 quotes (pprClassAssertion assertion),
722 ptext SLIT("in the context:")],
723 nest 4 (pprContext ctxt)]
726 = hsep [ptext SLIT("Illegal data constructor name"), quotes (ppr name)]
728 ctxtErr1 doc tyvars ty (constraint, _)
730 sep [ptext SLIT("The constraint") <+> quotes (pprClassAssertion constraint) <+>
731 ptext SLIT("does not mention any of"),
732 nest 4 (ptext SLIT("the universally quantified type variables") <+> braces (interpp'SP tyvars)),
733 nest 4 (ptext SLIT("of the type") <+> quotes (ppr ty))
736 (ptext SLIT("In") <+> doc)
739 ctxtErr2 doc ty (constraint,_)
741 sep [ptext SLIT("The constraint") <+> quotes (pprClassAssertion constraint),
742 nest 4 (ptext SLIT("mentions type variables that do not appear in the type")),
743 nest 4 (quotes (ppr ty))]
745 (ptext SLIT("In") <+> doc)