Ticket #2881 (closed bug: fixed)

Opened 5 years ago

Last modified 4 years ago

Basic Fibonacci function using Word causes ghci to panic. - 6.10.1

Reported by: axman6 Owned by: simonmar
Priority: low Milestone: 6.12 branch
Component: GHCi Version: 6.10.1
Keywords: panic Word fibonacci Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Difficulty: Easy (less than 1 hour)
Test Case: Blocked By:
Blocking: Related Tickets:

Description

When inputting the function:

let fib :: Word -> Word; fib 0 = 1; fib 1 = 1; fib n = l + r where l = fib (n-2); r = fib (n-1)

GHCi produces a panic error:

ghc: panic! (the 'impossible' happened)
  (GHC version 6.10.1 for i386-apple-darwin):
	schemeE(AnnCase).my_discr __word 0

It has been confirmed on both OS X 10.5.5 and linux

Change History

Changed 5 years ago by axman6

  • summary changed from Basif Fibonacci function using Word causes ghci to panic. - 6.10.1 to Basic Fibonacci function using Word causes ghci to panic. - 6.10.1

from #ghc:

14:02 < mmorrow> weird:
14:02 < mmorrow> ghci> case undefined of (0::Word) -> undefined
14:02 < mmorrow> panics
14:02 < mmorrow> but
14:02 < mmorrow> ghci> case undefined of (0::Word32) -> undefined
14:02 < mmorrow> *** Exception: Prelude.undefined
14:02 < mmorrow> (and Word{8,16,32,64} all work)
14:03 < mmorrow> this works too
14:03 < mmorrow> case (0::Word) of _ -> undefined
[and]
14:03 < mmorrow> case (0::Word) of 0 -> undefined
14:05 < mmorrow> ghci> case 0 of (0::Word) -> undefined
14:05 < mmorrow> *** Exception: Prelude.undefined
14:05 < mmorrow> ghci> case undefined of (0::Word) -> undefined
14:05 < mmorrow> ghc: panic! (the 'impossible' happened)...

Changed 5 years ago by axman6

The full error message from the previous comment:

ghc: panic! (the 'impossible' happened)
   (GHC version 6.10.1 for i386-unknown-linux):
         schemeE(AnnCase).my_discr __word 0

Changed 4 years ago by simonpj

  • owner set to simonmar
  • difficulty set to Unknown
  • milestone set to 6.10 branch

Ah. It seems that GHC's bytecode lacks an instruction for comparing Word values, for use when discriminating among case alternatives.

I'm going to assign this to Simon M to decide what to do:

  • Add a suitable byte code, or
  • Call a primop as a Haskell function (probably better; more general)

What about string literals too?

In general, it's bad that the bytecode generator just falls over; it'd be much better for it to say "I can't do X", and recover gracefully.

Simon

Changed 4 years ago by simonmar

There's no good reason for this not to work, but it's not a 1-line fix. I'll try to get around to it sometime.

Changed 4 years ago by simonmar

  • priority changed from normal to low
  • difficulty changed from Unknown to Easy (1 hr)
  • component changed from Compiler to GHCi
  • architecture changed from x86 to Unknown/Multiple

Changed 4 years ago by igloo

  • milestone changed from 6.10 branch to 6.12 branch

Changed 4 years ago by igloo

Duplicated by #3431.

Changed 4 years ago by simonmar

  • status changed from new to closed
  • resolution set to fixed

Fixed

Fri Sep 18 06:32:04 PDT 2009  Simon Marlow <marlowsd@gmail.com>
  * implement case-on-Word in the byte code generator/interpreter (#2881)

Changed 4 years ago by simonmar

  • difficulty changed from Easy (1 hr) to Easy (less than 1 hour)
Note: See TracTickets for help on using tickets.