Thread overview
Functions cannot be interpreted while being compiled
Aug 25, 2016
ketmar
Aug 25, 2016
Walter Bright
Aug 25, 2016
ketmar
Aug 25, 2016
ketmar
Aug 25, 2016
Walter Bright
Aug 25, 2016
Timon Gehr
August 24, 2016
Just got the error above. Is this fundamental or an implementation artifact? -- Andrei
August 25, 2016
On Thursday, 25 August 2016 at 02:20:31 UTC, Andrei Alexandrescu wrote:
> Just got the error above. Is this fundamental or an implementation artifact? -- Andrei

fundamental. interpreter operates only on fully semanticed functions, where all the analysis, type inferencing and lowering is already complete (otherwise interpreter have to reimplement *all* the frontend again, to do exactly same work).

the error mesage you got means that CTFE tried to execute something that is still in semantic analysis stage.

this *may* be somewhat relaxed by doing lazy semantic (i.e. only mark something for "future analysis", and do real thing when interpreter/compiler really need semantic results), but it will require a huge efforts to implement this in current FE architecture.

still, this may be some obscure bug in semantic analyser, so it will be good to see a minified sample that triggers this.
August 24, 2016
On 8/24/2016 8:11 PM, ketmar wrote:
> On Thursday, 25 August 2016 at 02:20:31 UTC, Andrei Alexandrescu wrote:
>> Just got the error above. Is this fundamental or an implementation artifact?
>> -- Andrei
>
> fundamental. interpreter operates only on fully semanticed functions, where all
> the analysis, type inferencing and lowering is already complete (otherwise
> interpreter have to reimplement *all* the frontend again, to do exactly same work).
>
> the error mesage you got means that CTFE tried to execute something that is
> still in semantic analysis stage.
>
> this *may* be somewhat relaxed by doing lazy semantic (i.e. only mark something
> for "future analysis", and do real thing when interpreter/compiler really need
> semantic results), but it will require a huge efforts to implement this in
> current FE architecture.
>
> still, this may be some obscure bug in semantic analyser, so it will be good to
> see a minified sample that triggers this.

From the test suite:

diag8714.d:fail_compilation/diag8714.d(9): Error: function diag8714.foo circular dependency. Functions cannot be interpreted while being compiled

fail133.d:fail_compilation/fail133.d(13): Error: function D main circular dependency. Functions cannot be interpreted while being compiled

August 25, 2016
On Thursday, 25 August 2016 at 04:39:01 UTC, Walter Bright wrote:
> From the test suite

yeah, this is it. template instantiation wants semantic, and we are already semanticing the function.

while this restriction can be somewhat relaxed, it will require huge amount of hacks, will be PITA to maintain, and adds very little value (i think) in exchange.
August 25, 2016
p.s. i just thought that Andrei hits this somewhere in his own code, so i asked for a sample.
August 24, 2016
On 8/24/2016 10:51 PM, ketmar wrote:
> p.s. i just thought that Andrei hits this somewhere in his own code, so i asked
> for a sample.

It's fine if Andrei produces a sample, and it can be compared with the existing stuff in the test suite to see if it is fundamentally different.
August 25, 2016
On 25.08.2016 05:11, ketmar wrote:
> On Thursday, 25 August 2016 at 02:20:31 UTC, Andrei Alexandrescu wrote:
>> Just got the error above. Is this fundamental or an implementation
>> artifact? -- Andrei
>
> fundamental.

(The remainder of the post is describing implementation details; this doesn't explain why the limitation is fundamental.)

> interpreter operates only on fully semanticed functions,
> where all the analysis, type inferencing and lowering is already
> complete (otherwise interpreter have to reimplement *all* the frontend
> again, to do exactly same work).
> ...

Usually, to do exactly the same work, one would just use exactly the same code.

> the error mesage you got means that CTFE tried to execute something that
> is still in semantic analysis stage.

No, it means CTFE tried to execute a function of which some parts are still in semantic analysis stage. E.g., it is clear what the following function should mean, if it was assigned a meaning:

int foo(int x){
    if(x==0) return 1;
    enum r=foo(0);
    return r;
}

Usually CTFE only fails if the dynamic branch actually taken runs into a problem, so this is somewhat inconsistent.
August 25, 2016
On 08/25/2016 02:10 AM, Walter Bright wrote:
> On 8/24/2016 10:51 PM, ketmar wrote:
>> p.s. i just thought that Andrei hits this somewhere in his own code,
>> so i asked
>> for a sample.
>
> It's fine if Andrei produces a sample, and it can be compared with the
> existing stuff in the test suite to see if it is fundamentally different.

It's similar. I got convinced my code was attempting something unreasonable. Thanks! -- Andrei