Request for Comment assert(__ctfe)

Johannes Pfau nospam at example.com
Wed Apr 8 10:33:19 UTC 2020


Am Wed, 08 Apr 2020 08:42:52 +0000 schrieb Stefan Koch:


>>
>> My primary fear here is that the current implementation checks the
>> function too late in semantic and therefore such checks (or the "ensure
>> no non-ctfe function calls ctfe-only functions" check are much more
>> difficult to implement than they should be. Using a pragma or attribute
>> would easily solve this.
>>
>> Maybe you'd have to introduce something analog to "safetyInProgress"
>> which is "ctfeOnlyInProgress" to make this assert(__ctfe) detection
>> fully usable? But I think this adds way to much complexity. Even right
>> now, the code of the PR could probably be reduced by 1/2 when just
>> using a pragma.
> 
> The detection of assert __ctfe in the function body _can_ be done very
> early in the process I do not want to introduce a pragma or magic
> annotatation.
> When existing the language is perfectly able to express (only runs at
> ctfe).
> 
> Also the PR I have open is _only_ for that.
> I or someone else, might write code which does the detection earlier and
> then disables betterC checks, but this is only about turning off
> codegen.

The important point is that we do not bake in semantics now which might 
turn out to cause problems later. If we can do the assert detection before 
all betterC checking, nogc checking, and related checks, this is fine. 
But it should not be an afterthought, we should really be pretty sure 
that this will not cause issues later on and that this integrates well 
with all other language features. Especially betterC, nogc (if you have a 
@nogc: at module top, do you want to still enforce GC checks in CTFE only 
code, ...)

-- 
Johannes


More information about the Digitalmars-d mailing list