Request for Comment assert(__ctfe)
Timon Gehr
timon.gehr at gmx.ch
Sun Apr 5 20:31:15 UTC 2020
On 05.04.20 14:11, Stefan Koch wrote:
> Hi Guys,
>
> I am currently working on speeding up dmd. In the presence of templates
> and ctfe.
> and one thing that stood out is that we do codegen for symbols which are
> never used.
> (and hopefully eliminated by a smart linker but eh ...)
>
> I've seen the following pattern in the wild.
>
>
> string GenerateMixin(string[] params)
> {
> assert(__ctfe);
> .... more code ....
> }
>
> that means if we see assert(__ctfe) inside the outermost scope of a
> function body ( not in a branch) then we know that this function would
> assert if called at runtime.
Make sure it works with `in` contracts:
string generateMixin(string[] params)in{
assert(__ctfe);
}do{
.... more code ....
}
(The plain assertion slightly hurts my eyes, because if it fails, that
failure would be attributable to the GenerateMixin function, whereas
with the `in` contract it is clear that the caller is at fault.)
More information about the Digitalmars-d
mailing list