[Git][ghc/ghc][wip/marge_bot_batch_merge_job] 4 commits: Remove undefined FP_PROG_LD_BUILD_ID from configure.ac's

Marge Bot (@marge-bot) gitlab at gitlab.haskell.org
Tue Jun 27 14:52:27 UTC 2023



Marge Bot pushed to branch wip/marge_bot_batch_merge_job at Glasgow Haskell Compiler / GHC


Commits:
d95cb595 by Greg Steuck at 2023-06-27T10:52:11-04:00
Remove undefined FP_PROG_LD_BUILD_ID from configure.ac's

- - - - -
6f4e01d3 by Andrei Borzenkov at 2023-06-27T10:52:12-04:00
Remove arity inference in type declarations (#23514)

Arity inference in type declarations was introduced
as a workaround for the lack of @k-binders.

They were added in 4aea0a72040, so I simplified all
of this by simply removing arity inference altogether.

This is part of GHC Proposal #425 "Invisible binders in type
declarations".

- - - - -
a11624a5 by Torsten Schmits at 2023-06-27T10:52:12-04:00
Relax defaulting of RuntimeRep/Levity when printing

Fixes #16468

MR: !10702

Only default RuntimeRep to LiftedRep when variables are bound by the toplevel forall

- - - - -
771e6f62 by Torsten Schmits at 2023-06-27T10:52:13-04:00
Remove duplicate link label in linear types docs

- - - - -


29 changed files:

- compiler/GHC/Iface/Syntax.hs
- compiler/GHC/Iface/Type.hs
- compiler/GHC/Tc/Gen/HsType.hs
- compiler/GHC/Tc/Gen/Splice.hs
- compiler/GHC/Types/Unique/DFM.hs
- configure.ac
- distrib/configure.ac.in
- docs/users_guide/exts/linear_types.rst
- libraries/template-haskell/Language/Haskell/TH/Syntax.hs
- libraries/template-haskell/changelog.md
- + testsuite/tests/ghci/scripts/T16468.script
- + testsuite/tests/ghci/scripts/T16468.stdout
- testsuite/tests/ghci/scripts/all.T
- testsuite/tests/perf/compiler/CoOpt_Singletons.hs
- testsuite/tests/saks/should_compile/T16724.stdout
- testsuite/tests/saks/should_compile/saks030.hs
- testsuite/tests/saks/should_compile/saks032.hs
- + testsuite/tests/th/CodeQ_HKD.hs
- testsuite/tests/th/all.T
- + testsuite/tests/typecheck/should_compile/T23514b.hs
- + testsuite/tests/typecheck/should_compile/T23514c.hs
- testsuite/tests/typecheck/should_compile/all.T
- testsuite/tests/typecheck/should_fail/T18640a.hs
- testsuite/tests/typecheck/should_fail/T18640a.stderr
- testsuite/tests/typecheck/should_fail/T18640c.hs
- testsuite/tests/typecheck/should_fail/T18640c.stderr
- + testsuite/tests/typecheck/should_fail/T23514a.hs
- + testsuite/tests/typecheck/should_fail/T23514a.stderr
- testsuite/tests/typecheck/should_fail/all.T


Changes:

=====================================
compiler/GHC/Iface/Syntax.hs
=====================================
@@ -920,12 +920,7 @@ pprIfaceDecl ss (IfaceData { ifName = tycon, ifCType = ctype,
     cons       = visibleIfConDecls condecls
     pp_where   = ppWhen (gadt && not (null cons)) $ text "where"
     pp_cons    = ppr_trim (map show_con cons) :: [SDoc]
-    pp_kind    = ppUnless (if ki_sig_printable
-                              then isIfaceRhoType kind
-                                      -- Even in the presence of a standalone kind signature, a non-tau
-                                      -- result kind annotation cannot be discarded as it determines the arity.
-                                      -- See Note [Arity inference in kcCheckDeclHeader_sig] in GHC.Tc.Gen.HsType
-                              else isIfaceLiftedTypeKind kind)
+    pp_kind    = ppUnless (ki_sig_printable || isIfaceLiftedTypeKind kind)
                           (dcolon <+> ppr kind)
 
     pp_lhs = case parent of


=====================================
compiler/GHC/Iface/Type.hs
=====================================
@@ -821,7 +821,7 @@ pprIfaceLamBndr (b, IfaceNoOneShot) = ppr b
 pprIfaceLamBndr (b, IfaceOneShot)   = ppr b <> text "[OneShot]"
 
 pprIfaceIdBndr :: IfaceIdBndr -> SDoc
-pprIfaceIdBndr (w, name, ty) = parens (ppr name <> brackets (ppr w) <+> dcolon <+> ppr ty)
+pprIfaceIdBndr (w, name, ty) = parens (ppr name <> brackets (ppr_ty_nested w) <+> dcolon <+> ppr_ty_nested ty)
 
 {- Note [Suppressing binder signatures]
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -881,7 +881,7 @@ pprIfaceTvBndr :: IfaceTvBndr -> SuppressBndrSig -> UseBndrParens -> SDoc
 pprIfaceTvBndr (tv, ki) (SuppressBndrSig suppress_sig) (UseBndrParens use_parens)
   | suppress_sig             = ppr tv
   | isIfaceLiftedTypeKind ki = ppr tv
-  | otherwise                = maybe_parens (ppr tv <+> dcolon <+> ppr ki)
+  | otherwise                = maybe_parens (ppr tv <+> dcolon <+> ppr_ty_nested ki)
   where
     maybe_parens | use_parens = parens
                  | otherwise  = id
@@ -933,9 +933,13 @@ instance Binary IfaceOneShot where
 instance Outputable IfaceType where
   ppr ty = pprIfaceType ty
 
-pprIfaceType, pprParendIfaceType :: IfaceType -> SDoc
+-- The purpose of 'ppr_ty_nested' is to distinguish calls that should not
+-- trigger 'hideNonStandardTypes', see Note [Defaulting RuntimeRep variables]
+-- wrinkle (W2).
+pprIfaceType, pprParendIfaceType, ppr_ty_nested :: IfaceType -> SDoc
 pprIfaceType       = pprPrecIfaceType topPrec
 pprParendIfaceType = pprPrecIfaceType appPrec
+ppr_ty_nested = ppr_ty topPrec
 
 pprPrecIfaceType :: PprPrec -> IfaceType -> SDoc
 -- We still need `hideNonStandardTypes`, since the `pprPrecIfaceType` may be
@@ -987,7 +991,7 @@ ppr_ty ctxt_prec ty@(IfaceFunTy af w ty1 ty2)  -- Should be a visible argument
       | isVisibleFunArg af
       = (pprTypeArrow af wthis <+> ppr_ty funPrec ty1) : ppr_fun_tail wnext ty2
     ppr_fun_tail wthis other_ty
-      = [pprTypeArrow af wthis <+> pprIfaceType other_ty]
+      = [pprTypeArrow af wthis <+> ppr_ty_nested other_ty]
 
 ppr_ty ctxt_prec (IfaceAppTy t ts)
   = if_print_coercions
@@ -1044,9 +1048,11 @@ Haskell programs, so it makes little sense to make all users pay this
 syntactic overhead.
 
 For this reason it was decided that we would hide RuntimeRep variables
-for now (see #11549). We do this by defaulting all type variables of
-kind RuntimeRep to LiftedRep.
-Likewise, we default all Multiplicity variables to Many.
+for now (see #11549). We do this right in the pretty-printer, by pre-processing
+the type we are about to print, to default any type variables of kind RuntimeRep
+that are bound by toplevel invisible quantification to LiftedRep.
+Likewise, we default Multiplicity variables to Many and Levity variables to
+Lifted.
 
 This is done in a pass right before pretty-printing
 (defaultIfaceTyVarsOfKind, controlled by
@@ -1073,6 +1079,32 @@ metavariables are converted, skolem variables are not.
 There's one exception though: TyVarTv metavariables should not be defaulted,
 as they appear during kind-checking of "newtype T :: TYPE r where..."
 (test T18357a). Therefore, we additionally test for isTyConableTyVar.
+
+Wrinkles:
+
+(W1) The loop 'go' in 'defaultIfaceTyVarsOfKind' passes a Bool flag, 'rank1',
+     around that indicates whether we haven't yet descended into the arguments
+     of a function type.
+     This is used to decide whether newly bound variables are eligible for
+     defaulting – we do not want contravariant foralls to be defaulted because
+     that would result in an incorrect, rather than specialized, type.
+     For example:
+       ∀ p (r1 :: RuntimeRep) . (∀ (r2 :: RuntimeRep) . p r2) -> p r1
+     We want to default 'r1', but not 'r2'.
+     When examining the first forall, 'rank1' is True.
+     The toplevel function type is matched as IfaceFunTy, where we recurse into
+     'go' by passing False for 'rank1'.
+     The forall in the first argument then skips adding a substitution for 'r2'.
+
+(W2) 'defaultIfaceTyVarsOfKind' ought to be called only once when printing a
+     type.
+     A few components of the printing machinery used to invoke 'ppr' on types
+     nested in secondary structures like IfaceBndr, which would repeat the
+     defaulting process, but treating the type as if it were top-level, causing
+     unwanted defaulting.
+     In order to prevent future developers from using 'ppr' again or being
+     confused that @ppr_ty topPrec@ is used, we introduced a marker function,
+     'ppr_ty_nested'.
 -}
 
 -- | Default 'RuntimeRep' variables to 'LiftedRep',
@@ -1097,28 +1129,29 @@ as they appear during kind-checking of "newtype T :: TYPE r where..."
 defaultIfaceTyVarsOfKind :: Bool -- ^ default 'RuntimeRep'/'Levity' variables?
                          -> Bool -- ^ default 'Multiplicity' variables?
                          -> IfaceType -> IfaceType
-defaultIfaceTyVarsOfKind def_rep def_mult ty = go emptyFsEnv ty
+defaultIfaceTyVarsOfKind def_rep def_mult ty = go emptyFsEnv True ty
   where
     go :: FastStringEnv IfaceType -- Set of enclosing forall-ed RuntimeRep/Levity/Multiplicity variables
+       -> Bool -- Are we in a toplevel forall, where defaulting is allowed?
        -> IfaceType
        -> IfaceType
-    go subs (IfaceForAllTy (Bndr (IfaceTvBndr (var, var_kind)) argf) ty)
+    go subs True (IfaceForAllTy (Bndr (IfaceTvBndr (var, var_kind)) argf) ty)
      | isInvisibleForAllTyFlag argf  -- Don't default *visible* quantification
                                 -- or we get the mess in #13963
      , Just substituted_ty <- check_substitution var_kind
       = let subs' = extendFsEnv subs var substituted_ty
             -- Record that we should replace it with LiftedRep/Lifted/Many,
             -- and recurse, discarding the forall
-        in go subs' ty
+        in go subs' True ty
 
-    go subs (IfaceForAllTy bndr ty)
-      = IfaceForAllTy (go_ifacebndr subs bndr) (go subs ty)
+    go subs rank1 (IfaceForAllTy bndr ty)
+      = IfaceForAllTy (go_ifacebndr subs bndr) (go subs rank1 ty)
 
-    go subs ty@(IfaceTyVar tv) = case lookupFsEnv subs tv of
+    go subs _ ty@(IfaceTyVar tv) = case lookupFsEnv subs tv of
       Just s -> s
       Nothing -> ty
 
-    go _ ty@(IfaceFreeTyVar tv)
+    go _ _ ty@(IfaceFreeTyVar tv)
       -- See Note [Defaulting RuntimeRep variables], about free vars
       | def_rep
       , GHC.Core.Type.isRuntimeRepTy (tyVarKind tv)
@@ -1138,34 +1171,34 @@ defaultIfaceTyVarsOfKind def_rep def_mult ty = go emptyFsEnv ty
       | otherwise
       = ty
 
-    go subs (IfaceTyConApp tc tc_args)
+    go subs _ (IfaceTyConApp tc tc_args)
       = IfaceTyConApp tc (go_args subs tc_args)
 
-    go subs (IfaceTupleTy sort is_prom tc_args)
+    go subs _ (IfaceTupleTy sort is_prom tc_args)
       = IfaceTupleTy sort is_prom (go_args subs tc_args)
 
-    go subs (IfaceFunTy af w arg res)
-      = IfaceFunTy af (go subs w) (go subs arg) (go subs res)
+    go subs rank1 (IfaceFunTy af w arg res)
+      = IfaceFunTy af (go subs False w) (go subs False arg) (go subs rank1 res)
 
-    go subs (IfaceAppTy t ts)
-      = IfaceAppTy (go subs t) (go_args subs ts)
+    go subs _ (IfaceAppTy t ts)
+      = IfaceAppTy (go subs False t) (go_args subs ts)
 
-    go subs (IfaceCastTy x co)
-      = IfaceCastTy (go subs x) co
+    go subs rank1 (IfaceCastTy x co)
+      = IfaceCastTy (go subs rank1 x) co
 
-    go _ ty@(IfaceLitTy {}) = ty
-    go _ ty@(IfaceCoercionTy {}) = ty
+    go _ _ ty@(IfaceLitTy {}) = ty
+    go _ _ ty@(IfaceCoercionTy {}) = ty
 
     go_ifacebndr :: FastStringEnv IfaceType -> IfaceForAllBndr -> IfaceForAllBndr
     go_ifacebndr subs (Bndr (IfaceIdBndr (w, n, t)) argf)
-      = Bndr (IfaceIdBndr (w, n, go subs t)) argf
+      = Bndr (IfaceIdBndr (w, n, go subs False t)) argf
     go_ifacebndr subs (Bndr (IfaceTvBndr (n, t)) argf)
-      = Bndr (IfaceTvBndr (n, go subs t)) argf
+      = Bndr (IfaceTvBndr (n, go subs False t)) argf
 
     go_args :: FastStringEnv IfaceType -> IfaceAppArgs -> IfaceAppArgs
     go_args _ IA_Nil = IA_Nil
     go_args subs (IA_Arg ty argf args)
-      = IA_Arg (go subs ty) argf (go_args subs args)
+      = IA_Arg (go subs False ty) argf (go_args subs args)
 
     check_substitution :: IfaceType -> Maybe IfaceType
     check_substitution (IfaceTyConApp tc _)
@@ -1236,7 +1269,7 @@ ppr_app_arg ctx_prec (t, argf) =
        Specified |  print_kinds
                  -> char '@' <> ppr_ty appPrec t
        Inferred  |  print_kinds
-                 -> char '@' <> braces (ppr_ty topPrec t)
+                 -> char '@' <> braces (ppr_ty_nested t)
        _         -> empty
 
 -------------------
@@ -1367,7 +1400,7 @@ ppr_sigma show_forall ctxt_prec iface_ty
           -- Then it could handle both invisible and required binders, and
           -- splitIfaceReqForallTy wouldn't be necessary here.
     in ppr_iface_forall_part show_forall invis_tvs theta $
-       sep [pprIfaceForAll req_tvs, ppr tau']
+       sep [pprIfaceForAll req_tvs, ppr_ty_nested tau']
 
 pprUserIfaceForAll :: [IfaceForAllBndr] -> SDoc
 pprUserIfaceForAll tvs


=====================================
compiler/GHC/Tc/Gen/HsType.hs
=====================================
@@ -2556,37 +2556,30 @@ kcCheckDeclHeader_sig sig_kind name flav
                    --               ^^^^^^^^^
                    -- We do it here because at this point the environment has been
                    -- extended with both 'implicit_tcv_prs' and 'explicit_tv_prs'.
+                   --
+                   -- Also see Note [Arity of type families and type synonyms]
                  ; ctx_k <- kc_res_ki
 
-                 -- Work out extra_arity, the number of extra invisible binders from
-                 -- the kind signature that should be part of the TyCon's arity.
-                 -- See Note [Arity inference in kcCheckDeclHeader_sig]
-                 ; let n_invis_tcbs = countWhile isInvisibleTyConBinder excess_sig_tcbs
-                       invis_arity = case ctx_k of
-                          AnyKind    -> n_invis_tcbs -- No kind signature, so make all the invisible binders
-                                                     -- the signature into part of the arity of the TyCon
-                          OpenKind   -> n_invis_tcbs -- Result kind is (TYPE rr), so again make all the
-                                                     -- invisible binders part of the arity of the TyCon
-                          TheKind ki -> 0 `max` (n_invis_tcbs - invisibleTyBndrCount ki)
+                 ; let sig_res_kind' = mkTyConKind excess_sig_tcbs sig_res_kind
 
-                 ; let (invis_tcbs, resid_tcbs) = splitAt invis_arity excess_sig_tcbs
-                 ; let sig_res_kind' = mkTyConKind resid_tcbs sig_res_kind
-
-                 ; traceTc "kcCheckDeclHeader_sig 2" $ vcat [ ppr excess_sig_tcbs
-                                                            , ppr invis_arity, ppr invis_tcbs
-                                                            , ppr n_invis_tcbs ]
+                 ; traceTc "kcCheckDeclHeader_sig 2" $
+                    vcat [ text "excess_sig_tcbs" <+> ppr excess_sig_tcbs
+                         , text "ctx_k" <+> ppr ctx_k
+                         , text "sig_res_kind'" <+> ppr sig_res_kind'
+                         ]
 
                  -- Unify res_ki (from the type declaration) with the residual kind from
                  -- the kind signature. Don't forget to apply the skolemising 'subst' first.
                  ; case ctx_k of
                       AnyKind -> return ()   -- No signature
-                      _ -> do { res_ki <- newExpectedKind ctx_k
-                              ; discardResult (unifyKind Nothing sig_res_kind' res_ki) }
+                      _ -> do
+                        res_ki <- newExpectedKind ctx_k
+                        check_exp_res_ki sig_res_kind' res_ki
 
                  -- Add more binders for data/newtype, so the result kind has no arrows
                  -- See Note [Datatype return kinds]
-                 ; if null resid_tcbs || not (needsEtaExpansion flav)
-                   then return (invis_tcbs,      sig_res_kind')
+                 ; if null excess_sig_tcbs || not (needsEtaExpansion flav)
+                   then return ([],              sig_res_kind')
                    else return (excess_sig_tcbs, sig_res_kind)
           }
 
@@ -2642,6 +2635,22 @@ kcCheckDeclHeader_sig sig_kind name flav
           ]
         ; return tc }
 
+-- | Check the result kind annotation on a type constructor against
+-- the corresponding section of the standalone kind signature.
+-- Drops invisible binders that interfere with unification.
+check_exp_res_ki :: TcKind    -- ^ the actual kind
+                 -> TcKind    -- ^ the expected kind
+                 -> TcM ()
+check_exp_res_ki act_kind exp_kind
+  = discardResult $ unifyKind Nothing act_kind' exp_kind
+    where
+      (_, act_kind') = splitInvisPiTysN n_to_inst act_kind
+
+      -- by analogy with checkExpectedKind
+      n_exp_invis_bndrs = invisibleTyBndrCount exp_kind
+      n_act_invis_bndrs = invisibleTyBndrCount act_kind
+      n_to_inst         = n_act_invis_bndrs - n_exp_invis_bndrs
+
 matchUpSigWithDecl
   :: Name                        -- Name of the type constructor for error messages
   -> [TcTyConBinder]             -- TcTyConBinders (with skolem TcTyVars) from the separate kind signature
@@ -2739,8 +2748,8 @@ swizzleTcb swizzle_env subst (Bndr tv vis)
     -- See Note [Source locations for implicitly bound type variables]
     -- in GHC.Tc.Rename.HsType
 
-{- See Note [kcCheckDeclHeader_sig]
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+{- Note [kcCheckDeclHeader_sig]
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 Given a kind signature 'sig_kind' and a declaration header,
 kcCheckDeclHeader_sig verifies that the declaration conforms to the
 signature. The end result is a PolyTcTyCon 'tc' such that:
@@ -2781,85 +2790,43 @@ Basic plan is this:
     part of the signature (k -> Type) with the kind signature of the decl,
     (j -> Type).  This unification, done in kcCheckDeclHeader, needs TcTyVars.
 
-  * The tricky extra_arity part is described in
-    Note [Arity inference in kcCheckDeclHeader_sig]
-
-Note [Arity inference in kcCheckDeclHeader_sig]
+Note [Arity of type families and type synonyms]
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-Consider these declarations:
-  type family S1 :: forall k2. k1 -> k2 -> Type
-  type family S2 (a :: k1) (b :: k2) :: Type
-
-Both S1 and S2 can be given the same standalone kind signature:
-  type S1 :: forall k1 k2. k1 -> k2 -> Type
-  type S2 :: forall k1 k2. k1 -> k2 -> Type
-
-And, indeed, tyConKind S1 == tyConKind S2. However,
-tyConBinders and tyConResKind for S1 and S2 are different:
-
-  tyConBinders S1  ==  [spec k1]
-  tyConResKind S1  ==  forall k2. k1 -> k2 -> Type
-  tyConKind    S1  ==  forall k1 k2. k1 -> k2 -> Type
-
-  tyConBinders S2  ==  [spec k1, spec k2, anon-vis (a :: k1), anon-vis (b :: k2)]
-  tyConResKind S2  ==  Type
-  tyConKind    S1  ==  forall k1 k2. k1 -> k2 -> Type
-
-This difference determines the /arity/:
-  tyConArity tc == length (tyConBinders tc)
-That is, the arity of S1 is 1, while the arity of S2 is 4.
-
-'kcCheckDeclHeader_sig' needs to infer the desired arity, to split the
-standalone kind signature into binders and the result kind. It does so
-in two rounds:
-
-1. matchUpSigWithDecl matches up
-   - the [TyConBinder] from (applying splitTyConKind to) the kind signature
-   - with the [LHsTyVarBndr] from the type declaration.
-   That may leave some excess TyConBinder: in the case of S2 there are
-   no excess TyConBinders, but in the case of S1 there are two (since
-   there are no LHsTYVarBndrs.
-
-2. Split off further TyConBinders (in the case of S1, one more) to
-   make it possible to unify the residual return kind with the
-   signature in the type declaration.  More precisely, split off such
-   enough invisible that the remainder of the standalone kind
-   signature and the user-written result kind signature have the same
-   number of invisible quantifiers.
-
-As another example consider the following declarations:
+Consider
 
-    type F :: Type -> forall j. j -> forall k1 k2. (k1, k2) -> Type
-    type family F a b
+  type F0 :: forall k. k -> k -> Type
+  type family F0
 
-    type G :: Type -> forall j. j -> forall k1 k2. (k1, k2) -> Type
-    type family G a b :: forall r2. (r1, r2) -> Type
+  type F1 :: forall k. k -> k -> Type
+  type family F1 @k
 
-For both F and G, the signature (after splitTyConKind) has
-  sig_tcbs :: [TyConBinder]
-    = [ anon-vis (@a_aBq), spec (@j_auA), anon-vis (@(b_aBr :: j_auA))
-      , spec (@k1_auB), spec (@k2_auC)
-      , anon-vis (@(c_aBs :: (k1_auB, k2_auC)))]
+  type F2a :: forall k. k -> k -> Type
+  type family F2a @k a
 
-matchUpSigWithDecl will consume the first three of these, passing on
-  excess_sig_tcbs
-    = [ spec (@k1_auB), spec (@k2_auC)
-      , anon-vis (@(c_aBs :: (k1_auB, k2_auC)))]
+  type F2b :: forall k. k -> k -> Type
+  type family F2b a
 
-For F, there is no result kind signature in the declaration for F, so
-we absorb all invisible binders into F's arity. The resulting arity of
-F is 3+2=5.
+  type F3 :: forall k. k -> k -> Type
+  type family F3 a b
 
-Now, in the case of G, we have a result kind sig 'forall r2. (r2,r2)->Type'.
-This has one invisible binder, so we split of enough extra binders from
-our excess_sig_tcbs to leave just one to match 'r2'.
+All five have the same /kind/, but what /arity/ do they have?
+For a type family, the arity is critical:
+* A type family must always appear saturated (up to its arity)
+* A type family can match only on `arity` arguments, not further ones
+* The arity is recorded by `tyConArity`, and is equal to the number of
+  `TyConBinders` in the `TyCon`.
+* In this context "arity" includes both kind and type arguments.
 
-    res_ki  =  forall    r2. (r1, r2) -> Type
-    kisig   =  forall k1 k2. (k1, k2) -> Type
-                     ^^^
-                     split off this one.
+The arity is not determined by the kind signature (all five have the same signature).
+Rather, it is determined by the declaration of the family:
+* `F0` has arity 0.
+* `F1` has arity 1.
+* `F2a` has arity 2.
+* `F2b` also has arity 2: the kind argument is invisible.
+* `F3` has arity 3; again the kind argument is invisible.
 
-The resulting arity of G is 3+1=4.
+The matching-up of kind signature with the declaration itself is done by
+`matchUpWithSigDecl`.
 
 Note [discardResult in kcCheckDeclHeader_sig]
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -2950,6 +2917,12 @@ data ContextKind = TheKind TcKind   -- ^ a specific kind
                  | AnyKind        -- ^ any kind will do
                  | OpenKind       -- ^ something of the form @TYPE _@
 
+-- debug only
+instance Outputable ContextKind where
+  ppr AnyKind = text "AnyKind"
+  ppr OpenKind = text "OpenKind"
+  ppr (TheKind k) = text "TheKind" <+> ppr k
+
 -----------------------
 newExpectedKind :: ContextKind -> TcM TcKind
 newExpectedKind (TheKind k)   = return k


=====================================
compiler/GHC/Tc/Gen/Splice.hs
=====================================
@@ -797,7 +797,7 @@ tcTExpTy m_ty exp_ty
           TcRnTHError $ TypedTHError $ TypedTHWithPolyType exp_ty
        ; codeCon <- tcLookupTyCon codeTyConName
        ; let rep = getRuntimeRep exp_ty
-       ; return (mkTyConApp codeCon [rep, m_ty, exp_ty]) }
+       ; return (mkTyConApp codeCon [m_ty, rep, exp_ty]) }
 
 quotationCtxtDoc :: LHsExpr GhcRn -> SDoc
 quotationCtxtDoc br_body


=====================================
compiler/GHC/Types/Unique/DFM.hs
=====================================
@@ -94,7 +94,7 @@ import qualified Data.IntSet as I
 -- order then `udfmToList` returns them in deterministic order.
 --
 -- There is an implementation cost: each element is given a serial number
--- as it is added, and `udfmToList` sorts it's result by this serial
+-- as it is added, and `udfmToList` sorts its result by this serial
 -- number. So you should only use `UniqDFM` if you need the deterministic
 -- property.
 --


=====================================
configure.ac
=====================================
@@ -487,7 +487,6 @@ CFLAGS="$CFLAGS $GccUseLdOpt"
 AC_SUBST([LdCmd])
 
 FP_PROG_LD_IS_GNU
-FP_PROG_LD_BUILD_ID
 FP_PROG_LD_NO_COMPACT_UNWIND
 FP_PROG_LD_FILELIST
 


=====================================
distrib/configure.ac.in
=====================================
@@ -130,7 +130,6 @@ CFLAGS="$CFLAGS $GccUseLdOpt"
 AC_SUBST([LdCmd])
 
 FP_PROG_LD_IS_GNU
-FP_PROG_LD_BUILD_ID
 FP_PROG_LD_NO_COMPACT_UNWIND
 FP_PROG_LD_FILELIST
 


=====================================
docs/users_guide/exts/linear_types.rst
=====================================
@@ -14,7 +14,7 @@ Linear types
 warts, and bad error messages; everything down to the syntax is
 subject to change**.  See, in particular,
 :ref:`linear-types-limitations` below. We encourage you to experiment
-with this extension and report issues in the GHC bug tracker `the GHC
+with this extension and report issues in `the GHC
 bug tracker <https://gitlab.haskell.org/ghc/ghc/issues>`__, adding the
 tag ``LinearTypes``.
 


=====================================
libraries/template-haskell/Language/Haskell/TH/Syntax.hs
=====================================
@@ -378,8 +378,13 @@ The splice will evaluate to (MkAge 3) and you can't add that to
 4::Int. So you can't coerce a (Code Q Age) to a (Code Q Int). -}
 
 -- Code constructor
-
+#if __GLASGOW_HASKELL__ >= 909
+type Code :: (Kind.Type -> Kind.Type) -> forall r. TYPE r -> Kind.Type
+  -- The nested `forall` makes it possible to assign the arity of 0 to
+  --   type CodeQ = Code Q
+#else
 type Code :: (Kind.Type -> Kind.Type) -> TYPE r -> Kind.Type
+#endif
 type role Code representational nominal   -- See Note [Role of TExp]
 newtype Code m a = Code
   { examineCode :: m (TExp a) -- ^ Underlying monadic value


=====================================
libraries/template-haskell/changelog.md
=====================================
@@ -1,10 +1,15 @@
 # Changelog for [`template-haskell` package](http://hackage.haskell.org/package/template-haskell)
 
+## 2.22.0.0
+
+  * The kind of `Code` was changed from `forall r. (Type -> Type) -> TYPE r -> Type`
+    to `(Type -> Type) -> forall r. TYPE r -> Type`. This enables higher-kinded usage.
+
 ## 2.21.0.0
 
   * Record fields now belong to separate `NameSpace`s, keyed by the parent of
     the record field. This is the name of the first constructor of the parent type,
-    even if this constructor does not have the field in question.  
+    even if this constructor does not have the field in question.
 
     This change enables TemplateHaskell support for `DuplicateRecordFields`.
 
@@ -21,7 +26,7 @@
 
 ## 2.20.0.0
 
-  * The `Ppr.pprInfixT` function has gained a `Precedence` argument. 
+  * The `Ppr.pprInfixT` function has gained a `Precedence` argument.
   * The values of named precedence levels like `Ppr.appPrec` have changed.
 
   * Add `TypeDataD` constructor to the `Dec` type for `type data`


=====================================
testsuite/tests/ghci/scripts/T16468.script
=====================================
@@ -0,0 +1,52 @@
+:set -XLinearTypes -XImpredicativeTypes
+import GHC.Types (RuntimeRep (..), Levity (..), TYPE, Multiplicity, Type, LiftedRep)
+import Data.Proxy
+
+f :: forall p (r' :: RuntimeRep). (forall (r :: RuntimeRep). Int -> p r) -> p r'; f x = x 5
+g :: forall p. Int -> forall (r :: RuntimeRep). p r; g _ = undefined
+g' :: Int -> forall p (r :: RuntimeRep). p r; g' _ = undefined
+h :: Int -> forall (r :: RuntimeRep). TYPE r; h _ = undefined
+i :: forall (r :: RuntimeRep). Int -> TYPE r; i _ = undefined
+j :: forall p. Eq (p ('BoxedRep 'Lifted)) => Int -> forall (r :: RuntimeRep). p r; j _ = undefined
+k :: forall p (r' :: RuntimeRep). Eq (p r') => (forall (r :: RuntimeRep). Eq (p r) => Int -> p r) -> p r'; k x = x 5
+class C a where l :: forall (r :: RuntimeRep) (b :: TYPE r). a -> b
+m :: (forall (m :: Multiplicity). Int %m -> Int) -> Int; m x = x 5
+n :: forall (m :: Multiplicity). Int %m -> Int; n a = a
+o :: Maybe (forall (r :: RuntimeRep). Proxy r); o = Nothing
+p :: (forall (r :: RuntimeRep). Proxy r, Int); p = undefined
+q :: p (forall (r :: RuntimeRep). Proxy r); q = undefined
+r :: forall (a :: (forall (r :: RuntimeRep). TYPE r)) (p :: (forall (r :: RuntimeRep). TYPE r) -> Type). p a; r = r
+
+:set -XNoLinearTypes
+
+:type f
+:type g
+:type g'
+:type h
+:type i
+:type j
+:type k
+:type l
+:type m
+:type n
+:type o
+:type p
+:type q
+:type r
+
+:set -fprint-explicit-runtime-reps
+:set -XLinearTypes
+:type f
+:type g
+:type g'
+:type h
+:type i
+:type j
+:type k
+:type l
+:type m
+:type n
+:type o
+:type p
+:type q
+:type r


=====================================
testsuite/tests/ghci/scripts/T16468.stdout
=====================================
@@ -0,0 +1,34 @@
+f :: (forall (r :: RuntimeRep). Int -> p r) -> p LiftedRep
+g :: Int -> p LiftedRep
+g' :: Int -> forall (p :: RuntimeRep -> *). p LiftedRep
+h :: Int -> *
+i :: Int -> *
+j :: Eq (p LiftedRep) => Int -> p LiftedRep
+k :: Eq (p LiftedRep) =>
+     (forall (r :: RuntimeRep). Eq (p r) => Int -> p r) -> p LiftedRep
+l :: C a => a -> b
+m :: (forall (m :: Multiplicity). Int %m -> Int) -> Int
+n :: Int -> Int
+o :: Maybe (forall (r :: RuntimeRep). Proxy r)
+p :: (Proxy LiftedRep, Int)
+q :: p (forall (r :: RuntimeRep). Proxy r)
+r :: forall (a :: forall (r :: RuntimeRep). TYPE r)
+            (p :: (forall (r :: RuntimeRep). TYPE r) -> *).
+     p a
+f :: (forall (r :: RuntimeRep). Int -> p r) -> p r'
+g :: Int -> forall (r :: RuntimeRep). p r
+g' :: Int -> forall (p :: RuntimeRep -> *) (r :: RuntimeRep). p r
+h :: Int -> forall (r :: RuntimeRep). TYPE r
+i :: Int -> TYPE r
+j :: Eq (p LiftedRep) => Int -> forall (r :: RuntimeRep). p r
+k :: Eq (p r') =>
+     (forall (r :: RuntimeRep). Eq (p r) => Int -> p r) -> p r'
+l :: forall a (r :: RuntimeRep) (b :: TYPE r). C a => a -> b
+m :: (forall (m :: Multiplicity). Int %m -> Int) -> Int
+n :: Int %m -> Int
+o :: Maybe (forall (r :: RuntimeRep). Proxy r)
+p :: (forall (r :: RuntimeRep). Proxy r, Int)
+q :: p (forall (r :: RuntimeRep). Proxy r)
+r :: forall (a :: forall (r :: RuntimeRep). TYPE r)
+            (p :: (forall (r :: RuntimeRep). TYPE r) -> *).
+     p a


=====================================
testsuite/tests/ghci/scripts/all.T
=====================================
@@ -375,3 +375,4 @@ test('T22695', normal, ghci_script, ['T22695.script'])
 test('T22817', normal, ghci_script, ['T22817.script'])
 test('T22908', normal, ghci_script, ['T22908.script'])
 test('T23062', normal, ghci_script, ['T23062.script'])
+test('T16468', normal, ghci_script, ['T16468.script'])


=====================================
testsuite/tests/perf/compiler/CoOpt_Singletons.hs
=====================================
@@ -52,7 +52,7 @@ type SameKind :: k -> k -> Constraint
 type SameKind (a :: k) (b :: k) = (() :: Constraint)
 
 type Sing :: k -> Type
-type family Sing :: k -> Type
+type family Sing @k :: k -> Type
 
 type SLambda :: (k1 ~> k2) -> Type
 newtype SLambda (f :: k1 ~> k2) =
@@ -386,7 +386,7 @@ type family (<>@#@$$$) (a6989586621679047054 :: a_a9GJ) (a6989586621679047055 ::
 class PSemigroup a_a9GJ where
   type family (<>) (arg_a9GX :: a_a9GJ) (arg_a9GY :: a_a9GJ) :: a_a9GJ
 type MemptySym0 :: forall a_a9GK. a_a9GK
-type family MemptySym0 :: a_a9GK where
+type family MemptySym0 @a_a9GK :: a_a9GK where
   MemptySym0 = Mempty
 type MappendSym0 :: forall a_a9GK. (~>) a_a9GK ((~>) a_a9GK a_a9GK)
 data MappendSym0 :: (~>) a_a9GK ((~>) a_a9GK a_a9GK)
@@ -450,10 +450,10 @@ type family TFHelper_6989586621679047079Sym2 (a6989586621679047084 :: Dual a_a9G
 instance PSemigroup (Dual a_a9GL) where
   type (<>) a_a9Hn a_a9Ho = Apply (Apply TFHelper_6989586621679047079Sym0 a_a9Hn) a_a9Ho
 type Mempty_6989586621679047088 :: Dual a_a9GO
-type family Mempty_6989586621679047088 :: Dual a_a9GO where
+type family Mempty_6989586621679047088 @a_a9GO :: Dual a_a9GO where
   Mempty_6989586621679047088 = Apply DualSym0 MemptySym0
 type Mempty_6989586621679047088Sym0 :: Dual a_a9GO
-type family Mempty_6989586621679047088Sym0 :: Dual a_a9GO where
+type family Mempty_6989586621679047088Sym0 @a_a9GO :: Dual a_a9GO where
   Mempty_6989586621679047088Sym0 = Mempty_6989586621679047088
 instance PMonoid (Dual a_a9GO) where
   type Mempty = Mempty_6989586621679047088Sym0
@@ -549,10 +549,10 @@ type family TFHelper_6989586621679075091Sym2 (a6989586621679075096 :: Endo a_agC
 instance PSemigroup (Endo a_agCk) where
   type (<>) a_agZb a_agZc = Apply (Apply TFHelper_6989586621679075091Sym0 a_agZb) a_agZc
 type Mempty_6989586621679075313 :: Endo a_agCn
-type family Mempty_6989586621679075313 :: Endo a_agCn where
+type family Mempty_6989586621679075313 @a_agCn :: Endo a_agCn where
   Mempty_6989586621679075313 = Apply EndoSym0 IdSym0
 type Mempty_6989586621679075313Sym0 :: Endo a_agCn
-type family Mempty_6989586621679075313Sym0 :: Endo a_agCn where
+type family Mempty_6989586621679075313Sym0 @a_agCn :: Endo a_agCn where
   Mempty_6989586621679075313Sym0 = Mempty_6989586621679075313
 instance PMonoid (Endo a_agCn) where
   type Mempty = Mempty_6989586621679075313Sym0


=====================================
testsuite/tests/saks/should_compile/T16724.stdout
=====================================
@@ -1,6 +1,6 @@
 type T1 :: forall k (a :: k). Type
-type family T1 @k @a
+type family T1
   	-- Defined at T16724.hs:11:1
 type T2 :: forall {k} (a :: k). Type
-type family T2 @{k} @a
+type family T2
   	-- Defined at T16724.hs:15:1


=====================================
testsuite/tests/saks/should_compile/saks030.hs
=====================================
@@ -10,7 +10,7 @@ import Data.Type.Equality
 type T1 :: forall k (a :: k). Bool
 type T2 :: k -> Bool
 
-type family T1 where
+type family T1 @k @a where
   T1 @Bool @True  = False
   T1 @Bool @False = True
 


=====================================
testsuite/tests/saks/should_compile/saks032.hs
=====================================
@@ -18,4 +18,4 @@ type F1 :: Type -> forall j. j -> forall k1 k2. (k1, k2) -> Type
 type family F1 a b
 
 type F2 :: Type -> forall j. j -> forall k1 k2. (k1, k2) -> Type
-type family F2 a b :: forall r2. (r1, r2) -> Type
+type family F2 a b @r1 :: forall r2. (r1, r2) -> Type


=====================================
testsuite/tests/th/CodeQ_HKD.hs
=====================================
@@ -0,0 +1,13 @@
+{-# LANGUAGE MagicHash #-}
+{-# LANGUAGE TemplateHaskell #-}
+
+module CodeQ_HKD where
+import GHC.Exts
+import Data.Kind
+import Language.Haskell.TH hiding (Type)
+
+data T (f :: forall r . (TYPE r) -> Type) = MkT (f Int) (f Int#)
+
+
+tcodeq :: T CodeQ
+tcodeq = MkT [||5||] [||5#||]


=====================================
testsuite/tests/th/all.T
=====================================
@@ -579,3 +579,4 @@ test('T22559a', normal, compile_fail, [''])
 test('T22559b', normal, compile_fail, [''])
 test('T22559c', normal, compile_fail, [''])
 test('T23525', normal, compile, [''])
+test('CodeQ_HKD', normal, compile, [''])


=====================================
testsuite/tests/typecheck/should_compile/T23514b.hs
=====================================
@@ -0,0 +1,9 @@
+{-# LANGUAGE TypeFamilies, DataKinds #-}
+module T23514b where
+
+import GHC.Types
+
+type F :: Type -> forall k. Maybe k
+type family F x @k where
+  F Int @Type = Just Bool
+  F Int       = Just Either


=====================================
testsuite/tests/typecheck/should_compile/T23514c.hs
=====================================
@@ -0,0 +1,21 @@
+module T23514c where
+import Data.Kind
+
+
+type P1 :: forall k (a :: k) . k -> Type
+data P1 :: k -> Type
+
+type P2 :: forall k (a :: k) . k -> Type
+data P2 @k :: k -> Type
+
+type P3 :: forall k (a :: k) . k -> Type
+data P3 @k @a :: k -> Type
+
+type P4 :: forall k (a :: k) . k -> Type
+data P4 :: forall k (a :: k) . k -> Type
+
+type P5 :: forall k (a :: k) . k -> Type
+data P5 :: forall a . k -> Type
+
+type P6 :: forall k (a :: k) . k -> Type
+data P6 @k :: forall a . k -> Type


=====================================
testsuite/tests/typecheck/should_compile/all.T
=====================================
@@ -880,3 +880,5 @@ test('T22560b', normal, compile, [''])
 test('T22560c', normal, compile, [''])
 test('T22560d', extra_files(['T22560d.hs']), ghci_script, ['T22560d.script'])
 test('T22560e', normal, compile, [''])
+test('T23514b', normal, compile, [''])
+test('T23514c', normal, compile, [''])


=====================================
testsuite/tests/typecheck/should_fail/T18640a.hs
=====================================
@@ -8,4 +8,4 @@ module T18640a where
 import Data.Kind
 
 type F2 :: forall a b. Type -> a
-type family F2 :: forall b. Type -> Type where
+type family F2 @a :: forall b. Type -> Type where


=====================================
testsuite/tests/typecheck/should_fail/T18640a.stderr
=====================================
@@ -5,5 +5,5 @@ T18640a.hs:11:1: error: [GHC-25897]
         Actual: forall (b :: k). * -> a
       ‘a’ is a rigid type variable bound by
         the type family declaration for ‘F2’
-        at T18640a.hs:10:19
+        at T18640a.hs:11:17
     • In the type family declaration for ‘F2’


=====================================
testsuite/tests/typecheck/should_fail/T18640c.hs
=====================================
@@ -11,4 +11,4 @@ type F1 :: forall k -> Type
 type family F1 k :: Type
 
 type F2 :: forall x. forall k -> x
-type F2 = F1
+type F2 k = F1 k


=====================================
testsuite/tests/typecheck/should_fail/T18640c.stderr
=====================================
@@ -1,10 +1,8 @@
 
-T18640c.hs:14:11: error: [GHC-25897]
-    • Couldn't match kind ‘x’ with ‘*’
-      Expected kind ‘forall (k1 :: k) -> x’,
-        but ‘F1’ has kind ‘forall (k1 :: k) -> *’
+T18640c.hs:14:13: error: [GHC-25897]
+    • Expected kind ‘x’, but ‘F1 k’ has kind ‘*’
       ‘x’ is a rigid type variable bound by
         the type synonym declaration for ‘F2’
         at T18640c.hs:13:19
-    • In the type ‘F1’
+    • In the type ‘F1 k’
       In the type declaration for ‘F2’


=====================================
testsuite/tests/typecheck/should_fail/T23514a.hs
=====================================
@@ -0,0 +1,9 @@
+{-# LANGUAGE TypeFamilies, DataKinds #-}
+module T23514a where
+
+import GHC.Types
+
+type F :: Type -> forall k. Maybe k
+type family F x where
+  F Int @Type = Just Bool
+  F Int       = Just Either


=====================================
testsuite/tests/typecheck/should_fail/T23514a.stderr
=====================================
@@ -0,0 +1,6 @@
+
+T23514a.hs:9:17: error: [GHC-83865]
+    • Expected kind ‘forall k. Maybe k’,
+        but ‘Just Either’ has kind ‘Maybe (* -> * -> *)’
+    • In the type ‘Just Either’
+      In the type family declaration for ‘F’


=====================================
testsuite/tests/typecheck/should_fail/all.T
=====================================
@@ -696,3 +696,4 @@ test('VisFlag2', normal, compile_fail, [''])
 test('VisFlag3', normal, compile_fail, [''])
 test('VisFlag4', normal, compile_fail, [''])
 test('VisFlag5', normal, compile_fail, [''])
+test('T23514a', normal, compile_fail, [''])



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/931860b8aa7a3e7a9d5d7450b5fb2c58f89532fd...771e6f62d3c9df8fd8ab3362495aad091463ce6b

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/931860b8aa7a3e7a9d5d7450b5fb2c58f89532fd...771e6f62d3c9df8fd8ab3362495aad091463ce6b
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/20230627/9d49ddb2/attachment-0001.html>


More information about the ghc-commits mailing list