[GHC] #10460: Allow foreign prim to return Any

GHC ghc-devs at haskell.org
Fri May 29 21:15:21 UTC 2015


#10460: Allow foreign prim to return Any
-------------------------------------+-------------------------------------
        Reporter:  ezyang            |                   Owner:  ezyang
            Type:  feature request   |                  Status:  new
        Priority:  normal            |               Milestone:  7.12.1
       Component:  Compiler (Type    |                 Version:  7.11
  checker)                           |                Keywords:
      Resolution:                    |            Architecture:
Operating System:  Unknown/Multiple  |  Unknown/Multiple
 Type of failure:  GHC rejects       |               Test Case:
  valid program                      |                Blocking:
      Blocked By:                    |  Differential Revisions:
 Related Tickets:                    |
-------------------------------------+-------------------------------------
Changes (by ezyang):

 * owner:   => ezyang


Old description:

> Presently, we have
>
> {{{
> {-# LANGUAGE GHCForeignImportPrim #-}
> module Serum where
> import GHC.Exts
>
> foreign import prim "chenycopy" cheneycopy :: Any -> Any
> }}}
>
> induces the error
>
> {{{
> Serum.hs:5:1:
>     Unacceptable result type in foreign declaration:
>       ‘Any’ cannot be marshalled in a foreign call
>     When checking declaration:
>       foreign import prim safe "static chenycopy" cheneycopy
>         :: Any -> Any
> }}}
>
> We ought to allow a lifted value to be returned from a foreign primop; no
> reason not to, anyway; no reason not to, and there are plenty of built-in
> primops which do this.
>
> For reference, lifted arguments were allowed in arugments in this commit:
>
> {{{
> commit e29001c9e0f73885c0b85d86c3a854519448013a
> Author: Joachim Breitner <mail at joachim-breitner.de>  Mon Mar 12 01:20:12
> 2012
> Committer:      Simon Marlow <marlowsd at gmail.com>  Wed Mar 14 06:01:18
> 2012
>
> Allow Any as an argument type to foreign prim functions
> }}}

New description:

 Presently, we have

 {{{
 {-# LANGUAGE GHCForeignImportPrim #-}
 module Serum where
 import GHC.Exts

 foreign import prim "chenycopy" cheneycopy :: Any -> Any
 }}}

 induces the error

 {{{
 Serum.hs:5:1:
     Unacceptable result type in foreign declaration:
       ‘Any’ cannot be marshalled in a foreign call
     When checking declaration:
       foreign import prim safe "static chenycopy" cheneycopy
         :: Any -> Any
 }}}

 We ought to allow a lifted value to be returned from a foreign primop; no
 reason not to, anyway; no reason not to, and there are plenty of built-in
 primops which do this.

 For reference, lifted arguments were allowed in arugments in this commit:

 {{{
 commit e29001c9e0f73885c0b85d86c3a854519448013a
 Author: Joachim Breitner <mail at joachim-breitner.de>  Mon Mar 12 01:20:12
 2012
 Committer:      Simon Marlow <marlowsd at gmail.com>  Wed Mar 14 06:01:18
 2012

 Allow Any as an argument type to foreign prim functions
 }}}

 I can volunteer to write the patch but it would be good if someone else
 OKs this before I proceed.

--

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/10460#comment:1>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list