
Hi, Am Donnerstag, den 08.03.2012, 23:12 -0500 schrieb Edward Kmett:
But I can only pass unboxed types to foreign prim.
Is this an intrinsic limitation or just an artifact of the use cases that have presented themselves to date?
funny, I just stumbled over this two days ago as well. In my case, I’m trying to investigate the actual data on the heap, so I am also trying to pass arbitrary values to a foreign prim function, which then receive the pointer to the heap object as the argument. Since real primops (e.g. unpackClosure#) can take arbitrary values, I figured that this is an artifact, as you say. I made this change to enable this feature: diff --git a/compiler/typecheck/TcType.lhs b/compiler/typecheck/TcType.lhs index 669545a..83a59bd 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 @@ -1344,7 +1345,7 @@ isFFIPrimArgumentTy :: DynFlags -> Type -> Bool -- Checks for valid argument type for a 'foreign import prim' -- Currently they must all be simple unlifted types. 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' Initially, I had isFFIPrimArgumentTy modfified to really accept "a ->", but I found it cleaner to just accept the Any type, to make it more obvious that, morally speaking, not the value is passed to the function, but a pointer to Any thing. In the Haskell code, I’m unsafeCoerce#’ing the a to Any. Seems to work smoothly. Greetings, Joachim -- Joachim "nomeata" Breitner mail@joachim-breitner.de | nomeata@debian.org | GPG: 0x4743206C xmpp: nomeata@joachim-breitner.de | http://www.joachim-breitner.de/