I've been avoiding purity in D for a while but I decided to take a stab at it today. I encountered two issues which make inferring purity difficult.

(1) While the compiler infers purity for instantiated functions, it's unable to infer purity for "functions within templates". Consider the following three statements:

void foo()(){ }
template T(){  void foo()(){ }  }
template T(){  void foo(){ }  }

The compiler can infer purity for the first two statements but not the third. So even though the functions are within a template, you still have to make each individual function an "instantiated function" in order to infer purity for them.

I think the compiler should infer purity for all functions, but adding support for functions within templates would be good enough. Otherwise, you end up with a lot of syntactic noise by adding empty parenthesis to all of these function declarations without any clear reason why they're even there.


(2) When the compiler fails to infer purity, it prints an error "pure function [] cannot call impure function []". However, it fails to tell you where the impurity occurs. So if you have a series of "instantiated functions" spanning thousands of lines of code, you have to manually sift through all of that code to find the impurity.


Are there any bug reports for these two issues? I tried searching but couldn't find anything.

Reply via email to