summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Peyton Jones <simonpj@microsoft.com>2016-11-29 14:03:46 +0000
committerSimon Peyton Jones <simonpj@microsoft.com>2016-11-29 14:05:26 +0000
commitf8c8de8ebf73cd77faa0249d92f280e33a8d2624 (patch)
tree7fde6168d426106ed02118b8fd7e8dcb91ff6601
parentabd4a4c13e5dbaac8f1c28d8c9d9446e383f6037 (diff)
downloadhaskell-f8c8de8ebf73cd77faa0249d92f280e33a8d2624.tar.gz
Zonk the free tvs of a RULE lhs to TyVars
Previously we were making them into skolem TcTyVars, which is wrong for the output of the type checker, which no TcTyVars should surive. See Note [Zonking the LHS of a RULE] in TcHsSyn This was flushed out by the new IfaceTcTyVar thing; I found some more TcTyVars that were being serialised into an interface file, which is wrong wrong wrong.
-rw-r--r--compiler/deSugar/DsBinds.hs2
-rw-r--r--compiler/typecheck/TcHsSyn.hs20
-rw-r--r--compiler/typecheck/TcMType.hs2
3 files changed, 16 insertions, 8 deletions
diff --git a/compiler/deSugar/DsBinds.hs b/compiler/deSugar/DsBinds.hs
index 143d209b42..4253255bae 100644
--- a/compiler/deSugar/DsBinds.hs
+++ b/compiler/deSugar/DsBinds.hs
@@ -895,7 +895,7 @@ Consider
After type checking the LHS becomes (foo alpha (C alpha)), where alpha
is an unbound meta-tyvar. The zonker in TcHsSyn is careful not to
turn the free alpha into Any (as it usually does). Instead it turns it
-into a skolem 'a'. See TcHsSyn Note [Zonking the LHS of a RULE].
+into a TyVar 'a'. See TcHsSyn Note [Zonking the LHS of a RULE].
Now we must quantify over that 'a'. It's /really/ inconvenient to do that
in the zonker, because the HsExpr data type is very large. But it's /easy/
diff --git a/compiler/typecheck/TcHsSyn.hs b/compiler/typecheck/TcHsSyn.hs
index 5a455ead32..ebdc6176b2 100644
--- a/compiler/typecheck/TcHsSyn.hs
+++ b/compiler/typecheck/TcHsSyn.hs
@@ -187,7 +187,9 @@ the environment manipulation is tiresome.
-- Confused by zonking? See Note [What is zonking?] in TcMType.
type UnboundTyVarZonker = TcTyVar -> TcM Type
-- How to zonk an unbound type variable
- -- The TcTyVar is (a) a MetaTv (b) Flexi and
+ -- The TcTyVar is
+ -- (a) a MetaTv
+ -- (b) Flexi and
-- (c) its kind is alrady zonked
-- Note [Zonking the LHS of a RULE]
@@ -1617,8 +1619,13 @@ zonkTvSkolemising :: UnboundTyVarZonker
-- This variant is used for the LHS of rules
-- See Note [Zonking the LHS of a RULE].
zonkTvSkolemising tv
- = do { tv' <- skolemiseUnboundMetaTyVar tv
- ; return (mkTyVarTy tv') }
+ = do { let tv' = mkTyVar (tyVarName tv) (tyVarKind tv)
+ -- NB: the kind of tv is already zonked
+ ty = mkTyVarTy tv'
+ -- Make a proper TyVar (remember we
+ -- are now done with type checking)
+ ; writeMetaTyVar tv ty
+ ; return ty }
zonkTypeZapping :: UnboundTyVarZonker
-- This variant is used for everything except the LHS of rules
@@ -1652,9 +1659,10 @@ over it!
We do this in two stages.
-* During zonking, we skolemise 'alpha' to 'a'. We do this by using
- zonkTvSkolemising as the UnboundTyVarZonker in the ZonkEnv.
- (This is the whole reason that the ZonkEnv has a UnboundTyVarZonker.)
+* During zonking, we skolemise the TcTyVar 'alpha' to TyVar 'a'. We
+ do this by using zonkTvSkolemising as the UnboundTyVarZonker in the
+ ZonkEnv. (This is in fact the whole reason that the ZonkEnv has a
+ UnboundTyVarZonker.)
* In DsBinds, we quantify over it. See DsBinds
Note [Free tyvars on rule LHS]
diff --git a/compiler/typecheck/TcMType.hs b/compiler/typecheck/TcMType.hs
index eae7305b58..b5104a1a32 100644
--- a/compiler/typecheck/TcMType.hs
+++ b/compiler/typecheck/TcMType.hs
@@ -68,7 +68,7 @@ module TcMType (
zonkTidyTcType, zonkTidyOrigin,
mkTypeErrorThing, mkTypeErrorThingArgs,
tidyEvVar, tidyCt, tidySkolemInfo,
- skolemiseUnboundMetaTyVar, skolemiseRuntimeUnk,
+ skolemiseRuntimeUnk,
zonkTcTyVar, zonkTcTyVars, zonkTcTyVarToTyVar,
zonkTyCoVarsAndFV, zonkTcTypeAndFV,
zonkTyCoVarsAndFVList,