diff options
author | Simon Peyton Jones <simonpj@microsoft.com> | 2016-02-18 12:52:18 +0000 |
---|---|---|
committer | Simon Peyton Jones <simonpj@microsoft.com> | 2016-02-18 12:52:18 +0000 |
commit | a008eadfaa4816be349b4fefde9b9b9edc1ca359 (patch) | |
tree | 8da1347fd5d970b0598aa7837111bf8d37512532 /compiler | |
parent | 4d031cf91c5eed9b162703daee274bbbe94bdc42 (diff) | |
download | haskell-a008eadfaa4816be349b4fefde9b9b9edc1ca359.tar.gz |
Take type-function arity into account
...when computing the size of a call on the RHS of a type
instance declaration.
This came up in Trac #11581. The change is in
TcType.tcTyFamInsts
which now trims the type arguments in a call. See the
comments with that function definition.
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/typecheck/TcType.hs | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/compiler/typecheck/TcType.hs b/compiler/typecheck/TcType.hs index 8021c75a22..00b3a0f07b 100644 --- a/compiler/typecheck/TcType.hs +++ b/compiler/typecheck/TcType.hs @@ -693,13 +693,23 @@ isSigMaybe _ = Nothing -} -- | Finds outermost type-family applications occuring in a type, --- after expanding synonyms. +-- after expanding synonyms. In the list (F, tys) that is returned +-- we guarantee that tys matches F's arity. For example, given +-- type family F a :: * -> * (arity 1) +-- calling tcTyFamInsts on (Maybe (F Int Bool) will return +-- (F, [Int]), not (F, [Int,Bool]) +-- +-- This is important for its use in deciding termination of type +-- instances (see Trac #11581). E.g. +-- type instance G [Int] = ...(F Int <big type>)... +-- we don't need to take <big type> into account when asking if +-- the calls on the RHS are smaller than the LHS tcTyFamInsts :: Type -> [(TyCon, [Type])] tcTyFamInsts ty | Just exp_ty <- coreView ty = tcTyFamInsts exp_ty tcTyFamInsts (TyVarTy _) = [] tcTyFamInsts (TyConApp tc tys) - | isTypeFamilyTyCon tc = [(tc, tys)] + | isTypeFamilyTyCon tc = [(tc, take (tyConArity tc) tys)] | otherwise = concat (map tcTyFamInsts tys) tcTyFamInsts (LitTy {}) = [] tcTyFamInsts (ForAllTy bndr ty) = tcTyFamInsts (binderType bndr) |