Changes between Version 9 and Version 10 of ForeignData


Ignore:
Timestamp:
Feb 6, 2006 7:38:41 AM (9 years ago)
Author:
john@…
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • ForeignData

    v9 v10  
    22
    33One is forced to use an external C file to allocate data in the bss or data segment even though no code at all will be output and the object file will simply contain a linker directive to allocate some space. This is a deficiency in the current FFI spec.
     4
     5This is very easy to implement and is needed for low level haskell programming or when you wish to replace certain aspects of a haskell runtime with haskell code itself. It is currently the only thing one cannot do at all in haskell that one can do in C.
     6
     7In addition to low level programming, any program that uses large amounts of static (or preallocated) data can benefit due to
     8
     9 * decreased binary size
     10 * faster start up times
     11 * less memory consumption
     12 * constant data being shared among multiple running copies of the same program
    413
    514== Proposal (experimental in jhc) ==
     
    1726if the type is 'forall a . Ptr a' then the size will be assumed to be one byte.
    1827
    19 if 'const' is specified then that is an assertion the contents of memory there will never change and the haskell compiler may make use of that and the data may be allocated in the shared among processes, read-only data segment.
     28if 'const' is specified then that is an assertion the contents of memory there will never be modaified. It is a strong assertion in that the compiler is free to perform optimizations that rely on that fact, and place that memory in a segment that is unwritable and shared among processes.
    2029
    2130=== initialized data ===
    2231
    23 initialized data is trickier, a possible syntax is
     32The initial contents of the memory may also be specified:
    2433
    2534{{{
     
    4958== caveats ==
    5059
    51 It is anoying that <n> must be a constant and <type> must be a builtin, but there is not really any other recourse without defining a preprocessor in haskell or a staged system like template haskell. however, use of CPP or a preprocessor like hsc2hs will mitigate these problems and the situation is no worse (and somewhat better) than when having to link against an external C library.
    52 
    53 A possible extension would be to allow implementations to derive instances of Storable and allow types with such derived instances be used in foreign space declarations too.
    54 
    55 another possibility is the definition of 'manifestly constant' data. which is defined as declarations of the form
    56 {{{
    57 name :: built-in-type
    58 name = <constant>
    59 }}}
    60 
    61  * or sizeof a builtin
    62 
    63  * or 'foo <op> bar' where foo and bar are manifestly constant and op is a basic operation.
    64 
    65 
    66 then allow such manifestly constant values for n and allow types whose sizeof is manifestly constant to be used in foreign space declarations.
    67 
    68 however, this is probably a lot of work for a problem that has better workarounds unless other uses for manifestly constant data are found.
     60It is anoying that <n> must be a constant and <type> must be a builtin, but there is not really any other recourse without defining a preprocessor in haskell and the restrictions are no more onerous than those placed on the arguments to foreign function calls. Something like template haskell would mitigate this problem when available.