Skip to content

GHCi doesn't work Any and missing RealWorld foreign prim imports

Here are two issues with our GHCi support for foreign prim imports:

Here is a program that works:

{-# LANGUAGE GHCForeignImportPrim, MagicHash, UnliftedFFITypes, UnboxedTuples #-}
module Serum where
import GHC.Exts

foreign import prim "cheneycopy" cheneycopy :: Word# -> State# RealWorld -> (# State# RealWorld, Word# #)

If I remove the world token passing, as in here:

{-# LANGUAGE GHCForeignImportPrim, MagicHash, UnliftedFFITypes, UnboxedTuples #-}
module Serum where
import GHC.Exts

foreign import prim "cheneycopy" cheneycopy :: Word# -> Word#

I get:

  (GHC version 7.10.1 for x86_64-unknown-linux):
	ByteCodeGen.generateCCall: missing or invalid World token?

Another error is if I try to pass Any as an argument:

{-# LANGUAGE GHCForeignImportPrim, MagicHash, UnliftedFFITypes, UnboxedTuples #-}
module Serum where
import GHC.Exts

foreign import prim "cheneycopy" cheneycopy :: Any -> State# RealWorld -> (# State# RealWorld, Word# #)

Then I get:

ghc: panic! (the 'impossible' happened)
  (GHC version 7.10.1 for x86_64-unknown-linux):
	primRepToFFIType

Note to anyone who is running into this problem: an easy workaround is to use -fobject-code which bypasses bytecode generation.

Trac metadata
Trac field Value
Version 7.10.1
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component GHCi
Test case
Differential revisions
BlockedBy
Related
Blocking
CC hvr
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information