A little of Partial Compilation

Jarrett Billingsley kb3ctd2 at yahoo.com
Tue Aug 19 09:45:50 PDT 2008


"bearophile" <bearophileHUGS at lycos.com> wrote in message 
news:g8ek6e$13qj$1 at digitalmars.com...
> One simple example of partial compilation: if the D compiler sees that 
> some parameter N of a function is a known constant at compile time (or it 
> can be computed at compile time by other means) it may automatically turn 
> the function into a function template that takes N as a compilation 
> constant, and this may create an actual compiled function that is 
> simper/faster:
>
> foo(int N, float M) => foo(int N)(float M)
> automatically if N is a known constant at compile time.
>
> One disadvantage of this suggestion is that in some situations it can 
> produce more code to be compiled, and the resulting compiled code may 
> require more I/O traffic on the code L1 cache, and this may slow down the 
> running a little.
>
> Bye,
> bearophile

I think this is what Walter was (is?) going for with static params.  Yes, it 
means you have to do it manually, but still, it's nice to be able to offer 
an optimized version of a function for certain values for parameters.

If you're not familiar with the proposal, it's something like this:

int foo(static int N, float M)
{
    // here N is a compile-time constant
}

foo(5, 3.14) // similar to foo!(5)(3.14)

Partial application is something that doesn't seem to jive with the rest of 
D but it'd be nice if there were some way to do it.  Like if it could be 
done as an optional optimization, maybe just on pure functions. 





More information about the Digitalmars-d mailing list