summaryrefslogtreecommitdiff
path: root/compiler/GHC/Hs/Decls.hs
diff options
context:
space:
mode:
authorGert-Jan Bottu <gertjan.bottu@kuleuven.be>2020-03-23 09:36:28 +0100
committerMarge Bot <ben+marge-bot@smart-cactus.org>2020-05-21 12:11:31 -0400
commita9311cd53d33439e8fe79967ba5fb85bcd114fec (patch)
tree2254ef735a24f9de8d192203a3c6f4871a8b6ae9 /compiler/GHC/Hs/Decls.hs
parent55f0e783d234af103cf4e1d51cd31c99961c5abe (diff)
downloadhaskell-a9311cd53d33439e8fe79967ba5fb85bcd114fec.tar.gz
Explicit Specificity
Implementation for Ticket #16393. Explicit specificity allows users to manually create inferred type variables, by marking them with braces. This way, the user determines which variables can be instantiated through visible type application. The additional syntax is included in the parser, allowing users to write braces in type variable binders (type signatures, data constructors etc). This information is passed along through the renamer and verified in the type checker. The AST for type variable binders, data constructors, pattern synonyms, partial signatures and Template Haskell has been updated to include the specificity of type variables. Minor notes: - Bumps haddock submodule - Disables pattern match checking in GHC.Iface.Type with GHC 8.8
Diffstat (limited to 'compiler/GHC/Hs/Decls.hs')
-rw-r--r--compiler/GHC/Hs/Decls.hs38
1 files changed, 21 insertions, 17 deletions
diff --git a/compiler/GHC/Hs/Decls.hs b/compiler/GHC/Hs/Decls.hs
index 8044b37cc4..6dfe75005e 100644
--- a/compiler/GHC/Hs/Decls.hs
+++ b/compiler/GHC/Hs/Decls.hs
@@ -108,6 +108,7 @@ import GHC.Types.Basic
import GHC.Core.Coercion
import GHC.Types.ForeignCall
import GHC.Hs.Extension
+import GHC.Types.Name
import GHC.Types.Name.Set
-- others:
@@ -560,7 +561,7 @@ data TyClDecl pass
, tcdTyVars :: LHsQTyVars pass -- ^ Type variables; for an
-- associated type these
-- include outer binders
- , tcdFixity :: LexicalFixity -- ^ Fixity used in the declaration
+ , tcdFixity :: LexicalFixity -- ^ Fixity used in the declaration
, tcdRhs :: LHsType pass } -- ^ RHS of type declaration
| -- | @data@ declaration
@@ -579,10 +580,10 @@ data TyClDecl pass
, tcdFixity :: LexicalFixity -- ^ Fixity used in the declaration
, tcdDataDefn :: HsDataDefn pass }
- | ClassDecl { tcdCExt :: XClassDecl pass, -- ^ Post renamer, FVs
- tcdCtxt :: LHsContext pass, -- ^ Context...
- tcdLName :: Located (IdP pass), -- ^ Name of the class
- tcdTyVars :: LHsQTyVars pass, -- ^ Class type variables
+ | ClassDecl { tcdCExt :: XClassDecl pass, -- ^ Post renamer, FVs
+ tcdCtxt :: LHsContext pass, -- ^ Context...
+ tcdLName :: Located (IdP pass), -- ^ Name of the class
+ tcdTyVars :: LHsQTyVars pass, -- ^ Class type variables
tcdFixity :: LexicalFixity, -- ^ Fixity used in the declaration
tcdFDs :: [LHsFunDep pass], -- ^ Functional deps
tcdSigs :: [LSig pass], -- ^ Methods' signatures
@@ -1056,7 +1057,7 @@ data FamilyResultSig pass = -- see Note [FamilyResultSig]
-- For details on above see note [Api annotations] in GHC.Parser.Annotation
- | TyVarSig (XTyVarSig pass) (LHsTyVarBndr pass)
+ | TyVarSig (XTyVarSig pass) (LHsTyVarBndr () pass)
-- ^ - 'ApiAnnotation.AnnKeywordId' :
-- 'ApiAnnotation.AnnOpenP','ApiAnnotation.AnnDcolon',
-- 'ApiAnnotation.AnnCloseP', 'ApiAnnotation.AnnEqual'
@@ -1138,8 +1139,8 @@ famResultKindSignature (NoSig _) = Nothing
famResultKindSignature (KindSig _ ki) = Just ki
famResultKindSignature (TyVarSig _ bndr) =
case unLoc bndr of
- UserTyVar _ _ -> Nothing
- KindedTyVar _ _ ki -> Just ki
+ UserTyVar _ _ _ -> Nothing
+ KindedTyVar _ _ _ ki -> Just ki
-- | Maybe return name of the result type variable
resultVariableName :: FamilyResultSig (GhcPass a) -> Maybe (IdP (GhcPass a))
@@ -1386,7 +1387,7 @@ data ConDecl pass
-- AnnForall and AnnDot.
, con_forall :: Located Bool -- ^ True <=> explicit forall
-- False => hsq_explicit is empty
- , con_qvars :: LHsQTyVars pass
+ , con_qvars :: [LHsTyVarBndr Specificity pass]
-- Whether or not there is an /explicit/ forall, we still
-- need to capture the implicitly-bound type/kind variables
@@ -1407,16 +1408,19 @@ data ConDecl pass
-- e.g. data T a = forall b. MkT b (b->a)
-- con_ex_tvs = {b}
-- False => con_ex_tvs is empty
- , con_ex_tvs :: [LHsTyVarBndr pass] -- ^ Existentials only
- , con_mb_cxt :: Maybe (LHsContext pass) -- ^ User-written context (if any)
- , con_args :: HsConDeclDetails pass -- ^ Arguments; can be InfixCon
+ , con_ex_tvs :: [LHsTyVarBndr Specificity pass] -- ^ Existentials only
+ , con_mb_cxt :: Maybe (LHsContext pass) -- ^ User-written context (if any)
+ , con_args :: HsConDeclDetails pass -- ^ Arguments; can be InfixCon
, con_doc :: Maybe LHsDocString
-- ^ A possible Haddock comment.
}
| XConDecl !(XXConDecl pass)
-type instance XConDeclGADT (GhcPass _) = NoExtField
+type instance XConDeclGADT GhcPs = NoExtField
+type instance XConDeclGADT GhcRn = [Name] -- Implicitly bound type variables
+type instance XConDeclGADT GhcTc = NoExtField
+
type instance XConDeclH98 (GhcPass _) = NoExtField
type instance XXConDecl (GhcPass _) = NoExtCon
@@ -1542,7 +1546,7 @@ pprConDecl (ConDeclGADT { con_names = cons, con_qvars = qvars
, con_mb_cxt = mcxt, con_args = args
, con_res_ty = res_ty, con_doc = doc })
= ppr_mbDoc doc <+> ppr_con_names cons <+> dcolon
- <+> (sep [pprHsForAll ForallInvis (hsq_explicit qvars) cxt,
+ <+> (sep [pprHsForAll ForallInvis qvars cxt,
ppr_arrow_chain (get_args args ++ [ppr res_ty]) ])
where
get_args (PrefixCon args) = map ppr args
@@ -1691,7 +1695,7 @@ data FamEqn pass rhs
= FamEqn
{ feqn_ext :: XCFamEqn pass rhs
, feqn_tycon :: Located (IdP pass)
- , feqn_bndrs :: Maybe [LHsTyVarBndr pass] -- ^ Optional quantified type vars
+ , feqn_bndrs :: Maybe [LHsTyVarBndr () pass] -- ^ Optional quantified type vars
, feqn_pats :: HsTyPats pass
, feqn_fixity :: LexicalFixity -- ^ Fixity used in the declaration
, feqn_rhs :: rhs
@@ -1812,7 +1816,7 @@ pprDataFamInstFlavour (DataFamInstDecl { dfid_eqn = HsIB { hsib_body =
pprHsFamInstLHS :: (OutputableBndrId p)
=> IdP (GhcPass p)
- -> Maybe [LHsTyVarBndr (GhcPass p)]
+ -> Maybe [LHsTyVarBndr () (GhcPass p)]
-> HsTyPats (GhcPass p)
-> LexicalFixity
-> LHsContext (GhcPass p)
@@ -2209,7 +2213,7 @@ data RuleDecl pass
, rd_name :: Located (SourceText,RuleName)
-- ^ Note [Pragma source text] in GHC.Types.Basic
, rd_act :: Activation
- , rd_tyvs :: Maybe [LHsTyVarBndr (NoGhcTc pass)]
+ , rd_tyvs :: Maybe [LHsTyVarBndr () (NoGhcTc pass)]
-- ^ Forall'd type vars
, rd_tmvs :: [LRuleBndr pass]
-- ^ Forall'd term vars, before typechecking; after typechecking