+ lookupTopBndrRn tycon `thenRn` \ tycon' ->
+ bindTyVarsRn data_doc tyvars $ \ tyvars' ->
+ rnContext data_doc context `thenRn` \ context' ->
+ checkDupOrQualNames data_doc con_names `thenRn_`
+ mapRn rnConDecl condecls `thenRn` \ condecls' ->
+ lookupSysBinder gen_name1 `thenRn` \ name1' ->
+ lookupSysBinder gen_name2 `thenRn` \ name2' ->
+ rnDerivs derivings `thenRn` \ derivings' ->
+ returnRn (TyData new_or_data context' tycon' tyvars' condecls' nconstrs
+ derivings' src_loc name1' name2')
+ where
+ data_doc = text "the data type declaration for" <+> quotes (ppr tycon)
+ con_names = map conDeclName condecls
+
+rnTyClDecl (TySynonym name tyvars ty src_loc)
+ = pushSrcLocRn src_loc $
+ doptRn Opt_GlasgowExts `thenRn` \ glaExts ->
+ lookupTopBndrRn name `thenRn` \ name' ->
+ bindTyVarsRn syn_doc tyvars $ \ tyvars' ->
+ rnHsType syn_doc (unquantify glaExts ty) `thenRn` \ ty' ->
+ returnRn (TySynonym name' tyvars' ty' src_loc)
+ where
+ syn_doc = text "the declaration for type synonym" <+> quotes (ppr name)
+
+ -- For H98 we do *not* universally quantify on the RHS of a synonym
+ -- Silently discard context... but the tyvars in the rest won't be in scope
+ unquantify glaExts (HsForAllTy Nothing ctxt ty) | glaExts = ty
+ unquantify glaExys ty = ty
+
+rnTyClDecl (ClassDecl context cname tyvars fds sigs mbinds names src_loc)
+ = pushSrcLocRn src_loc $
+
+ lookupTopBndrRn cname `thenRn` \ cname' ->
+
+ -- Deal with the implicit tycon and datacon name
+ -- They aren't in scope (because they aren't visible to the user)
+ -- and what we want to do is simply look them up in the cache;
+ -- we jolly well ought to get a 'hit' there!
+ mapRn lookupSysBinder names `thenRn` \ names' ->
+
+ -- Tyvars scope over bindings and context
+ bindTyVars2Rn cls_doc tyvars $ \ clas_tyvar_names tyvars' ->
+
+ -- Check the superclasses
+ rnContext cls_doc context `thenRn` \ context' ->
+
+ -- Check the functional dependencies
+ rnFds cls_doc fds `thenRn` \ fds' ->
+
+ -- Check the signatures
+ -- First process the class op sigs (op_sigs), then the fixity sigs (non_op_sigs).
+ let
+ (op_sigs, non_op_sigs) = partition isClassOpSig sigs
+ sig_rdr_names_w_locs = [(op,locn) | ClassOpSig op _ _ locn <- sigs]
+ in
+ checkDupOrQualNames sig_doc sig_rdr_names_w_locs `thenRn_`
+ mapRn (rnClassOp cname' clas_tyvar_names fds') op_sigs `thenRn` \ sigs' ->
+ let
+ binders = mkNameSet [ nm | (ClassOpSig nm _ _ _) <- sigs' ]
+ in
+ renameSigs (okClsDclSig binders) non_op_sigs `thenRn` \ non_ops' ->
+
+ -- Typechecker is responsible for checking that we only
+ -- give default-method bindings for things in this class.
+ -- The renamer *could* check this for class decls, but can't
+ -- for instance decls.
+
+ returnRn (ClassDecl context' cname' tyvars' fds' (non_ops' ++ sigs') EmptyMonoBinds names' src_loc)
+ where
+ cls_doc = text "the declaration for class" <+> ppr cname
+ sig_doc = text "the signatures for class" <+> ppr cname
+
+rnClassOp clas clas_tyvars clas_fds sig@(ClassOpSig op maybe_dm_stuff ty locn)
+ = pushSrcLocRn locn $
+ lookupTopBndrRn op `thenRn` \ op_name ->
+
+ -- Check the signature
+ rnHsSigType (quotes (ppr op)) ty `thenRn` \ new_ty ->
+
+ -- Make the default-method name
+ (case maybe_dm_stuff of
+ Nothing -> returnRn Nothing -- Source-file class decl
+
+ Just (DefMeth dm_rdr_name)
+ -> -- Imported class that has a default method decl
+ -- See comments with tname, snames, above
+ lookupSysBinder dm_rdr_name `thenRn` \ dm_name ->
+ returnRn (Just (DefMeth dm_name))
+ -- An imported class decl for a class decl that had an explicit default
+ -- method, mentions, rather than defines,
+ -- the default method, so we must arrange to pull it in
+
+ Just GenDefMeth -> returnRn (Just GenDefMeth)
+ Just NoDefMeth -> returnRn (Just NoDefMeth)
+ ) `thenRn` \ maybe_dm_stuff' ->
+
+ returnRn (ClassOpSig op_name maybe_dm_stuff' new_ty locn)
+
+rnClassBinds :: RdrNameTyClDecl -> RenamedTyClDecl -> RnMS (RenamedTyClDecl, FreeVars)
+ -- Rename the mbinds only; the rest is done already
+rnClassBinds (ClassDecl _ _ _ _ _ mbinds _ _ ) -- Get mbinds from here
+ (ClassDecl context cname tyvars fds sigs _ names src_loc) -- Everything else is here
+ = -- The newLocals call is tiresome: given a generic class decl
+ -- class C a where
+ -- op :: a -> a
+ -- op {| x+y |} (Inl a) = ...
+ -- op {| x+y |} (Inr b) = ...
+ -- op {| a*b |} (a*b) = ...
+ -- we want to name both "x" tyvars with the same unique, so that they are
+ -- easy to group together in the typechecker.
+ -- Hence the
+ extendTyVarEnvFVRn (map hsTyVarName tyvars) $
+ getLocalNameEnv `thenRn` \ name_env ->
+ let
+ meth_rdr_names_w_locs = collectLocatedMonoBinders mbinds
+ gen_rdr_tyvars_w_locs = [(tv,src_loc) | tv <- extractGenericPatTyVars mbinds,
+ not (tv `elemRdrEnv` name_env)]
+ in
+ checkDupOrQualNames meth_doc meth_rdr_names_w_locs `thenRn_`
+ newLocalsRn mkLocalName gen_rdr_tyvars_w_locs `thenRn` \ gen_tyvars ->
+ rnMethodBinds gen_tyvars mbinds `thenRn` \ (mbinds', meth_fvs) ->
+ returnRn (ClassDecl context cname tyvars fds sigs mbinds' names src_loc, meth_fvs)
+ where
+ meth_doc = text "the default-methods for class" <+> ppr cname