+ fixTc (\ ~(unf_env ,_) ->
+ -- unf_env is used for type-checking interface pragmas
+ -- which is done lazily [ie failure just drops the pragma
+ -- without having any global-failure effect].
+ --
+ -- unf_env is also used to get the pragam info for dfuns.
+
+ -- The knot for instance information. This isn't used at all
+ -- till we type-check value declarations
+ fixTc ( \ ~(rec_inst_mapper, _, _, _, _) ->
+
+ -- Type-check the type and class decls
+ -- trace "tcTyAndClassDecls:" $
+ tcTyAndClassDecls1 unf_env rec_inst_mapper decls `thenTc` \ env ->
+
+ -- trace "tc3" $
+ -- Typecheck the instance decls, includes deriving
+ tcSetEnv env (
+ -- trace "tcInstDecls:" $
+ tcInstDecls1 unf_env decls mod_name rn_name_supply
+ ) `thenTc` \ (inst_info, deriv_binds, ddump_deriv) ->
+
+ -- trace "tc4" $
+ buildInstanceEnvs inst_info `thenTc` \ inst_mapper ->
+
+ returnTc (inst_mapper, env, inst_info, deriv_binds, ddump_deriv)
+
+ -- End of inner fix loop
+ ) `thenTc` \ (_, env, inst_info, deriv_binds, ddump_deriv) ->
+
+ -- trace "tc5" $
+ tcSetEnv env $
+
+ -- Default declarations
+ tcDefaults decls `thenTc` \ defaulting_tys ->
+ tcSetDefaultTys defaulting_tys $
+
+ -- Create any necessary record selector Ids and their bindings
+ -- "Necessary" includes data and newtype declarations
+ let
+ tycons = getEnv_TyCons env
+ classes = getEnv_Classes env
+ in
+ mkDataBinds tycons `thenTc` \ (data_ids, data_binds) ->
+
+ -- Extend the global value environment with
+ -- (a) constructors
+ -- (b) record selectors
+ -- (c) class op selectors
+ -- (d) default-method ids
+ tcExtendGlobalValEnv data_ids $
+ tcExtendGlobalValEnv (concat (map classSelIds classes)) $