Simon Peyton Jones pushed to branch wip/T28135 at Glasgow Haskell Compiler / GHC
Commits:
-
15ab4a00
by Simon Peyton Jones at 2026-11-17T11:15:51+00:00
6 changed files:
- + changelog.d/T28135
- compiler/GHC/Tc/Gen/HsType.hs
- compiler/GHC/Tc/Solver.hs
- compiler/GHC/Tc/TyCl.hs
- + testsuite/tests/typecheck/should_compile/T28135.hs
- testsuite/tests/typecheck/should_compile/all.T
Changes:
| 1 | +section: compiler
|
|
| 2 | +issues: #28135
|
|
| 3 | +mrs: !17006
|
|
| 4 | +synopsis:
|
|
| 5 | + Fix a bug in kind inference in data constructors
|
|
| 6 | +description:
|
|
| 7 | + This bug affected only data constructors using kind polymorphism,
|
|
| 8 | + and declared in GADT style. |
| ... | ... | @@ -29,7 +29,6 @@ module GHC.Tc.Gen.HsType ( |
| 29 | 29 | |
| 30 | 30 | bindOuterFamEqnTKBndrs_Q_Tv, bindOuterFamEqnTKBndrs,
|
| 31 | 31 | tcOuterTKBndrs, scopedSortOuter, outerTyVars, outerTyVarBndrs,
|
| 32 | - tcGadtConTyVarBndrs,
|
|
| 33 | 32 | bindOuterSigTKBndrs_Tv,
|
| 34 | 33 | tcExplicitTKBndrs,
|
| 35 | 34 | bindNamedWildCardBinders,
|
| ... | ... | @@ -3545,20 +3544,6 @@ tcOuterTKBndrsX skol_mode skol_info outer_bndrs thing_inside |
| 3545 | 3544 | , hso_bndrs = exp_bndrs }
|
| 3546 | 3545 | , thing) }
|
| 3547 | 3546 | |
| 3548 | ----------------
|
|
| 3549 | -tcGadtConTyVarBndrs :: SkolemInfo
|
|
| 3550 | - -> HsOuterSigTyVarBndrs GhcRn
|
|
| 3551 | - -> [LHsGadtTelescope GhcRn]
|
|
| 3552 | - -> TcM a -> TcM ([TcTyVarBinder], a)
|
|
| 3553 | -tcGadtConTyVarBndrs skol_info outer inner thing_inside
|
|
| 3554 | - = do { (outer_bndrs, (inner_tvbs, a)) <-
|
|
| 3555 | - tcOuterTKBndrs skol_info outer $
|
|
| 3556 | - tcExplicitTKBndrs skol_info (gadtTelescopeBndrs inner) $
|
|
| 3557 | - thing_inside
|
|
| 3558 | - ; outer_bndrs <- scopedSortOuter outer_bndrs
|
|
| 3559 | - ; let outer_tvbs = tyVarSpecToBinders (outerTyVarBndrs outer_bndrs)
|
|
| 3560 | - ; return (outer_tvbs ++ inner_tvbs, a) }
|
|
| 3561 | - |
|
| 3562 | 3547 | --------------------------------------
|
| 3563 | 3548 | -- Explicit tyvar binders
|
| 3564 | 3549 | --------------------------------------
|
| ... | ... | @@ -187,7 +187,7 @@ pushLevelAndSolveEqualitiesX callsite thing_inside |
| 187 | 187 | do { (res, wanted) <- captureConstraints thing_inside
|
| 188 | 188 | ; wanted <- runTcSEqualities (simplifyTopWanteds wanted)
|
| 189 | 189 | ; return (wanted,res) }
|
| 190 | - ; traceTc "pushLevelAndSolveEqualities }" (vcat [ text "Residual:" <+> ppr wanted
|
|
| 190 | + ; traceTc "pushLevelAndSolveEqualitiesX }" (vcat [ text "Residual:" <+> ppr wanted
|
|
| 191 | 191 | , text "Level:" <+> ppr tclvl ])
|
| 192 | 192 | ; return (tclvl, wanted, res) }
|
| 193 | 193 |
| ... | ... | @@ -4185,12 +4185,16 @@ tcConDecl new_or_data dd_info rep_tycon tc_bndrs _res_kind tag_map |
| 4185 | 4185 | , con_cxts = cxts, con_g_args = hs_args
|
| 4186 | 4186 | , con_res_ty = hs_res_ty })
|
| 4187 | 4187 | = addErrCtxt (DataConDefCtxt names) $
|
| 4188 | - do { traceTc "tcConDecl 1 gadt" (ppr names)
|
|
| 4188 | + do { traceTc "tcConDecl 1 gadt" $
|
|
| 4189 | + vcat [ text "data con names:" <+> ppr names
|
|
| 4190 | + , text "outer_bndrs:" <+> ppr outer_bndrs
|
|
| 4191 | + , text "inner_bndrs:" <+> ppr inner_bndrs ]
|
|
| 4189 | 4192 | ; let L _ name :| _ = names
|
| 4190 | 4193 | ; skol_info <- mkSkolemInfo (DataConSkol name)
|
| 4191 | - ; (tclvl, wanted, (tvbs, (ctxt, arg_tys, res_ty, field_lbls, stricts)))
|
|
| 4192 | - <- pushLevelAndSolveEqualitiesX "tcConDecl:GADT" $
|
|
| 4193 | - tcGadtConTyVarBndrs skol_info outer_bndrs inner_bndrs $
|
|
| 4194 | + ; (tclvl, wanted, (tc_outer, (inner_tvbs, (ctxt, arg_tys, res_ty, field_lbls, stricts))))
|
|
| 4195 | + <- pushLevelAndSolveEqualitiesX "tcConDecl:GADT" $
|
|
| 4196 | + tcOuterTKBndrs skol_info outer_bndrs $
|
|
| 4197 | + tcExplicitTKBndrs skol_info (gadtTelescopeBndrs inner_bndrs) $
|
|
| 4194 | 4198 | do { ctxt <- tcHsContext cxts
|
| 4195 | 4199 | ; (res_ty, res_kind) <- tcInferLHsTypeKind hs_res_ty
|
| 4196 | 4200 | -- See Note [GADT return kinds]
|
| ... | ... | @@ -4217,11 +4221,16 @@ tcConDecl new_or_data dd_info rep_tycon tc_bndrs _res_kind tag_map |
| 4217 | 4221 | ; return (ctxt, arg_tys, res_ty, field_lbls, stricts)
|
| 4218 | 4222 | }
|
| 4219 | 4223 | |
| 4224 | + -- Must do this scopedSortOut /after/ solving the equalities (#28135)
|
|
| 4225 | + ; tc_outer <- scopedSortOuter tc_outer
|
|
| 4226 | + ; let outer_tvbs = tyVarSpecToBinders (outerTyVarBndrs tc_outer)
|
|
| 4227 | + tvbs = outer_tvbs ++ inner_tvbs
|
|
| 4228 | + |
|
| 4220 | 4229 | ; inf_tkvs <- kindGeneralizeAll skol_info
|
| 4221 | - (mkForAllTys tvbs $
|
|
| 4222 | - tcMkPhiTy ctxt $
|
|
| 4223 | - tcMkScaledFunTys arg_tys $
|
|
| 4224 | - res_ty)
|
|
| 4230 | + (mkForAllTys tvbs $
|
|
| 4231 | + tcMkPhiTy ctxt $
|
|
| 4232 | + tcMkScaledFunTys arg_tys $
|
|
| 4233 | + res_ty)
|
|
| 4225 | 4234 | ; traceTc "tcConDecl:GADT" (ppr names $$ ppr res_ty $$ ppr inf_tkvs)
|
| 4226 | 4235 | ; reportUnsolvedEqualities skol_info inf_tkvs tclvl wanted
|
| 4227 | 4236 |
| 1 | +{-# LANGUAGE GADTs, TypeFamilies #-}
|
|
| 2 | + |
|
| 3 | +-- GHC 9.14.1 panics with "updateRole" when compiling this module.
|
|
| 4 | +-- Compiles fine with GHC 9.12 (but by a fluke)
|
|
| 5 | +module T28135 where
|
|
| 6 | + |
|
| 7 | +data S t where
|
|
| 8 | + W :: C f => (forall (a :: k). S (t a)) -> S (t f)
|
|
| 9 | + |
|
| 10 | +class C f |
| ... | ... | @@ -975,3 +975,4 @@ test('T26543_orig', normal, compile, ['']) |
| 975 | 975 | test('T27994', normal, compile, [''])
|
| 976 | 976 | test('T27994a', normal, compile, [''])
|
| 977 | 977 | test('T27994b', normal, compile, [''])
|
| 978 | +test('T28135', normal, compile, ['']) |