- -- The knot for instance information. This isn't used at all
- -- till we type-check value declarations.
- fixTc ( \ ~(rec_inst_mapper, _, _, _, _, _, _, _, _) ->
-
- -- The knot for TyCons and Classes
- fixTc ( \ ~(_, rec_tce, rec_ce, rec_datacons_gve, rec_ops_gve, _, _) ->
- let
- e3 = e2
- `plusE_GVE` rec_datacons_gve
- `plusE_GVE` rec_ops_gve
- `plusE_TCE` rec_tce
- `plusE_CE` rec_ce
- in
- -- DO THE TYPE DECLS
- -- Including the pragmas: {-# ABSTRACT TypeSyn #-}
- -- {-# SPECIALIZE data DataType ... #-}
- let
- (absty_sigs, specdata_sigs) = partition is_absty_sig ty_sigs
- is_absty_sig (AbstractTypeSig _ _) = True
- is_absty_sig (SpecDataSig _ _ _) = False
-
- is_abs_syn :: Name -> Bool -- a lookup fn for abs synonyms
- is_abs_syn n
- = n `is_elem` [ tc | (AbstractTypeSig tc _) <- absty_sigs ]
- where
- is_elem = isIn "tcModule"
-
- get_spec_sigs :: Name -> [RenamedDataTypeSig]
- get_spec_sigs n
- = [ sig | sig@(SpecDataSig tc _ _) <- specdata_sigs, n == tc]
- in
- babyTcMtoTcM (tcTyDecls e3 is_abs_syn get_spec_sigs tydecls)
- `thenTc` \ (tce, datacons_gve, tycon_specs) ->
-
- -- DO THE CLASS DECLS
- tcClassDecls1 e3 rec_inst_mapper classdecls
- `thenTc` \ (class_info, ce, ops_gve) ->
-
- -- End of TyCon/Class knot
- -- Augment whatever TCE/GVE/CE stuff was in orig_e
- returnTc (e3, tce, ce, datacons_gve, ops_gve, class_info, tycon_specs)
-
- -- End of inner fixTc
- ) `thenTc` ( \ (e3, tce_here, ce_here, _, _, class_info, tycon_specs) ->
- -- The "here" things are the extra decls defined in this
- -- module or its imports; but not including whatever was
- -- in the incoming e.
-
- -- Grab completed tce/ce and check for type/class cycles
- -- The tce/ce are now stable and lookable-at, with the
- -- exception of the instance information inside classes
- let
- ce3 = getE_CE e3
- tce3 = getE_TCE e3
- in
- checkMaybeErrTc (checkTypeCycles tce3) id `thenTc_`
- checkMaybeErrTc (checkClassCycles ce3) id `thenTc_`
-
- -- Now instance declarations
- tcInstDecls1 e3 ce3 tce3 instdecls `thenNF_Tc` \ decl_inst_info ->
-
- -- Handle "derived" instances; note that we only do derivings
- -- for things in this module; we ignore deriving decls from
- -- interfaces! We pass fixities, because they may be used in
- -- doing Text.
-
- tcDeriving mod_name renamer_name_funs decl_inst_info tce3 fixities
- `thenTc` \ (deriv_inst_info, extra_deriv_binds, ddump_deriv) ->
-
- let
- inst_info = deriv_inst_info `unionBags` decl_inst_info
- in
- -- Handle specialise instance pragmas
- getSwitchCheckerTc `thenNF_Tc` \ sw_chkr ->
- (if sw_chkr SpecialiseOverloaded then
- tcSpecInstSigs e3 ce3 tce3 inst_info specinst_sigs
- else
- returnTc emptyBag)
- `thenTc` \ spec_inst_info ->
- let
- full_inst_info = inst_info `unionBags` spec_inst_info
- in
- -- OK, now do the inst-mapper stuff
- buildInstanceEnvs full_inst_info `thenTc` \ all_insts_mapper ->
-
- returnTc (all_insts_mapper, e3, ce_here, tce_here, class_info, tycon_specs,
- full_inst_info, extra_deriv_binds, ddump_deriv)
-
- -- End of outer fixTc
- )) `thenTc` ( \ (_, e3, ce_here, tce_here, class_info, tycon_specs,
- full_inst_info, extra_deriv_binds, ddump_deriv) ->
-
- -- Default declarations
- tcDefaults e3 default_decls `thenTc` \ defaulting_tys ->
- setDefaultingTys 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
-
- babyTcMtoTcM (tcInterfaceSigs e3 sigs) `thenTc` \ gve_sigs ->
-
- returnTc (gve_sigs, e3, ce_here, tce_here, class_info, tycon_specs, defaulting_tys,
- full_inst_info, extra_deriv_binds, ddump_deriv)
-
- -- End of extremely outer fixTc
- ))) `thenTc` \ (_, e3, ce_here, tce_here, class_info, tycon_specs, defaulting_tys,
- full_inst_info, extra_deriv_binds, ddump_deriv) ->
-
- setDefaultingTys defaulting_tys ( -- to the end...