Opened 11 years ago

Closed 11 years ago

Last modified 9 years ago

#746 closed bug (fixed)

ghc panic! with foreign import wrapper involving Bool

Reported by: brianh@… Owned by:
Priority: normal Milestone: 6.6
Component: Compiler Version: 6.4
Keywords: DsForeign Bool FFI Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:


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


>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,

Change History (3)

comment:1 Changed 11 years ago by simonmar

Architecture: x86Multiple
Milestone: 6.6
Operating System: WindowsMultiple
Resolution: fixed
Status: newclosed

Fixed, but not in 6.4.2, sorry. The workaround is to use an integral type instead.

comment:2 Changed 9 years ago by simonmar

Architecture: MultipleUnknown/Multiple

comment:3 Changed 9 years ago by simonmar

Operating System: MultipleUnknown/Multiple
Note: See TracTickets for help on using tickets.