CTFE & code generators based on PEG grammars?

Alex AJ at gmail.com
Sun Apr 7 08:58:07 UTC 2019


On Sunday, 7 April 2019 at 06:39:05 UTC, zabruk wrote:
> On Sunday, 7 April 2019 at 03:32:45 UTC, Alex wrote:
>> just execute them at CT if possible(and the possibility simply 
>> is if the inputs are known at CT).
>
> imho, Bastiaan Veelo want to say about citate above: not just 
> "if possible", but "only if needed and possible"

True, but the only if needed is vacuous. As the meta parser does 
it's thing it will come across RT function usage and it can 
easily tell if the arguments are known at CT and then will 
evaluate them.

So, unless I'm mistaken about how the meta compiler works, it 
won't ever trigger CTFE on any CTFE'able functions that are not 
used.

The reason being is that any time a function call is made, the 
arguments must be known(including hidden/global arguments) and if 
they are determined at CT already then a CT call can and must be 
made(that is what makes CTFE what it is).

One can't CTFE if one doesn't have the inputs to the function... 
and the compiler doesn't just randomly compile RT functions 
without knowing the inputs... and the inputs are found at the use 
site.

I don't even thing the "only if needed" makes a lot of sense. The 
only time they are needed is exactly when they are needed, there 
is no other use cause in CTFE.


Can you give me a simple example that shows where a CTFE occurs 
that isn't needed and the compiler would try to CTFE it? By need, 
we mean with all optimizations, else CTFE is never needed.





More information about the Digitalmars-d-learn mailing list