new annotation or pragma to mark functions that are intended to be only used during compile time

Quirin Schroll qs.il.paperinik at gmail.com
Thu Feb 13 22:26:02 UTC 2025


On Thursday, 13 February 2025 at 14:56:42 UTC, Ilya wrote:
> […]

The easiest and in fact backwards compatible solution for this is 
to detect `in(__ctfe)` as a [function precondition 
contract](https://dlang.org/spec/function.html#preconditions) and 
make the compiler not emit the function into the object file. If 
for some reason you don’t like that, I suggest re-using the 
`__ctfe` keyword for that purpose.

For the purpose of accidentally calling the function at runtime, 
it does the job reasonably well already.

Even more generally, it could be a compile-error if the a 
function with a statically `false` contract is called.


More information about the dip.ideas mailing list