new annotation or pragma to mark functions that are intended to be only used during compile time
Hipreme
msnmancini at hotmail.com
Fri Feb 21 14:20:47 UTC 2025
On Friday, 21 February 2025 at 01:14:50 UTC, Richard (Rikki)
Andrew Cattermole wrote:
> On 21/02/2025 1:38 PM, Richard (Rikki) Andrew Cattermole wrote:
>> On 21/02/2025 8:44 AM, Steven Schveighoffer wrote:
>>> [...]
>>
>> I wouldn't call it any kind of standard.
>>
>> But since it cannot work at runtime, and can be seen during
>> compilation it doesn't need a DIP to see this statement and
>> turn off codegen for the function.
>>
>> Hmm, I should be able to implement it, gimmie a bit.
>
> Not possible.
>
> assert gets processed during semantic 3, but things like
> variable declarations are seen during semantic 2.
>
> It has to be an attribute seeable on the function declaration.
>
> ```d
> extern(C) void main() {
> __gshared global = func; // Error: cannot use non-constant
> CTFE pointer in an initializer `func()
> func; // Error: undefined reference to `void start.func()`
> }
>
> int* func() {
> assert(__ctfe);
> return new int;
> }
> ```
Instead of `@ctonly`, we could just reuse also the existing
identifier, and use it as `@__ctfe`, so it is easier for the
compiler to take it into account. Creating a new identifier only
for that would create a competition between those two needlessly
when they mean the same thing.
More information about the dip.ideas
mailing list