[commit: ghc] master: Allow Any return in foreign prim, fixes #10460. (cd9c5c6)

git at git.haskell.org git at git.haskell.org
Wed Jun 3 16:56:32 UTC 2015


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/cd9c5c6678e206ffcda955f66c26c7a4d89519c9/ghc

>---------------------------------------------------------------

commit cd9c5c6678e206ffcda955f66c26c7a4d89519c9
Author: Edward Z. Yang <ezyang at cs.stanford.edu>
Date:   Mon Jun 1 11:30:17 2015 -0700

    Allow Any return in foreign prim, fixes #10460.
    
    Signed-off-by: Edward Z. Yang <ezyang at cs.stanford.edu>
    
    Test Plan: validate
    
    Reviewers: simonpj, goldfire, austin
    
    Subscribers: bgamari, thomie
    
    Differential Revision: https://phabricator.haskell.org/D935
    
    GHC Trac Issues: #10460


>---------------------------------------------------------------

cd9c5c6678e206ffcda955f66c26c7a4d89519c9
 compiler/typecheck/TcType.hs                 | 6 ++++--
 docs/users_guide/ffi-chap.xml                | 3 ++-
 testsuite/tests/ffi/should_compile/T10460.hs | 5 +++++
 testsuite/tests/ffi/should_compile/all.T     | 1 +
 4 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/compiler/typecheck/TcType.hs b/compiler/typecheck/TcType.hs
index a131a05..485c1ba 100644
--- a/compiler/typecheck/TcType.hs
+++ b/compiler/typecheck/TcType.hs
@@ -1658,9 +1658,11 @@ isFFIPrimArgumentTy dflags ty
 
 isFFIPrimResultTy :: DynFlags -> Type -> Validity
 -- Checks for valid result type for a 'foreign import prim'
--- Currently it must be an unlifted type, including unboxed tuples.
+-- Currently it must be an unlifted type, including unboxed tuples,
+-- or the well-known type Any.
 isFFIPrimResultTy dflags ty
-   = checkRepTyCon (legalFIPrimResultTyCon dflags) ty
+  | isAnyTy ty = IsValid
+  | otherwise = checkRepTyCon (legalFIPrimResultTyCon dflags) ty
 
 isFunPtrTy :: Type -> Bool
 isFunPtrTy ty
diff --git a/docs/users_guide/ffi-chap.xml b/docs/users_guide/ffi-chap.xml
index a5ab9e7..38db2bf 100644
--- a/docs/users_guide/ffi-chap.xml
+++ b/docs/users_guide/ffi-chap.xml
@@ -76,7 +76,8 @@ OK:
          internal GHC calling convention.  The arguments and results must
          be unboxed types, except that an argument may be of type
          <literal>Any</literal> (by way of <literal>unsafeCoerce#</literal>)
-         and the result type is allowed to be an unboxed tuple.
+         and the result type is allowed to be an unboxed tuple or the
+         type <literal>Any</literal>.
        </para>
        <para>
          This feature is not intended for
diff --git a/testsuite/tests/ffi/should_compile/T10460.hs b/testsuite/tests/ffi/should_compile/T10460.hs
new file mode 100644
index 0000000..7481453
--- /dev/null
+++ b/testsuite/tests/ffi/should_compile/T10460.hs
@@ -0,0 +1,5 @@
+{-# LANGUAGE GHCForeignImportPrim #-}
+module T10460 where
+import GHC.Exts
+-- don't link me!
+foreign import prim "f" f :: Any -> Any
diff --git a/testsuite/tests/ffi/should_compile/all.T b/testsuite/tests/ffi/should_compile/all.T
index 84c7e86..ec6326b 100644
--- a/testsuite/tests/ffi/should_compile/all.T
+++ b/testsuite/tests/ffi/should_compile/all.T
@@ -29,3 +29,4 @@ test('T3624', normal, compile, [''])
 test('T3742', normal, compile, [''])
 test('cc015', normal, compile, [''])
 test('cc016', normal, compile, [''])
+test('T10460', normal, compile, [''])



More information about the ghc-commits mailing list