[GHC] #746: ghc panic! with foreign import wrapper involving Bool
GHC
trac at galois.com
Sun Apr 16 20:37:39 EDT 2006
#746: ghc panic! with foreign import wrapper involving Bool
------------------------------------+---------------------------------------
Reporter: brianh at metamilk.com | Owner:
Type: bug | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 6.4
Severity: normal | Keywords: DsForeign Bool FFI
Os: Windows | Difficulty: Unknown
Architecture: x86 |
------------------------------------+---------------------------------------
I encounter a strange 'ghc panic' bug when I try to export the function
onKeyDown below. I'm using ghc 6.4 and WindowsXP on x86.
The bug seems to be caused by the use of {{{Bool}}} in
{{{DumaKeyCallback}}}, because when I change the {{{Bool}}} to an
{{{Int}}} everything compiles ok. Therefore I wonder if this is something
to do with the compilation of "wrapper" imports not liking a Bool in the
type signature?
Anyway here is the full standalone example and session transcript:
{{{
module Keyboard
( Key(..)
, KeyCallback
, onKeyDown -- compiles fine if this export is commented out
) where
import Foreign.Ptr
data Key
= KeyLButton -- other keys ommitted
| KeyDown
deriving (Enum)
type KeyCallback = Key -> IO ()
type DumaKeyCallback = Bool -> Int -> IO () -- Crashes GHC
-- type DumaKeyCallback = Int -> Int -> IO () -- But this compiles
fine!!!! ?
foreign import ccall "wrapper" mkDumaKeyCallback :: DumaKeyCallback -> IO
(FunPtr DumaKeyCallback)
toDumaKeyCallback :: KeyCallback -> DumaKeyCallback
toDumaKeyCallback f = \alt key -> f (toEnum key)
foreign import ccall duma_onKeyDown :: FunPtr DumaKeyCallback -> IO ()
onKeyDown :: KeyCallback -> IO ()
onKeyDown f = mkDumaKeyCallback (toDumaKeyCallback f) >>= duma_onKeyDown
}}}
Transcript:
{{{
>ghc -fglasgow-exts -fffi -v keyboard.hs
Glasgow Haskell Compiler, Version 6.4, for Haskell 98, compiled by GHC
version 6.2.2
Using package config file: c:\ghc\ghc-6.4\package.conf
Hsc static flags: -static
*** Checking old interface for Keyboard:
*** Parser:
*** Renamer/typechecker:
*** Desugar:
Result size = 354
*** Simplify:
Result size = 528
Result size = 443
Result size = 415
*** Tidy Core:
Result size = 415
*** CorePrep:
Result size = 500
*** Stg2Stg:
*** CodeGen:
*** CodeOutput:
*** Deleting temp files
Deleting: C:/DOCUME~1/TYPHON~1/LOCALS~1/Temp/ghc4084.s
Warning: deleting non-existent
C:/DOCUME~1/TYPHON~1/LOCALS~1/Temp/ghc4084.s
ghc: panic! (the `impossible' happened, GHC version 6.4):
DsForeign.getPrimTyOf GHCziBase.Bool{(w) tc 3c}
Please report it as a compiler bug to glasgow-haskell-bugs at haskell.org,
or http://sourceforge.net/projects/ghc/.
}}}
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/746>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the Glasgow-haskell-bugs
mailing list