[GHC] #13311: Audit shady uses of tcSplitSigmaTy

GHC ghc-devs at haskell.org
Sun Feb 26 00:21:59 UTC 2017


#13311: Audit shady uses of tcSplitSigmaTy
-------------------------------------+-------------------------------------
        Reporter:  RyanGlScott       |                Owner:  RyanGlScott
            Type:  task              |               Status:  new
        Priority:  normal            |            Milestone:  8.4.1
       Component:  Compiler (Type    |              Version:  8.1
  checker)                           |
      Resolution:                    |             Keywords:
Operating System:  Unknown/Multiple  |         Architecture:
                                     |  Unknown/Multiple
 Type of failure:  None/Unknown      |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:                    |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by RyanGlScott):

 After a quick audit, I found two `tcSplitSigmaTy`-related bugs:

 *
 http://git.haskell.org/ghc.git/blob/8f20844d3435094583db92a30550ca319d2be863:/compiler/hsSyn/HsUtils.hs#l843

   When you type this into GHCi:

   {{{
   λ> let a :: forall a b. (Num a, Num b) => (# a, b #); !a = (# 1, 2 #)
   }}}

   you get this error:

   {{{
   You can't mix polymorphic and unlifted bindings
     !a = (# 1, 2 #)
     Probable fix: add a type signature
   }}}

   But if you type this instead:

   {{{
   λ> let a :: forall a . (Num a) => forall b. (Num b) => (# a, b #); !a =
 (# 1, 2 #)
   }}}

   then GHCi panics!

   {{{
   ghc: panic! (the 'impossible' happened)
     (GHC version 8.0.2 for x86_64-unknown-linux):
           dsLet: unlifted
     !a_a1Py = (# 1, 2 #)
     returnIO
       @ [()]
       (: @ ()
          (unsafeCoerce#
             @ 'PtrRepLifted
             @ 'PtrRepLifted
             @ (forall a_a1P7.
                Num a_a1P7 =>
                forall b_a1P8. Num b_a1P8 => (# a_a1P7, b_a1P8 #))
             @ ()
             a_a1P6)
          ([] @ ()))
   }}}

 *
 http://git.haskell.org/ghc.git/blob/8f20844d3435094583db92a30550ca319d2be863:/compiler/typecheck/TcExpr.hs#l2403

   Compare this error message:

   {{{
   λ> let f :: forall a b. (Monoid a, Monoid b) => Maybe a -> Maybe b; f _
 = mempty
   λ> do { f; putChar 'a' }

   <interactive>:30:6: error:
       • Couldn't match expected type ‘IO a1’
                     with actual type ‘Maybe a0 -> Maybe b0’
       • Probable cause: ‘f’ is applied to too few arguments
         In a stmt of a 'do' block: f
         In the expression:
           do { f;
                putChar 'a' }
         In an equation for ‘it’:
             it
               = do { f;
                      putChar 'a' }
   }}}

   with this one:

   {{{
   λ> let f :: forall a. (Monoid a) => forall b. (Monoid b) => Maybe a ->
 Maybe b; f _ = mempty
   λ> do { f; putChar 'a' }

   <interactive>:32:6: error:
       • Couldn't match expected type ‘IO a1’
                     with actual type ‘Maybe a0 -> Maybe b0’
       • In a stmt of a 'do' block: f
         In the expression:
           do { f;
                putChar 'a' }
         In an equation for ‘it’:
             it
               = do { f;
                      putChar 'a' }
   }}}

   The second one doesn't complain about `f` being applied to too few
 arguments!

 This is by no means an exhaustive list, as I only examine the parts of the
 codebase that I could make sense of.

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13311#comment:3>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list