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,
41 import Maybes ( maybeToBool )
42 import Bag ( bagToList )
44 import SrcLoc ( SrcLoc )
45 import Unique ( Unique )
46 import UniqSet ( UniqSet )
47 import UniqFM ( UniqFM, lookupUFM )
49 import List ( partition, nub )
52 rnDecl `renames' declarations.
53 It simultaneously performs dependency analysis and precedence parsing.
54 It also does the following error checks:
57 Checks that tyvars are used properly. This includes checking
58 for undefined tyvars, and tyvars in contexts that are ambiguous.
60 Checks that all variable occurences are defined.
62 Checks the (..) etc constraints in the export list.
66 %*********************************************************
68 \subsection{Value declarations}
70 %*********************************************************
73 rnDecl :: RdrNameHsDecl -> RnMS s RenamedHsDecl
75 rnDecl (ValD binds) = rnTopBinds binds `thenRn` \ new_binds ->
76 returnRn (ValD new_binds)
79 rnDecl (SigD (IfaceSig name ty id_infos loc))
81 lookupBndrRn name `thenRn` \ name' ->
82 rnHsType ty `thenRn` \ ty' ->
84 -- Get the pragma info (if any).
85 getModeRn `thenRn` \ (InterfaceMode _ print_unqual) ->
86 setModeRn (InterfaceMode Optional print_unqual) $
87 -- In all the rest of the signature we read in optional mode,
88 -- so that (a) we don't die
89 mapRn rnIdInfo id_infos `thenRn` \ id_infos' ->
90 returnRn (SigD (IfaceSig name' ty' id_infos' loc))
93 %*********************************************************
95 \subsection{Type declarations}
97 %*********************************************************
99 @rnTyDecl@ uses the `global name function' to create a new type
100 declaration in which local names have been replaced by their original
101 names, reporting any unknown names.
103 Renaming type variables is a pain. Because they now contain uniques,
104 it is necessary to pass in an association list which maps a parsed
105 tyvar to its Name representation. In some cases (type signatures of
106 values), it is even necessary to go over the type first in order to
107 get the set of tyvars used by it, make an assoc list, and then go over
108 it again to rename the tyvars! However, we can also do some scoping
109 checks at the same time.
112 rnDecl (TyD (TyData new_or_data context tycon tyvars condecls derivings pragmas src_loc))
113 = pushSrcLocRn src_loc $
114 lookupBndrRn tycon `thenRn` \ tycon' ->
115 bindTyVarsRn data_doc tyvars $ \ tyvars' ->
116 rnContext context `thenRn` \ context' ->
117 checkDupOrQualNames data_doc con_names `thenRn_`
118 mapRn rnConDecl condecls `thenRn` \ condecls' ->
119 rnDerivs derivings `thenRn` \ derivings' ->
120 ASSERT(isNoDataPragmas pragmas)
121 returnRn (TyD (TyData new_or_data context' tycon' tyvars' condecls' derivings' noDataPragmas src_loc))
123 data_doc = text "the data type declaration for" <+> ppr tycon
124 con_names = map conDeclName condecls
126 rnDecl (TyD (TySynonym name tyvars ty src_loc))
127 = pushSrcLocRn src_loc $
128 lookupBndrRn name `thenRn` \ name' ->
129 bindTyVarsRn syn_doc tyvars $ \ tyvars' ->
130 rnHsType ty `thenRn` \ ty' ->
131 returnRn (TyD (TySynonym name' tyvars' ty' src_loc))
133 syn_doc = text "the declaration for type synonym" <+> ppr name
136 %*********************************************************
138 \subsection{Class declarations}
140 %*********************************************************
142 @rnClassDecl@ uses the `global name function' to create a new
143 class declaration in which local names have been replaced by their
144 original names, reporting any unknown names.
147 rnDecl (ClD (ClassDecl context cname tyvars sigs mbinds pragmas tname dname src_loc))
148 = pushSrcLocRn src_loc $
150 lookupBndrRn cname `thenRn` \ cname' ->
151 lookupBndrRn tname `thenRn` \ tname' ->
152 lookupBndrRn dname `thenRn` \ dname' ->
154 bindTyVarsRn cls_doc tyvars ( \ tyvars' ->
155 rnContext context `thenRn` \ context' ->
157 -- Check the signatures
159 clas_tyvar_names = map getTyVarName tyvars'
161 checkDupOrQualNames sig_doc sig_rdr_names_w_locs `thenRn_`
162 mapRn (rn_op cname' clas_tyvar_names) sigs `thenRn` \ sigs' ->
163 returnRn (tyvars', context', sigs')
164 ) `thenRn` \ (tyvars', context', sigs') ->
167 checkDupOrQualNames meth_doc meth_rdr_names_w_locs `thenRn_`
168 rnMethodBinds mbinds `thenRn` \ mbinds' ->
170 -- Typechecker is responsible for checking that we only
171 -- give default-method bindings for things in this class.
172 -- The renamer *could* check this for class decls, but can't
173 -- for instance decls.
175 ASSERT(isNoClassPragmas pragmas)
176 returnRn (ClD (ClassDecl context' cname' tyvars' sigs' mbinds' NoClassPragmas tname' dname' src_loc))
178 cls_doc = text "the declaration for class" <+> ppr cname
179 sig_doc = text "the signatures for class" <+> ppr cname
180 meth_doc = text "the default-methods for class" <+> ppr cname
182 sig_rdr_names_w_locs = [(op,locn) | ClassOpSig op _ _ locn <- sigs]
183 meth_rdr_names_w_locs = bagToList (collectMonoBinders mbinds)
184 meth_rdr_names = map fst meth_rdr_names_w_locs
186 rn_op clas clas_tyvars sig@(ClassOpSig op maybe_dm ty locn)
187 = pushSrcLocRn locn $
188 lookupBndrRn op `thenRn` \ op_name ->
189 rnHsSigType (quotes (ppr op)) ty `thenRn` \ new_ty ->
191 -- Make the default-method name
193 dm_occ = prefixOccName SLIT("$m") (rdrNameOcc op)
195 getModuleRn `thenRn` \ mod_name ->
196 getModeRn `thenRn` \ mode ->
197 (case (mode, maybe_dm) of
198 (SourceMode, _) | op `elem` meth_rdr_names
199 -> -- There's an explicit method decl
200 newLocallyDefinedGlobalName mod_name dm_occ
201 (\_ -> Exported) locn `thenRn` \ dm_name ->
202 returnRn (Just dm_name)
204 (InterfaceMode _ _, Just _)
205 -> -- Imported class that has a default method decl
206 newImportedGlobalName mod_name dm_occ (ifaceFlavour clas) `thenRn` \ dm_name ->
207 addOccurrenceName dm_name `thenRn_`
208 returnRn (Just dm_name)
210 other -> returnRn Nothing
211 ) `thenRn` \ maybe_dm_name ->
213 -- Check that each class tyvar appears in op_ty
215 (ctxt, op_ty) = case new_ty of
216 HsForAllTy tvs ctxt op_ty -> (ctxt, op_ty)
217 other -> ([], new_ty)
218 ctxt_fvs = extractHsCtxtTyNames ctxt -- Includes tycons/classes but we
219 op_ty_fvs = extractHsTyNames op_ty -- don't care about that
221 check_in_op_ty clas_tyvar = checkRn (clas_tyvar `elemNameSet` op_ty_fvs)
222 (classTyVarNotInOpTyErr clas_tyvar sig)
224 mapRn check_in_op_ty clas_tyvars `thenRn_`
226 returnRn (ClassOpSig op_name maybe_dm_name new_ty locn)
230 %*********************************************************
232 \subsection{Instance declarations}
234 %*********************************************************
237 rnDecl (InstD (InstDecl inst_ty mbinds uprags maybe_dfun src_loc))
238 = pushSrcLocRn src_loc $
239 rnHsSigType (text "an instance decl") inst_ty `thenRn` \ inst_ty' ->
242 -- Rename the bindings
243 -- NB meth_names can be qualified!
244 checkDupNames meth_doc meth_names `thenRn_`
245 rnMethodBinds mbinds `thenRn` \ mbinds' ->
247 binders = mkNameSet (map fst (bagToList (collectMonoBinders mbinds')))
249 renameSigs NotTopLevel True binders uprags `thenRn` \ new_uprags ->
252 -- We use the class name and the name of the first
253 -- type constructor the class is applied to.
254 (cl_nm, tycon_nm) = mkDictPrefix inst_ty'
256 mkDictPrefix (MonoDictTy cl tys) =
258 [] -> (c_nm, nilOccName )
259 (ty:_) -> (c_nm, getInstHeadTy ty)
261 c_nm = nameOccName (getName cl)
263 mkDictPrefix (HsPreForAllTy _ ty) = mkDictPrefix ty
264 mkDictPrefix (HsForAllTy _ _ ty) = mkDictPrefix ty -- can this
265 mkDictPrefix _ = (nilOccName, nilOccName)
269 MonoTyVar tv -> nameOccName (getName tv)
270 MonoTyApp t _ -> getInstHeadTy t
272 -- I cannot see how the rest of HsType constructors
273 -- can occur, but this isn't really a failure condition,
274 -- so we return silently.
276 nilOccName = (VarOcc _NIL_) -- ToDo: add OccName constructor fun for this.
278 newDfunName cl_nm tycon_nm maybe_dfun src_loc `thenRn` \ dfun_name ->
279 addOccurrenceName dfun_name `thenRn_`
280 -- The dfun is not optional, because we use its version number
281 -- to identify the version of the instance declaration
283 -- The typechecker checks that all the bindings are for the right class.
284 returnRn (InstD (InstDecl inst_ty' mbinds' new_uprags (Just dfun_name) src_loc))
286 meth_doc = text "the bindings in an instance declaration"
287 meth_names = bagToList (collectMonoBinders mbinds)
290 %*********************************************************
292 \subsection{Default declarations}
294 %*********************************************************
297 rnDecl (DefD (DefaultDecl tys src_loc))
298 = pushSrcLocRn src_loc $
299 mapRn rnHsType tys `thenRn` \ tys' ->
300 lookupImplicitOccRn numClass_RDR `thenRn_`
301 returnRn (DefD (DefaultDecl tys' src_loc))
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 addImplicitOccRn name'
317 returnRn name') `thenRn_`
318 rnHsSigType fo_decl_msg ty `thenRn` \ ty' ->
319 -- hack: force the constructors of IO to be slurped in,
320 -- since we need 'em when desugaring a foreign decl.
321 addImplicitOccRn ioOkDataCon_NAME `thenRn_`
322 returnRn (ForD (ForeignDecl name' imp_exp ty' ext_nm cconv src_loc))
324 fo_decl_msg = ptext SLIT("a foreign declaration")
326 not (isDynamic ext_nm) &&
333 %*********************************************************
335 \subsection{Support code for type/data declarations}
337 %*********************************************************
340 rnDerivs :: Maybe [RdrName] -> RnMS s (Maybe [Name])
342 rnDerivs Nothing -- derivs not specified
343 = lookupImplicitOccRn evalClass_RDR `thenRn_`
347 = lookupImplicitOccRn evalClass_RDR `thenRn_`
348 mapRn rn_deriv ds `thenRn` \ derivs ->
349 returnRn (Just derivs)
352 = lookupOccRn clas `thenRn` \ clas_name ->
354 -- Now add extra "occurrences" for things that
355 -- the deriving mechanism will later need in order to
356 -- generate code for this class.
357 case lookupUFM derivingOccurrences clas_name of
358 Nothing -> addErrRn (derivingNonStdClassErr clas_name) `thenRn_`
361 Just occs -> mapRn lookupImplicitOccRn occs `thenRn_`
366 conDeclName :: RdrNameConDecl -> (RdrName, SrcLoc)
367 conDeclName (ConDecl n _ _ l) = (n,l)
369 rnConDecl :: RdrNameConDecl -> RnMS s RenamedConDecl
370 rnConDecl (ConDecl name cxt details locn)
371 = pushSrcLocRn locn $
372 checkConName name `thenRn_`
373 lookupBndrRn name `thenRn` \ new_name ->
374 rnConDetails name locn details `thenRn` \ new_details ->
375 rnContext cxt `thenRn` \ new_context ->
376 returnRn (ConDecl new_name new_context new_details locn)
378 rnConDetails con locn (VanillaCon tys)
379 = mapRn rnBangTy tys `thenRn` \ new_tys ->
380 returnRn (VanillaCon new_tys)
382 rnConDetails con locn (InfixCon ty1 ty2)
383 = rnBangTy ty1 `thenRn` \ new_ty1 ->
384 rnBangTy ty2 `thenRn` \ new_ty2 ->
385 returnRn (InfixCon new_ty1 new_ty2)
387 rnConDetails con locn (NewCon ty)
388 = rnHsType ty `thenRn` \ new_ty ->
389 returnRn (NewCon new_ty)
391 rnConDetails con locn (RecCon fields)
392 = checkDupOrQualNames fld_doc field_names `thenRn_`
393 mapRn rnField fields `thenRn` \ new_fields ->
394 returnRn (RecCon new_fields)
396 fld_doc = text "the fields of constructor" <> ppr con
397 field_names = [(fld, locn) | (flds, _) <- fields, fld <- flds]
400 = mapRn lookupBndrRn names `thenRn` \ new_names ->
401 rnBangTy ty `thenRn` \ new_ty ->
402 returnRn (new_names, new_ty)
405 = rnHsType ty `thenRn` \ new_ty ->
406 returnRn (Banged new_ty)
408 rnBangTy (Unbanged ty)
409 = rnHsType ty `thenRn` \ new_ty ->
410 returnRn (Unbanged new_ty)
412 -- This data decl will parse OK
414 -- treating "a" as the constructor.
415 -- It is really hard to make the parser spot this malformation.
416 -- So the renamer has to check that the constructor is legal
418 -- We can get an operator as the constructor, even in the prefix form:
419 -- data T = :% Int Int
420 -- from interface files, which always print in prefix form
423 = checkRn (isLexCon (occNameString (rdrNameOcc name)))
428 %*********************************************************
430 \subsection{Support code to rename types}
432 %*********************************************************
435 rnHsSigType :: SDoc -> RdrNameHsType -> RnMS s RenamedHsType
436 -- rnHsSigType is used for source-language type signatures,
437 -- which use *implicit* universal quantification.
439 -- Given the signature C => T we universally quantify over FV(T) \ {in-scope-tyvars}
441 -- We insist that the universally quantified type vars is a superset of FV(C)
442 -- It follows that FV(T) is a superset of FV(C), so that the context constrains
443 -- no type variables that don't appear free in the tau-type part.
445 rnHsSigType doc_str full_ty@(HsPreForAllTy ctxt ty) -- From source code (no kinds on tyvars)
446 = getLocalNameEnv `thenRn` \ name_env ->
448 mentioned_tyvars = extractHsTyVars ty
449 forall_tyvars = filter (not . in_scope) mentioned_tyvars
450 in_scope tv = maybeToBool (lookupFM name_env tv)
452 constrained_tyvars = extractHsCtxtTyVars ctxt
453 constrained_and_in_scope = filter in_scope constrained_tyvars
454 constrained_and_not_mentioned = filter (not . (`elem` mentioned_tyvars)) constrained_tyvars
456 -- Zap the context if there's a problem, to avoid duplicate error message.
457 ctxt' | null constrained_and_in_scope && null constrained_and_not_mentioned = ctxt
460 checkRn (null constrained_and_in_scope)
461 (ctxtErr1 sig_doc constrained_and_in_scope) `thenRn_`
462 checkRn (null constrained_and_not_mentioned)
463 (ctxtErr2 sig_doc constrained_and_not_mentioned ty) `thenRn_`
465 (bindTyVarsRn sig_doc (map UserTyVar forall_tyvars) $ \ new_tyvars ->
466 rnContext ctxt' `thenRn` \ new_ctxt ->
467 rnHsType ty `thenRn` \ new_ty ->
468 returnRn (HsForAllTy new_tyvars new_ctxt new_ty)
471 sig_doc = text "the type signature for" <+> doc_str
474 rnHsSigType doc_str other_ty = rnHsType other_ty
476 rnHsType :: RdrNameHsType -> RnMS s RenamedHsType
477 rnHsType (HsForAllTy tvs ctxt ty) -- From an interface file (tyvars may be kinded)
478 = rn_poly_help tvs ctxt ty
480 rnHsType full_ty@(HsPreForAllTy ctxt ty) -- A (context => ty) embedded in a type.
481 -- Universally quantify over tyvars in context
482 = getLocalNameEnv `thenRn` \ name_env ->
484 forall_tyvars = extractHsCtxtTyVars ctxt
486 rn_poly_help (map UserTyVar forall_tyvars) ctxt ty
488 rnHsType (MonoTyVar tyvar)
489 = lookupOccRn tyvar `thenRn` \ tyvar' ->
490 returnRn (MonoTyVar tyvar')
492 rnHsType (MonoFunTy ty1 ty2)
493 = andRn MonoFunTy (rnHsType ty1) (rnHsType ty2)
495 rnHsType (MonoListTy _ ty)
496 = lookupImplicitOccRn listType_RDR `thenRn` \ tycon_name ->
497 rnHsType ty `thenRn` \ ty' ->
498 returnRn (MonoListTy tycon_name ty')
500 rnHsType (MonoTupleTy _ tys)
501 = lookupImplicitOccRn (tupleType_RDR (length tys)) `thenRn` \ tycon_name ->
502 mapRn rnHsType tys `thenRn` \ tys' ->
503 returnRn (MonoTupleTy tycon_name tys')
505 rnHsType (MonoTyApp ty1 ty2)
506 = rnHsType ty1 `thenRn` \ ty1' ->
507 rnHsType ty2 `thenRn` \ ty2' ->
508 returnRn (MonoTyApp ty1' ty2')
510 rnHsType (MonoDictTy clas tys)
511 = lookupOccRn clas `thenRn` \ clas' ->
512 mapRn rnHsType tys `thenRn` \ tys' ->
513 returnRn (MonoDictTy clas' tys')
515 rn_poly_help :: [HsTyVar RdrName] -- Universally quantified tyvars
518 -> RnMS s RenamedHsType
519 rn_poly_help tyvars ctxt ty
520 = bindTyVarsRn sig_doc tyvars $ \ new_tyvars ->
521 rnContext ctxt `thenRn` \ new_ctxt ->
522 rnHsType ty `thenRn` \ new_ty ->
523 returnRn (HsForAllTy new_tyvars new_ctxt new_ty)
525 sig_doc = text "a nested for-all type"
530 rnContext :: RdrNameContext -> RnMS s RenamedContext
533 = mapRn rn_ctxt ctxt `thenRn` \ result ->
535 (_, dup_asserts) = removeDups cmp_assert result
536 (alls, theta) = partition (\(c,_) -> c == allClass_NAME) result
539 -- Check for duplicate assertions
540 -- If this isn't an error, then it ought to be:
541 mapRn (addWarnRn . dupClassAssertWarn theta) dup_asserts `thenRn_`
543 -- Check for All constraining a non-type-variable
544 mapRn check_All alls `thenRn_`
546 -- Done. Return a theta omitting all the "All" constraints.
547 -- They have done done their work by ensuring that we universally
548 -- quantify over their tyvar.
552 = -- Mini hack here. If the class is our pseudo-class "All",
553 -- then we don't want to record it as an occurrence, otherwise
554 -- we try to slurp it in later and it doesn't really exist at all.
555 -- Easiest thing is simply not to put it in the occurrence set.
556 lookupBndrRn clas `thenRn` \ clas_name ->
557 (if clas_name /= allClass_NAME then
558 addOccurrenceName clas_name
562 mapRn rnHsType tys `thenRn` \ tys' ->
563 returnRn (clas_name, tys')
566 cmp_assert (c1,tys1) (c2,tys2)
567 = (c1 `compare` c2) `thenCmp` (cmpHsTypes compare tys1 tys2)
569 check_All (c, [MonoTyVar _]) = returnRn () -- OK!
570 check_All assertion = addErrRn (wierdAllErr assertion)
574 %*********************************************************
578 %*********************************************************
581 rnIdInfo (HsStrictness strict)
582 = rnStrict strict `thenRn` \ strict' ->
583 returnRn (HsStrictness strict')
585 rnIdInfo (HsUnfold inline expr) = rnCoreExpr expr `thenRn` \ expr' ->
586 returnRn (HsUnfold inline expr')
587 rnIdInfo (HsArity arity) = returnRn (HsArity arity)
588 rnIdInfo (HsUpdate update) = returnRn (HsUpdate update)
589 rnIdInfo (HsFBType fb) = returnRn (HsFBType fb)
590 rnIdInfo (HsArgUsage au) = returnRn (HsArgUsage au)
591 rnIdInfo (HsSpecialise tyvars tys expr)
592 = bindTyVarsRn doc tyvars $ \ tyvars' ->
593 rnCoreExpr expr `thenRn` \ expr' ->
594 mapRn rnHsType tys `thenRn` \ tys' ->
595 returnRn (HsSpecialise tyvars' tys' expr')
597 doc = text "Specialise in interface pragma"
600 rnStrict (HsStrictnessInfo demands (Just (worker,cons)))
601 -- The sole purpose of the "cons" field is so that we can mark the constructors
602 -- needed to build the wrapper as "needed", so that their data type decl will be
603 -- slurped in. After that their usefulness is o'er, so we just put in the empty list.
604 = lookupOccRn worker `thenRn` \ worker' ->
605 mapRn lookupOccRn cons `thenRn_`
606 returnRn (HsStrictnessInfo demands (Just (worker',[])))
608 -- Boring, but necessary for the type checker.
609 rnStrict (HsStrictnessInfo demands Nothing) = returnRn (HsStrictnessInfo demands Nothing)
610 rnStrict HsBottom = returnRn HsBottom
617 = lookupOccRn v `thenRn` \ v' ->
620 rnCoreExpr (UfLit lit) = returnRn (UfLit lit)
622 rnCoreExpr (UfCon con args)
623 = lookupOccRn con `thenRn` \ con' ->
624 mapRn rnCoreArg args `thenRn` \ args' ->
625 returnRn (UfCon con' args')
627 rnCoreExpr (UfPrim prim args)
628 = rnCorePrim prim `thenRn` \ prim' ->
629 mapRn rnCoreArg args `thenRn` \ args' ->
630 returnRn (UfPrim prim' args')
632 rnCoreExpr (UfApp fun arg)
633 = rnCoreExpr fun `thenRn` \ fun' ->
634 rnCoreArg arg `thenRn` \ arg' ->
635 returnRn (UfApp fun' arg')
637 rnCoreExpr (UfCase scrut alts)
638 = rnCoreExpr scrut `thenRn` \ scrut' ->
639 rnCoreAlts alts `thenRn` \ alts' ->
640 returnRn (UfCase scrut' alts')
642 rnCoreExpr (UfNote note expr)
643 = rnNote note `thenRn` \ note' ->
644 rnCoreExpr expr `thenRn` \ expr' ->
645 returnRn (UfNote note' expr')
647 rnCoreExpr (UfLam bndr body)
648 = rnCoreBndr bndr $ \ bndr' ->
649 rnCoreExpr body `thenRn` \ body' ->
650 returnRn (UfLam bndr' body')
652 rnCoreExpr (UfLet (UfNonRec bndr rhs) body)
653 = rnCoreExpr rhs `thenRn` \ rhs' ->
654 rnCoreBndr bndr $ \ bndr' ->
655 rnCoreExpr body `thenRn` \ body' ->
656 returnRn (UfLet (UfNonRec bndr' rhs') body')
658 rnCoreExpr (UfLet (UfRec pairs) body)
659 = rnCoreBndrs bndrs $ \ bndrs' ->
660 mapRn rnCoreExpr rhss `thenRn` \ rhss' ->
661 rnCoreExpr body `thenRn` \ body' ->
662 returnRn (UfLet (UfRec (bndrs' `zip` rhss')) body')
664 (bndrs, rhss) = unzip pairs
668 rnCoreBndr (UfValBinder name ty) thing_inside
669 = rnHsType ty `thenRn` \ ty' ->
670 bindLocalsRn "unfolding value" [name] $ \ [name'] ->
671 thing_inside (UfValBinder name' ty')
673 rnCoreBndr (UfTyBinder name kind) thing_inside
674 = bindLocalsRn "unfolding tyvar" [name] $ \ [name'] ->
675 thing_inside (UfTyBinder name' kind)
677 rnCoreBndrs bndrs thing_inside -- Expect them all to be ValBinders
678 = mapRn rnHsType tys `thenRn` \ tys' ->
679 bindLocalsRn "unfolding value" names $ \ names' ->
680 thing_inside (zipWith UfValBinder names' tys')
682 names = map (\ (UfValBinder name _) -> name) bndrs
683 tys = map (\ (UfValBinder _ ty) -> ty) bndrs
685 rnCoreBndrNamess names thing_inside
686 = bindLocalsRn "unfolding value" names $ \ names' ->
691 rnCoreArg (UfVarArg v) = lookupOccRn v `thenRn` \ v' -> returnRn (UfVarArg v')
692 rnCoreArg (UfTyArg ty) = rnHsType ty `thenRn` \ ty' -> returnRn (UfTyArg ty')
693 rnCoreArg (UfLitArg lit) = returnRn (UfLitArg lit)
695 rnCoreAlts (UfAlgAlts alts deflt)
696 = mapRn rn_alt alts `thenRn` \ alts' ->
697 rnCoreDefault deflt `thenRn` \ deflt' ->
698 returnRn (UfAlgAlts alts' deflt')
700 rn_alt (con, bndrs, rhs) = lookupOccRn con `thenRn` \ con' ->
701 bindLocalsRn "unfolding alt" bndrs $ \ bndrs' ->
702 rnCoreExpr rhs `thenRn` \ rhs' ->
703 returnRn (con', bndrs', rhs')
705 rnCoreAlts (UfPrimAlts alts deflt)
706 = mapRn rn_alt alts `thenRn` \ alts' ->
707 rnCoreDefault deflt `thenRn` \ deflt' ->
708 returnRn (UfPrimAlts alts' deflt')
710 rn_alt (lit, rhs) = rnCoreExpr rhs `thenRn` \ rhs' ->
713 rnCoreDefault UfNoDefault = returnRn UfNoDefault
714 rnCoreDefault (UfBindDefault bndr rhs) = bindLocalsRn "unfolding default" [bndr] $ \ [bndr'] ->
715 rnCoreExpr rhs `thenRn` \ rhs' ->
716 returnRn (UfBindDefault bndr' rhs')
719 = rnHsType ty `thenRn` \ ty' ->
720 returnRn (UfCoerce ty')
722 rnNote (UfSCC cc) = returnRn (UfSCC cc)
723 rnNote UfInlineCall = returnRn UfInlineCall
725 rnCorePrim (UfOtherOp op)
726 = lookupOccRn op `thenRn` \ op' ->
727 returnRn (UfOtherOp op')
729 rnCorePrim (UfCCallOp str casm gc arg_tys res_ty)
730 = mapRn rnHsType arg_tys `thenRn` \ arg_tys' ->
731 rnHsType res_ty `thenRn` \ res_ty' ->
732 returnRn (UfCCallOp str casm gc arg_tys' res_ty')
735 %*********************************************************
739 %*********************************************************
742 derivingNonStdClassErr clas
743 = hsep [ptext SLIT("non-standard class"), ppr clas, ptext SLIT("in deriving clause")]
745 classTyVarNotInOpTyErr clas_tyvar sig
746 = hang (hsep [ptext SLIT("Class type variable"),
747 quotes (ppr clas_tyvar),
748 ptext SLIT("does not appear in method signature")])
751 dupClassAssertWarn ctxt (assertion : dups)
752 = sep [hsep [ptext SLIT("Duplicate class assertion"),
753 quotes (pprClassAssertion assertion),
754 ptext SLIT("in the context:")],
755 nest 4 (pprContext ctxt)]
758 = hsep [ptext SLIT("Illegal data constructor name"), quotes (ppr name)]
760 wierdAllErr assertion
761 = ptext SLIT("Mal-formed use of `All':") <+> pprClassAssertion assertion
764 = hsep [ptext SLIT("Context constrains in-scope type variable(s)"),
765 pprQuotedList tyvars]
767 nest 4 (ptext SLIT("in") <+> doc)
769 ctxtErr2 doc tyvars ty
770 = (ptext SLIT("Context constrains type variable(s)")
771 <+> pprQuotedList tyvars)
773 nest 4 (vcat [ptext SLIT("that do not appear in") <+> quotes (ppr ty),
774 ptext SLIT("in") <+> doc])