Why is there no "import import unsafe"?

This is a continuation of my previous question here . I was able to get something working for Reid Barton's answer , but I noticed mostly I see __pkg_ccall_GC :

  case {__pkg_ccall_GC hashabler-2.0.0 sipRound_s_x2 Word# -> Word# -> Word# -> Word# -> (# Word#, Word#, Word#, Word# #)} ww1 ww2 ww3 (xor# ww4 b1) 

What I think about what you expect from a "safe" ffi call. However, adding "unsafe" to the import import string is not allowed (although error messages do not say why):

 src/Data/Hashabler/SipHash.hs:60:1: error: β€’ The safe/unsafe annotation should not be used with `foreign import prim'. β€’ When checking declaration: foreign import prim unsafe "static sipRound_s_x4" sipRound_s_x4# :: Word# -> Word# -> Word# -> Word# -> (# Word#, Word#, Word#, Word# #) 

My external procedure is few in number, but a little cool, so I don’t think I want what _GC gives _GC . Some relevant GHC source bits I looked at are FWIW and background:

compiler / prelude / ForeignCall.hs: only "risky" skips "_GC"

 data Safety = PlaySafe -- Might invoke Haskell GC, or do a call back, or -- switch threads, etc. So make sure things are -- tidy before the call. Additionally, in the threaded -- RTS we arrange for the external call to be executed -- by a separate OS thread, ie, _concurrently_ to the -- execution of other Haskell threads. | PlayInterruptible -- Like PlaySafe, but additionally -- the worker thread running this foreign call may -- be unceremoniously killed, so it must be scheduled -- on an unbound thread. | PlayRisky -- None of the above can happen; the call will return -- without interacting with the runtime system at all deriving ( Eq, Show, Data ) -- Show used just for Show Lex.Token, I think 

I also see some foreign import prim unsafe and ... safe in the GHC tree, although I assume this is dead code. e.g. testsuite/tests/printer/Ppr046.hs .

So my questions are:

  • What is the difference between the code created with __pkg_ccall_GC vs a __pkg_ccall (where do I do foreign import prim not ccall )? Is it the same as described here ?
  • Why is foreign import prim unsafe not supported?
  • Assuming I understand (1): Is there a way around this by getting both the effective return of multiple values ​​and avoiding what happens in accounting (1)?

EDIT . Looking at the assembly from -ddump-asm , it clearly shows that nothing is happening (it shouldn't have been scary to look at the assembly), refer to Reid Burton's comment below:

 movq %rdi,%rax movq %r8,%rdi xorq %r9,%rdi movq %rsi,%rcx movq %rax,%rsi movq %r14,%rax movq %rcx,%r14 movq %rbx,%rcx movq %rax,%rbx movq %r9,-8(%rbp) movq %rcx,(%rbp) addq $-16,%rbp jmp sipRound_s_x2 

xorq at the top corresponds to haskell xor . All of these movq really seem like debris, though ...

+8
haskell ghc ffi
source share
1 answer

As Raid Barton points out, __pkg_ccall_GC does not indicate anything. The generated code does not carry out the accounting that you will see when you call FFI safe .

+2
source share

All Articles