[GHC] #14299: GHCi for GHC 8.2.1 crashed with simple function?

#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 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: --------------------------------------+------------------------------- I'm a newbie here, but I'm following your instructions! I started GHCi, defined a simple factorial function and then called it and... it crashed. {{{#!hs let f 0 = 0 f n = n * f (n-1) f 0 }}} That is what I introduced in the console... After that computer hanged and gave me the following error: {{{ ghc: panic! (the 'impossible' happened) (GHC version 8.2.1 for x86_64-apple-darwin): thread blocked indefinitely in an MVar operation Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14299 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#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: | -------------------------------+-------------------------------------- Description changed by mathiassm: Old description:
I'm a newbie here, but I'm following your instructions!
I started GHCi, defined a simple factorial function and then called it and... it crashed.
{{{#!hs let f 0 = 0 f n = n * f (n-1) f 0 }}}
That is what I introduced in the console... After that computer hanged and gave me the following error:
{{{ ghc: panic! (the 'impossible' happened) (GHC version 8.2.1 for x86_64-apple-darwin): thread blocked indefinitely in an MVar operation
Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug }}}
New description: I'm a newbie here, but I'm following your instructions! I started GHCi, defined a simple factorial function and then called it and... it crashed. {{{#!hs let f 0 = 0 f n = n * f (n-1) f 0 }}} That is what I introduced in the console... After that computer hanged and gave me the following error: {{{ ghc: panic! (the 'impossible' happened) (GHC version 8.2.1 for x86_64-apple-darwin): thread blocked indefinitely in an MVar operation Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug }}} EDIT: This was done on a macOS 10.12.6 system with the Haskell Platform installed via Homebrew, with no further "customization". -- -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14299#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#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

#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 mathiassm): Hello! Yes, I just learned about indentation problems one can run into writing Haskell. My intention was to have those three as a single definition for `f`, which I now accomplish with a multiline using the let syntax, as you stated. So that part was just my Haskell inexperience (plus the incorrect definition of factorial, my bad!). Now, I supposed the exception could be caused by only defining `f n`, but as I'm testing that, it doesn't happen; it understandably throws a stack overflow exception. It still hangs on the call to `f 0` and throws the MVar error (whatever that is). It doesn't seem to happen elsewhere, if I follow the correct indentation rules (and now I `:set +m` for convenience)... I'm sorry but I can't find another way to reproduce this, but following those simple statements /: I suppose it's my installation (maybe Homebrew failed compiling it, or downloading the binaries...) Thank you for your time (and sorry!) PD. The "instructions" I followed was the "Please report this bug" message. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14299#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#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 mathiassm): Hello! Yes, I just learned about indentation problems one can run into writing Haskell. My intention was to have those three as a single definition for f, which I now accomplish with a multiline using the let syntax, as you stated. So that part was just my Haskell inexperience (plus the incorrect definition of factorial, my bad!). Now, I supposed the exception could be caused by only defining f n, but as I'm testing that, it doesn't happen; it understandably throws a stack overflow exception. It still hangs on the call to f 0 and throws the MVar error (whatever that is). It doesn't seem to happen elsewhere, if I follow the correct indentation rules (and now I :set +m for convenience)... I'm sorry but I can't find another way to reproduce this, but following those simple statements /: I suppose it's my installation (maybe Homebrew failed compiling it, or downloading the binaries...) Thank you for your time (and sorry!) PD. The "instructions" I followed was the "Please report this bug" message. Replying to [comment:2 bgamari] -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14299#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#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): Well, it definitely seems like there is a bug here regardless of whether or not I can reproduce it. `MVar`s are mutable variables generally used in concurrent settings, so there is definitely the potential for bugs here.
Thank you for your time (and sorry!)
No need to be sorry! Thanks for reporting the bug. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14299#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#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): I'll admit I've looked through the `ghci` implementation and all of the `MVar` operations look exception-safe (which is likely the cause of the failure). I have a hard time believing that the issue lies in `ghc` itself, but I don't see much alternative. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14299#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#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: #11771 | Differential Rev(s): Wiki Page: | -------------------------------+-------------------------------------- Changes (by bgamari): * related: => #11771 Comment: This looks very similar to #11771. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14299#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC