Request for Comment assert(__ctfe)

Stefan Koch uplink.coder at googlemail.com
Sun Apr 5 12:11:23 UTC 2020


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?

Cheers,

Stefan


More information about the Digitalmars-d mailing list