Skip to content

Debug output fails to parenthesize prefix uses of symbolic names

Take this program:

{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE TypeOperators #-}
module Bug where

(+++) = (++)
pattern x :||: y = (x,y)
type (^^^) = Either
data (&&&)

If you compile it with -ddump-tc -ddump-simpl -dno-typeable-binds, you'll get the following debug output:

$ /opt/ghc/8.10.1/bin/ghc Bug.hs -ddump-tc -ddump-simpl -dno-typeable-binds
[1 of 1] Compiling Bug              ( Bug.hs, Bug.o )
TYPE SIGNATURES
  +++ :: forall a. [a] -> [a] -> [a]
TYPE CONSTRUCTORS
  data type &&&{0} :: *
  type synonym ^^^{0} :: * -> * -> *
PATTERN SYNONYMS
  :||: :: forall a b. a -> b -> (a, b)
Dependent modules: []
Dependent packages: [base-4.14.0.0, ghc-prim-0.6.1,
                     integer-gmp-1.0.3.0]

==================== Typechecker ====================
(:||:)
  = \ scrut_aig cont_aih fail_aii
      -> case scrut_aig of { (x_ahO, y_ahP) -> cont_aih x_ahO y_ahP }
(+++) = (++)
$b:||:_avU x_ahO y_ahP = (x_ahO, y_ahP)


==================== Tidy Core ====================
Result size of Tidy Core
  = {terms: 18, types: 53, coercions: 0, joins: 0/0}

-- RHS size: {terms: 1, types: 0, coercions: 0, joins: 0/0}
Bug.$b:||: :: forall a b. a -> b -> (a, b)
[GblId, Arity=2, Caf=NoCafRefs, Unf=OtherCon []]
Bug.$b:||: = GHC.Tuple.(,)

-- RHS size: {terms: 1, types: 0, coercions: 0, joins: 0/0}
+++ :: forall a. [a] -> [a] -> [a]
[GblId]
+++ = ++

-- RHS size: {terms: 13, types: 20, coercions: 0, joins: 0/0}
Bug.$m:||:
  :: forall (rep :: GHC.Types.RuntimeRep) (r :: TYPE rep) a b.
     (a, b) -> (a -> b -> r) -> (GHC.Prim.Void# -> r) -> r
[GblId, Arity=3, Caf=NoCafRefs, Unf=OtherCon []]
Bug.$m:||:
  = \ (@ (rep_aid :: GHC.Types.RuntimeRep))
      (@ (r_aie :: TYPE rep_aid))
      (@ a_ai9)
      (@ b_aia)
      (scrut_aig :: (a_ai9, b_aia))
      (cont_aih :: a_ai9 -> b_aia -> r_aie)
      _ [Occ=Dead] ->
      case scrut_aig of { (x_ahO, y_ahP) -> cont_aih x_ahO y_ahP }

This has several occurrences of symbolic names not being parenthesized when they should be:

  +++ :: forall a. [a] -> [a] -> [a]
  data type &&&{0} :: *
  type synonym ^^^{0} :: * -> * -> *
  :||: :: forall a b. a -> b -> (a, b)

...

+++ :: forall a. [a] -> [a] -> [a]
[GblId]
+++ = ++

Patch incoming.

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information