Note: This website is archived. For up-to-date information about D projects and development, please visit

Ticket #167 (reopened enhancement)

Opened 10 years ago

Last modified 10 years ago

CTFE indication

Reported by: doob Assigned to:
Priority: major Component: descent.core
Version: Keywords:


It would be nice if there was some kind of indication to every function that can be evaluated during compile time. Perhaps an icon in the left side where error icons appear.

Change History

03/26/09 00:07:18 changed by asterite

Can't do that. CTFE is a "try and see if we can" approach, as someone else mentioned in the newsgroup. For example:

int someFunc(int x) {
  if (x == 2) {
    int* y = &x;
    return x * 4;
  } else {
    return x * 3;

Now write below that this:

const int xxx = someFunc(3);

Hovering over xxx (or viewing the compile-time view) works as expected. Now change it to:

const int xxx = someFunc(2);

and you'll get a compile-time error.

So... CTFE depends on the arguments.

03/26/09 00:07:25 changed by asterite

  • status changed from new to closed.
  • resolution set to invalid.

03/26/09 15:32:48 changed by doob

Either you can add a ctfe indication because it can be evaluated sometimes or you do the opposite and only add a ctfe indication when the function always can be evaluated during compile-time. Or as a third option you can have a second icon indicating that the function can be evaluated during compile-time if the arguments are right.

03/26/09 23:30:11 changed by asterite

  • status changed from closed to reopened.
  • resolution deleted.

Solving that reminds me of solving the halting problem. :-P

So... if the arguments are ints I should try to evaluate them with random numbers? What if the evaluation enters an infinite loop? (suppose factorial with a negative number)

The only safe case is when there are no arguments, but that's equal to a constant, not much use.

Another option is to see if there are operators that are "safe". For example pointer reference can't be done in CTFE. A function call might be, only if the function can also be executed with CTFE. Mmm... maybe I can do that (with just throwing random parameters). :-P