[commit: ghc] master: Fix kind generalisation for pattern synonyms (b4dfe04)

git at git.haskell.org git at git.haskell.org
Fri Feb 26 17:14:52 UTC 2016


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/b4dfe04aa77bb2d0ce2c7d82cab5e4425e0b738c/ghc

>---------------------------------------------------------------

commit b4dfe04aa77bb2d0ce2c7d82cab5e4425e0b738c
Author: Simon Peyton Jones <simonpj at microsoft.com>
Date:   Fri Feb 26 09:20:12 2016 +0000

    Fix kind generalisation for pattern synonyms
    
    We were failing to zonk, after quantifyTyVars, and that left
    un-zonked type variables in the final PatSyn.
    
    This fixes the patsyn/ problems in Trac #11648, but not
    the polykinds/ ones.


>---------------------------------------------------------------

b4dfe04aa77bb2d0ce2c7d82cab5e4425e0b738c
 compiler/typecheck/TcPatSyn.hs | 35 ++++++++++++++++++++++-------------
 1 file changed, 22 insertions(+), 13 deletions(-)

diff --git a/compiler/typecheck/TcPatSyn.hs b/compiler/typecheck/TcPatSyn.hs
index 9b28758..f6562cc 100644
--- a/compiler/typecheck/TcPatSyn.hs
+++ b/compiler/typecheck/TcPatSyn.hs
@@ -119,9 +119,17 @@ tcPatSynSig name sig_ty
                  ; return ( (univ_tvs, req, ex_tvs, prov, arg_tys, body_ty)
                           , bound_tvs) }
 
+       -- Kind generalisation; c.f. kindGeneralise
+       ; let free_kvs = tyCoVarsOfTelescope (implicit_tvs ++ univ_tvs ++ ex_tvs) $
+                        tyCoVarsOfTypes (body_ty : req ++ prov ++ arg_tys)
+
+       ; kvs <- quantifyTyVars emptyVarSet (Pair free_kvs emptyVarSet)
+
        -- These are /signatures/ so we zonk to squeeze out any kind
-       -- unification variables.
+       -- unification variables.  Do this after quantifyTyVars which may
+       -- default kind variables to *.
        -- ToDo: checkValidType?
+       ; traceTc "about zonk" empty
        ; implicit_tvs <- mapM zonkTcTyCoVarBndr implicit_tvs
        ; univ_tvs     <- mapM zonkTcTyCoVarBndr univ_tvs
        ; ex_tvs       <- mapM zonkTcTyCoVarBndr ex_tvs
@@ -130,12 +138,6 @@ tcPatSynSig name sig_ty
        ; arg_tys      <- zonkTcTypes arg_tys
        ; body_ty      <- zonkTcType  body_ty
 
-       -- Kind generalisation; c.f. kindGeneralise
-       ; let free_kvs = tyCoVarsOfTelescope (implicit_tvs ++ univ_tvs ++ ex_tvs) $
-                        tyCoVarsOfTypes (body_ty : req ++ prov ++ arg_tys)
-
-       ; kvs <- quantifyTyVars emptyVarSet (Pair free_kvs emptyVarSet)
-
        -- Complain about:  pattern P :: () => forall x. x -> P x
        -- The renamer thought it was fine, but the existential 'x'
        -- should not appear in the result type
@@ -151,13 +153,13 @@ tcPatSynSig name sig_ty
              (extra_univ, extra_ex) = partition (`elemVarSet` univ_fvs) $
                                       kvs ++ implicit_tvs
        ; traceTc "tcTySig }" $
-         vcat [ text "implicit_tvs" <+> ppr implicit_tvs
-              , text "kvs" <+> ppr kvs
-              , text "extra_univ" <+> ppr extra_univ
-              , text "univ_tvs" <+> ppr univ_tvs
+         vcat [ text "implicit_tvs" <+> ppr_tvs implicit_tvs
+              , text "kvs" <+> ppr_tvs kvs
+              , text "extra_univ" <+> ppr_tvs extra_univ
+              , text "univ_tvs" <+> ppr_tvs univ_tvs
               , text "req" <+> ppr req
-              , text "extra_ex" <+> ppr extra_ex
-              , text "ex_tvs" <+> ppr ex_tvs
+              , text "extra_ex" <+> ppr_tvs extra_ex
+              , text "ex_tvs" <+> ppr_tvs ex_tvs
               , text "prov" <+> ppr prov
               , text "arg_tys" <+> ppr arg_tys
               , text "body_ty" <+> ppr body_ty ]
@@ -168,6 +170,11 @@ tcPatSynSig name sig_ty
                       , patsig_prov     = prov
                       , patsig_arg_tys  = arg_tys
                       , patsig_body_ty  = body_ty }) }
+  where
+
+ppr_tvs :: [TyVar] -> SDoc
+ppr_tvs tvs = braces (vcat [ ppr tv <+> dcolon <+> ppr (tyVarKind tv)
+                           | tv <- tvs])
 
 
 {-
@@ -251,6 +258,8 @@ tcCheckPatSynDecl psb at PSB{ psb_id = lname@(L _ name), psb_args = details
                                     else newMetaSigTyVars ex_tvs
                     -- See the "Existential type variables" part of
                     -- Note [Checking against a pattern signature]
+              ; traceTc "tcpatsyn1" (vcat [ ppr v <+> dcolon <+> ppr (tyVarKind v) | v <- ex_tvs])
+              ; traceTc "tcpatsyn2" (vcat [ ppr v <+> dcolon <+> ppr (tyVarKind v) | v <- ex_tvs'])
               ; prov_dicts <- mapM (emitWanted origin)
                   (substTheta (extendTCvInScopeList subst univ_tvs) prov_theta)
                   -- Add the free vars of 'prov_theta' to the in_scope set to



More information about the ghc-commits mailing list