2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1998
4 \section[RnSource]{Main pass of renamer}
7 module RnSource ( rnIfaceDecl, rnSourceDecls, rnHsType, 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 bindTyVarsFVRn, bindTyVarsFV2Rn, extendTyVarEnvRn,
25 checkDupOrQualNames, checkDupNames,
26 newLocallyDefinedGlobalName, newImportedGlobalName,
27 newImportedGlobalFromRdrName,
28 ifaceFlavour, newDFunName,
29 FreeVars, emptyFVs, plusFV, plusFVs, unitFV, addOneFV
33 import Name ( Name, OccName,
34 ExportFlag(..), Provenance(..),
35 nameOccName, NamedThing(..), isConOcc,
36 mkDefaultMethodOcc, mkDFunOcc
39 import BasicTypes ( TopLevelFlag(..), IfaceFlavour(..) )
40 import TysWiredIn ( tupleTyCon, unboxedTupleTyCon, listTyCon )
41 import Type ( funTyCon )
42 import FiniteMap ( elemFM )
43 import PrelInfo ( derivingOccurrences, numClass_RDR,
44 deRefStablePtr_NAME, makeStablePtr_NAME,
47 import Bag ( bagToList )
49 import SrcLoc ( SrcLoc )
50 import UniqFM ( lookupUFM )
51 import Maybes ( maybeToBool )
55 rnDecl `renames' declarations.
56 It simultaneously performs dependency analysis and precedence parsing.
57 It also does the following error checks:
60 Checks that tyvars are used properly. This includes checking
61 for undefined tyvars, and tyvars in contexts that are ambiguous.
63 Checks that all variable occurences are defined.
65 Checks the (..) etc constraints in the export list.
69 %*********************************************************
71 \subsection{Value declarations}
73 %*********************************************************
76 rnSourceDecls :: [RdrNameHsDecl] -> RnMS s ([RenamedHsDecl], FreeVars)
77 -- The decls get reversed, but that's ok
80 = go emptyFVs [] decls
82 -- Fixity decls have been dealt with already; ignore them
83 go fvs ds' [] = returnRn (ds', fvs)
84 go fvs ds' (FixD _:ds) = go fvs ds' ds
85 go fvs ds' (d:ds) = rnDecl d `thenRn` \(d', fvs) ->
86 go (fvs `plusFV` fvs) (d':ds') ds
88 rnIfaceDecl :: RdrNameHsDecl -> RnMS s RenamedHsDecl
90 = rnDecl d `thenRn` \ (d', fvs) ->
95 %*********************************************************
97 \subsection{Value declarations}
99 %*********************************************************
102 -- rnDecl does all the work
103 rnDecl :: RdrNameHsDecl -> RnMS s (RenamedHsDecl, FreeVars)
105 rnDecl (ValD binds) = rnTopBinds binds `thenRn` \ (new_binds, fvs) ->
106 returnRn (ValD new_binds, fvs)
109 rnDecl (SigD (IfaceSig name ty id_infos loc))
111 lookupBndrRn name `thenRn` \ name' ->
112 rnIfaceType doc_str ty `thenRn` \ ty' ->
114 -- Get the pragma info (if any).
115 setModeRn (InterfaceMode Optional) $
116 -- In all the rest of the signature we read in optional mode,
117 -- so that (a) we don't die
118 mapRn rnIdInfo id_infos `thenRn` \ id_infos' ->
119 returnRn (SigD (IfaceSig name' ty' id_infos' loc), emptyFVs)
120 -- Don't need free-var info for iface binds
122 doc_str = text "the interface signature for" <+> quotes (ppr name)
125 %*********************************************************
127 \subsection{Type declarations}
129 %*********************************************************
131 @rnTyDecl@ uses the `global name function' to create a new type
132 declaration in which local names have been replaced by their original
133 names, reporting any unknown names.
135 Renaming type variables is a pain. Because they now contain uniques,
136 it is necessary to pass in an association list which maps a parsed
137 tyvar to its Name representation. In some cases (type signatures of
138 values), it is even necessary to go over the type first in order to
139 get the set of tyvars used by it, make an assoc list, and then go over
140 it again to rename the tyvars! However, we can also do some scoping
141 checks at the same time.
144 rnDecl (TyClD (TyData new_or_data context tycon tyvars condecls derivings pragmas src_loc))
145 = pushSrcLocRn src_loc $
146 lookupBndrRn tycon `thenRn` \ tycon' ->
147 bindTyVarsFVRn data_doc tyvars $ \ tyvars' ->
148 rnContext data_doc context `thenRn` \ (context', cxt_fvs) ->
149 checkDupOrQualNames data_doc con_names `thenRn_`
150 mapAndUnzipRn rnConDecl condecls `thenRn` \ (condecls', con_fvs_s) ->
151 rnDerivs derivings `thenRn` \ (derivings', deriv_fvs) ->
152 ASSERT(isNoDataPragmas pragmas)
153 returnRn (TyClD (TyData new_or_data context' tycon' tyvars' condecls' derivings' noDataPragmas src_loc),
154 cxt_fvs `plusFV` plusFVs con_fvs_s `plusFV` deriv_fvs)
156 data_doc = text "the data type declaration for" <+> ppr tycon
157 con_names = map conDeclName condecls
159 rnDecl (TyClD (TySynonym name tyvars ty src_loc))
160 = pushSrcLocRn src_loc $
161 lookupBndrRn name `thenRn` \ name' ->
162 bindTyVarsFVRn syn_doc tyvars $ \ tyvars' ->
163 rnHsType syn_doc ty `thenRn` \ (ty', ty_fvs) ->
164 returnRn (TyClD (TySynonym name' tyvars' ty' src_loc), ty_fvs)
166 syn_doc = text "the declaration for type synonym" <+> quotes (ppr name)
168 rnDecl (TyClD (ClassDecl context cname tyvars sigs mbinds pragmas tname dname src_loc))
169 = pushSrcLocRn src_loc $
171 lookupBndrRn cname `thenRn` \ cname' ->
173 -- Deal with the implicit tycon and datacon name
174 -- They aren't in scope (because they aren't visible to the user)
175 -- and what we want to do is simply look them up in the cache;
176 -- we jolly well ought to get a 'hit' there!
177 -- So the 'Imported' part of this call is not relevant.
178 -- Unclean; but since these two are the only place this happens
179 -- I can't work up the energy to do it more beautifully
180 newImportedGlobalFromRdrName tname `thenRn` \ tname' ->
181 newImportedGlobalFromRdrName dname `thenRn` \ dname' ->
183 -- Tyvars scope over bindings and context
184 bindTyVarsFV2Rn cls_doc tyvars ( \ clas_tyvar_names tyvars' ->
186 -- Check the superclasses
187 rnContext cls_doc context `thenRn` \ (context', cxt_fvs) ->
189 -- Check the signatures
191 -- Filter out fixity signatures;
192 -- they are done at top level
193 nofix_sigs = nonFixitySigs sigs
195 checkDupOrQualNames sig_doc sig_rdr_names_w_locs `thenRn_`
196 mapAndUnzipRn (rn_op cname' clas_tyvar_names) nofix_sigs `thenRn` \ (sigs', sig_fvs_s) ->
199 checkDupOrQualNames meth_doc meth_rdr_names_w_locs `thenRn_`
200 rnMethodBinds mbinds `thenRn` \ (mbinds', meth_fvs) ->
202 -- Typechecker is responsible for checking that we only
203 -- give default-method bindings for things in this class.
204 -- The renamer *could* check this for class decls, but can't
205 -- for instance decls.
207 ASSERT(isNoClassPragmas pragmas)
208 returnRn (TyClD (ClassDecl context' cname' tyvars' sigs' mbinds' NoClassPragmas tname' dname' src_loc),
209 plusFVs sig_fvs_s `plusFV` cxt_fvs `plusFV` meth_fvs)
212 cls_doc = text "the declaration for class" <+> ppr cname
213 sig_doc = text "the signatures for class" <+> ppr cname
214 meth_doc = text "the default-methods for class" <+> ppr cname
216 sig_rdr_names_w_locs = [(op,locn) | ClassOpSig op _ _ locn <- sigs]
217 meth_rdr_names_w_locs = bagToList (collectMonoBinders mbinds)
218 meth_rdr_names = map fst meth_rdr_names_w_locs
220 rn_op clas clas_tyvars sig@(ClassOpSig op maybe_dm ty locn)
221 = pushSrcLocRn locn $
222 lookupBndrRn op `thenRn` \ op_name ->
224 -- Check the signature
225 rnHsSigType (quotes (ppr op)) ty `thenRn` \ (new_ty, op_ty_fvs) ->
227 check_in_op_ty clas_tyvar = checkRn (clas_tyvar `elemNameSet` op_ty_fvs)
228 (classTyVarNotInOpTyErr clas_tyvar sig)
230 mapRn check_in_op_ty clas_tyvars `thenRn_`
232 -- Make the default-method name
234 dm_occ = mkDefaultMethodOcc (rdrNameOcc op)
236 getModuleRn `thenRn` \ mod_name ->
237 getModeRn `thenRn` \ mode ->
238 (case (mode, maybe_dm) of
239 (SourceMode, _) | op `elem` meth_rdr_names
240 -> -- There's an explicit method decl
241 newLocallyDefinedGlobalName mod_name dm_occ
242 (\_ -> Exported) locn `thenRn` \ dm_name ->
243 returnRn (Just dm_name)
245 (InterfaceMode _, Just _)
246 -> -- Imported class that has a default method decl
247 newImportedGlobalName mod_name dm_occ (ifaceFlavour clas) `thenRn` \ dm_name ->
248 addOccurrenceName dm_name `thenRn_`
249 returnRn (Just dm_name)
251 other -> returnRn Nothing
252 ) `thenRn` \ maybe_dm_name ->
255 returnRn (ClassOpSig op_name maybe_dm_name new_ty locn, op_ty_fvs)
259 %*********************************************************
261 \subsection{Instance declarations}
263 %*********************************************************
266 rnDecl (InstD (InstDecl inst_ty mbinds uprags maybe_dfun src_loc))
267 = pushSrcLocRn src_loc $
268 rnHsSigType (text "an instance decl") inst_ty `thenRn` \ (inst_ty', inst_fvs) ->
270 inst_tyvars = case inst_ty' of
271 HsForAllTy inst_tyvars _ _ -> inst_tyvars
273 -- (Slightly strangely) the forall-d tyvars scope over
274 -- the method bindings too
276 extendTyVarEnvRn inst_tyvars $
278 -- Rename the bindings
279 -- NB meth_names can be qualified!
280 checkDupNames meth_doc meth_names `thenRn_`
281 rnMethodBinds mbinds `thenRn` \ (mbinds', meth_fvs) ->
283 binders = mkNameSet (map fst (bagToList (collectMonoBinders mbinds')))
285 renameSigs NotTopLevel True binders uprags `thenRn` \ new_uprags ->
286 mkDFunName inst_ty' maybe_dfun src_loc `thenRn` \ dfun_name ->
287 addOccurrenceName dfun_name `thenRn_`
288 -- The dfun is not optional, because we use its version number
289 -- to identify the version of the instance declaration
291 -- The typechecker checks that all the bindings are for the right class.
292 returnRn (InstD (InstDecl inst_ty' mbinds' new_uprags (Just dfun_name) src_loc),
293 inst_fvs `plusFV` meth_fvs)
295 meth_doc = text "the bindings in an instance declaration"
296 meth_names = bagToList (collectMonoBinders mbinds)
299 %*********************************************************
301 \subsection{Default declarations}
303 %*********************************************************
306 rnDecl (DefD (DefaultDecl tys src_loc))
307 = pushSrcLocRn src_loc $
308 rnHsTypes doc_str tys `thenRn` \ (tys', fvs) ->
309 lookupImplicitOccRn numClass_RDR `thenRn_`
310 returnRn (DefD (DefaultDecl tys' src_loc), fvs)
312 doc_str = text "a `default' declaration"
315 %*********************************************************
317 \subsection{Foreign declarations}
319 %*********************************************************
322 rnDecl (ForD (ForeignDecl name imp_exp ty ext_nm cconv src_loc))
323 = pushSrcLocRn src_loc $
324 lookupBndrRn name `thenRn` \ name' ->
326 FoImport _ | not isDyn -> addImplicitOccRn name'
327 FoLabel -> addImplicitOccRn name'
329 addImplicitOccRn makeStablePtr_NAME `thenRn_`
330 addImplicitOccRn deRefStablePtr_NAME `thenRn_`
331 addImplicitOccRn bindIO_NAME `thenRn_`
333 _ -> returnRn name') `thenRn_`
334 rnHsSigType fo_decl_msg ty `thenRn` \ (ty', fvs) ->
335 returnRn (ForD (ForeignDecl name' imp_exp ty' ext_nm cconv src_loc), fvs)
337 fo_decl_msg = ptext SLIT("a foreign declaration")
338 isDyn = isDynamic ext_nm
342 %*********************************************************
344 \subsection{Support code for type/data declarations}
346 %*********************************************************
349 rnDerivs :: Maybe [RdrName] -> RnMS s (Maybe [Name], FreeVars)
351 rnDerivs Nothing -- derivs not specified
352 = returnRn (Nothing, emptyFVs)
355 = mapRn rn_deriv ds `thenRn` \ derivs ->
356 returnRn (Just derivs, mkNameSet derivs)
359 = lookupOccRn clas `thenRn` \ clas_name ->
361 -- Now add extra "occurrences" for things that
362 -- the deriving mechanism will later need in order to
363 -- generate code for this class.
364 case lookupUFM derivingOccurrences clas_name of
365 Nothing -> addErrRn (derivingNonStdClassErr clas_name) `thenRn_`
368 Just occs -> mapRn lookupImplicitOccRn occs `thenRn_`
374 conDeclName :: RdrNameConDecl -> (RdrName, SrcLoc)
375 conDeclName (ConDecl n _ _ _ l) = (n,l)
377 rnConDecl :: RdrNameConDecl -> RnMS s (RenamedConDecl, FreeVars)
378 rnConDecl (ConDecl name tvs cxt details locn)
379 = pushSrcLocRn locn $
380 checkConName name `thenRn_`
381 lookupBndrRn name `thenRn` \ new_name ->
382 bindTyVarsFVRn doc tvs $ \ new_tyvars ->
383 rnContext doc cxt `thenRn` \ (new_context, cxt_fvs) ->
384 rnConDetails doc locn details `thenRn` \ (new_details, det_fvs) ->
385 returnRn (ConDecl new_name new_tyvars new_context new_details locn,
386 cxt_fvs `plusFV` det_fvs)
388 doc = text "the definition of data constructor" <+> quotes (ppr name)
390 rnConDetails doc locn (VanillaCon tys)
391 = mapAndUnzipRn (rnBangTy doc) tys `thenRn` \ (new_tys, fvs_s) ->
392 returnRn (VanillaCon new_tys, plusFVs fvs_s)
394 rnConDetails doc locn (InfixCon ty1 ty2)
395 = rnBangTy doc ty1 `thenRn` \ (new_ty1, fvs1) ->
396 rnBangTy doc ty2 `thenRn` \ (new_ty2, fvs2) ->
397 returnRn (InfixCon new_ty1 new_ty2, fvs1 `plusFV` fvs2)
399 rnConDetails doc locn (NewCon ty mb_field)
400 = rnHsType doc ty `thenRn` \ (new_ty, fvs) ->
401 rn_field mb_field `thenRn` \ new_mb_field ->
402 returnRn (NewCon new_ty new_mb_field, fvs)
404 rn_field Nothing = returnRn Nothing
406 lookupBndrRn f `thenRn` \ new_f ->
407 returnRn (Just new_f)
409 rnConDetails doc locn (RecCon fields)
410 = checkDupOrQualNames doc field_names `thenRn_`
411 mapAndUnzipRn (rnField doc) fields `thenRn` \ (new_fields, fvs_s) ->
412 returnRn (RecCon new_fields, plusFVs fvs_s)
414 field_names = [(fld, locn) | (flds, _) <- fields, fld <- flds]
416 rnField doc (names, ty)
417 = mapRn lookupBndrRn names `thenRn` \ new_names ->
418 rnBangTy doc ty `thenRn` \ (new_ty, fvs) ->
419 returnRn ((new_names, new_ty), fvs)
421 rnBangTy doc (Banged ty)
422 = rnHsType doc ty `thenRn` \ (new_ty, fvs) ->
423 returnRn (Banged new_ty, fvs)
425 rnBangTy doc (Unbanged ty)
426 = rnHsType doc ty `thenRn` \ (new_ty, fvs) ->
427 returnRn (Unbanged new_ty, fvs)
429 -- This data decl will parse OK
431 -- treating "a" as the constructor.
432 -- It is really hard to make the parser spot this malformation.
433 -- So the renamer has to check that the constructor is legal
435 -- We can get an operator as the constructor, even in the prefix form:
436 -- data T = :% Int Int
437 -- from interface files, which always print in prefix form
440 = checkRn (isConOcc (rdrNameOcc name))
445 %*********************************************************
447 \subsection{Naming a dfun}
449 %*********************************************************
451 Make a name for the dict fun for an instance decl
454 mkDFunName :: RenamedHsType -- Instance type
455 -> Maybe RdrName -- Dfun thing from decl; Nothing <=> source
459 mkDFunName inst_ty maybe_df src_loc
460 = newDFunName cl_occ tycon_occ maybe_df src_loc
462 (cl_occ, tycon_occ) = get_key inst_ty
464 get_key (HsForAllTy _ _ ty) = get_key ty
465 get_key (MonoFunTy _ ty) = get_key ty
466 get_key (MonoDictTy cls (ty:_)) = (nameOccName cls, get_tycon_key ty)
468 get_tycon_key (MonoTyVar tv) = nameOccName (getName tv)
469 get_tycon_key (MonoTyApp ty _) = get_tycon_key ty
470 get_tycon_key (MonoTupleTy tys True) = getOccName (tupleTyCon (length tys))
471 get_tycon_key (MonoTupleTy tys False) = getOccName (unboxedTupleTyCon (length tys))
472 get_tycon_key (MonoListTy _) = getOccName listTyCon
473 get_tycon_key (MonoFunTy _ _) = getOccName funTyCon
477 %*********************************************************
479 \subsection{Support code to rename types}
481 %*********************************************************
484 rnHsSigType :: SDoc -> RdrNameHsType -> RnMS s (RenamedHsType, FreeVars)
485 -- rnHsSigType is used for source-language type signatures,
486 -- which use *implicit* universal quantification.
487 rnHsSigType doc_str ty
488 = rnHsType (text "the type signature for" <+> doc_str) ty
490 rnIfaceType :: SDoc -> RdrNameHsType -> RnMS s RenamedHsType
492 = rnHsType doc ty `thenRn` \ (ty,_) ->
495 rnHsType :: SDoc -> RdrNameHsType -> RnMS s (RenamedHsType, FreeVars)
497 rnHsType doc (HsForAllTy [] ctxt ty)
498 -- From source code (no kinds on tyvars)
500 -- Given the signature C => T we universally quantify
501 -- over FV(T) \ {in-scope-tyvars}
503 -- We insist that the universally quantified type vars is a superset of FV(C)
504 -- It follows that FV(T) is a superset of FV(C), so that the context constrains
505 -- no type variables that don't appear free in the tau-type part.
507 = getLocalNameEnv `thenRn` \ name_env ->
509 mentioned_tyvars = extractHsTyVars ty
510 forall_tyvars = filter (not . (`elemFM` name_env)) mentioned_tyvars
512 ctxt_w_ftvs :: [((RdrName,[RdrNameHsType]), [RdrName])]
513 ctxt_w_ftvs = [ (constraint, foldr ((++) . extractHsTyVars) [] tys)
514 | constraint@(_,tys) <- ctxt]
516 -- A 'non-poly constraint' is one that does not mention *any*
517 -- of the forall'd type variables
518 non_poly_constraints = filter non_poly ctxt_w_ftvs
519 non_poly (c,ftvs) = not (any (`elem` forall_tyvars) ftvs)
521 -- A 'non-mentioned' constraint is one that mentions a
522 -- type variable that does not appear in 'ty'
523 non_mentioned_constraints = filter non_mentioned ctxt_w_ftvs
524 non_mentioned (c,ftvs) = any (not . (`elem` mentioned_tyvars)) ftvs
526 -- Zap the context if there's a problem, to avoid duplicate error message.
527 ctxt' | null non_poly_constraints && null non_mentioned_constraints = ctxt
530 mapRn (ctxtErr1 doc forall_tyvars ty) non_poly_constraints `thenRn_`
531 mapRn (ctxtErr2 doc ty) non_mentioned_constraints `thenRn_`
533 (bindTyVarsFVRn doc (map UserTyVar forall_tyvars) $ \ new_tyvars ->
534 rnContext doc ctxt' `thenRn` \ (new_ctxt, cxt_fvs) ->
535 rnHsType doc ty `thenRn` \ (new_ty, ty_fvs) ->
536 returnRn (mkHsForAllTy new_tyvars new_ctxt new_ty,
537 cxt_fvs `plusFV` ty_fvs)
540 rnHsType doc (HsForAllTy tvs ctxt ty)
541 -- tvs are non-empty, hence must be from an interface file
542 -- (tyvars may be kinded)
543 = bindTyVarsFVRn doc tvs $ \ new_tyvars ->
544 rnContext doc ctxt `thenRn` \ (new_ctxt, cxt_fvs) ->
545 rnHsType doc ty `thenRn` \ (new_ty, ty_fvs) ->
546 returnRn (mkHsForAllTy new_tyvars new_ctxt new_ty,
547 cxt_fvs `plusFV` ty_fvs)
549 rnHsType doc (MonoTyVar tyvar)
550 = lookupOccRn tyvar `thenRn` \ tyvar' ->
551 returnRn (MonoTyVar tyvar', unitFV tyvar')
553 rnHsType doc (MonoFunTy ty1 ty2)
554 = rnHsType doc ty1 `thenRn` \ (ty1', fvs1) ->
555 rnHsType doc ty2 `thenRn` \ (ty2', fvs2) ->
556 returnRn (MonoFunTy ty1' ty2', fvs1 `plusFV` fvs2)
558 rnHsType doc (MonoListTy ty)
559 = addImplicitOccRn listTyCon_name `thenRn_`
560 rnHsType doc ty `thenRn` \ (ty', fvs) ->
561 returnRn (MonoListTy ty', fvs `addOneFV` listTyCon_name)
563 rnHsType doc (MonoTupleTy tys boxed)
564 = addImplicitOccRn tup_con_name `thenRn_`
565 rnHsTypes doc tys `thenRn` \ (tys', fvs) ->
566 returnRn (MonoTupleTy tys' boxed, fvs `addOneFV` tup_con_name)
568 tup_con_name = tupleTyCon_name boxed (length tys)
570 rnHsType doc (MonoTyApp ty1 ty2)
571 = rnHsType doc ty1 `thenRn` \ (ty1', fvs1) ->
572 rnHsType doc ty2 `thenRn` \ (ty2', fvs2) ->
573 returnRn (MonoTyApp ty1' ty2', fvs1 `plusFV` fvs2)
575 rnHsType doc (MonoDictTy clas tys)
576 = lookupOccRn clas `thenRn` \ clas' ->
577 rnHsTypes doc tys `thenRn` \ (tys', fvs) ->
578 returnRn (MonoDictTy clas' tys', fvs `addOneFV` clas')
581 = mapAndUnzipRn (rnHsType doc) tys `thenRn` \ (tys, fvs_s) ->
582 returnRn (tys, plusFVs fvs_s)
587 rnContext :: SDoc -> RdrNameContext -> RnMS s (RenamedContext, FreeVars)
590 = mapAndUnzipRn rn_ctxt ctxt `thenRn` \ (theta, fvs_s) ->
592 (_, dup_asserts) = removeDups cmp_assert theta
594 -- Check for duplicate assertions
595 -- If this isn't an error, then it ought to be:
596 mapRn (addWarnRn . dupClassAssertWarn theta) dup_asserts `thenRn_`
598 returnRn (theta, plusFVs fvs_s)
601 = lookupOccRn clas `thenRn` \ clas_name ->
602 rnHsTypes doc tys `thenRn` \ (tys', fvs) ->
603 returnRn ((clas_name, tys'), fvs `addOneFV` clas_name)
605 cmp_assert (c1,tys1) (c2,tys2)
606 = (c1 `compare` c2) `thenCmp` (cmpHsTypes compare tys1 tys2)
610 %*********************************************************
614 %*********************************************************
617 rnIdInfo (HsStrictness strict)
618 = rnStrict strict `thenRn` \ strict' ->
619 returnRn (HsStrictness strict')
621 rnIdInfo (HsUnfold inline (Just expr)) = rnCoreExpr expr `thenRn` \ expr' ->
622 returnRn (HsUnfold inline (Just expr'))
623 rnIdInfo (HsUnfold inline Nothing) = returnRn (HsUnfold inline Nothing)
624 rnIdInfo (HsArity arity) = returnRn (HsArity arity)
625 rnIdInfo (HsUpdate update) = returnRn (HsUpdate update)
626 rnIdInfo (HsNoCafRefs) = returnRn (HsNoCafRefs)
627 rnIdInfo (HsSpecialise tyvars tys expr)
628 = bindTyVarsRn doc tyvars $ \ tyvars' ->
629 rnCoreExpr expr `thenRn` \ expr' ->
630 mapRn (rnIfaceType doc) tys `thenRn` \ tys' ->
631 returnRn (HsSpecialise tyvars' tys' expr')
633 doc = text "Specialise in interface pragma"
636 rnStrict (HsStrictnessInfo demands (Just (worker,cons)))
637 -- The sole purpose of the "cons" field is so that we can mark the constructors
638 -- needed to build the wrapper as "needed", so that their data type decl will be
639 -- slurped in. After that their usefulness is o'er, so we just put in the empty list.
640 = lookupOccRn worker `thenRn` \ worker' ->
641 mapRn lookupOccRn cons `thenRn_`
642 returnRn (HsStrictnessInfo demands (Just (worker',[])))
644 -- Boring, but necessary for the type checker.
645 rnStrict (HsStrictnessInfo demands Nothing) = returnRn (HsStrictnessInfo demands Nothing)
646 rnStrict HsBottom = returnRn HsBottom
652 rnCoreExpr (UfType ty)
653 = rnIfaceType (text "unfolding type") ty `thenRn` \ ty' ->
654 returnRn (UfType ty')
657 = lookupOccRn v `thenRn` \ v' ->
660 rnCoreExpr (UfCon con args)
661 = rnUfCon con `thenRn` \ con' ->
662 mapRn rnCoreExpr args `thenRn` \ args' ->
663 returnRn (UfCon con' args')
665 rnCoreExpr (UfTuple con args)
666 = lookupOccRn con `thenRn` \ con' ->
667 mapRn rnCoreExpr args `thenRn` \ args' ->
668 returnRn (UfTuple con' args')
670 rnCoreExpr (UfApp fun arg)
671 = rnCoreExpr fun `thenRn` \ fun' ->
672 rnCoreExpr arg `thenRn` \ arg' ->
673 returnRn (UfApp fun' arg')
675 rnCoreExpr (UfCase scrut bndr alts)
676 = rnCoreExpr scrut `thenRn` \ scrut' ->
677 bindLocalsRn "UfCase" [bndr] $ \ [bndr'] ->
678 mapRn rnCoreAlt alts `thenRn` \ alts' ->
679 returnRn (UfCase scrut' bndr' alts')
681 rnCoreExpr (UfNote note expr)
682 = rnNote note `thenRn` \ note' ->
683 rnCoreExpr expr `thenRn` \ expr' ->
684 returnRn (UfNote note' expr')
686 rnCoreExpr (UfLam bndr body)
687 = rnCoreBndr bndr $ \ bndr' ->
688 rnCoreExpr body `thenRn` \ body' ->
689 returnRn (UfLam bndr' body')
691 rnCoreExpr (UfLet (UfNonRec bndr rhs) body)
692 = rnCoreExpr rhs `thenRn` \ rhs' ->
693 rnCoreBndr bndr $ \ bndr' ->
694 rnCoreExpr body `thenRn` \ body' ->
695 returnRn (UfLet (UfNonRec bndr' rhs') body')
697 rnCoreExpr (UfLet (UfRec pairs) body)
698 = rnCoreBndrs bndrs $ \ bndrs' ->
699 mapRn rnCoreExpr rhss `thenRn` \ rhss' ->
700 rnCoreExpr body `thenRn` \ body' ->
701 returnRn (UfLet (UfRec (bndrs' `zip` rhss')) body')
703 (bndrs, rhss) = unzip pairs
707 rnCoreBndr (UfValBinder name ty) thing_inside
708 = rnIfaceType (text str) ty `thenRn` \ ty' ->
709 bindLocalsRn str [name] $ \ [name'] ->
710 thing_inside (UfValBinder name' ty')
714 rnCoreBndr (UfTyBinder name kind) thing_inside
715 = bindLocalsRn "unfolding tyvar" [name] $ \ [name'] ->
716 thing_inside (UfTyBinder name' kind)
718 rnCoreBndrs bndrs thing_inside -- Expect them all to be ValBinders
719 = mapRn (rnIfaceType (text str)) tys `thenRn` \ tys' ->
720 bindLocalsRn str names $ \ names' ->
721 thing_inside (zipWith UfValBinder names' tys')
724 names = map (\ (UfValBinder name _ ) -> name) bndrs
725 tys = map (\ (UfValBinder _ ty) -> ty) bndrs
729 rnCoreAlt (con, bndrs, rhs)
730 = rnUfCon con `thenRn` \ con' ->
731 bindLocalsRn "unfolding alt" bndrs $ \ bndrs' ->
732 rnCoreExpr rhs `thenRn` \ rhs' ->
733 returnRn (con', bndrs', rhs')
737 = rnIfaceType (text "unfolding coerce") ty `thenRn` \ ty' ->
738 returnRn (UfCoerce ty')
740 rnNote (UfSCC cc) = returnRn (UfSCC cc)
741 rnNote UfInlineCall = returnRn UfInlineCall
747 rnUfCon (UfDataCon con)
748 = lookupOccRn con `thenRn` \ con' ->
749 returnRn (UfDataCon con')
751 rnUfCon (UfLitCon lit)
752 = returnRn (UfLitCon lit)
754 rnUfCon (UfLitLitCon lit ty)
755 = rnIfaceType (text "litlit") ty `thenRn` \ ty' ->
756 returnRn (UfLitLitCon lit ty')
758 rnUfCon (UfPrimOp op)
759 = lookupOccRn op `thenRn` \ op' ->
760 returnRn (UfPrimOp op')
762 rnUfCon (UfCCallOp str casm gc)
763 = returnRn (UfCCallOp str casm gc)
766 %*********************************************************
770 %*********************************************************
773 derivingNonStdClassErr clas
774 = hsep [ptext SLIT("non-standard class"), ppr clas, ptext SLIT("in deriving clause")]
776 classTyVarNotInOpTyErr clas_tyvar sig
777 = hang (hsep [ptext SLIT("Class type variable"),
778 quotes (ppr clas_tyvar),
779 ptext SLIT("does not appear in method signature")])
782 dupClassAssertWarn ctxt (assertion : dups)
783 = sep [hsep [ptext SLIT("Duplicate class assertion"),
784 quotes (pprClassAssertion assertion),
785 ptext SLIT("in the context:")],
786 nest 4 (pprContext ctxt)]
789 = hsep [ptext SLIT("Illegal data constructor name"), quotes (ppr name)]
791 ctxtErr1 doc tyvars ty (constraint, _)
793 sep [ptext SLIT("The constraint") <+> quotes (pprClassAssertion constraint) <+>
794 ptext SLIT("does not mention any of"),
795 nest 4 (ptext SLIT("the universally quantified type variables") <+> braces (interpp'SP tyvars)),
796 nest 4 (ptext SLIT("of the type") <+> quotes (ppr ty))
799 (ptext SLIT("In") <+> doc)
802 ctxtErr2 doc ty (constraint,_)
804 sep [ptext SLIT("The constraint") <+> quotes (pprClassAssertion constraint),
805 nest 4 (ptext SLIT("mentions type variables that do not appear in the type")),
806 nest 4 (quotes (ppr ty))]
808 (ptext SLIT("In") <+> doc)