[commit: ghc] master: Allow Any as an argument type to foreign prim functions (e29001c)
Simon Marlow
marlowsd at gmail.com
Wed Mar 14 15:06:08 CET 2012
Repository : ssh://darcs.haskell.org//srv/darcs/ghc
On branch : master
http://hackage.haskell.org/trac/ghc/changeset/e29001c9e0f73885c0b85d86c3a854519448013a
>---------------------------------------------------------------
commit e29001c9e0f73885c0b85d86c3a854519448013a
Author: Joachim Breitner <mail at joachim-breitner.de>
Date: Mon Mar 12 09:20:12 2012 +0100
Allow Any as an argument type to foreign prim functions
Real primops can take boxed arguments, and the Cmm code will receive the
pointer to the object on the Haskell heap, e.g. for unpackClosure#. To
be able to implement such a function in a "foreign prim" call, this
needs to be allowed as well. By only allowing Any here (instead of
arbitrary types), it is clearer that the function will not receive the
value in any marshalled form, but just the raw pointer. Haskell code
using such functions are likely to use unsafeCoerce# to turn a haskell
value into a value of type Any.
>---------------------------------------------------------------
compiler/typecheck/TcType.lhs | 9 ++++++---
1 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/compiler/typecheck/TcType.lhs b/compiler/typecheck/TcType.lhs
index 669545a..ea134ed 100644
--- a/compiler/typecheck/TcType.lhs
+++ b/compiler/typecheck/TcType.lhs
@@ -1166,7 +1166,7 @@ isOverloadedTy _ = False
\begin{code}
isFloatTy, isDoubleTy, isIntegerTy, isIntTy, isWordTy, isBoolTy,
- isUnitTy, isCharTy :: Type -> Bool
+ isUnitTy, isCharTy, isAnyTy :: Type -> Bool
isFloatTy = is_tc floatTyConKey
isDoubleTy = is_tc doubleTyConKey
isIntegerTy = is_tc integerTyConKey
@@ -1175,6 +1175,7 @@ isWordTy = is_tc wordTyConKey
isBoolTy = is_tc boolTyConKey
isUnitTy = is_tc unitTyConKey
isCharTy = is_tc charTyConKey
+isAnyTy = is_tc anyTyConKey
isStringTy :: Type -> Bool
isStringTy ty
@@ -1342,9 +1343,11 @@ isFFILabelTy = checkRepTyConKey [ptrTyConKey, funPtrTyConKey]
isFFIPrimArgumentTy :: DynFlags -> Type -> Bool
-- Checks for valid argument type for a 'foreign import prim'
--- Currently they must all be simple unlifted types.
+-- Currently they must all be simple unlifted types, or the well-known type
+-- Any, which can be used to pass the address to a Haskell object on the heap to
+-- the foreign function.
isFFIPrimArgumentTy dflags ty
- = checkRepTyCon (legalFIPrimArgTyCon dflags) ty
+ = isAnyTy ty || checkRepTyCon (legalFIPrimArgTyCon dflags) ty
isFFIPrimResultTy :: DynFlags -> Type -> Bool
-- Checks for valid result type for a 'foreign import prim'
More information about the Cvs-ghc
mailing list