Skip to content

ghc panic! with foreign import wrapper involving Bool

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@haskell.org,
or http://sourceforge.net/projects/ghc/.
Trac metadata
Trac field Value
Version 6.4
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system Windows
Architecture x86
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information