-gen_inst_info :: FAST_STRING -- Module name
- -> [RenamedFixityDecl] -- all known fixities;
- -- may be needed for Text
- -> GlobalNameFuns -- lookup stuff for names we may use
- -> InstInfo -- the main stuff to work on
- -> TcM InstInfo -- the gen'd (filled-in) "instance decl"
-
-gen_inst_info modname fixities deriver_name_funs
- info@(InstInfo clas tyvar_tmpls ty inst_decl_theta _ _ _ _ _ _ locn _)
- =
- -- Generate the various instance-related Ids
- mkInstanceRelatedIds
- (panic "add_solns:E")
- -- These two are only needed if there are pragmas to typecheck;
- -- but there ain't since we are generating the code right here.
- True {-yes, from_here-}
- NoInstancePragmas
- mkGeneratedSrcLoc
- clas
- tyvar_tmpls ty
- inst_decl_theta
- [{-no user pragmas-}]
- `thenTc` \ (dfun_id, dfun_theta, const_meth_ids) ->
-
- -- Generate the bindings for the new instance declaration,
- -- rename it, and check for errors
- getSwitchCheckerTc `thenNF_Tc` \ sw_chkr ->
- let
- (tycon,_,_) = getUniDataTyCon ty
-
- omit_readsPrec = sw_chkr OmitDerivedRead
-
- proto_mbinds
- = if clas_key == textClassKey then gen_Text_binds fixities omit_readsPrec tycon
- else if clas_key == eqClassKey then gen_Eq_binds tycon
- else if clas_key == ordClassKey then gen_Ord_binds tycon
- else if clas_key == enumClassKey then gen_Enum_binds tycon
- else if clas_key == ixClassKey then gen_Ix_binds tycon
- else if clas_key == binaryClassKey then gen_Binary_binds tycon
- else panic "gen_inst_info:bad derived class"
- in
- rn4MtoTcM deriver_name_funs (
- rnMethodBinds4 clas_Name proto_mbinds
- ) `thenNF_Tc` \ (mbinds, errs) ->
-
- if not (isEmptyBag errs) then
- pprPanic "gen_inst_info:renamer errs!\n" (ppAbove (pprBagOfErrors PprDebug errs) (ppr PprDebug proto_mbinds))
- else
- --pprTrace "derived binds:" (ppr PprDebug proto_mbinds) (
-
- -- All done
- let
- from_here = isLocallyDefined tycon -- If so, then from here
- in
- returnTc (InstInfo clas tyvar_tmpls ty
- inst_decl_theta dfun_theta dfun_id const_meth_ids
- -- and here comes the main point...
- (if from_here then mbinds else EmptyMonoBinds)
- from_here modname locn [])
- --)
+-- Generate the method bindings for the required instance
+-- (paired with class name, as we need that when generating dict
+-- names.)
+gen_bind :: (Name -> Maybe Fixity) -> DFunId -> RdrNameMonoBinds
+gen_bind get_fixity dfun
+ | clas `hasKey` showClassKey = gen_Show_binds get_fixity tycon
+ | clas `hasKey` readClassKey = gen_Read_binds get_fixity tycon
+ | otherwise
+ = assoc "gen_bind:bad derived class"
+ [(eqClassKey, gen_Eq_binds)
+ ,(ordClassKey, gen_Ord_binds)
+ ,(enumClassKey, gen_Enum_binds)
+ ,(boundedClassKey, gen_Bounded_binds)
+ ,(ixClassKey, gen_Ix_binds)
+ ]
+ (classKey clas)
+ tycon