[Git][ghc/ghc][master] Fix :i Constraint printing "type Constraint = Constraint"

Marge Bot (@marge-bot) gitlab at gitlab.haskell.org
Tue Nov 15 03:21:38 UTC 2022



Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC


Commits:
65ce43cc by Krzysztof Gogolewski at 2022-11-14T22:21:05-05:00
Fix :i Constraint printing "type Constraint = Constraint"

Since Constraint became a synonym for CONSTRAINT 'LiftedRep,
we need the same code for handling printing as for the synonym
Type = TYPE 'LiftedRep.
This addresses the same bug as #18594, so I'm reusing the test.

- - - - -


4 changed files:

- compiler/GHC/Iface/Syntax.hs
- compiler/GHC/Iface/Type.hs
- testsuite/tests/ghci/should_run/T18594.script
- testsuite/tests/ghci/should_run/T18594.stdout


Changes:

=====================================
compiler/GHC/Iface/Syntax.hs
=====================================
@@ -44,7 +44,8 @@ module GHC.Iface.Syntax (
 
 import GHC.Prelude
 
-import GHC.Builtin.Names ( unrestrictedFunTyConKey, liftedTypeKindTyConKey )
+import GHC.Builtin.Names ( unrestrictedFunTyConKey, liftedTypeKindTyConKey,
+                           constraintKindTyConKey )
 import GHC.Types.Unique ( hasKey )
 import GHC.Iface.Type
 import GHC.Iface.Recomp.Binary
@@ -988,7 +989,8 @@ pprIfaceDecl ss (IfaceSynonym { ifName    = tc
 
     -- See Note [Printing type abbreviations] in GHC.Iface.Type
     ppr_tau | tc `hasKey` liftedTypeKindTyConKey ||
-              tc `hasKey` unrestrictedFunTyConKey
+              tc `hasKey` unrestrictedFunTyConKey ||
+              tc `hasKey` constraintKindTyConKey
             = updSDocContext (\ctx -> ctx { sdocPrintTypeAbbreviations = False }) $ ppr tau
             | otherwise = ppr tau
 


=====================================
compiler/GHC/Iface/Type.hs
=====================================
@@ -846,7 +846,7 @@ Note [Printing type abbreviations]
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 Normally, we pretty-print
    `TYPE       'LiftedRep` as `Type` (or `*`)
-   `CONSTRAINT 'LiftedRep` as `Constraint` (or `*`)
+   `CONSTRAINT 'LiftedRep` as `Constraint`
    `FUN 'Many`             as `(->)`.
 This way, error messages don't refer to representation polymorphism
 or linearity if it is not necessary.  Normally we'd would represent
@@ -856,14 +856,16 @@ command we specifically expand synonyms (see GHC.Tc.Module.tcRnExpr).
 So here in the pretty-printing we effectively collapse back Type
 and Constraint to their synonym forms.  A bit confusing!
 
-However, when printing the definition of Type or (->) with :info,
+However, when printing the definition of Type, Constraint or (->) with :info,
 this would give confusing output: `type (->) = (->)` (#18594).
 Solution: detect when we are in :info and disable displaying the synonym
 with the SDoc option sdocPrintTypeAbbreviations.
+If you are creating a similar synonym, make sure it is listed in pprIfaceDecl,
+see reference to this Note.
 
 If there will be a need, in the future we could expose it as a flag
--fprint-type-abbreviations or even two separate flags controlling
-TYPE 'LiftedRep and FUN 'Many.
+-fprint-type-abbreviations or even three separate flags controlling
+TYPE 'LiftedRep, CONSTRAINT 'LiftedRep and FUN 'Many.
 -}
 
 -- | Do we want to suppress kind annotations on binders?


=====================================
testsuite/tests/ghci/should_run/T18594.script
=====================================
@@ -1,5 +1,6 @@
 :m GHC.Types
 :i (->)
+:i Constraint
 :set -XStarIsType
 :i Type
 :set -XNoStarIsType


=====================================
testsuite/tests/ghci/should_run/T18594.stdout
=====================================
@@ -7,6 +7,9 @@ instance Semigroup b => Semigroup (a -> b) -- Defined in ‘GHC.Base’
 instance Applicative ((->) r) -- Defined in ‘GHC.Base’
 instance Functor ((->) r) -- Defined in ‘GHC.Base’
 instance Monad ((->) r) -- Defined in ‘GHC.Base’
+type Constraint :: *
+type Constraint = CONSTRAINT LiftedRep
+  	-- Defined in ‘GHC.Types’
 type Type :: *
 type Type = TYPE LiftedRep
   	-- Defined in ‘GHC.Types’



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/65ce43cc647109fb18c8703563cf25fc8cf103fc

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/65ce43cc647109fb18c8703563cf25fc8cf103fc
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/20221114/5dbf772d/attachment-0001.html>


More information about the ghc-commits mailing list