X-Git-Url: http://git.megacz.com/?p=ghc-hetmet.git;a=blobdiff_plain;f=compiler%2Ftypes%2FFunDeps.lhs;h=b8b97b11e2d3a2835c89cba9840cd995c42d4b5f;hp=cad292b1207230ed1c3ed784538a270c5ac107ec;hb=2e9952b703341351298739b5d4f869fbdfc8490e;hpb=dfcbc18e016540cb136ec3298a07a4a55b488db0 diff --git a/compiler/types/FunDeps.lhs b/compiler/types/FunDeps.lhs index cad292b..b8b97b1 100644 --- a/compiler/types/FunDeps.lhs +++ b/compiler/types/FunDeps.lhs @@ -21,8 +21,6 @@ import Name import Var import Class import TcGadt -import Type -import Coercion import TcType import InstEnv import VarSet @@ -125,24 +123,43 @@ oclose preds fixed_tvs ] \end{code} +Note [Growing the tau-tvs using constraints] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +(grow preds tvs) is the result of extend the set of tyvars tvs + using all conceivable links from pred + +E.g. tvs = {a}, preds = {H [a] b, K (b,Int) c, Eq e} +Then grow precs tvs = {a,b,c} + +All the type variables from an implicit parameter are added, whether or +not they are mentioned in tvs; see Note [Implicit parameters and ambiguity] +in TcSimplify. + +See also Note [Ambiguity] in TcSimplify + \begin{code} grow :: [PredType] -> TyVarSet -> TyVarSet --- See Note [Ambiguity] in TcSimplify grow preds fixed_tvs - | null preds = fixed_tvs - | otherwise = loop fixed_tvs + | null preds = real_fixed_tvs + | otherwise = loop real_fixed_tvs where + -- Add the implicit parameters; + -- see Note [Implicit parameters and ambiguity] in TcSimplify + real_fixed_tvs = foldr unionVarSet fixed_tvs ip_tvs + loop fixed_tvs | new_fixed_tvs `subVarSet` fixed_tvs = fixed_tvs | otherwise = loop new_fixed_tvs where - new_fixed_tvs = foldl extend fixed_tvs pred_sets + new_fixed_tvs = foldl extend fixed_tvs non_ip_tvs extend fixed_tvs pred_tvs | fixed_tvs `intersectsVarSet` pred_tvs = fixed_tvs `unionVarSet` pred_tvs | otherwise = fixed_tvs - pred_sets = [tyVarsOfPred pred | pred <- preds] + (ip_tvs, non_ip_tvs) = partitionWith get_ip preds + get_ip (IParam _ ty) = Left (tyVarsOfType ty) + get_ip other = Right (tyVarsOfPred other) \end{code} %************************************************************************ @@ -276,7 +293,7 @@ improveOne inst_env pred@(ClassP cls tys, _) preds , let rough_fd_tcs = trimRoughMatchTcs cls_tvs fd rough_tcs , ispec@(Instance { is_tvs = qtvs, is_tys = tys_inst, is_tcs = mb_tcs_inst }) <- instances - , not (instanceCantMatch mb_tcs_inst rough_tcs) + , not (instanceCantMatch mb_tcs_inst rough_fd_tcs) , eqn <- checkClsFD qtvs fd cls_tvs tys_inst tys , let p_inst = (mkClassPred cls tys_inst, ptext SLIT("arising from the instance declaration at")