Stefan Koch: New CTFE fix

Johnson via Digitalmars-d digitalmars-d at puremagic.com
Mon Aug 14 18:41:58 PDT 2017


On Tuesday, 15 August 2017 at 01:31:13 UTC, Moritz Maxeiner wrote:
> 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.
>

wow, way to fail to realize generalities.

>>
>> 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.

So, that is a generic answer for a generic post. It says nothing 
about what can be done, but what only can't be done. There is 
nothing stopping one's ability to output compile time information 
at compile time from compile time functions. Again, way to fail 
to realize generalities. Just because something is defined to be 
something doesn't mean that it can't be defined to be something 
different. It happens all the time. People create false 
constraints based on ignorance and then someone has to come along 
and clean up the mess. But some people like messes I suppose...



>> 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

It seems like he's already done all the heavy lifting and who 
knows best rather than him to implement it in his own redesign of 
ctfe(to fix the mess that it was in precisely for the reasons I 
stated above)?





More information about the Digitalmars-d mailing list