summaryrefslogtreecommitdiff
path: root/compiler/hsSyn/HsDecls.hs
diff options
context:
space:
mode:
authorSimon Peyton Jones <simonpj@microsoft.com>2019-02-07 09:51:36 +0000
committerMarge Bot <ben+marge-bot@smart-cactus.org>2019-02-08 11:00:26 -0500
commit9bb23d5f8bd7a135670864dfa09dd39a60e94d28 (patch)
tree9c090ff340e0e46ee0a9840b9c011bc0a9f6a063 /compiler/hsSyn/HsDecls.hs
parentcefb780ee7ae3c3be873324423358eafd4ba5a17 (diff)
downloadhaskell-9bb23d5f8bd7a135670864dfa09dd39a60e94d28.tar.gz
Minor refactor of CUSK handling
Previously, in getFamDeclInitialKind, we were figuring out whether the enclosing class decl had a CUSK very indirectly, via tcTyConIsPoly. This patch just makes the computation much more direct and easy to grok. No change in behaviour.
Diffstat (limited to 'compiler/hsSyn/HsDecls.hs')
-rw-r--r--compiler/hsSyn/HsDecls.hs29
1 files changed, 19 insertions, 10 deletions
diff --git a/compiler/hsSyn/HsDecls.hs b/compiler/hsSyn/HsDecls.hs
index 5b06db8c02..c18a9ae1fc 100644
--- a/compiler/hsSyn/HsDecls.hs
+++ b/compiler/hsSyn/HsDecls.hs
@@ -680,7 +680,9 @@ countTyClDecls decls
-- | Does this declaration have a complete, user-supplied kind signature?
-- See Note [CUSKs: complete user-supplied kind signatures]
hsDeclHasCusk :: TyClDecl GhcRn -> Bool
-hsDeclHasCusk (FamDecl { tcdFam = fam_decl }) = famDeclHasCusk Nothing fam_decl
+hsDeclHasCusk (FamDecl { tcdFam = fam_decl })
+ = famDeclHasCusk False fam_decl
+ -- False: this is not: an associated type of a class with no cusk
hsDeclHasCusk (SynDecl { tcdTyVars = tyvars, tcdRhs = rhs })
-- NB: Keep this synchronized with 'getInitialKind'
= hsTvbAllKinded tyvars && rhs_annotated rhs
@@ -1078,15 +1080,22 @@ data FamilyInfo pass
-- | Does this family declaration have a complete, user-supplied kind signature?
-- See Note [CUSKs: complete user-supplied kind signatures]
-famDeclHasCusk :: Maybe Bool
- -- ^ if associated, does the enclosing class have a CUSK?
- -> FamilyDecl pass -> Bool
-famDeclHasCusk _ (FamilyDecl { fdInfo = ClosedTypeFamily _
- , fdTyVars = tyvars
- , fdResultSig = L _ resultSig })
- = hsTvbAllKinded tyvars && hasReturnKindSignature resultSig
-famDeclHasCusk mb_class_cusk _ = mb_class_cusk `orElse` True
- -- all un-associated open families have CUSKs
+famDeclHasCusk :: Bool -- ^ True <=> this is an associated type family,
+ -- and the parent class has /no/ CUSK
+ -> FamilyDecl pass
+ -> Bool
+famDeclHasCusk assoc_with_no_cusk
+ (FamilyDecl { fdInfo = fam_info
+ , fdTyVars = tyvars
+ , fdResultSig = L _ resultSig })
+ = case fam_info of
+ ClosedTypeFamily {} -> hsTvbAllKinded tyvars
+ && hasReturnKindSignature resultSig
+ _ -> not assoc_with_no_cusk
+ -- Un-associated open type/data families have CUSKs
+ -- Associated type families have CUSKs iff the parent class does
+
+famDeclHasCusk _ (XFamilyDecl {}) = panic "famDeclHasCusk"
-- | Does this family declaration have user-supplied return kind signature?
hasReturnKindSignature :: FamilyResultSig a -> Bool