Favonia | 7 Jul 2012 06:06
Picon
Gravatar

Imported foreign functions should be strict

Hi all,

Recently I am tuning one of our incomplete libraries that uses FFI.
After dumping the interface file I realized strictness/demand analysis
failed for imported foreign functions---that is, they are not inferred
to be strict in their arguments. In my naive understanding all
imported foreign functions are strict! Here's a minimum example (with
GHC 7.4.2):

{-# LANGUAGE ForeignFunctionInterface #-}
module Main where
import Foreign.C
foreign import ccall unsafe "sin" sin' :: CDouble -> CDouble

where in the interface file the function sin' will have strictness
U(L) (meaning Unpackable(Lazy)).

Regards,
Favonia
Simon Marlow | 10 Jul 2012 09:57
Picon

Re: Imported foreign functions should be strict

On 07/07/2012 05:06, Favonia wrote:
> Hi all,
>
> Recently I am tuning one of our incomplete libraries that uses FFI.
> After dumping the interface file I realized strictness/demand analysis
> failed for imported foreign functions---that is, they are not inferred
> to be strict in their arguments. In my naive understanding all
> imported foreign functions are strict! Here's a minimum example (with
> GHC 7.4.2):
>
> {-# LANGUAGE ForeignFunctionInterface #-}
> module Main where
> import Foreign.C
> foreign import ccall unsafe "sin" sin' :: CDouble -> CDouble
>
> where in the interface file the function sin' will have strictness
> U(L) (meaning Unpackable(Lazy)).

This is fine - it means the CDouble is unpacked into its unboxed Double# 
component.  An unboxed value is always represented by L in strictness 
signatures.

Cheers,
	Simon
Favonia | 12 Jul 2012 20:29
Picon
Gravatar

Re: Imported foreign functions should be strict

I see. Thanks for the response! Perhaps it is better for the pretty
printer to print out "U(S)" instead?

Regards,
Favonia

On Tue, Jul 10, 2012 at 3:57 AM, Simon Marlow <marlowsd <at> gmail.com> wrote:
>
> This is fine - it means the CDouble is unpacked into its unboxed Double#
> component.  An unboxed value is always represented by L in strictness
> signatures.
>
> Cheers,
>         Simon
Johan Tibell | 12 Jul 2012 20:33
Picon
Gravatar

Re: Imported foreign functions should be strict

On Thu, Jul 12, 2012 at 11:29 AM, Favonia <favonia <at> gmail.com> wrote:
> I see. Thanks for the response! Perhaps it is better for the pretty
> printer to print out "U(S)" instead?
>
> Regards,
> Favonia

I'd love to see a cheat sheet documenting the strictness output. It
confuses me every time, even when I make the effort to read the source
code that generates the demand signature!

-- Johan

Gmane