Opened 9 years ago

Closed 9 years ago

Last modified 7 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: 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 [email protected],

Change History (3)

comment:1 Changed 9 years ago by simonmar

  • Architecture changed from x86 to Multiple
  • Milestone set to 6.6
  • Operating System changed from Windows to Multiple
  • Resolution set to fixed
  • Status changed from new to closed

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

comment:2 Changed 7 years ago by simonmar

  • Architecture changed from Multiple to Unknown/Multiple

comment:3 Changed 7 years ago by simonmar

  • Operating System changed from Multiple to Unknown/Multiple
Note: See TracTickets for help on using tickets.