Compile time function execution...
Michiel
nomail at please.com
Thu Feb 15 13:23:39 PST 2007
Frits van Bommel wrote:
>> * Why is the second sqrt(10) run at runtime? In theory it's still a
>> constant, right? Is this something that will work in a later version?
>
> From the spec:
> """
> In order to be executed at compile time, the function must appear in a
> context where it must be so executed, for example:
>
> * initialization of a static variable
> * dimension of a static array
> * argument for a template value parameter
> """
>
> So this is only done if it's used in a context where only compile-time
> constants are allowed.
Well, then there is room for improvement. (Good thing, too. Can you
imagine how bad it would be if perfection had already been achieved? ;))
Anyway, it looks to me like every subtree of the abstract syntax tree
could potentially be collapsed by compile time function execution. This
would include the mentioned sqrt call. Of course, I don't really know
how the D compiler works internally, so I can't be sure in this case.
And I don't see a real reason why structs and at least scope classes
couldn't be included. But I don't suppose it's all that easy.
Maybe the perfect compiler would also pre-execute everything up until
the first input is needed. And maybe some bits after.
--
Michiel
More information about the Digitalmars-d
mailing list