Is it possible to "cache" results of compile-time executions between compiles?

TheFlyingFiddle via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Jan 24 08:41:13 PST 2017


On Tuesday, 24 January 2017 at 12:19:33 UTC, ketmar wrote:
> On Tuesday, 24 January 2017 at 12:14:05 UTC, TheFlyingFiddle 
> wrote:
>> unittest
>> {
>>    enum s = import("myfile");
>> }
>>
>> Is there something similar to this for outputting files at 
>> compile-time?
>
> no. this is by design, so it won't be fixed. sorry. you may use 
> build script that will create the code first, and you can dump 
> `pragma(msg, …);` to file, but that's all.

Thanks again. Wrapping dmd with a script worked wonders!

Now i'm able to do this:
 From the old: (a)
unittest
{
    mixin Sql!(...);
    mixin Sql!(...);
    ...
    mixin Sql!(...);
}

To the new:  (b)
unittest
{
    mixin Cache!(Sql, ...);
    mixin Cache!(Sql, ...);
    ...
    mixin Cache!(Sql, ...);
}

For (a) the build times are in the 10-30s always
For (b) the build times are in the 10-30s the first time and 
subseconds later.
Each query just adds a few ms to the build time now!

Additionally even if dmd crashes with an out of memory exception 
(which still happens with the current ctfe engine) most of the 
queries will have already been built and dmd can be restarted. 
After the restart the built queries are loaded via caching and 
dmd can finish working on the leftovers.

Everything turned out soooo much better than expected :)



More information about the Digitalmars-d-learn mailing list