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 15:29:32 PST 2017


On Tuesday, 24 January 2017 at 21:41:12 UTC, Profile Anaysis 
wrote:
> On Tuesday, 24 January 2017 at 21:36:50 UTC, Profile Anaysis 
> wrote:
>>...
>
> Maybe with all this talk of the new CTFE engine being 
> developed, a similar mechanism can be used optionally? This 
> could help with debugging also.
>
> In debug mode, the cfte mixin's are written to disk with hash, 
> if they are not a string themselves. (could be done with all 
> cfte's, I suppose, but not sure about performance and 
> consistency)
>
> Then debuggers can use the outputed cfte's for proper analysis, 
> line breaking, etc...

Would be nice to have something like this in dmd. Would be even 
better if it could work on templates as well. No more stepping 
though functions filled with static if :).

I think it would be possible to make something like this work to:

template Generator(T...)
{
    string Generator()
    {
       //Complex ctfe with T... that generates strings and nothing 
else.
    }
}

If it's possible to quickly detect changes to all T arguments one 
could cache things on this form to.

For example:

mixin Cache!("some_file_name", Generator, size_t, int, 2,
                                "hello", MyStruct(3),
                                MyType);

The problem would be detecting changes in the arguments. As long 
as one is able to get a unique hash from each input element it 
should work fine I think. I guess it would be required to reflect 
over the members of the structs/classes to lookup attributes and 
such. If the generation stage is time consuming this might be 
worth it... But it's not gonna be "almost free" like for DSLs. 
Basic types (not including functions/delegates don't see how this 
could work without writing mixin code targeted at caching) should 
be simple/trivial to detect changes to however.






More information about the Digitalmars-d-learn mailing list