summaryrefslogtreecommitdiff
path: root/compiler/iface
diff options
context:
space:
mode:
authorSimon Peyton Jones <simonpj@microsoft.com>2018-08-22 09:51:26 +0100
committerSimon Peyton Jones <simonpj@microsoft.com>2018-08-22 16:28:31 +0100
commitdb6f1d9cfc74690798645a7cc5b25040c36bb35d (patch)
treed878104f195f4f8855861ae8007fd287df5cd276 /compiler/iface
parent44ba66527ae207ce2dd64eb2bce14656d474f6d1 (diff)
downloadhaskell-db6f1d9cfc74690798645a7cc5b25040c36bb35d.tar.gz
Turn infinite loop into a panic
In these two functions * TcIface.toIfaceAppTyArgsX * Type.piResultTys we take a type application (f t1 .. tn) and try to find its kind. It turned out that, if (f t1 .. tn) was ill-kinded the function would go into an infinite loop. That's not good: it caused the loop in Trac #15473. This patch doesn't fix the bug in #15473, but it does turn the loop into a decent panic, which is a step forward.
Diffstat (limited to 'compiler/iface')
-rw-r--r--compiler/iface/ToIface.hs15
1 files changed, 12 insertions, 3 deletions
diff --git a/compiler/iface/ToIface.hs b/compiler/iface/ToIface.hs
index 8452b8bac2..0b0782d6e8 100644
--- a/compiler/iface/ToIface.hs
+++ b/compiler/iface/ToIface.hs
@@ -305,11 +305,20 @@ toIfaceAppArgsX fr kind ty_args
go env (FunTy _ res) (t:ts) -- No type-class args in tycon apps
= IA_Vis (toIfaceTypeX fr t) (go env res ts)
- go env ty ts = ASSERT2( not (isEmptyTCvSubst env)
- , ppr kind $$ ppr ty_args )
- go (zapTCvSubst env) (substTy env ty) ts
+ go env ty ts@(t1:ts1)
+ | not (isEmptyTCvSubst env)
+ = go (zapTCvSubst env) (substTy env ty) ts
-- See Note [Care with kind instantiation] in Type.hs
+ | otherwise
+ = -- There's a kind error in the type we are trying to print
+ -- e.g. kind = k, ty_args = [Int]
+ -- This is probably a compiler bug, so we print a trace and
+ -- carry on as if it were FunTy. Without the test for
+ -- isEmptyTCvSubst we'd get an infinite loop (Trac #15473)
+ WARN( True, ppr kind $$ ppr ty_args )
+ IA_Vis (toIfaceTypeX fr t1) (go env ty ts1)
+
tidyToIfaceType :: TidyEnv -> Type -> IfaceType
tidyToIfaceType env ty = toIfaceType (tidyType env ty)