2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1996
4 \section[RnSource]{Main pass of renamer}
7 #include "HsVersions.h"
9 module RnSource ( rnSource, rnTyDecl, rnClassDecl, rnInstDecl, rnPolyType ) where
12 import RnLoop -- *check* the RnPass/RnExpr/RnBinds loop-breaking
19 import RnBinds ( rnTopBinds, rnMethodBinds )
20 import RnUtils ( lookupGlobalRnEnv, lubExportFlag )
22 import Bag ( emptyBag, unitBag, consBag, unionManyBags, unionBags, listToBag, bagToList )
23 import Class ( derivableClassKeys )
24 import ErrUtils ( addErrLoc, addShortErrLocLine, addShortWarnLocLine )
25 import FiniteMap ( emptyFM, lookupFM, addListToFM_C )
26 import ListSetOps ( unionLists, minusList )
27 import Maybes ( maybeToBool, catMaybes )
28 import Name ( Name, isLocallyDefined, isLexVarId, getLocalName, ExportFlag(..),
29 nameImportFlag, RdrName, pprNonSym )
30 import Outputable -- ToDo:rm
31 import PprStyle -- ToDo:rm
32 import PrelInfo ( consDataCon )
34 import SrcLoc ( SrcLoc )
35 import Unique ( Unique )
36 import UniqFM ( emptyUFM, addListToUFM_C, listToUFM, lookupUFM, eltsUFM )
37 import UniqSet ( UniqSet(..) )
38 import Util ( isIn, isn'tIn, sortLt, removeDups, cmpPString, assertPanic, pprTrace{-ToDo:rm-} )
41 rnSource `renames' the source module and export list.
42 It simultaneously performs dependency analysis and precedence parsing.
43 It also does the following error checks:
46 Checks that tyvars are used properly. This includes checking
47 for undefined tyvars, and tyvars in contexts that are ambiguous.
49 Checks that all variable occurences are defined.
51 Checks the (..) etc constraints in the export list.
56 rnSource :: [Module] -- imported modules
57 -> Bag (Module,RnName) -- unqualified imports from module
58 -> Bag RenamedFixityDecl -- fixity info for imported names
60 -> RnM s (RenamedHsModule,
61 Name -> ExportFlag, -- export info
62 Bag (RnName, RdrName)) -- occurrence info
64 rnSource imp_mods unqual_imps imp_fixes
65 (HsModule mod version exports _ fixes
66 ty_decls specdata_sigs class_decls
67 inst_decls specinst_sigs defaults
70 = pushSrcLocRn src_loc $
72 rnExports (mod:imp_mods) unqual_imps exports `thenRn` \ exported_fn ->
73 rnFixes fixes `thenRn` \ src_fixes ->
75 all_fixes = src_fixes ++ bagToList imp_fixes
76 all_fixes_fm = listToUFM (map pair_name all_fixes)
78 pair_name inf = (fixDeclName inf, inf)
80 setExtraRn all_fixes_fm $
82 mapRn rnTyDecl ty_decls `thenRn` \ new_ty_decls ->
83 mapRn rnSpecDataSig specdata_sigs `thenRn` \ new_specdata_sigs ->
84 mapRn rnClassDecl class_decls `thenRn` \ new_class_decls ->
85 mapRn rnInstDecl inst_decls `thenRn` \ new_inst_decls ->
86 mapRn rnSpecInstSig specinst_sigs `thenRn` \ new_specinst_sigs ->
87 rnDefaultDecl defaults `thenRn` \ new_defaults ->
88 rnTopBinds binds `thenRn` \ new_binds ->
90 getOccurrenceUpRn `thenRn` \ occ_info ->
94 trashed_exports trashed_imports all_fixes
95 new_ty_decls new_specdata_sigs new_class_decls
96 new_inst_decls new_specinst_sigs new_defaults
102 trashed_exports = {-trace "rnSource:trashed_exports"-} Nothing
103 trashed_imports = {-trace "rnSource:trashed_imports"-} []
107 %*********************************************************
109 \subsection{Export list}
111 %*********************************************************
114 rnExports :: [Module]
115 -> Bag (Module,RnName)
117 -> RnM s (Name -> ExportFlag)
119 rnExports mods unqual_imps Nothing
120 = returnRn (\n -> if isLocallyDefined n then ExportAll else NotExported)
122 rnExports mods unqual_imps (Just exps)
123 = mapAndUnzipRn (rnIE mods) exps `thenRn` \ (mod_maybes, exp_bags) ->
125 exp_names = bagToList (unionManyBags exp_bags)
126 exp_mods = catMaybes mod_maybes
128 -- Warn for duplicate names and modules
129 (uniq_exp_names, dup_names) = removeDups cmp_fst exp_names
130 (uniq_exp_mods, dup_mods) = removeDups cmpPString exp_mods
131 cmp_fst (x,_) (y,_) = x `cmp` y
133 -- Build finite map of exported names to export flag
134 exp_map0 = addListToUFM_C lub_expflag emptyUFM (map pair_fst uniq_exp_names)
135 (exp_map1, empty_mods) = foldl add_mod_names (exp_map0, []) uniq_exp_mods
137 mod_fm = addListToFM_C unionBags emptyFM
138 [(mod, unitBag (getName rn, nameImportFlag (getName rn)))
139 | (mod,rn) <- bagToList unqual_imps, isRnDecl rn]
141 add_mod_names (exp_map, empty) mod
142 = case lookupFM mod_fm mod of
143 Nothing -> (exp_map, mod:empty)
144 Just mod_names -> (addListToUFM_C lub_expflag exp_map (map pair_fst (bagToList mod_names)), empty)
146 pair_fst p@(f,_) = (f,p)
147 lub_expflag (n, flag1) (_, flag2) = (n, lubExportFlag flag1 flag2)
149 -- Check for exporting of duplicate local names
150 exp_locals = [(getLocalName n, n) | (n,_) <- eltsUFM exp_map1]
151 (_, dup_locals) = removeDups cmp_local exp_locals
152 cmp_local (x,_) (y,_) = x `cmpPString` y
154 -- Build export flag function
155 exp_fn n = case lookupUFM exp_map1 n of
156 Nothing -> NotExported
157 Just (_,flag) -> flag
159 getSrcLocRn `thenRn` \ src_loc ->
160 mapRn (addWarnRn . dupNameExportWarn src_loc) dup_names `thenRn_`
161 mapRn (addWarnRn . dupModExportWarn src_loc) dup_mods `thenRn_`
162 mapRn (addWarnRn . emptyModExportWarn src_loc) empty_mods `thenRn_`
163 mapRn (addErrRn . dupLocalsExportErr src_loc) dup_locals `thenRn_`
167 rnIE mods (IEVar name)
168 = lookupValue name `thenRn` \ rn ->
169 checkIEVar rn `thenRn` \ exps ->
170 returnRn (Nothing, exps)
172 checkIEVar (RnName n) = returnRn (unitBag (n,ExportAll))
173 checkIEVar rn@(RnClassOp _ _) = getSrcLocRn `thenRn` \ src_loc ->
174 failButContinueRn emptyBag (classOpExportErr rn src_loc)
175 checkIEVar rn = returnRn emptyBag
177 rnIE mods (IEThingAbs name)
178 = lookupTyConOrClass name `thenRn` \ rn ->
179 checkIEAbs rn `thenRn` \ exps ->
180 returnRn (Nothing, exps)
182 checkIEAbs (RnSyn n) = returnRn (unitBag (n,ExportAbs))
183 checkIEAbs (RnData n _ _) = returnRn (unitBag (n,ExportAbs))
184 checkIEAbs (RnClass n _) = returnRn (unitBag (n,ExportAbs))
185 checkIEAbs rn = returnRn emptyBag
187 rnIE mods (IEThingAll name)
188 = lookupTyConOrClass name `thenRn` \ rn ->
189 checkIEAll rn `thenRn` \ exps ->
190 checkImportAll rn `thenRn_`
191 returnRn (Nothing, exps)
193 checkIEAll (RnData n cons fields) = returnRn (exp_all n `consBag` listToBag (map exp_all cons)
194 `unionBags` listToBag (map exp_all fields))
195 checkIEAll (RnClass n ops) = returnRn (exp_all n `consBag` listToBag (map exp_all ops))
196 checkIEAll rn@(RnSyn n) = getSrcLocRn `thenRn` \ src_loc ->
197 warnAndContinueRn (unitBag (n, ExportAbs))
198 (synAllExportErr False{-warning-} rn src_loc)
199 checkIEAll rn = returnRn emptyBag
201 exp_all n = (n, ExportAll)
203 rnIE mods (IEThingWith name names)
204 = lookupTyConOrClass name `thenRn` \ rn ->
205 mapRn lookupValue names `thenRn` \ rns ->
206 checkIEWith rn rns `thenRn` \ exps ->
207 checkImportAll rn `thenRn_`
208 returnRn (Nothing, exps)
210 checkIEWith rn@(RnData n cons fields) rns
211 | same_names (cons++fields) rns
212 = returnRn (consBag (exp_all n) (listToBag (map exp_all cons)))
214 = rnWithErr "constructrs (and fields)" rn (cons++fields) rns
215 checkIEWith rn@(RnClass n ops) rns
217 = returnRn (consBag (exp_all n) (listToBag (map exp_all ops)))
219 = rnWithErr "class ops" rn ops rns
220 checkIEWith rn@(RnSyn _) rns
221 = getSrcLocRn `thenRn` \ src_loc ->
222 failButContinueRn emptyBag (synAllExportErr True{-error-} rn src_loc)
226 exp_all n = (n, ExportAll)
229 = all (not.isRnUnbound) rns &&
230 sortLt (<) (map uniqueOf has) == sortLt (<) (map uniqueOf rns)
232 rnWithErr str rn has rns
233 = getSrcLocRn `thenRn` \ src_loc ->
234 failButContinueRn emptyBag (withExportErr str rn has rns src_loc)
236 rnIE mods (IEModuleContents mod)
237 | isIn "rnIE:IEModule" mod mods
238 = returnRn (Just mod, emptyBag)
240 = getSrcLocRn `thenRn` \ src_loc ->
241 failButContinueRn (Nothing,emptyBag) (badModExportErr mod src_loc)
245 = case nameImportFlag (getName rn) of
246 ExportAll -> returnRn ()
247 exp -> getSrcLocRn `thenRn` \ src_loc ->
248 addErrRn (importAllErr rn src_loc)
251 %*********************************************************
253 \subsection{Type declarations}
255 %*********************************************************
257 @rnTyDecl@ uses the `global name function' to create a new type
258 declaration in which local names have been replaced by their original
259 names, reporting any unknown names.
261 Renaming type variables is a pain. Because they now contain uniques,
262 it is necessary to pass in an association list which maps a parsed
263 tyvar to its Name representation. In some cases (type signatures of
264 values), it is even necessary to go over the type first in order to
265 get the set of tyvars used by it, make an assoc list, and then go over
266 it again to rename the tyvars! However, we can also do some scoping
267 checks at the same time.
270 rnTyDecl :: RdrNameTyDecl -> RnM_Fixes s RenamedTyDecl
272 rnTyDecl (TyData context tycon tyvars condecls derivings pragmas src_loc)
273 = pushSrcLocRn src_loc $
274 lookupTyCon tycon `thenRn` \ tycon' ->
275 mkTyVarNamesEnv src_loc tyvars `thenRn` \ (tv_env, tyvars') ->
276 rnContext tv_env context `thenRn` \ context' ->
277 rnConDecls tv_env condecls `thenRn` \ condecls' ->
278 rn_derivs tycon' src_loc derivings `thenRn` \ derivings' ->
279 ASSERT(isNoDataPragmas pragmas)
280 returnRn (TyData context' tycon' tyvars' condecls' derivings' noDataPragmas src_loc)
282 rnTyDecl (TyNew context tycon tyvars condecl derivings pragmas src_loc)
283 = pushSrcLocRn src_loc $
284 lookupTyCon tycon `thenRn` \ tycon' ->
285 mkTyVarNamesEnv src_loc tyvars `thenRn` \ (tv_env, tyvars') ->
286 rnContext tv_env context `thenRn` \ context' ->
287 rnConDecls tv_env condecl `thenRn` \ condecl' ->
288 rn_derivs tycon' src_loc derivings `thenRn` \ derivings' ->
289 ASSERT(isNoDataPragmas pragmas)
290 returnRn (TyNew context' tycon' tyvars' condecl' derivings' noDataPragmas src_loc)
292 rnTyDecl (TySynonym name tyvars ty src_loc)
293 = pushSrcLocRn src_loc $
294 lookupTyCon name `thenRn` \ name' ->
295 mkTyVarNamesEnv src_loc tyvars `thenRn` \ (tv_env, tyvars') ->
296 rnMonoType tv_env ty `thenRn` \ ty' ->
297 returnRn (TySynonym name' tyvars' ty' src_loc)
299 rn_derivs tycon2 locn Nothing -- derivs not specified
302 rn_derivs tycon2 locn (Just ds)
303 = mapRn (rn_deriv tycon2 locn) ds `thenRn` \ derivs ->
304 returnRn (Just derivs)
306 rn_deriv tycon2 locn clas
307 = lookupClass clas `thenRn` \ clas_name ->
308 addErrIfRn (uniqueOf clas_name `not_elem` derivableClassKeys)
309 (derivingNonStdClassErr clas locn)
313 not_elem = isn'tIn "rn_deriv"
316 @rnConDecls@ uses the `global name function' to create a new
317 constructor in which local names have been replaced by their original
318 names, reporting any unknown names.
321 rnConDecls :: TyVarNamesEnv
323 -> RnM_Fixes s [RenamedConDecl]
325 rnConDecls tv_env con_decls
326 = mapRn rn_decl con_decls
328 rn_decl (ConDecl name tys src_loc)
329 = pushSrcLocRn src_loc $
330 lookupConstr name `thenRn` \ new_name ->
331 mapRn rn_bang_ty tys `thenRn` \ new_tys ->
332 returnRn (ConDecl new_name new_tys src_loc)
334 rn_decl (ConOpDecl ty1 op ty2 src_loc)
335 = pushSrcLocRn src_loc $
336 lookupConstr op `thenRn` \ new_op ->
337 rn_bang_ty ty1 `thenRn` \ new_ty1 ->
338 rn_bang_ty ty2 `thenRn` \ new_ty2 ->
339 returnRn (ConOpDecl new_ty1 new_op new_ty2 src_loc)
341 rn_decl (NewConDecl name ty src_loc)
342 = pushSrcLocRn src_loc $
343 lookupConstr name `thenRn` \ new_name ->
344 rn_mono_ty ty `thenRn` \ new_ty ->
345 returnRn (NewConDecl new_name new_ty src_loc)
347 rn_decl (RecConDecl name fields src_loc)
348 = pushSrcLocRn src_loc $
349 lookupConstr name `thenRn` \ new_name ->
350 mapRn rn_field fields `thenRn` \ new_fields ->
351 returnRn (RecConDecl new_name new_fields src_loc)
354 = mapRn lookupField names `thenRn` \ new_names ->
355 rn_bang_ty ty `thenRn` \ new_ty ->
356 returnRn (new_names, new_ty)
358 rn_mono_ty = rnMonoType tv_env
359 rn_poly_ty = rnPolyType tv_env
361 rn_bang_ty (Banged ty)
362 = rn_poly_ty ty `thenRn` \ new_ty ->
363 returnRn (Banged new_ty)
364 rn_bang_ty (Unbanged ty)
365 = rn_poly_ty ty `thenRn` \ new_ty ->
366 returnRn (Unbanged new_ty)
369 %*********************************************************
371 \subsection{SPECIALIZE data pragmas}
373 %*********************************************************
376 rnSpecDataSig :: RdrNameSpecDataSig
377 -> RnM_Fixes s RenamedSpecDataSig
379 rnSpecDataSig (SpecDataSig tycon ty src_loc)
380 = pushSrcLocRn src_loc $
382 tyvars = extractMonoTyNames is_tyvar_name ty
384 mkTyVarNamesEnv src_loc tyvars `thenRn` \ (tv_env,_) ->
385 lookupTyCon tycon `thenRn` \ tycon' ->
386 rnMonoType tv_env ty `thenRn` \ ty' ->
387 returnRn (SpecDataSig tycon' ty' src_loc)
389 is_tyvar_name n = isLexVarId (getLocalName n)
392 %*********************************************************
394 \subsection{Class declarations}
396 %*********************************************************
398 @rnClassDecl@ uses the `global name function' to create a new
399 class declaration in which local names have been replaced by their
400 original names, reporting any unknown names.
403 rnClassDecl :: RdrNameClassDecl -> RnM_Fixes s RenamedClassDecl
405 rnClassDecl (ClassDecl context cname tyvar sigs mbinds pragmas src_loc)
406 = pushSrcLocRn src_loc $
407 mkTyVarNamesEnv src_loc [tyvar] `thenRn` \ (tv_env, [tyvar']) ->
408 rnContext tv_env context `thenRn` \ context' ->
409 lookupClass cname `thenRn` \ cname' ->
410 mapRn (rn_op cname' tv_env) sigs `thenRn` \ sigs' ->
411 rnMethodBinds cname' mbinds `thenRn` \ mbinds' ->
412 ASSERT(isNoClassPragmas pragmas)
413 returnRn (ClassDecl context' cname' tyvar' sigs' mbinds' NoClassPragmas src_loc)
415 rn_op clas tv_env (ClassOpSig op ty pragmas locn)
416 = pushSrcLocRn locn $
417 lookupClassOp clas op `thenRn` \ op_name ->
418 rnPolyType tv_env ty `thenRn` \ new_ty ->
421 *** Please check here that tyvar' appears in new_ty ***
422 *** (used to be in tcClassSig, but it's better here)
423 *** not_elem = isn'tIn "tcClassSigs"
424 *** -- Check that the class type variable is mentioned
425 *** checkTc (clas_tyvar `not_elem` extractTyVarTemplatesFromTy local_ty)
426 *** (methodTypeLacksTyVarErr clas_tyvar (_UNPK_ op_name) src_loc) `thenTc_`
429 ASSERT(isNoClassOpPragmas pragmas)
430 returnRn (ClassOpSig op_name new_ty noClassOpPragmas locn)
434 %*********************************************************
436 \subsection{Instance declarations}
438 %*********************************************************
441 @rnInstDecl@ uses the `global name function' to create a new of
442 instance declaration in which local names have been replaced by their
443 original names, reporting any unknown names.
446 rnInstDecl :: RdrNameInstDecl -> RnM_Fixes s RenamedInstDecl
448 rnInstDecl (InstDecl cname ty mbinds from_here modname uprags pragmas src_loc)
449 = pushSrcLocRn src_loc $
450 lookupClass cname `thenRn` \ cname' ->
452 rnPolyType [] ty `thenRn` \ ty' ->
453 -- [] tv_env ensures that tyvars will be foralled
455 rnMethodBinds cname' mbinds `thenRn` \ mbinds' ->
456 mapRn (rn_uprag cname') uprags `thenRn` \ new_uprags ->
458 ASSERT(isNoInstancePragmas pragmas)
459 returnRn (InstDecl cname' ty' mbinds'
460 from_here modname new_uprags noInstancePragmas src_loc)
462 rn_uprag class_name (SpecSig op ty using locn)
463 = pushSrcLocRn src_loc $
464 lookupClassOp class_name op `thenRn` \ op_name ->
465 rnPolyType nullTyVarNamesEnv ty `thenRn` \ new_ty ->
466 rn_using using `thenRn` \ new_using ->
467 returnRn (SpecSig op_name new_ty new_using locn)
469 rn_uprag class_name (InlineSig op locn)
470 = pushSrcLocRn locn $
471 lookupClassOp class_name op `thenRn` \ op_name ->
472 returnRn (InlineSig op_name locn)
474 rn_uprag class_name (DeforestSig op locn)
475 = pushSrcLocRn locn $
476 lookupClassOp class_name op `thenRn` \ op_name ->
477 returnRn (DeforestSig op_name locn)
479 rn_uprag class_name (MagicUnfoldingSig op str locn)
480 = pushSrcLocRn locn $
481 lookupClassOp class_name op `thenRn` \ op_name ->
482 returnRn (MagicUnfoldingSig op_name str locn)
487 = lookupValue v `thenRn` \ new_v ->
488 returnRn (Just new_v)
491 %*********************************************************
493 \subsection{@SPECIALIZE instance@ user-pragmas}
495 %*********************************************************
498 rnSpecInstSig :: RdrNameSpecInstSig
499 -> RnM_Fixes s RenamedSpecInstSig
501 rnSpecInstSig (SpecInstSig clas ty src_loc)
502 = pushSrcLocRn src_loc $
504 tyvars = extractMonoTyNames is_tyvar_name ty
506 mkTyVarNamesEnv src_loc tyvars `thenRn` \ (tv_env,_) ->
507 lookupClass clas `thenRn` \ new_clas ->
508 rnMonoType tv_env ty `thenRn` \ new_ty ->
509 returnRn (SpecInstSig new_clas new_ty src_loc)
512 %*********************************************************
514 \subsection{Default declarations}
516 %*********************************************************
518 @rnDefaultDecl@ uses the `global name function' to create a new set
519 of default declarations in which local names have been replaced by
520 their original names, reporting any unknown names.
523 rnDefaultDecl :: [RdrNameDefaultDecl] -> RnM_Fixes s [RenamedDefaultDecl]
525 rnDefaultDecl [] = returnRn []
526 rnDefaultDecl [DefaultDecl tys src_loc]
527 = pushSrcLocRn src_loc $
528 mapRn (rnMonoType nullTyVarNamesEnv) tys `thenRn` \ tys' ->
529 returnRn [DefaultDecl tys' src_loc]
530 rnDefaultDecl defs@(d:ds)
531 = addErrRn (dupDefaultDeclErr defs) `thenRn_`
535 %*************************************************************************
537 \subsection{Fixity declarations}
539 %*************************************************************************
542 rnFixes :: [RdrNameFixityDecl] -> RnM s [RenamedFixityDecl]
545 = getSrcLocRn `thenRn` \ src_loc ->
547 (_, dup_fixes) = removeDups cmp_fix fixities
548 cmp_fix fix1 fix2 = fixDeclName fix1 `cmp` fixDeclName fix2
550 rn_fixity fix@(InfixL name i)
551 = rn_fixity_pieces InfixL name i fix
552 rn_fixity fix@(InfixR name i)
553 = rn_fixity_pieces InfixR name i fix
554 rn_fixity fix@(InfixN name i)
555 = rn_fixity_pieces InfixN name i fix
557 rn_fixity_pieces mk_fixity name i fix
558 = getRnEnv `thenRn` \ env ->
559 case lookupGlobalRnEnv env name of
560 Just res | isLocallyDefined res
561 -> returnRn (Just (mk_fixity res i))
562 _ -> failButContinueRn Nothing (undefinedFixityDeclErr src_loc fix)
564 mapRn (addErrRn . dupFixityDeclErr src_loc) dup_fixes `thenRn_`
565 mapRn rn_fixity fixities `thenRn` \ fixes_maybe ->
566 returnRn (catMaybes fixes_maybe)
569 %*********************************************************
571 \subsection{Support code to rename types}
573 %*********************************************************
576 rnPolyType :: TyVarNamesEnv
578 -> RnM_Fixes s RenamedPolyType
580 rnPolyType tv_env (HsForAllTy tvs ctxt ty)
581 = rn_poly_help tv_env tvs ctxt ty
583 rnPolyType tv_env (HsPreForAllTy ctxt ty)
584 = rn_poly_help tv_env forall_tyvars ctxt ty
586 mentioned_tyvars = extractCtxtTyNames ctxt `unionLists` extractMonoTyNames is_tyvar_name ty
588 pprTrace "mentioned:" (ppCat (map (ppr PprShowAll) mentioned_tyvars)) $
589 pprTrace "from_ty:" (ppCat (map (ppr PprShowAll) (extractMonoTyNames is_tyvar_name ty))) $
591 mentioned_tyvars `minusList` domTyVarNamesEnv tv_env
594 rn_poly_help :: TyVarNamesEnv
598 -> RnM_Fixes s RenamedPolyType
600 rn_poly_help tv_env tyvars ctxt ty
602 pprTrace "rnPolyType:"
603 (ppCat [ppCat (map (ppr PprShowAll . snd) tv_env),
604 ppStr ";tvs=", ppCat (map (ppr PprShowAll) tyvars),
605 ppStr ";ctxt=", ppCat (map (ppr PprShowAll) ctxt),
606 ppStr ";ty=", ppr PprShowAll ty]) $
608 getSrcLocRn `thenRn` \ src_loc ->
609 mkTyVarNamesEnv src_loc tyvars `thenRn` \ (tv_env1, new_tyvars) ->
611 tv_env2 = catTyVarNamesEnvs tv_env1 tv_env
613 rnContext tv_env2 ctxt `thenRn` \ new_ctxt ->
614 rnMonoType tv_env2 ty `thenRn` \ new_ty ->
615 returnRn (HsForAllTy new_tyvars new_ctxt new_ty)
619 rnMonoType :: TyVarNamesEnv
621 -> RnM_Fixes s RenamedMonoType
623 rnMonoType tv_env (MonoTyVar tyvar)
624 = lookupTyVarName tv_env tyvar `thenRn` \ tyvar' ->
625 returnRn (MonoTyVar tyvar')
627 rnMonoType tv_env (MonoListTy ty)
628 = rnMonoType tv_env ty `thenRn` \ ty' ->
629 returnRn (MonoListTy ty')
631 rnMonoType tv_env (MonoFunTy ty1 ty2)
632 = andRn MonoFunTy (rnMonoType tv_env ty1)
633 (rnMonoType tv_env ty2)
635 rnMonoType tv_env (MonoTupleTy tys)
636 = mapRn (rnMonoType tv_env) tys `thenRn` \ tys' ->
637 returnRn (MonoTupleTy tys')
639 rnMonoType tv_env (MonoTyApp name tys)
641 lookup_fn = if isLexVarId (getLocalName name)
642 then lookupTyVarName tv_env
645 lookup_fn name `thenRn` \ name' ->
646 mapRn (rnMonoType tv_env) tys `thenRn` \ tys' ->
647 returnRn (MonoTyApp name' tys')
651 rnContext :: TyVarNamesEnv -> RdrNameContext -> RnM_Fixes s RenamedContext
653 rnContext tv_env ctxt
656 rn_ctxt (clas, tyvar)
657 = lookupClass clas `thenRn` \ clas_name ->
658 lookupTyVarName tv_env tyvar `thenRn` \ tyvar_name ->
659 returnRn (clas_name, tyvar_name)
664 dupNameExportWarn locn names@((n,_):_)
665 = addShortWarnLocLine locn (\ sty ->
666 ppCat [pprNonSym sty n, ppStr "exported", ppInt (length names), ppStr "times"])
668 dupLocalsExportErr locn locals@((str,_):_)
669 = addErrLoc locn "exported names have same local name" (\ sty ->
670 ppInterleave ppSP (map (pprNonSym sty . snd) locals))
672 classOpExportErr op locn
673 = addShortErrLocLine locn (\ sty ->
674 ppBesides [ppStr "class operation `", ppr sty op, ppStr "' can only be exported with class"])
676 synAllExportErr is_error syn locn
677 = (if is_error then addShortErrLocLine else addShortWarnLocLine) locn (\ sty ->
678 ppBesides [ppStr "type synonym `", ppr sty syn, ppStr "' should be exported abstractly"])
680 withExportErr str rn has rns locn
681 = addErrLoc locn "" (\ sty ->
682 ppAboves [ ppBesides [ppStr "inconsistent list of ", ppStr str, ppStr " in export list for `", ppr sty rn, ppStr "'"],
683 ppCat [ppStr " expected:", ppInterleave ppComma (map (ppr sty) has)],
684 ppCat [ppStr " found: ", ppInterleave ppComma (map (ppr sty) rns)] ])
687 = addShortErrLocLine locn (\ sty ->
688 ppBesides [ ppStr "`", pprNonSym sty rn, ppStr "' has been exported with (..), but is only imported abstractly"])
690 badModExportErr mod locn
691 = addShortErrLocLine locn (\ sty ->
692 ppCat [ ppStr "unknown module in export list: module", ppPStr mod])
694 emptyModExportWarn locn mod
695 = addShortWarnLocLine locn (\ sty ->
696 ppCat [ppStr "module", ppPStr mod, ppStr "has no unqualified imports to export"])
698 dupModExportWarn locn mods@(mod:_)
699 = addShortWarnLocLine locn (\ sty ->
700 ppCat [ppStr "module", ppPStr mod, ppStr "appears", ppInt (length mods), ppStr "times in export list"])
702 derivingNonStdClassErr clas locn
703 = addShortErrLocLine locn (\ sty ->
704 ppCat [ppStr "non-standard class in deriving:", ppr sty clas])
706 dupDefaultDeclErr (DefaultDecl _ locn1 : dup_things) sty
707 = ppAboves (item1 : map dup_item dup_things)
710 = addShortErrLocLine locn1 (\ sty -> ppStr "multiple default declarations") sty
712 dup_item (DefaultDecl _ locn)
713 = addShortErrLocLine locn (\ sty -> ppStr "here was another default declaration") sty
715 undefinedFixityDeclErr locn decl
716 = addErrLoc locn "fixity declaration for unknown operator" (\ sty ->
719 dupFixityDeclErr locn dups
720 = addErrLoc locn "multiple fixity declarations for same operator" (\ sty ->
721 ppAboves (map (ppr sty) dups))