- getTyVarsToGen is_unrestricted mono_id_tys lie_req `thenNF_Tc` \ (tyvars_not_to_gen, tyvars_to_gen) ->
-
- -- Finally, zonk the generalised type variables to real TyVars
- -- This commits any unbound kind variables to boxed kind
- -- I'm a little worried that such a kind variable might be
- -- free in the environment, but I don't think it's possible for
- -- this to happen when the type variable is not free in the envt
- -- (which it isn't). SLPJ Nov 98
- mapTc zonkTcTyVarToTyVar (varSetElems tyvars_to_gen) `thenTc` \ real_tyvars_to_gen_list ->
- let
- real_tyvars_to_gen = mkVarSet real_tyvars_to_gen_list
- -- It's important that the final list
- -- (real_tyvars_to_gen and real_tyvars_to_gen_list) is fully
- -- zonked, *including boxity*, because they'll be included in the forall types of
- -- the polymorphic Ids, and instances of these Ids will be generated from them.
- --
- -- Also NB that tcSimplify takes zonked tyvars as its arg, hence we pass
- -- real_tyvars_to_gen
- in
-
- -- SIMPLIFY THE LIE
- tcExtendGlobalTyVars tyvars_not_to_gen (
- let ips = getIPsOfLIE lie_avail_req in
- if null real_tyvars_to_gen_list && (null ips || not is_unrestricted) then
- -- No polymorphism, and no IPs, so no need to simplify context
- returnTc (lie_req, EmptyMonoBinds, [])
- else
- case maybe_sig_theta of
- Nothing ->
- -- No signatures, so just simplify the lie
- -- NB: no signatures => no polymorphic recursion, so no
- -- need to use lie_avail (which will be empty anyway)
- tcSimplify (text "tcBinds1" <+> ppr binder_names)
- real_tyvars_to_gen lie_req `thenTc` \ (lie_free, dict_binds, lie_bound) ->
- returnTc (lie_free, dict_binds, map instToId (bagToList lie_bound))
-
- Just (sig_theta, lie_avail) ->
- -- There are signatures, and their context is sig_theta
- -- Furthermore, lie_avail is an LIE containing the 'method insts'
- -- for the things bound here
-
- zonkTcThetaType sig_theta `thenNF_Tc` \ sig_theta' ->
- newDicts SignatureOrigin sig_theta' `thenNF_Tc` \ (dicts_sig, dict_ids) ->
- -- It's important that sig_theta is zonked, because
- -- dict_id is later used to form the type of the polymorphic thing,
- -- and forall-types must be zonked so far as their bound variables
- -- are concerned
-
- let
- -- The "givens" is the stuff available. We get that from
- -- the context of the type signature, BUT ALSO the lie_avail
- -- so that polymorphic recursion works right (see comments at end of fn)
- givens = dicts_sig `plusLIE` lie_avail
- in
-
- -- Check that the needed dicts can be expressed in
- -- terms of the signature ones
- tcAddErrCtxt (bindSigsCtxt tysig_names) $
- tcSimplifyAndCheck
- (ptext SLIT("type signature for") <+> pprQuotedList binder_names)
- real_tyvars_to_gen givens lie_req `thenTc` \ (lie_free, dict_binds) ->
-
- returnTc (lie_free, dict_binds, dict_ids)
-
- ) `thenTc` \ (lie_free, dict_binds, dicts_bound) ->
-
- -- GET THE FINAL MONO_ID_TYS
- zonkTcTypes mono_id_tys `thenNF_Tc` \ zonked_mono_id_types ->
-
-
- -- CHECK FOR BOGUS UNPOINTED BINDINGS
- (if any isUnLiftedType zonked_mono_id_types then
- -- Unlifted bindings must be non-recursive,
- -- not top level, and non-polymorphic
- checkTc (isNotTopLevel top_lvl)
- (unliftedBindErr "Top-level" mbind) `thenTc_`
- checkTc (case is_rec of {Recursive -> False; NonRecursive -> True})
- (unliftedBindErr "Recursive" mbind) `thenTc_`
- checkTc (null real_tyvars_to_gen_list)
- (unliftedBindErr "Polymorphic" mbind)
- else
- returnTc ()
- ) `thenTc_`
-
- ASSERT( not (any ((== unboxedTypeKind) . tyVarKind) real_tyvars_to_gen_list) )
- -- The instCantBeGeneralised stuff in tcSimplify should have
- -- already raised an error if we're trying to generalise an
- -- unboxed tyvar (NB: unboxed tyvars are always introduced
- -- along with a class constraint) and it's better done there
- -- because we have more precise origin information.
- -- That's why we just use an ASSERT here.
-