Request for Comment assert(__ctfe)
Johannes Pfau
nospam at example.com
Wed Apr 8 20:23:36 UTC 2020
Am Wed, 08 Apr 2020 09:26:36 -0400 schrieb Steven Schveighoffer:
>
>> 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.
>
> This is a legitimate concern. Indeed, it might not fix this issue just
> to not emit the code to the binary.
>
> -Steve
I've posted a proof-of-concept PR using pragma(ctfe) here:
https://github.com/dlang/dmd/pull/11014
Unlike the `assert(__ctfe)` check, this is done very early in the
semantic analysis. I added support to bypass all -betterC checks I could
find in the DMD source code. If one is missing, it should be trivial to
add. I've also added examples to the tests in the PR.
I also tried to backport the commit which introduces the betterC bypass
to Stefan's PR. But as expected it does not work, as the assert detection
is done too late. I'm not saying that we must go for pragma(ctfe), but
whatever implementation we merge, it should at least support those tests
as well. Especially considering the pragma implementation is also way
less complex.
Another thing we could think about is how to handle this code:
@nogc:
pragma(ctfe)
string mixinHelper2(string a)
{
return "int " ~ a ~ ";";
}
void main() @nogc
{
mixin(mixinHelper("a"));
}
I'd probably disable nogc checks in ctfe-only functions for convenience.
But I guess that is debatable.
--
Johannes
More information about the Digitalmars-d
mailing list