GHC: Ticket #2846: Impredicativity bug: GHC crash by type signature
http://ghc.haskell.org/trac/ghc/ticket/2846
<p>
Quick and dirty, this is the bug:
</p>
<pre class="wiki">Prelude> [1,2,3] :: [Num a => a]
ghc: panic! (the 'impossible' happened)
(GHC version 6.10.1 for i386-unknown-linux):
TcTyFuns.flattenType: unexpected PredType
</pre><p>
I'm running Gentoo Linux. I can reproduce this bug in the interpreter as well as in the compiler. It seems like it happens only with <tt>-fglasgow-exts</tt>, and only if you use <tt>show</tt> on that specific list. It doesn't happen, if you only use the head or the tail of the list. There is also no problem with appending something using <tt>(++)</tt> or consing through <tt>(:)</tt>.
</p>
<p>
This is an amd64 architecture, but I'm using a 32 bits system, so this should be irrelevant.
</p>
en-usGHChttp://ghc.haskell.org/trac/ghc/chrome/site/ghc_logo.png
http://ghc.haskell.org/trac/ghc/ticket/2846
Trac 1.0.7iglooSun, 07 Dec 2008 00:48:48 GMTos, architecture changed; difficulty, milestone set
http://ghc.haskell.org/trac/ghc/ticket/2846#comment:1
http://ghc.haskell.org/trac/ghc/ticket/2846#comment:1
<ul>
<li><strong>difficulty</strong>
set to <em>Unknown</em>
</li>
<li><strong>os</strong>
changed from <em>Linux</em> to <em>Unknown/Multiple</em>
</li>
<li><strong>architecture</strong>
changed from <em>x86_64 (amd64)</em> to <em>Unknown/Multiple</em>
</li>
<li><strong>milestone</strong>
set to <em>6.10.2</em>
</li>
</ul>
<p>
Thanks for the report.
</p>
TicketsimonpjWed, 31 Dec 2008 14:16:39 GMTsummary, milestone changed
http://ghc.haskell.org/trac/ghc/ticket/2846#comment:2
http://ghc.haskell.org/trac/ghc/ticket/2846#comment:2
<ul>
<li><strong>summary</strong>
changed from <em>GHC crash by type signature</em> to <em>Impredicativity bug: GHC crash by type signature</em>
</li>
<li><strong>milestone</strong>
changed from <em>6.10.2</em> to <em>6.12 branch</em>
</li>
</ul>
<p>
What's happening here is that <tt>-fglasgow-exts</tt> implies <tt>-XImpredicativeTypes</tt> and <tt>-XFlexibleContexts</tt>. Then we get a constraint <tt>(Show [Num a => a])</tt>, which should never happen. The impredicative machinery should not allow polymorphism in class constraints, but that check isn't implemented.
</p>
<p>
The impredicative stuff needs a proper overhaul (Dimitrios is working on it) so I do not propose to tweak it now. But this should be fixed in due course.
</p>
<p>
Meanwhile, I propose to <strong>stop</strong> <tt>-fglasgow-exts</tt> from implying <tt>-XImpredicativeTypes</tt>. I don't want to encourage use of impredicativity until it's working properly.
</p>
<p>
Simon
</p>
TicketnccbSun, 15 Mar 2009 00:45:01 GMT
http://ghc.haskell.org/trac/ghc/ticket/2846#comment:3
http://ghc.haskell.org/trac/ghc/ticket/2846#comment:3
<p>
Just to add another example, I believe this is the same bug:
</p>
<pre class="wiki">forFD :: (forall a. Floating a => a -> IO ()) -> [forall a. Floating a => a] -> IO ()
forFD f xs = mapM_ f xsf >> mapM_ f xsd
where
xsf :: [Float]
xsf = [x | x <- xs]
xsd :: [Double]
xsd = [x | x <- xs]
forIFD :: (forall a. Num a => a -> IO ()) -> [forall a. Num a => a] -> IO ()
forIFD f xs = mapM_ f xsi >> forFD f xs'
where
xsi :: [Int]
xsi = [x | x <- xs]
xs' :: [Floating a => a]
xs' = [x | x <- xs]
</pre><p>
Then "ghc -XRank2Types -XImpredicativeTypes -XFlexibleContexts tmp.hs" gives:
</p>
<pre class="wiki">ghc: panic! (the 'impossible' happened)
(GHC version 6.10.1 for x86_64-unknown-linux):
TcTyFuns.flattenType: unexpected PredType
</pre><p>
Adding "forall a." to the type of the list xs' fixes the bug (even if the code cannot type-check in its current form) but I thought I'd post it here in case it helps.
</p>
TicketsimonpjMon, 16 Mar 2009 15:24:41 GMT
http://ghc.haskell.org/trac/ghc/ticket/2846#comment:4
http://ghc.haskell.org/trac/ghc/ticket/2846#comment:4
<p>
Thanks. FWIW, we did not remove <tt>-XImpredicativeTypes</tt> from <tt>-fglasgow-exts</tt> in 6.10.2, because that's an interface change. But it's gone from <tt>-fglasgow-exts</tt> in the HEAD.
</p>
<p>
Cleaning the impredicative stables is still in the pipeline for 6.12.
</p>
<p>
Simon
</p>
TicketiglooFri, 30 Apr 2010 16:40:36 GMTmilestone changed
http://ghc.haskell.org/trac/ghc/ticket/2846#comment:5
http://ghc.haskell.org/trac/ghc/ticket/2846#comment:5
<ul>
<li><strong>milestone</strong>
changed from <em>6.12 branch</em> to <em>6.12.3</em>
</li>
</ul>
TicketiglooSat, 19 Jun 2010 16:58:25 GMTpriority, milestone changed
http://ghc.haskell.org/trac/ghc/ticket/2846#comment:6
http://ghc.haskell.org/trac/ghc/ticket/2846#comment:6
<ul>
<li><strong>priority</strong>
changed from <em>normal</em> to <em>low</em>
</li>
<li><strong>milestone</strong>
changed from <em>6.12.3</em> to <em>6.14.1</em>
</li>
</ul>
TicketmichaltFri, 29 Oct 2010 17:58:04 GMTcc, failure set
http://ghc.haskell.org/trac/ghc/ticket/2846#comment:7
http://ghc.haskell.org/trac/ghc/ticket/2846#comment:7
<ul>
<li><strong>cc</strong>
<em>michal.terepeta@…</em> added
</li>
<li><strong>failure</strong>
set to <em>None/Unknown</em>
</li>
</ul>
<p>
Seems to be fixed:
</p>
<pre class="wiki">Prelude> [1,2,3] :: [Num a => a]
<interactive>:1:1:
No instance for (Show (Num a => a))
arising from a use of `print'
Possible fix: add an instance declaration for (Show (Num a => a))
In a stmt of an interactive GHCi command: print it
</pre><p>
This is from ghc 7.1.20101028, but I'm getting pretty much the same error with 6.12.3.
</p>
TicketiglooFri, 29 Oct 2010 19:08:21 GMTtestcase, owner set
http://ghc.haskell.org/trac/ghc/ticket/2846#comment:8
http://ghc.haskell.org/trac/ghc/ticket/2846#comment:8
<ul>
<li><strong>testcase</strong>
set to <em>T2846, T2846b</em>
</li>
<li><strong>owner</strong>
set to <em>simonpj</em>
</li>
</ul>
<p>
Thanks, I've added a test.
</p>
<p>
Simon, is the current behaviour OK - i.e. can we close this ticket?
</p>
TicketsimonpjMon, 01 Nov 2010 08:16:37 GMTstatus changed; resolution set
http://ghc.haskell.org/trac/ghc/ticket/2846#comment:9
http://ghc.haskell.org/trac/ghc/ticket/2846#comment:9
<ul>
<li><strong>status</strong>
changed from <em>new</em> to <em>closed</em>
</li>
<li><strong>resolution</strong>
set to <em>fixed</em>
</li>
</ul>
<p>
Yes, that's fine. The error message Michal gives is with <tt>-XImpredicativeTypes</tt>. Without we get
</p>
<pre class="wiki">T2846.hs:4:5:
Illegal polymorphic or qualified type: Num a => a
Perhaps you intended to use -XImpredicativeTypes
In an expression type signature: [Num a => a]
In the expression: [1, 2, 3] :: [Num a => a]
In an equation for `x': x = [1, 2, 3] :: [Num a => a]
</pre>
Ticket