[Git][ghc/ghc][wip/soulomoon/25647-allow-newtype-instance-in-gadt-syntax] rename and add note

Patrick (@soulomoon) gitlab at gitlab.haskell.org
Mon Jan 20 08:57:15 UTC 2025



Patrick pushed to branch wip/soulomoon/25647-allow-newtype-instance-in-gadt-syntax at Glasgow Haskell Compiler / GHC


Commits:
370ccc3e by Patrick at 2025-01-20T16:56:59+08:00
rename and add note

- - - - -


2 changed files:

- compiler/GHC/Tc/TyCl.hs
- compiler/GHC/Tc/TyCl/Instance.hs


Changes:

=====================================
compiler/GHC/Tc/TyCl.hs
=====================================
@@ -14,7 +14,7 @@
 
 -- | Typecheck type and class declarations
 module GHC.Tc.TyCl (
-        LHSUserSuppliedResultKind(..),
+        UserHeaderKindSig(..),
         tcTyAndClassDecls,
         -- Functions used by GHC.Tc.TyCl.Instance to check
         -- data/type family instance declarations
@@ -1775,8 +1775,8 @@ kcTyClDecl (DataDecl { tcdLName    = (L _ _name)
     do { traceTc "kcTyClDecl" (ppr tycon $$ ppr (tyConTyVars tycon) $$ ppr (tyConResKind tycon))
        ; _ <- tcHsContext ctxt
        ; kcConDecls (tyConResKind tycon) (if (isJust kindSig)
-                                          then LHSUserSuppliedResultKind
-                                          else NoLHSUserSuppliedResultKind) cons
+                                          then UserHeaderKindSig
+                                          else NoUserHeaderKindSig) cons
        }
 
 kcTyClDecl (SynDecl { tcdLName = L _ _name, tcdRhs = rhs }) tycon
@@ -1836,14 +1836,21 @@ kcConGADTArgs exp_kind con_args = case con_args of
   RecConGADT _ (L _ flds) -> kcConArgTys exp_kind $
                              map (hsLinear . cd_fld_type . unLoc) flds
 
--- Specifically for GADT style declarations
--- do we have lhs user supplied kind signature?
--- as in `data xxx :: UserSuppliedKind where ...`
-data LHSUserSuppliedResultKind = LHSUserSuppliedResultKind | NoLHSUserSuppliedResultKind deriving Eq
+
+{- Note [Header kind signatures for GADTs]
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+Specifically for GADT style declarations
+Do we have user supplied header kind signature?
+as in `data xxx :: UserHeaderKindSig where ...`
+If not and it is newtype we can infer the kind of the data type
+from the data constructors
+-}
+-- see Note [Header kind signatures for GADTs]
+data UserHeaderKindSig = UserHeaderKindSig | NoUserHeaderKindSig deriving Eq
 
 kcConDecls :: TcKind  -- Result kind of tycon
                       -- Used only in H98 case
-           -> LHSUserSuppliedResultKind
+           -> UserHeaderKindSig
            -> DataDefnCons (LConDecl GhcRn) -> TcM ()
 -- See Note [kcConDecls: kind-checking data type decls]
 kcConDecls tc_res_kind usrk cons
@@ -1856,7 +1863,7 @@ kcConDecls tc_res_kind usrk cons
 -- declared with data or newtype, and we need to know the result kind of
 -- this type. See Note [Implementation of UnliftedNewtypes] for why
 -- we need the first two arguments.
-kcConDecl :: NewOrData -> LHSUserSuppliedResultKind -> TcKind -> ConDecl GhcRn -> TcM ()
+kcConDecl :: NewOrData -> UserHeaderKindSig -> TcKind -> ConDecl GhcRn -> TcM ()
 kcConDecl new_or_data _usrk tc_res_kind
           (ConDeclH98 { con_name = name, con_ex_tvs = ex_tvs
                       , con_mb_cxt = ex_ctxt, con_args = args })
@@ -1886,7 +1893,7 @@ kcConDecl new_or_data usrk tc_res_kind
         -- Why "_Tv"?  See Note [Using TyVarTvs for kind-checking GADTs]
     do { _ <- tcHsContext cxt
        ; traceTc "kcConDecl:GADT {" (ppr names $$ ppr res_ty $$ ppr tc_res_kind)
-       ; con_res_kind <-  if NewType == new_or_data && NoLHSUserSuppliedResultKind == usrk
+       ; con_res_kind <-  if NewType == new_or_data && NoUserHeaderKindSig == usrk
                           then return tc_res_kind
                           else newOpenTypeKind
        ; _ <- tcCheckLHsTypeInContext res_ty $ (TheKind con_res_kind)


=====================================
compiler/GHC/Tc/TyCl/Instance.hs
=====================================
@@ -947,8 +947,8 @@ tcDataFamInstHeader mb_clsinfo skol_info fam_tc hs_outer_bndrs fixity
                   -- Fix #25611
                   -- See DESIGN CHOICE in Note [Kind inference for data family instances]
                   ; when is_H98_or_newtype $ kcConDecls lhs_applied_kind  (if (isJust m_ksig)
-                                          then LHSUserSuppliedResultKind
-                                          else NoLHSUserSuppliedResultKind)
+                                          then UserHeaderKindSig
+                                          else NoUserHeaderKindSig)
                                           hs_cons
 
 



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/370ccc3e1a4fec17f1046b1e89f9c4e7e05f7f28

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/370ccc3e1a4fec17f1046b1e89f9c4e7e05f7f28
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20250120/132def3d/attachment-0001.html>


More information about the ghc-commits mailing list