[GHC] #10460: Allow foreign prim to return Any
#10460: Allow foreign prim to return Any -------------------------------------+------------------------------------- Reporter: ezyang | Owner: Type: feature | Status: new request | Milestone: 7.12.1 Priority: normal | Version: 7.11 Component: Compiler | Operating System: Unknown/Multiple (Type checker) | Type of failure: GHC rejects Keywords: | valid program Architecture: | Blocked By: Unknown/Multiple | Related Tickets: Test Case: | Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- 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@joachim-breitner.de> Mon Mar 12 01:20:12 2012 Committer: Simon Marlow <marlowsd@gmail.com> Wed Mar 14 06:01:18 2012 Allow Any as an argument type to foreign prim functions }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/10460> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#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@joachim-breitner.de> Mon Mar 12 01:20:12 2012 Committer: Simon Marlow <marlowsd@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@joachim-breitner.de> Mon Mar 12 01:20:12 2012 Committer: Simon Marlow <marlowsd@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
#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: | -------------------------------------+------------------------------------- Comment (by simonpj): Generally ok but * The ability to pass `Any` to `foreign import prim` is not documented in [https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/ffi.html #ffi-prim 8.1.3 of the user manual], and it jolly well should be. If you want to extend this to arbitrary FFI imports then we should document that too. * Who converts the argument to `Any`? The caller? With `unsafeCoerce`? * You should never combine a '''safe''' foreign import with `Any`. "Safe" means that the call may block and GC may happen, so passing a pointer into the heap is a bad idea. (And this constraint should be documented.) Simon -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/10460#comment:2> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#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: | -------------------------------------+------------------------------------- Comment (by Edward Z. Yang <ezyang@…>): In [changeset:"98b0b2e41f2bdc66bf815ff5f3825832b2b6d34d/ghc"]: {{{ #!CommitTicketReference repository="ghc" revision="98b0b2e41f2bdc66bf815ff5f3825832b2b6d34d" Add information about allowed foreign prim args, see #10460. Signed-off-by: Edward Z. Yang <ezyang@cs.stanford.edu> }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/10460#comment:3> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#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: | -------------------------------------+------------------------------------- Comment (by simonpj): Sorry I think I was mixed up. A `foreign prim` is always `unsafe`, isn't it. And you are only proposing to add `Any` as a possible result for `foreign prim` not for other `foreign` declarations, correct? So my third bullet is irrelevant. There's a missing close-paren in the (welcome) doc fix. Simon -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/10460#comment:4> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#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: | -------------------------------------+------------------------------------- Comment (by ezyang):
And you are only proposing to add Any as a possible result for foreign prim not for other foreign declarations, correct?
Yep.
Who converts the argument to Any? The caller? With unsafeCoerce?
Yes and yes. Another possibility is to accept arbitrary types for foreign prim ops (in the same way that GHC's primop mechanism works), but that's more work. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/10460#comment:5> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#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: | -------------------------------------+------------------------------------- Comment (by Edward Z. Yang <ezyang@…>): In [changeset:"e5be846ba929da54472c03a7c3b05fdd1e483c01/ghc"]: {{{ #!CommitTicketReference repository="ghc" revision="e5be846ba929da54472c03a7c3b05fdd1e483c01" Typofix: missing period. (#10460) Signed-off-by: Edward Z. Yang <ezyang@cs.stanford.edu> }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/10460#comment:6> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#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: | -------------------------------------+------------------------------------- Comment (by Edward Z. Yang <ezyang@…>): In [changeset:"cd9c5c6678e206ffcda955f66c26c7a4d89519c9/ghc"]: {{{ #!CommitTicketReference repository="ghc" revision="cd9c5c6678e206ffcda955f66c26c7a4d89519c9" Allow Any return in foreign prim, fixes #10460. Signed-off-by: Edward Z. Yang <ezyang@cs.stanford.edu> Test Plan: validate Reviewers: simonpj, goldfire, austin Subscribers: bgamari, thomie Differential Revision: https://phabricator.haskell.org/D935 GHC Trac Issues: #10460 }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/10460#comment:7> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#10460: Allow foreign prim to return Any -------------------------------------+------------------------------------- Reporter: ezyang | Owner: ezyang Type: feature request | Status: closed Priority: normal | Milestone: 7.12.1 Component: Compiler (Type | Version: 7.11 checker) | Keywords: Resolution: fixed | 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): * status: new => closed * resolution: => fixed -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/10460#comment:8> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
participants (1)
-
GHC