[GHC] #11032: Missing result type handling for State# s in foreign import prim.

#11032: Missing result type handling for State# s in foreign import prim. -------------------------------------+------------------------------------- Reporter: ekmett | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.10.2 (FFI) | Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: GHC rejects Unknown/Multiple | valid program Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- I've been using `foreign import prim` for a while now to craft custom primops on an as-needed basis. Attempting to write {{{#!hs {-# LANGUAGE MagicHash #-} {-# LANGUAGE UnboxedTuples #-} {-# LANGUAGE UnliftedFFITypes #-} {-# LANGUAGE GHCForeignImportPrim #-} {-# LANGUAGE ForeignFunctionInterface #-} foreign import prim "pinThreadzh" pinThread# :: State# s -> (# State# s, Int#, Int# #) foreign import prim "unpinThreadzh" unpinThread# :: State# s -> State# s }}} threw me for a loop when it didn't work. The former works fine. The latter complains that `State# s` isn't a valid result type! {{{ src/Concurrent/Internal/Thread.hs:23:1: Unacceptable result type in foreign declaration: ‘State# s’ cannot be marshalled in a foreign call When checking declaration: foreign import prim safe "static unpinThreadzh" unpinThread# :: State# s -> State# s }}} Builtin primitives work this way all the time, so I'm guessing we just missed it in a case statement somewhere inside the compiler when dealing with `foreign import prim` support. I can likely hack around it by giving back something like `(# State# s #)` for now but that is a rather unsatisfying solution. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11032 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11032: Missing result type handling for State# s in foreign import prim. -------------------------------------+------------------------------------- Reporter: ekmett | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler (FFI) | Version: 7.10.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: GHC rejects | Unknown/Multiple valid program | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by fryguybob): * cc: fryguybob@… (added) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11032#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11032: Missing result type handling for State# s in foreign import prim. -------------------------------------+------------------------------------- Reporter: ekmett | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler (FFI) | Version: 7.10.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: GHC rejects | Unknown/Multiple valid program | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by simonpj): I see in `TcType` this comment: {{{ Note [Marshalling VoidRep] ~~~~~~~~~~~~~~~~~~~~~~~~~~ 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 don't think there is any fundamental reason not to allow this. Would someone like to free it up? It'd mean looking at that `ptrRepHint` stuff. Thanks! Simon -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11032#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11032: Missing result type handling for State# s in foreign import prim. -------------------------------------+------------------------------------- Reporter: ekmett | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler (FFI) | Version: 7.10.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: GHC rejects | Unknown/Multiple valid program | Test Case: Blocked By: | Blocking: Related Tickets: #9352 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * related: => #9352 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11032#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11032: Missing result type handling for State# s in foreign import prim. -------------------------------------+------------------------------------- Reporter: ekmett | Owner: (none) Type: bug | Status: closed Priority: normal | Milestone: Component: Compiler (FFI) | Version: 7.10.2 Resolution: duplicate | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: GHC rejects | Unknown/Multiple valid program | Test Case: Blocked By: | Blocking: Related Tickets: #9352 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * status: new => closed * resolution: => duplicate -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11032#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC