[Git][ghc/ghc][master] 2 commits: Update equality-type documenation in GHC.Builtin.Types.Prim
Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC
Commits:
d910b353 by Simon Peyton Jones at 2026-07-08T04:48:36-04:00
Update equality-type documenation in GHC.Builtin.Types.Prim
Fix #27466
- - - - -
b2530542 by Simon Peyton Jones at 2026-07-08T04:48:36-04:00
Honour -dsuppress-coercions in GHC.Core.TyCo.pprCo
Fixes #27467
- - - - -
11 changed files:
- compiler/GHC/Builtin/Types/Prim.hs
- compiler/GHC/Core/Ppr.hs
- compiler/GHC/Core/TyCo/Ppr.hs
- compiler/GHC/Core/TyCo/Rep.hs
- testsuite/tests/codeGen/should_compile/T25177.stderr
- testsuite/tests/numeric/should_compile/T15547.stderr
- testsuite/tests/simplCore/should_compile/DataToTagFamilyScrut.stderr
- testsuite/tests/simplCore/should_compile/T14978.stdout
- testsuite/tests/simplCore/should_compile/T18013.stderr
- testsuite/tests/simplCore/should_compile/T24229a.stderr
- testsuite/tests/simplCore/should_compile/T24229b.stderr
Changes:
=====================================
compiler/GHC/Builtin/Types/Prim.hs
=====================================
@@ -1002,26 +1002,29 @@ doublePrimTyCon = pcPrimTyCon0 doublePrimTyConName doubleRepDataConTy
Note [The equality types story]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-GHC sports a veritable menagerie of equality types:
-
- Type or Lifted? Hetero? Role Built in Defining module
- class? L/U TyCon
------------------------------------------------------------------------------------------
-~# T U hetero nominal eqPrimTyCon GHC.Prim
-~~ C L hetero nominal heqTyCon GHC.Types
-~ C L homo nominal eqTyCon GHC.Types
-:~: T L homo nominal (not built-in) Data.Type.Equality
-:~~: T L hetero nominal (not built-in) Data.Type.Equality
-
-~R# T U hetero repr eqReprPrimTy GHC.Prim
-Coercible C L homo repr coercibleTyCon GHC.Types
-Coercion T L homo repr (not built-in) Data.Type.Coercion
-~P# T U hetero phantom eqPhantPrimTyCon GHC.Prim
+GHC sports a veritable menagerie of equality types.
+
+ Result kind Hetero? Role Built in Defining module
+---------------------------------------------------------------------------------
+~# Constraint# hetero nominal eqPrimTyCon GHC.Prim
+~~ Constraint hetero nominal heqTyCon GHC.Types
+~ Constraint homo nominal eqTyCon GHC.Types
+:~: Type homo nominal (not built-in) Data.Type.Equality
+:~~: Type hetero nominal (not built-in) Data.Type.Equality
+
+~R# Constraint# hetero repr eqReprPrimTy GHC.Prim
+Coercible Constraint homo repr coercibleTyCon GHC.Types
+Coercion Type homo repr (not built-in) Data.Type.Coercion
+~P# Constraint# hetero phantom eqPhantPrimTyCon GHC.Prim
+
+Here `Constraint#` means `CONSTRAINT (TupleRep [])`, a constraint kind that is
+represented by a zero-width tuple.
Recall that "hetero" means the equality can related types of different
kinds. Knowing that (t1 ~# t2) or (t1 ~R# t2) or even that (t1 ~P# t2)
also means that (k1 ~# k2), where (t1 :: k1) and (t2 :: k2).
+
To produce less confusion for end users, when not dumping and without
-fprint-equality-relations, each of these groups is printed as the bottommost
listed equality. That is, (~#) and (~~) are both rendered as (~) in
@@ -1030,7 +1033,7 @@ error messages, and (~R#) is rendered as Coercible.
Let's take these one at a time:
--------------------------
- (~#) :: forall k1 k2. k1 -> k2 -> TYPE (TupleRep '[])
+ (~#) :: forall k1 k2. k1 -> k2 -> CONSTRAINT (TupleRep '[])
--------------------------
This is The Type Of Equality in GHC. It classifies nominal coercions.
This type is used in the solver for recording equality constraints.
@@ -1054,8 +1057,6 @@ This is (almost) an ordinary class, defined as if by
Here's what's unusual about it:
* We can't actually declare it that way because we don't have syntax for ~#.
- And ~# isn't a constraint, so even if we could write it, it wouldn't kind
- check.
* Users cannot write instances of it.
@@ -1112,7 +1113,7 @@ They are not defined within GHC at all.
--------------------------
- (~R#) :: forall k1 k2. k1 -> k2 -> TYPE (TupleRep '[])
+ (~R#) :: forall k1 k2. k1 -> k2 -> CONSTRAINT (TupleRep '[])
--------------------------
The is the representational analogue of ~#. This is the type of representational
equalities that the solver works on. All wanted constraints of this type are
@@ -1147,7 +1148,7 @@ within GHC at all.
--------------------------
- (~P#) :: forall k1 k2. k1 -> k2 -> TYPE (TupleRep '[])
+ (~P#) :: forall k1 k2. k1 -> k2 -> CONSTRAINT (TupleRep '[])
--------------------------
This is the phantom analogue of ~# and it is barely used at all.
(The solver has no idea about this one.) Here is the motivation:
=====================================
compiler/GHC/Core/Ppr.hs
=====================================
@@ -292,14 +292,14 @@ noParens :: SDoc -> SDoc
noParens pp = pp
pprOptCo :: Coercion -> SDoc
--- Print a coercion optionally; i.e. honouring -dsuppress-coercions
-pprOptCo co = sdocOption sdocSuppressCoercions $ \case
- True -> angleBrackets (text "Co:" <> int (coercionSize co)) <+> dcolon <+> co_type
- False -> parens $ sep [ppr co, dcolon <+> co_type]
- where
- co_type = sdocOption sdocSuppressCoercionTypes $ \case
- True -> ellipsis
- False -> ppr (coercionType co)
+-- Print a coercion with its type (unless suppressed by -dsuppress-coercion-types)
+-- Honour -dsuppress-coercions
+-- Placed here because it needs GHC.Core.Coercion.coercionType
+pprOptCo co = sdocOption sdocSuppressCoercionTypes $ \case
+ True -> pprParendCo co
+ False -> parens (sep [pprCo co, dcolon <+> pp_co_type])
+ where
+ pp_co_type = ppr (coercionType co)
ppr_id_occ :: (SDoc -> SDoc) -> Id -> SDoc
ppr_id_occ add_par id
=====================================
compiler/GHC/Core/TyCo/Ppr.hs
=====================================
@@ -132,8 +132,14 @@ tidyToIfaceTypeX env ty = toIfaceTypeX (mkVarSet free_tcvs) (tidyType env' ty)
------------
pprCo, pprParendCo :: Coercion -> SDoc
-pprCo co = getPprStyle $ \ sty -> pprIfaceCoercion (tidyToIfaceCoSty co sty)
-pprParendCo co = getPprStyle $ \ sty -> pprParendIfaceCoercion (tidyToIfaceCoSty co sty)
+-- Print a coercion without its type
+-- Honour -dsuppress-coercions
+pprCo co = sdocOption sdocSuppressCoercions $ \case
+ True -> angleBrackets (text "Co:" <> int (coercionSize co))
+ False -> getPprStyle $ \ sty -> pprIfaceCoercion (tidyToIfaceCoSty co sty)
+pprParendCo co = sdocOption sdocSuppressCoercions $ \case
+ True -> angleBrackets (text "Co:" <> int (coercionSize co))
+ False -> getPprStyle $ \ sty -> pprParendIfaceCoercion (tidyToIfaceCoSty co sty)
tidyToIfaceCoSty :: Coercion -> PprStyle -> IfaceCoercion
tidyToIfaceCoSty co sty
=====================================
compiler/GHC/Core/TyCo/Rep.hs
=====================================
@@ -1640,7 +1640,7 @@ Here,
co3 = UnivCo ProofIrrelProv Nominal (CoercionTy co1) (CoercionTy co2) [co5]
where
co5 :: (a1 ~# Bool) ~# (a2 ~# Bool)
- co5 = TyConAppCo Nominal (~#) [
participants (1)
-
Marge Bot (@marge-bot)