summaryrefslogtreecommitdiff
path: root/compiler/types/Type.hs
diff options
context:
space:
mode:
authorSimon Peyton Jones <simonpj@microsoft.com>2018-07-24 08:57:34 +0100
committerSimon Peyton Jones <simonpj@microsoft.com>2018-07-24 08:57:34 +0100
commite1b5a1174e42e390855b153015ce5227b3251d89 (patch)
treefde15f0774013eb06559da5a5173ec53b0b7803f /compiler/types/Type.hs
parentf0d27f515ffbc476144d1d1dd1a71bf9fa93c94b (diff)
downloadhaskell-e1b5a1174e42e390855b153015ce5227b3251d89.tar.gz
Fix a nasty bug in piResultTys
I was failing to instantiate vigorously enough in Type.piResultTys and in the very similar function ToIface.toIfaceAppArgsX This caused Trac #15428. The fix is easy. See Note [Care with kind instantiation] in Type.hs
Diffstat (limited to 'compiler/types/Type.hs')
-rw-r--r--compiler/types/Type.hs43
1 files changed, 35 insertions, 8 deletions
diff --git a/compiler/types/Type.hs b/compiler/types/Type.hs
index e96188f218..a38bd1f0a6 100644
--- a/compiler/types/Type.hs
+++ b/compiler/types/Type.hs
@@ -1038,13 +1038,12 @@ piResultTys ty orig_args@(arg:args)
| ForAllTy (TvBndr tv _) res <- ty
= go (extendVarEnv tv_env tv arg) res args
- | TyVarTy tv <- ty
- , Just ty' <- lookupVarEnv tv_env tv
- -- Deals with piResultTys (forall a. a) [forall b.b, Int]
- = piResultTys ty' all_args
-
- | otherwise
- = pprPanic "piResultTys2" (ppr ty $$ ppr orig_args $$ ppr all_args)
+ | otherwise -- See Note [Care with kind instantiation]
+ = ASSERT2( not (isEmptyVarEnv tv_env)
+ , ppr ty $$ ppr orig_args $$ ppr all_args )
+ go emptyTvSubstEnv
+ (substTy (mkTvSubst in_scope tv_env) ty)
+ all_args
applyTysX :: [TyVar] -> Type -> [Type] -> Type
-- applyTyxX beta-reduces (/\tvs. body_ty) arg_tys
@@ -1058,7 +1057,35 @@ applyTysX tvs body_ty arg_tys
pp_stuff = vcat [ppr tvs, ppr body_ty, ppr arg_tys]
n_tvs = length tvs
-{-
+
+
+{- Note [Care with kind instantiation]
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+Suppose we have
+ T :: forall k. k
+and we are finding the kind of
+ T (forall b. b -> b) * Int
+Then
+ T (forall b. b->b) :: k[ k :-> forall b. b->b]
+ :: forall b. b -> b
+So
+ T (forall b. b->b) * :: (b -> b)[ b :-> *]
+ :: * -> *
+
+In other words wwe must intantiate the forall!
+
+Similarly (Trac #154218)
+ S :: forall k f. k -> f k
+and we are finding the kind of
+ S * (* ->) Int Bool
+We have
+ S * (* ->) :: (k -> f k)[ k :-> *, f :-> (* ->)]
+ :: * -> * -> *
+So again we must instantiate.
+
+The same thing happens in ToIface.toIfaceAppArgsX.
+
+
---------------------------------------------------------------------
TyConApp
~~~~~~~~