Stefan Koch: New CTFE fix

Moritz Maxeiner via Digitalmars-d digitalmars-d at puremagic.com
Mon Aug 14 18:31:13 PDT 2017


On Monday, 14 August 2017 at 22:51:04 UTC, Johnson Jones wrote:
>
> string do()
> {
>    string x;
>    x = "adsf";
>    pragma(msg, x);
>    return x;
> }

"do" is a keyword in D, you can't use it as an identifier.

>
> fails because the compiler believes that x is not known at 
> compile time.

There are multiple phases making up D's compile time, the wiki 
has an excellent page by H. S. Teoh on the subject [1]. Applied 
to your example: The pragma in the function body is handled 
before the function body is interpreted, so the compiler error is 
correct; whether or not the error message should be more explicit 
is another matter.

> It obviously is when do is ran as a ctfe. This makes some types 
> of programming difficult to debug because we have to duplicate 
> any instance of "do" and cannot output intermediate values.
>
> But, how can we make this actually work?
>
> [...]

I recommend reading up on the history of CTFE output in 
D[2][3][4][5][6].
If you want to see CTFE output in D, you could pick up where 
Stefan left off in the latest attempt[6].

[1] 
https://wiki.dlang.org/User:Quickfur/Compile-time_vs._compile-time
[2] 
http://www.digitalmars.com/d/archives/digitalmars/D/CTFE_writeln_140241.html
[3] http://forum.dlang.org/thread/j1n0l7$235r$1@digitalmars.com
[4] https://github.com/dlang/dmd/pull/296
[5] https://github.com/dlang/dmd/pull/692
[6] https://github.com/dlang/dmd/pull/6101


More information about the Digitalmars-d mailing list