Opened 3 years ago

Closed 2 years ago

Last modified 2 years ago

#10403 closed bug (fixed)

GHC crashes on a partial type signature

Reported by: Artyom.Kazak Owned by:
Priority: normal Milestone:
Component: Compiler Version: 7.10.1
Keywords: Cc: vlad.z.4096@…
Operating System: Linux Architecture: x86_64 (amd64)
Type of failure: Compile-time crash Test Case: partial-sigs/should_compile/T10403
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description (last modified by Artyom.Kazak)

The following code crashes GHC 7.10.1 as is, but doesn't result in a crash if the signature is specified completely or isn't specified at all (inferred):

{-# LANGUAGE PartialTypeSignatures #-}
module Main where

main :: IO ()
main = return ()

data I a = I a
instance Functor I where
    fmap f (I a) = I (f a)
 
newtype B t a = B a
instance Functor (B t) where
    fmap f (B a) = B (f a)
 
newtype H f = H (f ())
 
app :: H (B t)
app = h (H . I) (B ())
 
h :: _
--h :: Functor m => (a -> b) -> m a -> H m
h f b = (H . fmap (const ())) (fmap f b)

Change History (18)

comment:1 Changed 3 years ago by Artyom.Kazak

Cc: vlad.z.4096@… added

comment:2 Changed 3 years ago by Artyom.Kazak

Description: modified (diff)

comment:3 Changed 3 years ago by lelf

Seems to work correctly for HEAD-20150403

comment:4 Changed 3 years ago by Artyom.Kazak

Error message (in GHCi 7.10.1):

$ ghci
GHCi, version 7.10.1: http://www.haskell.org/ghc/  :? for help
Prelude Control.Applicative Control.Monad Data.Ratio> :l Bug.hs 
[1 of 1] Compiling Main             ( Bug.hs, interpreted )

Bug.hs:18:10:
    Couldn't match type `b' with `H I'
      `b' is untouchable
        inside the constraints ()
        bound by the type signature for app :: H (B t)
        at Bug.hs:17:8-14ghc: panic! (the 'impossible' happened)
  (GHC version 7.10.1 for x86_64-unknown-linux):
    No skolem info: b_aFd[sk]

Please report this as a GHC bug:  http://www.haskell.org/ghc/reportabug

comment:5 Changed 3 years ago by Artyom.Kazak

Possibly (most likely?) a duplicate of #10045. Could someone knowledgeable confirm this?

Last edited 3 years ago by Artyom.Kazak (previous) (diff)

comment:6 Changed 3 years ago by Simon Peyton Jones <simonpj@…>

comment:7 Changed 3 years ago by simonpj

Resolution: fixed
Status: newclosed

Seems ok in 7.10 too.

comment:8 Changed 3 years ago by Austin Seipp <austin@…>

In 3cf8ecdc70cb295a2b9606080a1c7b5fa8eb16f4/ghc:

Revert multiple commits

This reverts multiple commits from Simon:

  - 04a484eafc9eb9f8774b4bdd41a5dc6c9f640daf Test Trac #10359
  - a9ccd37add8315e061c02e5bf26c08f05fad9ac9 Test Trac #10403
  - c0aae6f699cbd222d826d0b8d78d6cb3f682079e Test Trac #10248
  - eb6ca851f553262efe0824b8dcbe64952de4963d Make the "matchable-given" check happen first
  - ca173aa30467a0b1023682d573fcd94244d85c50 Add a case to checkValidTyCon
  - 51cbad15f86fca1d1b0e777199eb1079a1b64d74 Update haddock submodule
  - 6e1174da5b8e0b296f5bfc8b39904300d04eb5b7 Separate transCloVarSet from fixVarSet
  - a8493e03b89f3b3bfcdb6005795de050501f5c29 Fix imports in HscMain (stage2)
  - a154944bf07b2e13175519bafebd5a03926bf105 Two wibbles to fix the build
  - 5910a1bc8142b4e56a19abea104263d7bb5c5d3f Change in capitalisation of error msg
  - 130e93aab220bdf14d08028771f83df210da340b Refactor tuple constraints
  - 8da785d59f5989b9a9df06386d5bd13f65435bc0 Delete commented-out line

These break the build by causing Haddock to fail mysteriously when
trying to examine GHC.Prim it seems.

comment:9 Changed 3 years ago by Artyom.Kazak

Resolution: fixed
Status: closednew

Can the testcase in Simon's Test Trac #10403 commit be changed to how it should be? h :: _ => _ doesn't trigger the bug, only h :: _ does (and I don't know why Simon changed it).

comment:10 Changed 3 years ago by Simon Peyton Jones <simonpj@…>

comment:11 Changed 2 years ago by Simon Peyton Jones <simonpj@…>

In c45f8ceb0de0f83d374909f4cb8dd411154e2bce/ghc:

Elaborate test for Trac #10403

comment:12 Changed 2 years ago by simonpj

Resolution: fixed
Status: newclosed
Test Case: partial-sigs/should_compile/T10403

I've elaborate the test to check both h :: _ and h :: _ => _.

comment:13 Changed 2 years ago by int-index

Resolution: fixed
Status: closednew

comment:14 Changed 2 years ago by int-index

Simon, could you please add the code from the ticket to the test suite verbatim? Your new variation does not trigger the bug because you removed the app function.

Since you want to test both h1 :: _ and h2 :: _ => _, please do not forget to include add1 and add2 so they get called. Here's code that triggers the bug:

{-# LANGUAGE PartialTypeSignatures #-}
module T10403 where

main :: IO ()
main = return ()

data I a = I a
instance Functor I where
    fmap f (I a) = I (f a)
 
newtype B t a = B a
instance Functor (B t) where
    fmap f (B a) = B (f a)
 
newtype H f = H (f ())
 
app1 :: H (B t)
app1 = h1 (H . I) (B ())

app2 :: H (B t)
app2 = h2 (H . I) (B ())
 
h1 :: _ => _
--h1 :: Functor m => (a -> b) -> m a -> H m
h1 f b = (H . fmap (const ())) (fmap f b)

h2 :: _
--h2 :: Functor m => (a -> b) -> m a -> H m
h2 f b = (H . fmap (const ())) (fmap f b)

The error message I'm getting when loading it in GHCi is:

GHCi, version 7.10.1: http://www.haskell.org/ghc/  :? for help
λ> :l Bug.hs
[1 of 1] Compiling T10403           ( Bug.hs, interpreted )

Bug.hs:21:12:
    Couldn't match type ‘b’ with ‘H I’
      ‘b’ is untouchable
        inside the constraints ()
        bound by the type signature for app2 :: H (B t)
        at Bug.hs:20:9-15ghc: panic! (the 'impossible' happened)
  (GHC version 7.10.1 for x86_64-unknown-linux):
	No skolem info: b_ao6[sk]

Please report this as a GHC bug:  http://www.haskell.org/ghc/reportabug
Last edited 2 years ago by int-index (previous) (diff)

comment:15 Changed 2 years ago by Simon Peyton Jones <simonpj@…>

In 55843f1c43ec3721a924cbbe5d422798819030c1/ghc:

Further elaborate Trac #10403 test

Adding app1, app2, as requested in the ticket

comment:16 Changed 2 years ago by simonpj

OK, I've elaborated the test with the extra pieces you suggest.

It all works fine in HEAD.

It does not work in 7.10; and, as you'll see in #10045, we don't propose to fix in 7.10. I hope you can live without it.

Sound OK?

Simon

comment:17 Changed 2 years ago by simonpj

Resolution: fixed
Status: newclosed

comment:18 Changed 2 years ago by int-index

Yes, it sounds ok. I just wanted to make sure that the bug is known of and reflected in the test suite. Thanks.

Note: See TracTickets for help on using tickets.