Implementing Pure Functions

bearophile bearophileHUGS at lycos.com
Fri Jun 17 06:39:38 PDT 2011


Andrei:

> Automatic inference should not be slower than verification of 
> conditional purity. The work involved is the same.

> No, it would work for all template functions and ran either 
> opportunistically or only as needed.

The first thing you say goes against the second: if you run the verification algorithm even if the template is not tagged with pure, then you are doing more work than running it only on templates tagged as pure.

And even if it runs only on templates tagged with pure, I think the compiler is able to do a bit less work if you use pure(CTcond) instead, because the CTcond is chosen by the programmer to be quite discriminating. I guess this can be solved adding some heuristics to the compiler: to test first the most probable places where something impure is (like the functions given as function or template arguments), to prune the impurity search graph faster.

In the end I think your idea of automatic purity is better (if it works), because it's more handy for the programmer. But I suggest to add some pruning heuristics, and to run it only on templates tagged with pure.

Bye,
bearophile


More information about the Digitalmars-d mailing list