new annotation or pragma to mark functions that are intended to be only used during compile time
Ilya
ilya.yanok at gmail.com
Sat Feb 15 12:37:58 UTC 2025
On Thursday, 13 February 2025 at 22:26:02 UTC, Quirin Schroll
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
Oh, that's a brilliant idea actually! Thanks, I should have
experimented with it before trying to introduce my own attribute.
It seems like it would do _almost_ what I want to achieve. The
two missing bits would be:
1. Static check, as you pointed out we could even generalize it
to static contract violation.
2. Skipping codegen of functions that have `in(__ctfe)` in
preconditions.
Both seem like smaller changes in comparison to what I suggested,
I really like that. They probably could also be submitted
independently.
I have some reservations though:
- I really-really-really need to skip codegen of these functions
in the release build, that's really important for us. But I think
contracts are ignored in release builds, would that even work?
- (less important) Ideally I'd also like to skip codegen for
high-order templates using these functions, like in the `map`
example above. Probably if I implement skipping codegen via
setting `skipCodegen` bit on the function, it will be propagated
to the callers with the existing `skipCodegen` implementation,
but I'm not entirely sure.
> file. If for some reason you don’t like that, I suggest
> re-using the `__ctfe` keyword for that purpose.
Ok, I've already got the same suggestion on my PR, so I guess we
have a leader :)
More information about the dip.ideas
mailing list