-tcModule :: GlobalNameMappers -- final renamer info for derivings
- -> RenamedHsModule -- input
- -> TcM s ((TypecheckedHsBinds, -- record selector binds
- TypecheckedHsBinds, -- binds from class decls; does NOT
- -- include default-methods bindings
- TypecheckedHsBinds, -- binds from instance decls; INCLUDES
- -- class default-methods binds
- TypecheckedHsBinds, -- binds from value decls
-
- [(Id, TypecheckedHsExpr)]), -- constant instance binds
-
- ([RenamedFixityDecl], [Id], [TyCon], [Class], Bag InstInfo),
- -- things for the interface generator
-
- ([TyCon], [Class]),
- -- environments of info from this module only
-
- FiniteMap TyCon [(Bool, [Maybe Type])],
- -- source tycon specialisation requests
-
- PprStyle -> Pretty) -- -ddump-deriving info
-
-tcModule renamer_name_funs
- (HsModule mod_name verion exports imports fixities
- ty_decls specdata_sigs cls_decls inst_decls specinst_sigs
- default_decls val_decls sigs src_loc)
-
- = ASSERT(null imports)
-
- tcAddSrcLoc src_loc $ -- record where we're starting
-
- -- Tie the knot for inteface-file value declaration signatures
- -- This info is only used inside the knot for type-checking the
- -- pragmas, which is done lazily [ie failure just drops the pragma
- -- without having any global-failure effect].
-
- fixTc (\ ~(_, _, _, _, _, _, sig_ids) ->
- tcExtendGlobalValEnv sig_ids (
-
- -- 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 rec_inst_mapper ty_decls_bag cls_decls_bag
- `thenTc` \ (env, record_binds) ->
-
- -- Typecheck the instance decls, includes deriving
- tcSetEnv env (
- trace "tcInstDecls:" $
- tcInstDecls1 inst_decls_bag specinst_sigs
- mod_name renamer_name_funs fixities
- ) `thenTc` \ (inst_info, deriv_binds, ddump_deriv) ->
-
- buildInstanceEnvs inst_info `thenTc` \ inst_mapper ->
-
- returnTc (inst_mapper, env, record_binds, inst_info, deriv_binds, ddump_deriv)
-
- ) `thenTc` \ (_, env, record_binds, inst_info, deriv_binds, ddump_deriv) ->
- tcSetEnv env (
-
- -- Default declarations
- tcDefaults default_decls `thenTc` \ defaulting_tys ->
- tcSetDefaultTys defaulting_tys ( -- for the iface sigs...
-
- -- Interface type signatures
- -- We tie a knot so that the Ids read out of interfaces are in scope
- -- when we read their pragmas.
- -- What we rely on is that pragmas are typechecked lazily; if
- -- any type errors are found (ie there's an inconsistency)
- -- we silently discard the pragma
- tcInterfaceSigs sigs `thenTc` \ sig_ids ->
-
- returnTc (env, inst_info, record_binds, deriv_binds, ddump_deriv, defaulting_tys, sig_ids)
-
- )))) `thenTc` \ (env, inst_info, record_binds, deriv_binds, ddump_deriv, defaulting_tys, _) ->
-
- tcSetEnv env ( -- to the end...
- tcSetDefaultTys defaulting_tys ( -- ditto
-
- -- Value declarations next.
- -- We also typecheck any extra binds that came out of the "deriving" process
- trace "tcBinds:" $
- tcBindsAndThen
- (\ binds1 (binds2, thing) -> (binds1 `ThenBinds` binds2, thing))
- (val_decls `ThenBinds` deriv_binds)
- ( -- Second pass over instance declarations,
- -- to compile the bindings themselves.
- tcInstDecls2 inst_info `thenNF_Tc` \ (lie_instdecls, inst_binds) ->
- tcClassDecls2 cls_decls_bag `thenNF_Tc` \ (lie_clasdecls, cls_binds) ->
- tcGetEnv `thenNF_Tc` \ env ->
- returnTc ( (EmptyBinds, (inst_binds, cls_binds, env)),
- lie_instdecls `plusLIE` lie_clasdecls,
- () ))
-
- `thenTc` \ ((val_binds, (inst_binds, cls_binds, final_env)), lie_alldecls, _) ->
-
- checkTopLevelIds mod_name final_env `thenTc_`
-
- -- Deal with constant or ambiguous InstIds. How could
- -- there be ambiguous ones? They can only arise if a
- -- top-level decl falls under the monomorphism
- -- restriction, and no subsequent decl instantiates its
- -- type. (Usually, ambiguous type variables are resolved
- -- during the generalisation step.)
- tcSimplifyTop lie_alldecls `thenTc` \ const_insts ->