Request for Comment assert(__ctfe)
Jacob Carlborg
doob at me.com
Tue Apr 7 17:52:44 UTC 2020
On 2020-04-05 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.
> And therefore no correct code can be calling it.
> which also means we can forgo having code-gen or optimization for the
> function body.
> and reduce the count of names which has to get mangled.
>
> They only downside to this, is that giving assert(__ctfe) the special
> meaning to skip codegen might be confusing to some people .... then
> again you wouldn't use assert(__ctfe) unless you expect that function to
> not be available at run-time
>
> What do you guys think?
For many years I wanted a feature that could indicate a function is only
used at compile time.
BTW, this is a breaking change. Consider this code:
import core.exception;
void foo()
{
assert(__ctfe);
}
void main() @system
{
try
foo();
catch (AssertError)
{}
}
--
/Jacob Carlborg
More information about the Digitalmars-d
mailing list