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

Reply via email to