D's treatment of values versus side-effect free nullary functions

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Sat Jul 24 15:19:11 PDT 2010


Walter Bright wrote:
> Andrei Alexandrescu wrote:
>> The analysis I discussed is a flow- and path-independent analysis. It 
>> always terminates and produces conservative results (i.e. it 
>> associates one Boolean with each function, not on each tuple of a 
>> function and inputs. This is how the current compiler works - if you 
>> tried your example, it will refuse to evaluate foo during compilation.
> 
> That's because there's an unrelated bug in it :-( Here's the corrected 
> example:
> 
>  import std.c.stdio;
> 
>  int foo(int x, int y)
>  {
>     if (x == 3)
>         return y + 1;
>     printf("hello\n");
>     return 0;
>  }
> 
>  const z = foo(3, 7);
> 
> The compiler does not work as you suggest it does.

That's actually good, meaning that the compiler can and will, when 
pressed, forge forward with CTFE even if unsure. The analysis I 
suggested would allow the compiler to automatically CTFE certain 
functions in confidence that they are, in fact, CTFE-able.

Andrei


More information about the Digitalmars-d mailing list