diff options
author | Krzysztof Gogolewski <krzysztof.gogolewski@tweag.io> | 2022-11-14 16:43:47 +0100 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2022-11-14 22:21:05 -0500 |
commit | 65ce43cc647109fb18c8703563cf25fc8cf103fc (patch) | |
tree | 174b8c3c9624da6c22577560a9d4589cfca38f9b | |
parent | 78f7ecb053340388236300e7e8d458a1a5a42344 (diff) | |
download | haskell-65ce43cc647109fb18c8703563cf25fc8cf103fc.tar.gz |
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.
-rw-r--r-- | compiler/GHC/Iface/Syntax.hs | 6 | ||||
-rw-r--r-- | compiler/GHC/Iface/Type.hs | 10 | ||||
-rw-r--r-- | testsuite/tests/ghci/should_run/T18594.script | 1 | ||||
-rw-r--r-- | testsuite/tests/ghci/should_run/T18594.stdout | 3 |
4 files changed, 14 insertions, 6 deletions
diff --git a/compiler/GHC/Iface/Syntax.hs b/compiler/GHC/Iface/Syntax.hs index 2e7a39bc97..a633f59fbc 100644 --- a/compiler/GHC/Iface/Syntax.hs +++ b/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 diff --git a/compiler/GHC/Iface/Type.hs b/compiler/GHC/Iface/Type.hs index a7bdf04a4b..04b34849f8 100644 --- a/compiler/GHC/Iface/Type.hs +++ b/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? diff --git a/testsuite/tests/ghci/should_run/T18594.script b/testsuite/tests/ghci/should_run/T18594.script index 815275914c..4589dcdec8 100644 --- a/testsuite/tests/ghci/should_run/T18594.script +++ b/testsuite/tests/ghci/should_run/T18594.script @@ -1,5 +1,6 @@ :m GHC.Types :i (->) +:i Constraint :set -XStarIsType :i Type :set -XNoStarIsType diff --git a/testsuite/tests/ghci/should_run/T18594.stdout b/testsuite/tests/ghci/should_run/T18594.stdout index 1c6c93ad7a..216186a632 100644 --- a/testsuite/tests/ghci/should_run/T18594.stdout +++ b/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’ |