[jhc] bugs/issues in jhc-0.7.6‏

Korcan Hussein korcan_h at hotmail.com
Sat Aug 7 07:27:10 EDT 2010

Hello, I just wanted to report some bugs & issues with jhc using SDL bindings (https://patch-tag.com/r/snk_kid) I've put links to the original Haskell code and generated C (which was outputted from compile-time error) at the end of this email.
C Compile-time errors:
This one comes up quite lot, and happens quite randomly:
test_code.c:4136: error: ‘v74’ undeclared (first use in this function)
test_code.c:4136: error: (Each undeclared identifier is reported only once
test_code.c:4136: error: for each function it appears in.)
This is generated for the code:
failWithError :: String -> IO a
failWithError msg
    = do err <- fmap (fromMaybe "No SDL error") getError
         ioError $ userError $ msg ++ "\nSDL message: " ++ err
Sometimes it goes away just by shuffling some code, even just commenting a line and uncomment it again can make it go away but it happens a lot and sometimes it's really hard to make it go for a long period of time. The problem is there is a function called
but the argument given is not defined in the scope it's used in.
test_code.c:5182: error: expected expression before ‘;’ token
test_code.c: In function ‘fW$__fInstance$__iForeign_Storable_pokeByteOff_default’:
This is caused by the code generated for the "whileEvents" in the Haskell source I've attached. It just generates incorrect C code, like it was a serious failure.
jhc issues:
The action "pollEvent" defined as:
foreign import ccall "SDL_PollEvent" sdlPollEvent :: Ptr Event -> IO Int
-- | Polls for currently pending events.
pollEvent :: IO Event
    = alloca poll
    where poll ptr
              = do ret <- sdlPollEvent ptr
                   case ret of
                     0 -> return NoEvent
                     _ -> do event <- peek ptr
                             case event of
                               NoEvent -> poll ptr
                               _ -> return event
When used, while compiling with jhc, when it reaches the compile stage "-- Boxy WorkWrap" jhc consumes a lot of memory and takes a large amount time to finish.
Next jhc crashed with the message:
"jhc: internal error: evacuate: strange closure type 65350"
This happened using the loop function and cross-compiling.
Program Runtime issues:
When you do get this code to compile (by not using the loop function, use delay), if you comment out the lines I've marked there is a bug where (foreign) pointers in the same scope some how overwrite the values of previously defined pointers even though there is no re-assignment going on so they end up all being the same address value, this code works correctly in ghc. I haven't checked this yet but it feels like a C name-hiding bug from nested scopes.
Minor issue, ForeignPtr  is missing a Show instance.                           

Test.hs: http://www.mediafire.com/?e93sbeaoib26539
test_code.c: http://www.mediafire.com/?16mj8agucypvp1x


More information about the jhc mailing list