new annotation or pragma to mark functions that are intended to be only used during compile time
Richard (Rikki) Andrew Cattermole
richard at cattermole.co.nz
Fri Feb 21 01:14:50 UTC 2025
On 21/02/2025 1:38 PM, Richard (Rikki) Andrew Cattermole wrote:
> On 21/02/2025 8:44 AM, Steven Schveighoffer wrote:
>> On Thursday, 20 February 2025 at 17:42:25 UTC, Ilya wrote:
>>
>> On Thursday, 20 February 2025 at 15:50:33 UTC, Steven Schveighoffer
>> wrote:
>>
>> This has been proposed before, and it doesn't require language
>> changes:
>>
>> |void foo() { assert(__ctfe); } |
>>
>> Yes, I've seen that. But did it go anywhere? I think on the thread
>> I've found there are some discussions with no conclusion.
>>
>> It has not gone anywhere, but if we were to consider a language
>> change, I'd want to evaluate whether this is a better option, since
>> it's a de- facto standard.
>
> 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;
}
```
More information about the dip.ideas
mailing list