Commit e29001c9 authored by Joachim Breitner's avatar Joachim Breitner Committed by Simon Marlow
Browse files

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.
parent e562e59a
......@@ -1166,7 +1166,7 @@ isOverloadedTy _ = False
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'
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment