[GHC] #3008: Strange behavior when using newtyped version of IO
monad in FFI import declarations
GHC
trac at galois.com
Fri Feb 6 18:45:15 EST 2009
#3008: Strange behavior when using newtyped version of IO monad in FFI import
declarations
-------------------+--------------------------------------------------------
Reporter: waern | Owner:
Type: bug | Status: new
Priority: normal | Component: Compiler
Version: 6.10.1 | Severity: normal
Keywords: FFI | Testcase:
Os: Linux | Architecture: x86_64 (amd64)
-------------------+--------------------------------------------------------
Take a look at these two modules:
A.hs:
{{{
module A (GL) where
import Control.Monad
import Control.Monad.Trans
newtype GL a = GL (IO a) deriving (Functor, Monad, MonadIO)
}}}
B.hs:
{{{
module B where
import A
foreign import CALLCONV unsafe "glFlush" flush :: GL ()
}}}
Now, compile them with optimizations:
{{{
[david at alonzo temp]$ $HOME/ghc-6.10.1/bin/ghc A.hs B.hs
-XGeneralizedNewtypeDeriving -XForeignFunctionInterface -DCALLCONV=ccall
-XCPP -O
compilation IS NOT required
compilation IS NOT required
A.o:(.text+0x8e): undefined reference to
`mtlzm1zi1zi0zi2_ControlziMonadziTrans_ZCDMonadIO_con_info'
A.o:(.text+0x237): undefined reference to
`__stginit_mtlzm1zi1zi0zi2_ControlziMonadziTrans_'
B.o:(.text+0x1e): undefined reference to `glFlush'
/home/david/ghc-6.10.1//lib/ghc-6.10.1/libHSrts.a(Main.o): In function
`real_main':
Main.c:(.text+0x12): undefined reference to `__stginit_ZCMain'
Main.c:(.text+0x26): undefined reference to `ZCMain_main_closure'
collect2: ld returnerade avslutningsstatus 1
}}}
It's OK - we pass the typechecking phase.
Now, see what happens when we compile without `-O`:
{{{
[david at alonzo temp]$ rm -f *.hi *.o
[david at alonzo temp]$ $HOME/ghc-6.10.1/bin/ghc A.hs B.hs
-XGeneralizedNewtypeDeriving -XForeignFunctionInterface -DCALLCONV=ccall
-XCPP
B.hs:5:0:
Unacceptable result type in foreign declaration: GL ()
When checking declaration:
foreign import ccall unsafe "static &glFlush" flush :: GL ()
}}}
Putting everything into one single module makes the type error go away
completely (that is, also when compiling without `-O`).
Something strange must be going on.
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/3008>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the Glasgow-haskell-bugs
mailing list