diff options
author | Simon Peyton Jones <simonpj@microsoft.com> | 2017-04-12 15:09:37 +0100 |
---|---|---|
committer | Simon Peyton Jones <simonpj@microsoft.com> | 2017-04-13 09:23:53 +0100 |
commit | 0ae72512255ba66ef89bdfeea65a23ea6eb35124 (patch) | |
tree | a21ffcb040c1f53cfb8a1f548a8c284208dd623d /compiler/typecheck/TcBinds.hs | |
parent | 037c2495d83bb7da7f15c8e076df2c575500d0fd (diff) | |
download | haskell-0ae72512255ba66ef89bdfeea65a23ea6eb35124.tar.gz |
Yet more work on TcSimplify.simplifyInfer
The proximate cause for this patch is Trac #13482, which pointed out
further subtle interactions between
- Inferring the most general type of a function
- A partial type signature for that function
That led me into /further/ changes to the shiny new stuff in
TcSimplify.simplifyInfer, decideQuantification, decideMonoTyVars,
and related functions.
Happily, I was able to make some of it quite a bit simpler,
notably the bit about promoting free tyvars. I'm happy with
the result.
Moreover I fixed Trac #13524 at the same time. Happy days.
Diffstat (limited to 'compiler/typecheck/TcBinds.hs')
-rw-r--r-- | compiler/typecheck/TcBinds.hs | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/compiler/typecheck/TcBinds.hs b/compiler/typecheck/TcBinds.hs index 74f4b62708..a9c6f6cbfd 100644 --- a/compiler/typecheck/TcBinds.hs +++ b/compiler/typecheck/TcBinds.hs @@ -921,7 +921,8 @@ chooseInferredQuantifiers inferred_theta tau_tvs qtvs ; let free_tvs = closeOverKinds (tyCoVarsOfTypes annotated_theta `unionVarSet` tau_tvs) ; traceTc "ciq" (vcat [ ppr sig, ppr annotated_theta, ppr free_tvs]) - ; return (mk_binders free_tvs, annotated_theta) } + ; psig_qtvs <- mk_psig_qtvs annotated_tvs + ; return (mk_final_qtvs psig_qtvs free_tvs, annotated_theta) } | Just wc_var <- wcx = do { annotated_theta <- zonkTcTypes annotated_theta @@ -930,7 +931,11 @@ chooseInferredQuantifiers inferred_theta tau_tvs qtvs -- Omitting this caused #12844 seed_tvs = tyCoVarsOfTypes annotated_theta -- These are put there `unionVarSet` tau_tvs -- by the user - my_theta = pickCapturedPreds free_tvs inferred_theta + + ; psig_qtvs <- mk_psig_qtvs annotated_tvs + ; let my_qtvs = mk_final_qtvs psig_qtvs free_tvs + keep_me = psig_qtvs `unionVarSet` free_tvs + my_theta = pickCapturedPreds keep_me inferred_theta -- Report the inferred constraints for an extra-constraints wildcard/hole as -- an error message, unless the PartialTypeSignatures flag is enabled. In this @@ -946,25 +951,30 @@ chooseInferredQuantifiers inferred_theta tau_tvs qtvs , ppr annotated_theta, ppr inferred_theta , ppr inferred_diff ] - ; return (mk_binders free_tvs, my_theta) } + ; return (my_qtvs, my_theta) } | otherwise -- A complete type signature is dealt with in mkInferredPolyId = pprPanic "chooseInferredQuantifiers" (ppr sig) where - spec_tv_set = mkVarSet $ map snd annotated_tvs - mk_binders free_tvs + mk_final_qtvs psig_qtvs free_tvs = [ mkTyVarBinder vis tv - | tv <- qtvs - , tv `elemVarSet` free_tvs - , let vis | tv `elemVarSet` spec_tv_set = Specified - | otherwise = Inferred ] - -- Pulling from qtvs maintains original order + | tv <- qtvs -- Pulling from qtvs maintains original order + , tv `elemVarSet` keep_me + , let vis | tv `elemVarSet` psig_qtvs = Specified + | otherwise = Inferred ] + where + keep_me = free_tvs `unionVarSet` psig_qtvs mk_ctuple [pred] = return pred mk_ctuple preds = do { tc <- tcLookupTyCon (cTupleTyConName (length preds)) ; return (mkTyConApp tc preds) } + mk_psig_qtvs :: [(Name,TcTyVar)] -> TcM TcTyVarSet + mk_psig_qtvs annotated_tvs + = do { psig_qtvs <- mapM (zonkTcTyVarToTyVar . snd) annotated_tvs + ; return (mkVarSet psig_qtvs) } + mk_impedance_match_msg :: MonoBindInfo -> TcType -> TcType -> TidyEnv -> TcM (TidyEnv, SDoc) |