Krzysztof Gogolewski pushed to branch wip/T27727 at Glasgow Haskell Compiler / GHC Commits: bcb7d61a by Krzysztof Gogolewski at 2026-08-24T00:23:53+02:00 haddock: Fix overeager defaulting When defaulting RuntimeReps, we don't want to display forall (f :: forall r. TYPE r -> Type) . f Int# -> f Int# as forall (f :: Type -> Type) . f Int# -> f Int# because that's ill-kinded. This was already fixed in GHC in #16468, but Haddock has its own defaulting which needs a similar change. Fixes #27727. - - - - - 5 changed files: - compiler/GHC/Iface/Type.hs - utils/haddock/haddock-api/src/Haddock/GhcUtils.hs - utils/haddock/html-test/Main.hs - + utils/haddock/html-test/ref/T27727.html - + utils/haddock/html-test/src/T27727.hs Changes: ===================================== compiler/GHC/Iface/Type.hs ===================================== @@ -1258,6 +1258,8 @@ Wrinkles: 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'. + The same wrinkle applies to Haddock, which has its own copy of defaulting + in 'defaultRuntimeRepVars'. (W2) 'defaultIfaceTyVarsOfKind' ought to be called only once when printing a type. ===================================== utils/haddock/haddock-api/src/Haddock/GhcUtils.hs ===================================== @@ -843,37 +843,40 @@ orderedFVs ignore_tvs tys ------------------------------------------------------------------------------- --- | Traverses the type, defaulting type variables of kind 'RuntimeRep' to --- 'LiftedType'. See 'defaultRuntimeRepVars' in GHC.Iface.Type the original such +-- | Traverses the type, defaulting top-level type variables of kind 'RuntimeRep' to +-- 'LiftedType'. See 'defaultIfaceTyVarsOfKind' in GHC.Iface.Type the original such -- function working over `IfaceType`'s. defaultRuntimeRepVars :: Type -> Type -defaultRuntimeRepVars = go emptyVarEnv +defaultRuntimeRepVars = go True emptyVarEnv where - go :: TyVarEnv () -> Type -> Type - go subs (ForAllTy (Bndr var flg) ty) - | isRuntimeRepVar var + go :: Bool -> TyVarEnv () -> Type -> Type + -- See Wrinkle (W1) in Note [Defaulting RuntimeRep variables] in GHC.Iface.Type + -- for why we have the 'rank1' parameter. + go rank1 subs (ForAllTy (Bndr var flg) ty) + | rank1 + , isRuntimeRepVar var , isInvisibleForAllTyFlag flg = let subs' = extendVarEnv subs var () - in go subs' ty + in go rank1 subs' ty | otherwise = ForAllTy - (Bndr (updateTyVarKind (go subs) var) flg) - (go subs ty) - go subs (TyVarTy tv) + (Bndr (updateTyVarKind (go False subs) var) flg) + (go rank1 subs ty) + go _ subs (TyVarTy tv) | tv `elemVarEnv` subs = liftedRepTy | otherwise = - TyVarTy (updateTyVarKind (go subs) tv) - go subs (TyConApp tc tc_args) = - TyConApp tc (map (go subs) tc_args) - go subs (FunTy af w arg res) = - FunTy af (go subs w) (go subs arg) (go subs res) - go subs (AppTy t u) = - AppTy (go subs t) (go subs u) - go subs (CastTy x co) = - CastTy (go subs x) co - go _ ty@(LitTy{}) = ty - go _ ty@(CoercionTy{}) = ty + TyVarTy (updateTyVarKind (go False subs) tv) + go _ subs (TyConApp tc tc_args) = + TyConApp tc (map (go False subs) tc_args) + go rank1 subs (FunTy af w arg res) = + FunTy af (go False subs w) (go False subs arg) (go rank1 subs res) + go _ subs (AppTy t u) = + AppTy (go False subs t) (go False subs u) + go rank1 subs (CastTy x co) = + CastTy (go rank1 subs x) co + go _ _ ty@(LitTy{}) = ty + go _ _ ty@(CoercionTy{}) = ty fromMaybeContext :: Maybe (LHsContext DocNameI) -> HsContext DocNameI fromMaybeContext Nothing = HsContext noExtField [] ===================================== utils/haddock/html-test/Main.hs ===================================== @@ -53,8 +53,8 @@ stripIfRequired mdl = preserveLinksModules :: [String] preserveLinksModules = ["Bug253.html", "NamespacedIdentifiers.html"] -ingoredTests :: [String] -ingoredTests = +ignoredTests :: [String] +ignoredTests = [ -- Currently some declarations are exported twice -- we need a reliable way to deduplicate here. @@ -76,6 +76,6 @@ ignoredOneShotTests = ] checkIgnore :: FilePath -> Bool -checkIgnore file | takeBaseName file `elem` ingoredTests = True +checkIgnore file | takeBaseName file `elem` ignoredTests = True checkIgnore file@(c:_) | takeExtension file == ".html" && isUpper c = False checkIgnore _ = True ===================================== utils/haddock/html-test/ref/T27727.html ===================================== @@ -0,0 +1,84 @@ +<html xmlns="http://www.w3.org/1999/xhtml" +><head + ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" + /><meta name="viewport" content="width=device-width, initial-scale=1" + /><title + >T27727</title + ><link href="#" rel="stylesheet" type="text/css" title="Linuwial" + /><link rel="stylesheet" type="text/css" href="#" + /><link rel="stylesheet" type="text/css" href="#" + /><script src="haddock-bundle.min.js" async="async" type="text/javascript" + ></script + ><script type="text/x-mathjax-config" + >MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script + ><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-A..." type="text/javascript" + ></script + ></head + ><body + ><div id="package-header" + ><span class="caption empty" + > </span + ><ul class="links" id="page-menu" + ><li + ><a href="#" + >Contents</a + ></li + ><li + ><a href="#" + >Index</a + ></li + ></ul + ></div + ><div id="content" + ><div id="module-header" + ><table class="info" + ><tr + ><th + >Safe Haskell</th + ><td + >None</td + ></tr + ></table + ><p class="caption" + >T27727</p + ></div + ><div id="interface" + ><h1 + >Documentation</h1 + ><div class="top" + ><p class="src" + ><a id="v:demonstration" class="def" + >demonstration</a + > :: <span class="keyword" + >forall</span + > (f :: <span class="keyword" + >forall</span + > r. <a href="#" title="GHC.Exts" + >TYPE</a + > r -> <a href="#" title="Data.Kind" + >Type</a + >). f <a href="#" title="GHC.Exts" + >Int#</a + > -> f <a href="#" title="GHC.Exts" + >Int#</a + > <a href="#" class="selflink" + >#</a + ></p + ></div + ><div class="top" + ><p class="src" + ><a id="v:f" class="def" + >f</a + > :: (<span class="keyword" + >forall</span + > r. P r) -> P <a href="#" title="GHC.Exts" + >LiftedRep</a + > <a href="#" class="selflink" + >#</a + ></p + ></div + ></div + ></div + ></body + ></html +> ===================================== utils/haddock/html-test/src/T27727.hs ===================================== @@ -0,0 +1,16 @@ +{-# LANGUAGE MagicHash #-} +{-# LANGUAGE RankNTypes #-} +{-# LANGUAGE PolyKinds #-} + +module T27727 (demonstration, f) where + +import Data.Kind (Type) +import GHC.Exts (Int#, TYPE, RuntimeRep) + +demonstration :: forall (f :: forall r. TYPE r -> Type) . f Int# -> f Int# +demonstration x = x + +data P :: RuntimeRep -> Type + +f :: (forall r. P r) -> P s +f x = x View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/bcb7d61a4c3ec0fb738c23e54346b0ba... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/bcb7d61a4c3ec0fb738c23e54346b0ba... 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
participants (1)
-
Krzysztof Gogolewski (@monoidal)