[Git][ghc/ghc][wip/T25647] zonk_quant outer binders for families

Patrick (@soulomoon) gitlab at gitlab.haskell.org
Sun Mar 9 19:26:32 UTC 2025


Patrick pushed to branch wip/T25647 at Glasgow Haskell Compiler / GHC


Commits:
5a03c614 by Patrick at 2025-03-10T03:26:20+08:00
zonk_quant outer binders for families

- - - - -


3 changed files:

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


Changes:

=====================================
compiler/GHC/Tc/TyCl.hs
=====================================
@@ -3462,8 +3462,8 @@ tcTyFamInstEqnGuts fam_tc mb_clsinfo outer_hs_bndrs hs_pats hs_rhs_ty
        -- check there too!
 
        -- See Note [Generalising in tcTyFamInstEqnGuts]
-       ; dvs  <- candidateQTyVarsOfType lhs_ty
-       ; qtvs <- quantifyTyVars skol_info dvs
+       ; dvs  <- candidateQTyVarsWithBinders outer_tvs lhs_ty
+       ; qtvs <- quantifyTyVars' outer_tvs skol_info dvs
        ; let final_tvs = scopedSort qtvs
              -- This scopedSort is important: the qtvs may be /interleaved/ with
              -- the outer_tvs.  See Note [Generalising in tcTyFamInstEqnGuts]


=====================================
compiler/GHC/Tc/TyCl/Instance.hs
=====================================
@@ -975,8 +975,8 @@ tcDataFamInstHeader mb_clsinfo skol_info fam_tc hs_outer_bndrs fixity
        -- check there too!
 
        -- See GHC.Tc.TyCl Note [Generalising in tcTyFamInstEqnGuts]
-       ; dvs  <- candidateQTyVarsOfType lhs_ty
-       ; qtvs <- quantifyTyVars skol_info dvs
+       ; dvs  <- candidateQTyVarsWithBinders outer_tvs lhs_ty
+       ; qtvs <- quantifyTyVars' outer_tvs skol_info dvs
                  -- Have to make a same defaulting choice for reuslt kind here
                  -- and the `kindGeneralizeAll` in `tcConDecl`.
                  -- see (GT4) in


=====================================
compiler/GHC/Tc/Utils/TcMType.hs
=====================================
@@ -81,6 +81,7 @@ module GHC.Tc.Utils.TcMType (
   defaultTyVar, promoteMetaTyVarTo, promoteTyVarSet,
   quantifyTyVars, doNotQuantifyTyVars,
   zonkAndSkolemise, skolemiseQuantifiedTyVar,
+  quantifyTyVars',
 
   candidateQTyVarsOfType,  candidateQTyVarsOfKind,
   candidateQTyVarsOfTypes, candidateQTyVarsOfKinds,
@@ -1751,6 +1752,14 @@ quantifyTyVars :: SkolemInfo
                -> CandidatesQTvs   -- See Note [Dependent type variables]
                                    -- Already zonked
                -> TcM [TcTyVar]
+quantifyTyVars = quantifyTyVars' []
+
+quantifyTyVars' ::
+               [TcTyVar]
+               -> SkolemInfo
+               -> CandidatesQTvs   -- See Note [Dependent type variables]
+                                   -- Already zonked
+               -> TcM [TcTyVar]
 -- See Note [quantifyTyVars]
 -- Can be given a mixture of TcTyVars and TyVars, in the case of
 --   associated type declarations. Also accepts covars, but *never* returns any.
@@ -1758,9 +1767,9 @@ quantifyTyVars :: SkolemInfo
 -- invariants on CandidateQTvs, we do not have to filter out variables
 -- free in the environment here. Just quantify unconditionally, subject
 -- to the restrictions in Note [quantifyTyVars].
-quantifyTyVars skol_info dvs
+quantifyTyVars' cvs skol_info dvs
        -- short-circuit common case
-  | isEmptyCandidates dvs
+  | isEmptyCandidates dvs && null cvs
   = do { traceTc "quantifyTyVars has nothing to quantify" empty
        ; return [] }
 
@@ -1769,7 +1778,7 @@ quantifyTyVars skol_info dvs
            ( vcat [ text "dvs =" <+> ppr dvs ])
 
        ; undefaulted <- defaultTyVars dvs
-       ; final_qtvs  <- liftZonkM $ mapMaybeM zonk_quant undefaulted
+       ; final_qtvs  <- liftZonkM $ mapMaybeM zonk_quant (undefaulted++cvs)
 
        ; traceTc "quantifyTyVars }"
            (vcat [ text "undefaulted:" <+> pprTyVars undefaulted



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/5a03c614f5813aad25d8885dde8b43a3939e5cd9

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/5a03c614f5813aad25d8885dde8b43a3939e5cd9
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/20250309/01d08e5b/attachment-0001.html>


More information about the ghc-commits mailing list