On 03/27/2013 03:48 PM, Andrei Alexandrescu wrote:
Found this:
http://stackoverflow.com/questions/15652718/object-error-access-violation-when-printing-result-of-std-algorithm-cartesianpr


Soon we'll need to clearly define the limits of CTFE, and what happens
when it fails.
...

Attempt 1:

CTFE may compute the result of an arbitrary D expression according to the usual language semantics, provided that:

 - D source code is available at all definitions of called functions.

 - No mutable variables/fields are loaded or stored that were not
   allocated during the same CTFE execution.

 - Only type casts are evaluated whose kind may not harm type safety.

 - No function enclosing the evaluated expression is called during
   evaluation.

We might also want:

 - No stack references are accessed after the declaring function has
   returned.

 - There is no reliance on the indeterminism inherent in array
   appends.

But they are quite hard to check efficiently.

If CTFE does not terminate, compilation is not allowed to succeed.
If CTFE fails because the above criteria are not met, the evaluated expression is in error.


There are further funny complications, but those should be addressed in a general way as they are not exclusive to CTFE. Eg:

class A{ auto foo(){ return "A"; } }
class B{ auto foo(){ return "B"; } }

template ID(alias a){ alias a ID; }
template P(C){ alias ID!(mixin((new C()).foo())) P; }

class C : P!C{ } // error
class D : P!D{ override foo(){ return "A"; } } // ok
static assert(is(D:A));


Reply via email to