Ticket #3008 (closed bug: fixed)
Strange behavior when using newtyped version of IO monad in FFI import declarations
| Reported by: | waern | Owned by: | igloo |
|---|---|---|---|
| Priority: | normal | Milestone: | 7.4.1 |
| Component: | Compiler (FFI) | Version: | 6.10.1 |
| Keywords: | FFI | Cc: | david.waern@… |
| Operating System: | Linux | Architecture: | x86_64 (amd64) |
| Type of failure: | None/Unknown | Difficulty: | Unknown |
| Test Case: | Blocked By: | ||
| Blocking: | Related Tickets: |
Description
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@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@alonzo temp]$ rm -f *.hi *.o
[david@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.
Change History
Note: See
TracTickets for help on using
tickets.
