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 )
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.
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 = (nameFixDecl 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 _) = getSrcLocRn `thenRn` \ src_loc ->
197 warnAndContinueRn emptyBag (synAllExportErr rn src_loc)
198 checkIEAll rn = returnRn emptyBag
200 exp_all n = (n, ExportAll)
202 rnIE mods (IEThingWith name names)
203 = lookupTyConOrClass name `thenRn` \ rn ->
204 mapRn lookupValue names `thenRn` \ rns ->
205 checkIEWith rn rns `thenRn` \ exps ->
206 checkImportAll rn `thenRn_`
207 returnRn (Nothing, exps)
209 checkIEWith rn@(RnData n cons fields) rns
210 | same_names (cons++fields) rns
211 = returnRn (consBag (exp_all n) (listToBag (map exp_all cons)))
213 = rnWithErr "constructrs (and fields)" rn (cons++fields) rns
214 checkIEWith rn@(RnClass n ops) rns
216 = returnRn (consBag (exp_all n) (listToBag (map exp_all ops)))
218 = rnWithErr "class ops" rn ops rns
219 checkIEWith rn@(RnSyn _) rns
220 = getSrcLocRn `thenRn` \ src_loc ->
221 failButContinueRn emptyBag (synAllExportErr rn src_loc)
225 exp_all n = (n, ExportAll)
228 = all (not.isRnUnbound) rns &&
229 sortLt (<) (map uniqueOf has) == sortLt (<) (map uniqueOf rns)
231 rnWithErr str rn has rns
232 = getSrcLocRn `thenRn` \ src_loc ->
233 failButContinueRn emptyBag (withExportErr str rn has rns src_loc)
235 rnIE mods (IEModuleContents mod)
236 | isIn "rnIE:IEModule" mod mods
237 = returnRn (Just mod, emptyBag)
239 = getSrcLocRn `thenRn` \ src_loc ->
240 failButContinueRn (Nothing,emptyBag) (badModExportErr mod src_loc)
244 = case nameImportFlag (getName rn) of
245 ExportAll -> returnRn ()
246 exp -> getSrcLocRn `thenRn` \ src_loc ->
247 addErrRn (importAllErr rn src_loc)
250 %*********************************************************
252 \subsection{Type declarations}
254 %*********************************************************
256 @rnTyDecl@ uses the `global name function' to create a new type
257 declaration in which local names have been replaced by their original
258 names, reporting any unknown names.
260 Renaming type variables is a pain. Because they now contain uniques,
261 it is necessary to pass in an association list which maps a parsed
262 tyvar to its Name representation. In some cases (type signatures of
263 values), it is even necessary to go over the type first in order to
264 get the set of tyvars used by it, make an assoc list, and then go over
265 it again to rename the tyvars! However, we can also do some scoping
266 checks at the same time.
269 rnTyDecl :: RdrNameTyDecl -> RnM_Fixes s RenamedTyDecl
271 rnTyDecl (TyData context tycon tyvars condecls derivings pragmas src_loc)
272 = pushSrcLocRn src_loc $
273 lookupTyCon tycon `thenRn` \ tycon' ->
274 mkTyVarNamesEnv src_loc tyvars `thenRn` \ (tv_env, tyvars') ->
275 rnContext tv_env context `thenRn` \ context' ->
276 rnConDecls tv_env condecls `thenRn` \ condecls' ->
277 rn_derivs tycon' src_loc derivings `thenRn` \ derivings' ->
278 ASSERT(isNoDataPragmas pragmas)
279 returnRn (TyData context' tycon' tyvars' condecls' derivings' noDataPragmas src_loc)
281 rnTyDecl (TyNew context tycon tyvars condecl derivings pragmas src_loc)
282 = pushSrcLocRn src_loc $
283 lookupTyCon tycon `thenRn` \ tycon' ->
284 mkTyVarNamesEnv src_loc tyvars `thenRn` \ (tv_env, tyvars') ->
285 rnContext tv_env context `thenRn` \ context' ->
286 rnConDecls tv_env condecl `thenRn` \ condecl' ->
287 rn_derivs tycon' src_loc derivings `thenRn` \ derivings' ->
288 ASSERT(isNoDataPragmas pragmas)
289 returnRn (TyNew context' tycon' tyvars' condecl' derivings' noDataPragmas src_loc)
291 rnTyDecl (TySynonym name tyvars ty src_loc)
292 = pushSrcLocRn src_loc $
293 lookupTyCon name `thenRn` \ name' ->
294 mkTyVarNamesEnv src_loc tyvars `thenRn` \ (tv_env, tyvars') ->
295 rnMonoType tv_env ty `thenRn` \ ty' ->
296 returnRn (TySynonym name' tyvars' ty' src_loc)
298 rn_derivs tycon2 locn Nothing -- derivs not specified
301 rn_derivs tycon2 locn (Just ds)
302 = mapRn (rn_deriv tycon2 locn) ds `thenRn` \ derivs ->
303 returnRn (Just derivs)
305 rn_deriv tycon2 locn clas
306 = lookupClass clas `thenRn` \ clas_name ->
307 addErrIfRn (uniqueOf clas_name `not_elem` derivableClassKeys)
308 (derivingNonStdClassErr clas locn)
312 not_elem = isn'tIn "rn_deriv"
315 @rnConDecls@ uses the `global name function' to create a new
316 constructor in which local names have been replaced by their original
317 names, reporting any unknown names.
320 rnConDecls :: TyVarNamesEnv
322 -> RnM_Fixes s [RenamedConDecl]
324 rnConDecls tv_env con_decls
325 = mapRn rn_decl con_decls
327 rn_decl (ConDecl name tys src_loc)
328 = pushSrcLocRn src_loc $
329 lookupConstr name `thenRn` \ new_name ->
330 mapRn rn_bang_ty tys `thenRn` \ new_tys ->
331 returnRn (ConDecl new_name new_tys src_loc)
333 rn_decl (ConOpDecl ty1 op ty2 src_loc)
334 = pushSrcLocRn src_loc $
335 lookupConstr op `thenRn` \ new_op ->
336 rn_bang_ty ty1 `thenRn` \ new_ty1 ->
337 rn_bang_ty ty2 `thenRn` \ new_ty2 ->
338 returnRn (ConOpDecl new_ty1 new_op new_ty2 src_loc)
340 rn_decl (NewConDecl name ty src_loc)
341 = pushSrcLocRn src_loc $
342 lookupConstr name `thenRn` \ new_name ->
343 rn_mono_ty ty `thenRn` \ new_ty ->
344 returnRn (NewConDecl new_name new_ty src_loc)
346 rn_decl (RecConDecl name fields src_loc)
347 = pushSrcLocRn src_loc $
348 lookupConstr name `thenRn` \ new_name ->
349 mapRn rn_field fields `thenRn` \ new_fields ->
350 returnRn (RecConDecl new_name new_fields src_loc)
353 = mapRn lookupField names `thenRn` \ new_names ->
354 rn_bang_ty ty `thenRn` \ new_ty ->
355 returnRn (new_names, new_ty)
357 rn_mono_ty = rnMonoType tv_env
358 rn_poly_ty = rnPolyType tv_env
360 rn_bang_ty (Banged ty)
361 = rn_poly_ty ty `thenRn` \ new_ty ->
362 returnRn (Banged new_ty)
363 rn_bang_ty (Unbanged ty)
364 = rn_poly_ty ty `thenRn` \ new_ty ->
365 returnRn (Unbanged new_ty)
368 %*********************************************************
370 \subsection{SPECIALIZE data pragmas}
372 %*********************************************************
375 rnSpecDataSig :: RdrNameSpecDataSig
376 -> RnM_Fixes s RenamedSpecDataSig
378 rnSpecDataSig (SpecDataSig tycon ty src_loc)
379 = pushSrcLocRn src_loc $
381 tyvars = extractMonoTyNames is_tyvar_name ty
383 mkTyVarNamesEnv src_loc tyvars `thenRn` \ (tv_env,_) ->
384 lookupTyCon tycon `thenRn` \ tycon' ->
385 rnMonoType tv_env ty `thenRn` \ ty' ->
386 returnRn (SpecDataSig tycon' ty' src_loc)
388 is_tyvar_name n = isLexVarId (getLocalName n)
391 %*********************************************************
393 \subsection{Class declarations}
395 %*********************************************************
397 @rnClassDecl@ uses the `global name function' to create a new
398 class declaration in which local names have been replaced by their
399 original names, reporting any unknown names.
402 rnClassDecl :: RdrNameClassDecl -> RnM_Fixes s RenamedClassDecl
404 rnClassDecl (ClassDecl context cname tyvar sigs mbinds pragmas src_loc)
405 = pushSrcLocRn src_loc $
406 mkTyVarNamesEnv src_loc [tyvar] `thenRn` \ (tv_env, [tyvar']) ->
407 rnContext tv_env context `thenRn` \ context' ->
408 lookupClass cname `thenRn` \ cname' ->
409 mapRn (rn_op cname' tv_env) sigs `thenRn` \ sigs' ->
410 rnMethodBinds cname' mbinds `thenRn` \ mbinds' ->
411 ASSERT(isNoClassPragmas pragmas)
412 returnRn (ClassDecl context' cname' tyvar' sigs' mbinds' NoClassPragmas src_loc)
414 rn_op clas tv_env (ClassOpSig op ty pragmas locn)
415 = pushSrcLocRn locn $
416 lookupClassOp clas op `thenRn` \ op_name ->
417 rnPolyType tv_env ty `thenRn` \ new_ty ->
420 *** Please check here that tyvar' appears in new_ty ***
421 *** (used to be in tcClassSig, but it's better here)
422 *** not_elem = isn'tIn "tcClassSigs"
423 *** -- Check that the class type variable is mentioned
424 *** checkTc (clas_tyvar `not_elem` extractTyVarTemplatesFromTy local_ty)
425 *** (methodTypeLacksTyVarErr clas_tyvar (_UNPK_ op_name) src_loc) `thenTc_`
428 ASSERT(isNoClassOpPragmas pragmas)
429 returnRn (ClassOpSig op_name new_ty noClassOpPragmas locn)
433 %*********************************************************
435 \subsection{Instance declarations}
437 %*********************************************************
440 @rnInstDecl@ uses the `global name function' to create a new of
441 instance declaration in which local names have been replaced by their
442 original names, reporting any unknown names.
445 rnInstDecl :: RdrNameInstDecl -> RnM_Fixes s RenamedInstDecl
447 rnInstDecl (InstDecl cname ty mbinds from_here modname uprags pragmas src_loc)
448 = pushSrcLocRn src_loc $
449 lookupClass cname `thenRn` \ cname' ->
451 rnPolyType [] ty `thenRn` \ ty' ->
452 -- [] tv_env ensures that tyvars will be foralled
454 rnMethodBinds cname' mbinds `thenRn` \ mbinds' ->
455 mapRn (rn_uprag cname') uprags `thenRn` \ new_uprags ->
457 ASSERT(isNoInstancePragmas pragmas)
458 returnRn (InstDecl cname' ty' mbinds'
459 from_here modname new_uprags noInstancePragmas src_loc)
461 rn_uprag class_name (SpecSig op ty using locn)
462 = pushSrcLocRn src_loc $
463 lookupClassOp class_name op `thenRn` \ op_name ->
464 rnPolyType nullTyVarNamesEnv ty `thenRn` \ new_ty ->
465 rn_using using `thenRn` \ new_using ->
466 returnRn (SpecSig op_name new_ty new_using locn)
468 rn_uprag class_name (InlineSig op locn)
469 = pushSrcLocRn locn $
470 lookupClassOp class_name op `thenRn` \ op_name ->
471 returnRn (InlineSig op_name locn)
473 rn_uprag class_name (DeforestSig op locn)
474 = pushSrcLocRn locn $
475 lookupClassOp class_name op `thenRn` \ op_name ->
476 returnRn (DeforestSig op_name locn)
478 rn_uprag class_name (MagicUnfoldingSig op str locn)
479 = pushSrcLocRn locn $
480 lookupClassOp class_name op `thenRn` \ op_name ->
481 returnRn (MagicUnfoldingSig op_name str locn)
486 = lookupValue v `thenRn` \ new_v ->
487 returnRn (Just new_v)
490 %*********************************************************
492 \subsection{@SPECIALIZE instance@ user-pragmas}
494 %*********************************************************
497 rnSpecInstSig :: RdrNameSpecInstSig
498 -> RnM_Fixes s RenamedSpecInstSig
500 rnSpecInstSig (SpecInstSig clas ty src_loc)
501 = pushSrcLocRn src_loc $
503 tyvars = extractMonoTyNames is_tyvar_name ty
505 mkTyVarNamesEnv src_loc tyvars `thenRn` \ (tv_env,_) ->
506 lookupClass clas `thenRn` \ new_clas ->
507 rnMonoType tv_env ty `thenRn` \ new_ty ->
508 returnRn (SpecInstSig new_clas new_ty src_loc)
511 %*********************************************************
513 \subsection{Default declarations}
515 %*********************************************************
517 @rnDefaultDecl@ uses the `global name function' to create a new set
518 of default declarations in which local names have been replaced by
519 their original names, reporting any unknown names.
522 rnDefaultDecl :: [RdrNameDefaultDecl] -> RnM_Fixes s [RenamedDefaultDecl]
524 rnDefaultDecl [] = returnRn []
525 rnDefaultDecl [DefaultDecl tys src_loc]
526 = pushSrcLocRn src_loc $
527 mapRn (rnMonoType nullTyVarNamesEnv) tys `thenRn` \ tys' ->
528 returnRn [DefaultDecl tys' src_loc]
529 rnDefaultDecl defs@(d:ds)
530 = addErrRn (dupDefaultDeclErr defs) `thenRn_`
534 %*************************************************************************
536 \subsection{Fixity declarations}
538 %*************************************************************************
541 rnFixes :: [RdrNameFixityDecl] -> RnM s [RenamedFixityDecl]
544 = getSrcLocRn `thenRn` \ src_loc ->
546 (_, dup_fixes) = removeDups cmp_fix fixities
547 cmp_fix fix1 fix2 = nameFixDecl fix1 `cmp` nameFixDecl fix2
549 rn_fixity fix@(InfixL name i)
550 = rn_fixity_pieces InfixL name i fix
551 rn_fixity fix@(InfixR name i)
552 = rn_fixity_pieces InfixR name i fix
553 rn_fixity fix@(InfixN name i)
554 = rn_fixity_pieces InfixN name i fix
556 rn_fixity_pieces mk_fixity name i fix
557 = getRnEnv `thenRn` \ env ->
558 case lookupGlobalRnEnv env name of
559 Just res | isLocallyDefined res
560 -> returnRn (Just (mk_fixity res i))
561 _ -> failButContinueRn Nothing (undefinedFixityDeclErr src_loc fix)
563 mapRn (addErrRn . dupFixityDeclErr src_loc) dup_fixes `thenRn_`
564 mapRn rn_fixity fixities `thenRn` \ fixes_maybe ->
565 returnRn (catMaybes fixes_maybe)
567 nameFixDecl (InfixL name i) = name
568 nameFixDecl (InfixR name i) = name
569 nameFixDecl (InfixN name i) = name
572 %*********************************************************
574 \subsection{Support code to rename types}
576 %*********************************************************
579 rnPolyType :: TyVarNamesEnv
581 -> RnM_Fixes s RenamedPolyType
583 rnPolyType tv_env (HsForAllTy tvs ctxt ty)
584 = rn_poly_help tv_env tvs ctxt ty
586 rnPolyType tv_env (HsPreForAllTy ctxt ty)
587 = rn_poly_help tv_env forall_tyvars ctxt ty
589 mentioned_tyvars = extractCtxtTyNames ctxt `unionLists` extractMonoTyNames is_tyvar_name ty
591 pprTrace "mentioned:" (ppCat (map (ppr PprShowAll) mentioned_tyvars)) $
592 pprTrace "from_ty:" (ppCat (map (ppr PprShowAll) (extractMonoTyNames is_tyvar_name ty))) $
594 mentioned_tyvars `minusList` domTyVarNamesEnv tv_env
597 rn_poly_help :: TyVarNamesEnv
601 -> RnM_Fixes s RenamedPolyType
603 rn_poly_help tv_env tyvars ctxt ty
605 pprTrace "rnPolyType:"
606 (ppCat [ppCat (map (ppr PprShowAll . snd) tv_env),
607 ppStr ";tvs=", ppCat (map (ppr PprShowAll) tyvars),
608 ppStr ";ctxt=", ppCat (map (ppr PprShowAll) ctxt),
609 ppStr ";ty=", ppr PprShowAll ty]) $
611 getSrcLocRn `thenRn` \ src_loc ->
612 mkTyVarNamesEnv src_loc tyvars `thenRn` \ (tv_env1, new_tyvars) ->
614 tv_env2 = catTyVarNamesEnvs tv_env1 tv_env
616 rnContext tv_env2 ctxt `thenRn` \ new_ctxt ->
617 rnMonoType tv_env2 ty `thenRn` \ new_ty ->
618 returnRn (HsForAllTy new_tyvars new_ctxt new_ty)
622 rnMonoType :: TyVarNamesEnv
624 -> RnM_Fixes s RenamedMonoType
626 rnMonoType tv_env (MonoTyVar tyvar)
627 = lookupTyVarName tv_env tyvar `thenRn` \ tyvar' ->
628 returnRn (MonoTyVar tyvar')
630 rnMonoType tv_env (MonoListTy ty)
631 = rnMonoType tv_env ty `thenRn` \ ty' ->
632 returnRn (MonoListTy ty')
634 rnMonoType tv_env (MonoFunTy ty1 ty2)
635 = andRn MonoFunTy (rnMonoType tv_env ty1)
636 (rnMonoType tv_env ty2)
638 rnMonoType tv_env (MonoTupleTy tys)
639 = mapRn (rnMonoType tv_env) tys `thenRn` \ tys' ->
640 returnRn (MonoTupleTy tys')
642 rnMonoType tv_env (MonoTyApp name tys)
644 lookup_fn = if isLexVarId (getLocalName name)
645 then lookupTyVarName tv_env
648 lookup_fn name `thenRn` \ name' ->
649 mapRn (rnMonoType tv_env) tys `thenRn` \ tys' ->
650 returnRn (MonoTyApp name' tys')
654 rnContext :: TyVarNamesEnv -> RdrNameContext -> RnM_Fixes s RenamedContext
656 rnContext tv_env ctxt
659 rn_ctxt (clas, tyvar)
660 = lookupClass clas `thenRn` \ clas_name ->
661 lookupTyVarName tv_env tyvar `thenRn` \ tyvar_name ->
662 returnRn (clas_name, tyvar_name)
667 dupNameExportWarn locn names@((n,_):_)
668 = addShortErrLocLine locn (\ sty ->
669 ppCat [pprNonSym sty n, ppStr "exported", ppInt (length names), ppStr "times"])
671 dupLocalsExportErr locn locals@((str,_):_)
672 = addErrLoc locn "exported names have same local name" (\ sty ->
673 ppInterleave ppSP (map (pprNonSym sty . snd) locals))
675 classOpExportErr op locn
676 = addShortErrLocLine locn (\ sty ->
677 ppBesides [ppStr "class operation `", ppr sty op, ppStr "' can only be exported with class"])
679 synAllExportErr syn locn
680 = addShortErrLocLine locn (\ sty ->
681 ppBesides [ppStr "type synonym `", ppr sty syn, ppStr "' should be exported abstractly"])
683 withExportErr str rn has rns locn
684 = addErrLoc locn "" (\ sty ->
685 ppAboves [ ppBesides [ppStr "inconsistent list of", ppStr str, ppStr "in export list for `", ppr sty rn, ppStr "'"],
686 ppCat [ppStr " expected:", ppInterleave ppComma (map (ppr sty) has)],
687 ppCat [ppStr " found: ", ppInterleave ppComma (map (ppr sty) rns)] ])
690 = addShortErrLocLine locn (\ sty ->
691 ppBesides [ ppStr "`", pprNonSym sty rn, ppStr "' has been exported with (..), but is only imported abstractly"])
693 badModExportErr mod locn
694 = addShortErrLocLine locn (\ sty ->
695 ppCat [ ppStr "unknown module in export list:", ppPStr mod])
697 dupModExportWarn locn mods@(mod:_)
698 = addShortErrLocLine locn (\ sty ->
699 ppCat [ppStr "module", ppPStr mod, ppStr "appears", ppInt (length mods), ppStr "times in export list"])
701 emptyModExportWarn locn mod
702 = addShortErrLocLine locn (\ sty ->
703 ppCat [ppStr "module", ppPStr mod, ppStr "has no unqualified imports to export"])
705 derivingNonStdClassErr clas locn
706 = addShortErrLocLine locn (\ sty ->
707 ppCat [ppStr "non-standard class in deriving:", ppr sty clas])
709 dupDefaultDeclErr (DefaultDecl _ locn1 : dup_things) sty
710 = ppAboves (item1 : map dup_item dup_things)
713 = addShortErrLocLine locn1 (\ sty -> ppStr "multiple default declarations") sty
715 dup_item (DefaultDecl _ locn)
716 = addShortErrLocLine locn (\ sty -> ppStr "here was another default declaration") sty
718 undefinedFixityDeclErr locn decl
719 = addErrLoc locn "fixity declaration for unknown operator" (\ sty ->
722 dupFixityDeclErr locn dups
723 = addErrLoc locn "multiple fixity declarations for same operator" (\ sty ->
724 ppAboves (map (ppr sty) dups))