Skip to content

Allow State# RealWorld in foreign import prim

Currently programs such as:

foreign import prim do_something :: State# RealWorld -> State# RealWorld

are rejected by GHC as State# RealWorld is not considered to be marshalable.

The rationale for this is rather questionable:

Note [Marshalling void]
~~~~~~~~~~~~~~~~~~~~~~~
We don't treat State# (whose PrimRep is VoidRep) as marshalable.
In turn that means you can't write
        foreign import foo :: Int -> State# RealWorld

Reason: the back end falls over with panic "primRepHint:VoidRep";
        and there is no compelling reason to permit it

I have run into this multiple times in the past, most recently while fixing #24595 (closed), and the restriction seems rather indefensible.

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information