[GHC] #14299: GHCi for GHC 8.2.1 crashed with simple function?
GHC
ghc-devs at haskell.org
Sat Sep 30 15:19:40 UTC 2017
#14299: GHCi for GHC 8.2.1 crashed with simple function?
-------------------------------+--------------------------------------
Reporter: mathiassm | Owner: (none)
Type: bug | Status: new
Priority: normal | Milestone:
Component: GHCi | Version: 8.2.1
Resolution: | Keywords:
Operating System: MacOS X | Architecture: x86_64 (amd64)
Type of failure: GHCi crash | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s):
Wiki Page: |
-------------------------------+--------------------------------------
Comment (by bgamari):
Wow, what a disaster. Thanks for reporting this.
There are a few issues intertwined here. Let's cover them in turn.
== Problem 1: Unexpected binding shadowing
The first problem here is a bit subtle and has to do with the fact that
GHCi accepts two different types of syntax for defining bindings. You can
say,
{{{#!hs
let f n = n * f (n-1)
}}}
or you can use
{{{#!hs
f n = n * f (n-1)
}}}
In your case you used both; GHCi interpreted this as two distinct
bindings, one shadowing the other. That is to say, first you defined `f 0
= 0`, then you "overwrote" `f` with, `f n = n * f (n-1)`. When you end up
with is a factorial function that doesn't define its base case and
consequently will never terminate. When I do this on my machine I get the
error,
{{{
$ ghci
GHCi, version 8.2.1: http://www.haskell.org/ghc/ :? for help
Prelude> let f 0 = 0
Prelude> f n = n * f (n-1)
Prelude> f 0
Stopped in <exception thrown>, <unknown>
_exception :: e = _
[<unknown>] λ> :force _exception
_exception = GHC.Exception.SomeException
(GHC.IO.Exception.SomeAsyncException
GHC.IO.Exception.StackOverflow)
}}}
That is, a `StackOverflow` exception.
In contrast, if I defining these two bindings in one GHCi command, I get
the expected behavior (modulo the incorrect definition of factorial),
{{{
Prelude> f 0 = 0; f n = n * f (n-1)
Prelude> f 0
0
Prelude> f 2
0
}}}
or, using the `let` syntax,
{{{
Prelude> :{
Prelude| let f 0 = 0
Prelude| f n = n * f (n-1)
Prelude| :}
Prelude> f 0
0
Prelude> f 4
0
}}}
I can see that the fact that the syntax works out this way would be quite
surprising. I'm not entirely sure what to do about it, however. Out of
curiosity, what instructions are you following?
== Problem 2: MVar exception
This is almost certainly a bug in GHC(i)
{{{
ghc: panic! (the 'impossible' happened)
(GHC version 8.2.1 for x86_64-apple-darwin):
thread blocked indefinitely in an MVar operation
}}}
Unfortunately I'm able to reproduce on neither my Linux box nor an OS X
machine, both running 8.2.1. Are you able to reliably reproduce this
crash?
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14299#comment:2>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list