Implementing Pure Functions

KennyTM~ kennytm at gmail.com
Fri Jun 17 08:28:49 PDT 2011


On Jun 17, 11 22:41, Timon Gehr wrote:
[snip]
>
> A small problem I can see with the purity validation algorithm proposed by Andrei
> relates to incremental builds (again):
>
> module A;
> int iampure(){
>      return 5;
> }
>
> module B;
> int puretemplate()(){ // inferred pure
>      return iampure();
> }
>
> int main(){
>      import std.stdio;
>      writeln(puretemplate(), puretemplate()); // compiler caches result
> }
>
> $ dmd -c A
> $ dmd -c B
> $ dmd A.o B.o; ./A
> 55
>
> Some funny guy decides to change A.iampure:
> module A;
> int iampure(){
>      static int x;
>      return ++x;
> }
>
> $ dmd -c A
> $ dmd A.o B.o; ./A
> 11
>
> Wrong! Should be 12.

That happens too if 'iampure' is a template or the compiler inline a 
function which should be modified, with or without caching. I don't see 
this as a problem of attribute inference.

>
[snip]
>
> Timon



More information about the Digitalmars-d mailing list