Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC Commits: 64f821c6 by Simon Peyton Jones at 2026-11-22T16:41:09-05:00 Fix a zonking bug As #28135 showed, we were failing to zonk some type-variable binders before doing scoped-sort dependency analysis, resulting in chaos. The fix is easy. - - - - - 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: ===================================== changelog.d/T28135 ===================================== @@ -0,0 +1,8 @@ +section: compiler +issues: #28135 +mrs: !17006 +synopsis: + Fix a bug in kind inference in data constructors +description: + This bug affected only data constructors using kind polymorphism, + and declared in GADT style. ===================================== compiler/GHC/Tc/Gen/HsType.hs ===================================== @@ -29,7 +29,6 @@ module GHC.Tc.Gen.HsType ( bindOuterFamEqnTKBndrs_Q_Tv, bindOuterFamEqnTKBndrs, tcOuterTKBndrs, scopedSortOuter, outerTyVars, outerTyVarBndrs, - tcGadtConTyVarBndrs, bindOuterSigTKBndrs_Tv, tcExplicitTKBndrs, bindNamedWildCardBinders, @@ -3545,20 +3544,6 @@ tcOuterTKBndrsX skol_mode skol_info outer_bndrs thing_inside , hso_bndrs = exp_bndrs } , thing) } ---------------- -tcGadtConTyVarBndrs :: SkolemInfo - -> HsOuterSigTyVarBndrs GhcRn - -> [LHsGadtTelescope GhcRn] - -> TcM a -> TcM ([TcTyVarBinder], a) -tcGadtConTyVarBndrs skol_info outer inner thing_inside - = do { (outer_bndrs, (inner_tvbs, a)) <- - tcOuterTKBndrs skol_info outer $ - tcExplicitTKBndrs skol_info (gadtTelescopeBndrs inner) $ - thing_inside - ; outer_bndrs <- scopedSortOuter outer_bndrs - ; let outer_tvbs = tyVarSpecToBinders (outerTyVarBndrs outer_bndrs) - ; return (outer_tvbs ++ inner_tvbs, a) } - -------------------------------------- -- Explicit tyvar binders -------------------------------------- ===================================== compiler/GHC/Tc/Solver.hs ===================================== @@ -187,7 +187,7 @@ pushLevelAndSolveEqualitiesX callsite thing_inside do { (res, wanted) <- captureConstraints thing_inside ; wanted <- runTcSEqualities (simplifyTopWanteds wanted) ; return (wanted,res) } - ; traceTc "pushLevelAndSolveEqualities }" (vcat [ text "Residual:" <+> ppr wanted + ; traceTc "pushLevelAndSolveEqualitiesX }" (vcat [ text "Residual:" <+> ppr wanted , text "Level:" <+> ppr tclvl ]) ; return (tclvl, wanted, res) } ===================================== compiler/GHC/Tc/TyCl.hs ===================================== @@ -4185,12 +4185,16 @@ tcConDecl new_or_data dd_info rep_tycon tc_bndrs _res_kind tag_map , con_cxts = cxts, con_g_args = hs_args , con_res_ty = hs_res_ty }) = addErrCtxt (DataConDefCtxt names) $ - do { traceTc "tcConDecl 1 gadt" (ppr names) + do { traceTc "tcConDecl 1 gadt" $ + vcat [ text "data con names:" <+> ppr names + , text "outer_bndrs:" <+> ppr outer_bndrs + , text "inner_bndrs:" <+> ppr inner_bndrs ] ; let L _ name :| _ = names ; skol_info <- mkSkolemInfo (DataConSkol name) - ; (tclvl, wanted, (tvbs, (ctxt, arg_tys, res_ty, field_lbls, stricts))) - <- pushLevelAndSolveEqualitiesX "tcConDecl:GADT" $ - tcGadtConTyVarBndrs skol_info outer_bndrs inner_bndrs $ + ; (tclvl, wanted, (tc_outer, (inner_tvbs, (ctxt, arg_tys, res_ty, field_lbls, stricts)))) + <- pushLevelAndSolveEqualitiesX "tcConDecl:GADT" $ + tcOuterTKBndrs skol_info outer_bndrs $ + tcExplicitTKBndrs skol_info (gadtTelescopeBndrs inner_bndrs) $ do { ctxt <- tcHsContext cxts ; (res_ty, res_kind) <- tcInferLHsTypeKind hs_res_ty -- See Note [GADT return kinds] @@ -4217,11 +4221,16 @@ tcConDecl new_or_data dd_info rep_tycon tc_bndrs _res_kind tag_map ; return (ctxt, arg_tys, res_ty, field_lbls, stricts) } + -- Must do this scopedSortOut /after/ solving the equalities (#28135) + ; tc_outer <- scopedSortOuter tc_outer + ; let outer_tvbs = tyVarSpecToBinders (outerTyVarBndrs tc_outer) + tvbs = outer_tvbs ++ inner_tvbs + ; inf_tkvs <- kindGeneralizeAll skol_info - (mkForAllTys tvbs $ - tcMkPhiTy ctxt $ - tcMkScaledFunTys arg_tys $ - res_ty) + (mkForAllTys tvbs $ + tcMkPhiTy ctxt $ + tcMkScaledFunTys arg_tys $ + res_ty) ; traceTc "tcConDecl:GADT" (ppr names $$ ppr res_ty $$ ppr inf_tkvs) ; reportUnsolvedEqualities skol_info inf_tkvs tclvl wanted ===================================== testsuite/tests/typecheck/should_compile/T28135.hs ===================================== @@ -0,0 +1,10 @@ +{-# LANGUAGE GADTs, TypeFamilies #-} + +-- GHC 9.14.1 panics with "updateRole" when compiling this module. +-- Compiles fine with GHC 9.12 (but by a fluke) +module T28135 where + +data S t where + W :: C f => (forall (a :: k). S (t a)) -> S (t f) + +class C f ===================================== testsuite/tests/typecheck/should_compile/all.T ===================================== @@ -975,3 +975,4 @@ test('T26543_orig', normal, compile, ['']) test('T27994', normal, compile, ['']) test('T27994a', normal, compile, ['']) test('T27994b', normal, compile, ['']) +test('T28135', normal, compile, ['']) View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/64f821c6e8da5af8558e10016105bb4a... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/64f821c6e8da5af8558e10016105bb4a... You're receiving this email because of your account on gitlab.haskell.org. Manage all notifications: https://gitlab.haskell.org/-/profile/notifications | Help: https://gitlab.haskell.org/help