[GHC] #8281: The impossible happened: primRepToFFIType
GHC
ghc-devs
Sat Oct 5 20:12:54 UTC 2013
#8281: The impossible happened: primRepToFFIType
---------------------------------------+-----------------------------------
Reporter: tibbe | Owner:
Type: bug | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 7.6.2
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
Type of failure: Compile-time crash | Unknown/Multiple
Test Case: | Difficulty: Unknown
Blocking: | Blocked By:
| Related Tickets:
---------------------------------------+-----------------------------------
Comment (by simonmar):
We used to use `UnliftedFFITypes` quite a lot in the IO library in the
base package, but I just looked and we use it very little now (only for
`ThreadId#`). It does have a brief entry in the flags reference in the
user's guide, but no proper documentation. As far as I recall we didn't
intend it to be an advertised feature, so I'm not sure why it appears in
the docs at all.
So what's going wrong here is that we have a foreign call that takes a
`ThreadId#`. The foreign call is marked unsafe, because (as you note,
Simon) it couldn't work if it was safe. But GHCi only knows how to
compile safe foreign calls - it ignores `unsafe` - so there's no way GHCi
can compile this code such that it works.
What I would like to do is get rid of `UnliftedFFITypes` and use `foreign
import prim` instead. The example above is a good use for `foreign import
prim`, and indeed we should change `GHC.Conc.Sync` to do it that way
(where the example above was copy/pasted from, incidentally).
But there are some places where `UnliftedFFITypes` is really useful, e.g.:
{{{
foreign import ccall unsafe "memcpy"
memcpy_freeze :: MutableByteArray# s -> MutableByteArray# s -> CSize
-> IO (Ptr a)
}}}
from the `array` package. To do this with `foreign import prim` would
mean another function call.
So I think we have little choice here.
- disallow passing boxed-but-unlifted types to safe foreign calls, except
for arrays. This error would also trigger in GHCi for an unsafe call,
because GHCi compiles unsafe calls as safe calls. Hence the above code
would be rejected by GHCi, but accepted by GHC.
- document `UnliftedFFITypes`, and explain the pitfalls: not fully
supported by GHCi, and be careful passing arrays to `safe` calls (they
must be pinned).
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/8281#comment:3>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list