[Git][ghc/ghc][master] Documentation only
Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC Commits: 246d4d72 by Simon Peyton Jones at 2026-08-06T15:52:25-04:00 Documentation only ...driven by my investigation of #27591 - - - - - 3 changed files: - compiler/GHC/Core/Class.hs - compiler/GHC/Rename/HsType.hs - compiler/GHC/Types/Id/Make.hs Changes: ===================================== compiler/GHC/Core/Class.hs ===================================== @@ -84,9 +84,9 @@ data Class -- Here fun-deps are [([a,b],[c]), ([a,c],[b])] type FunDep a = ([a],[a]) -type ClassOpItem = (Id, DefMethInfo) - -- Selector function; contains unfolding - -- Default-method info +type ClassOpItem = ( Id -- Dictionary selector function + -- See Note [Dictionary selectors] + , DefMethInfo) -- Default-method info type DefMethInfo = Maybe (Name, DefMethSpec Type) -- Nothing No default method @@ -164,7 +164,19 @@ classMinimalDef :: Class -> ClassMinimalDef classMinimalDef Class{ classBody = ConcreteClass{ cls_min_def = d } } = d classMinimalDef _ = mkTrue -- TODO: make sure this is the right direction -{- +{- Note [Dictionary selectors] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Each `ClassOpItem` stores a dictionary selector `Id`: + +* The type of the selector is always closed, and has form + forall a1..an. C a1 .. an => blah + where `a1..an` are the class variables, and + `blah` is the method type. + See GHC.Types.Id.Make.mkDictSelId, which constructs them. + +* The selector has no unfolding, but one RULE. + See Note [ClassOp/DFun selection] in GHC.Tc.TyCl.Instance + Note [Associated type defaults] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The following is an example of associated type defaults: ===================================== compiler/GHC/Rename/HsType.hs ===================================== @@ -1188,10 +1188,20 @@ bindHsOuterTyVarBndrs :: OutputableBndrFlag flag 'Renamed -> RnM (a, FreeNames) bindHsOuterTyVarBndrs doc mb_cls implicit_vars outer_bndrs thing_inside = case outer_bndrs of + HsOuterImplicit{} -> + -- Add an implicit `forall a1..an` at the top, where `a1..an` + -- are not-otherwise-in-scope type variables. + -- Used when there is no forall, or a /visible/ (forall a -> blah) + -- See Note [forall-or-nothing rule] in Language.Haskell.Syntax.Type rnImplicitTvOccs mb_cls implicit_vars $ \implicit_vars' -> thing_inside $ HsOuterImplicit { hso_ximplicit = implicit_vars' } + HsOuterExplicit{hso_bndrs = exp_bndrs} -> + -- The type already has an explicit, user-written, invisible forall, + -- so do not add an implicit forall + -- See Note [forall-or-nothing rule] in Language.Haskell.Syntax.Type + -- -- Note: If we pass mb_cls instead of Nothing below, bindLHsTyVarBndrs -- will use class variables for any names the user meant to bring in -- scope here. This is an explicit forall, so we want fresh names, not ===================================== compiler/GHC/Types/Id/Make.hs ===================================== @@ -480,7 +480,7 @@ Therefore there is no loss of generality if we make all selectors unrestricted. mkDictSelId :: Name -- Name of one of the *value* selectors -- (dictionary superclass or method) -> Class -> Id --- Important: see Note [ClassOp/DFun selection] in GHC.Tc.TyCl.Instance +-- See Note [Dictionary selectors] mkDictSelId name clas = mkGlobalId (ClassOpId clas terminating) name sel_ty info where View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/246d4d72c05111928ae3a8ef42c12d18... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/246d4d72c05111928ae3a8ef42c12d18... 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)
-
Marge Bot (@marge-bot)